Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cmd/influxd): add nats-port config option to influxd server #20561

Merged
merged 2 commits into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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