Skip to content

Commit

Permalink
feat(cmd/influxd): add launcher options to configure NATS server (#20591
Browse files Browse the repository at this point in the history
)
  • Loading branch information
danxmoran authored Jan 27, 2021
1 parent a31cadc commit 9d0eae1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Replacement `tsi1` indexes will be automatically generated on startup for shards
1. [20537](https://github.com/influxdata/influxdb/pull/20537): Add `--overwrite-existing-v2` flag to `influxd upgrade` to overwrite existing files at output paths (instead of aborting).
1. [20616](https://github.com/influxdata/influxdb/pull/20616): Update telegraf plugins list in UI to include Beat, Intel PowerStats, and Rienmann.
1. [20550](https://github.com/influxdata/influxdb/pull/20550): Add `influxd print-config` command to support automated config inspection.
1. [20591](https://github.com/influxdata/influxdb/pull/20591): Add `nats-port` config option for `influxd` server.
1. [20591](https://github.com/influxdata/influxdb/pull/20591): Add `nats-max-payload-bytes` config option for `influxd` server.

### Bug Fixes

Expand Down
22 changes: 22 additions & 0 deletions cmd/influxd/launcher/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import (
"github.com/influxdata/influxdb/v2/kit/cli"
"github.com/influxdata/influxdb/v2/kit/signals"
influxlogger "github.com/influxdata/influxdb/v2/logger"
"github.com/influxdata/influxdb/v2/nats"
"github.com/influxdata/influxdb/v2/storage"
"github.com/influxdata/influxdb/v2/v1/coordinator"
"github.com/influxdata/influxdb/v2/vault"
natsserver "github.com/nats-io/gnatsd/server"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.uber.org/zap/zapcore"
Expand Down Expand Up @@ -127,6 +129,9 @@ type InfluxdOpts struct {
SessionLength int // in minutes
SessionRenewDisabled bool

NatsPort int
NatsMaxPayloadBytes int

NoTasks bool
FeatureFlags map[string]string

Expand Down Expand Up @@ -171,6 +176,9 @@ func newOpts(viper *viper.Viper) *InfluxdOpts {
StoreType: BoltStore,
SecretStore: BoltStore,

NatsPort: nats.RandomPort,
NatsMaxPayloadBytes: natsserver.MAX_PAYLOAD_SIZE,

NoTasks: false,

ConcurrencyQuota: 10,
Expand Down Expand Up @@ -472,5 +480,19 @@ func (o *InfluxdOpts) bindCliOpts() []cli.Opt {
Flag: "influxql-max-select-buckets",
Desc: "The maximum number of group by time bucket a SELECT can create. A value of zero will max the maximum number of buckets unlimited.",
},

// NATS config
{
DestP: &o.NatsPort,
Flag: "nats-port",
Desc: fmt.Sprintf("Port that should be bound by the NATS streaming server. A value of %d will cause a random port to be selected.", nats.RandomPort),
Default: o.NatsPort,
},
{
DestP: &o.NatsMaxPayloadBytes,
Flag: "nats-max-payload-bytes",
Desc: "The maximum number of bytes allowed in a NATS message payload.",
Default: o.NatsMaxPayloadBytes,
},
}
}
6 changes: 4 additions & 2 deletions cmd/influxd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,13 +572,15 @@ func (m *Launcher) run(ctx context.Context, opts *InfluxdOpts) (err error) {

// NATS streaming server
natsOpts := nats.NewDefaultServerOptions()
natsOpts.Port = nats.RandomPort
natsOpts.Port = opts.NatsPort
natsOpts.MaxPayload = opts.NatsMaxPayloadBytes
m.natsServer = nats.NewServer(&natsOpts)
if err := m.natsServer.Open(); err != nil {
m.log.Error("Failed to start nats streaming server", zap.Error(err))
return err
}
m.natsPort = natsOpts.Port // updated with random port
// If a random port was used, the opts will be updated to include the selected value.
m.natsPort = natsOpts.Port
publisher := nats.NewAsyncPublisher(m.log, fmt.Sprintf("nats-publisher-%d", m.natsPort), m.NatsURL())
if err := publisher.Open(); err != nil {
m.log.Error("Failed to connect to streaming server", zap.Error(err))
Expand Down

0 comments on commit 9d0eae1

Please sign in to comment.