Skip to content

Commit

Permalink
feat(cmd/influxd): add nats-port config option to influxd server (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
danxmoran authored Jan 20, 2021
1 parent a15c041 commit d8a4b4d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Replacement `tsi1` indexes will be automatically generated on startup for shards
1. [19811](https://github.com/influxdata/influxdb/pull/19811): Add Geo graph type to be able to store in Dashboard cells.
1. [20473](https://github.com/influxdata/influxdb/pull/20473): Add `--overwrite-existing-v2` flag to `influxd upgrade` to overwrite existing files at output paths (instead of aborting).
1. [20524](https://github.com/influxdata/influxdb/pull/20524): Add `influxd print-config` command to support automated config inspection.
1. [20561](https://github.com/influxdata/influxdb/pull/20561): Add `nats-port` config option for `influxd` server.

### Bug Fixes

Expand Down
13 changes: 13 additions & 0 deletions cmd/influxd/launcher/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ 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"
Expand Down Expand Up @@ -127,6 +128,8 @@ type InfluxdOpts struct {
SessionLength int // in minutes
SessionRenewDisabled bool

NatsPort int

NoTasks bool
FeatureFlags map[string]string

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

NatsPort: nats.RandomPort,

NoTasks: false,

ConcurrencyQuota: 10,
Expand Down Expand Up @@ -472,5 +477,13 @@ 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,
},
}
}
5 changes: 3 additions & 2 deletions cmd/influxd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,13 +572,14 @@ 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
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 d8a4b4d

Please sign in to comment.