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

Support multiple HTTP inputs #6333

Closed
wants to merge 1 commit into from
Closed
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 @@ -9,6 +9,7 @@
- [#5707](https://github.com/influxdata/influxdb/issues/5707): Return a deprecated message when IF NOT EXISTS is used.
- [#6334](https://github.com/influxdata/influxdb/pull/6334): Allow environment variables to be set per input type.
- [#6394](https://github.com/influxdata/influxdb/pull/6394): Allow time math with integer timestamps.
- [#6333](https://github.com/influxdata/influxdb/pull/6333): Support for multiple listeners for HTTP inputs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be moved to next release.


### Bugfixes

Expand Down
11 changes: 6 additions & 5 deletions cmd/influxd/run/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ type Config struct {
Retention retention.Config `toml:"retention"`
Precreator precreator.Config `toml:"shard-precreation"`

Admin admin.Config `toml:"admin"`
Monitor monitor.Config `toml:"monitor"`
Subscriber subscriber.Config `toml:"subscriber"`
HTTPD httpd.Config `toml:"http"`
Admin admin.Config `toml:"admin"`
Monitor monitor.Config `toml:"monitor"`
Subscriber subscriber.Config `toml:"subscriber"`

HTTPDInputs []httpd.Config `toml:"http"`
GraphiteInputs []graphite.Config `toml:"graphite"`
CollectdInputs []collectd.Config `toml:"collectd"`
OpenTSDBInputs []opentsdb.Config `toml:"opentsdb"`
Expand Down Expand Up @@ -78,8 +79,8 @@ func NewConfig() *Config {
c.Admin = admin.NewConfig()
c.Monitor = monitor.NewConfig()
c.Subscriber = subscriber.NewConfig()
c.HTTPD = httpd.NewConfig()

c.HTTPDInputs = []httpd.Config{httpd.NewConfig()}
c.GraphiteInputs = []graphite.Config{graphite.NewConfig()}
c.CollectdInputs = []collectd.Config{collectd.NewConfig()}
c.OpenTSDBInputs = []opentsdb.Config{opentsdb.NewConfig()}
Expand Down
55 changes: 42 additions & 13 deletions cmd/influxd/run/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@ dir = "/tmp/data"
[admin]
bind-address = ":8083"

[http]
[[http]]
bind-address = ":8087"

[[http]]
bind-address = ":8077"

[[http]]
bind-address = ":8067"
auth-enabled = true

[[graphite]]
protocol = "udp"

Expand Down Expand Up @@ -72,26 +79,32 @@ enabled = true
t.Fatalf("unexpected data dir: %s", c.Data.Dir)
} else if c.Admin.BindAddress != ":8083" {
t.Fatalf("unexpected admin bind address: %s", c.Admin.BindAddress)
} else if c.HTTPD.BindAddress != ":8087" {
t.Fatalf("unexpected api bind address: %s", c.HTTPD.BindAddress)
} else if len(c.HTTPDInputs) != 3 {
t.Fatalf("unexpected http inputs count: %d", len(c.HTTPDInputs))
} else if c.HTTPDInputs[0].BindAddress != ":8087" {
t.Fatalf("unexpected http input bind address: %s", c.HTTPDInputs[0].BindAddress)
} else if c.HTTPDInputs[1].BindAddress != ":8077" {
t.Fatalf("unexpected http input bind address: %s", c.HTTPDInputs[1].BindAddress)
} else if c.HTTPDInputs[2].AuthEnabled != true {
t.Fatalf("unexpected http input auth enabled: %s", c.HTTPDInputs[2].AuthEnabled)
} else if len(c.GraphiteInputs) != 2 {
t.Fatalf("unexpected graphiteInputs count: %d", len(c.GraphiteInputs))
t.Fatalf("unexpected graphite inputs count: %d", len(c.GraphiteInputs))
} else if c.GraphiteInputs[0].Protocol != "udp" {
t.Fatalf("unexpected graphite protocol(0): %s", c.GraphiteInputs[0].Protocol)
t.Fatalf("unexpected graphite input protocol(0): %s", c.GraphiteInputs[0].Protocol)
} else if c.GraphiteInputs[1].Protocol != "tcp" {
t.Fatalf("unexpected graphite protocol(1): %s", c.GraphiteInputs[1].Protocol)
t.Fatalf("unexpected graphite input protocol(1): %s", c.GraphiteInputs[1].Protocol)
} else if c.CollectdInputs[0].BindAddress != ":1000" {
t.Fatalf("unexpected collectd bind address: %s", c.CollectdInputs[0].BindAddress)
t.Fatalf("unexpected collectd input bind address: %s", c.CollectdInputs[0].BindAddress)
} else if c.CollectdInputs[1].BindAddress != ":1010" {
t.Fatalf("unexpected collectd bind address: %s", c.CollectdInputs[1].BindAddress)
t.Fatalf("unexpected collectd input bind address: %s", c.CollectdInputs[1].BindAddress)
} else if c.OpenTSDBInputs[0].BindAddress != ":2000" {
t.Fatalf("unexpected opentsdb bind address: %s", c.OpenTSDBInputs[0].BindAddress)
t.Fatalf("unexpected opentsdb input bind address: %s", c.OpenTSDBInputs[0].BindAddress)
} else if c.OpenTSDBInputs[1].BindAddress != ":2010" {
t.Fatalf("unexpected opentsdb bind address: %s", c.OpenTSDBInputs[1].BindAddress)
t.Fatalf("unexpected opentsdb input bind address: %s", c.OpenTSDBInputs[1].BindAddress)
} else if c.OpenTSDBInputs[2].BindAddress != ":2020" {
t.Fatalf("unexpected opentsdb bind address: %s", c.OpenTSDBInputs[2].BindAddress)
t.Fatalf("unexpected opentsdb input bind address: %s", c.OpenTSDBInputs[2].BindAddress)
} else if c.UDPInputs[0].BindAddress != ":4444" {
t.Fatalf("unexpected udp bind address: %s", c.UDPInputs[0].BindAddress)
t.Fatalf("unexpected udp input bind address: %s", c.UDPInputs[0].BindAddress)
} else if c.Subscriber.Enabled != true {
t.Fatalf("unexpected subscriber enabled: %v", c.Subscriber.Enabled)
} else if c.ContinuousQuery.Enabled != true {
Expand All @@ -117,7 +130,7 @@ dir = "/tmp/data"
[admin]
bind-address = ":8083"

[http]
[[http]]
bind-address = ":8087"

[[graphite]]
Expand Down Expand Up @@ -164,6 +177,18 @@ enabled = true
t.Fatalf("failed to set env var: %v", err)
}

if err := os.Setenv("INFLUXDB_HTTP_0_BIND_ADDRESS", ":8086"); err != nil {
t.Fatalf("failed to set env var: %v", err)
}

if err := os.Setenv("INFLUXDB_UDP_BIND_ADDRESS", ":1234"); err != nil {
t.Fatalf("failed to set env var: %v", err)
}

if err := os.Setenv("INFLUXDB_GRAPHITE_1_PROTOCOL", "udp"); err != nil {
t.Fatalf("failed to set env var: %v", err)
}

if err := os.Setenv("INFLUXDB_COLLECTD_1_BIND_ADDRESS", ":1020"); err != nil {
t.Fatalf("failed to set env var: %v", err)
}
Expand All @@ -188,6 +213,10 @@ enabled = true
t.Fatalf("unexpected graphite protocol: %s", c.GraphiteInputs[1].Protocol)
}

if c.HTTPDInputs[0].BindAddress != ":8086" {
t.Fatalf("unexpected http bind address: %s", c.HTTPDInputs[0].BindAddress)
}

if c.CollectdInputs[1].BindAddress != ":1020" {
t.Fatalf("unexpected collectd bind address: %s", c.CollectdInputs[1].BindAddress)
}
Expand Down
31 changes: 20 additions & 11 deletions cmd/influxd/run/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,26 @@ func NewServer(c *Config, buildInfo *BuildInfo) (*Server, error) {
err: make(chan error),
closing: make(chan struct{}),

BindAddress: bind,

MetaClient: meta.NewClient(c.Meta),

Monitor: monitor.New(c.Monitor),

BindAddress: bind,
MetaClient: meta.NewClient(c.Meta),
Monitor: monitor.New(c.Monitor),
reportingDisabled: c.ReportingDisabled,
tcpAddr: bind,
config: c,
}

httpAPIAddr: c.HTTPD.BindAddress,
httpUseTLS: c.HTTPD.HTTPSEnabled,
tcpAddr: bind,
for _, i := range c.HTTPDInputs {
if i.BindAddress != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So first listed HTTP input is the one we use for any code that returns an HTTP address?

s.httpAPIAddr = i.BindAddress
break
}
}

config: c,
for _, i := range c.HTTPDInputs {
if i.HTTPSEnabled {
s.httpUseTLS = i.HTTPSEnabled
break
}
}

if err := s.MetaClient.Open(); err != nil {
Expand Down Expand Up @@ -240,8 +247,10 @@ func (s *Server) Open() error {
s.appendCopierService()
s.appendAdminService(s.config.Admin)
s.appendContinuousQueryService(s.config.ContinuousQuery)
s.appendHTTPDService(s.config.HTTPD)
s.appendRetentionPolicyService(s.config.Retention)
for _, i := range s.config.HTTPDInputs {
s.appendHTTPDService(i)
}
for _, i := range s.config.GraphiteInputs {
if err := s.appendGraphiteService(i); err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions cmd/influxd/run/server_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ func NewConfig() *run.Config {
c.Data.WALDir = MustTempFile()
c.Data.WALLoggingEnabled = false

c.HTTPD.Enabled = true
c.HTTPD.BindAddress = "127.0.0.1:0"
c.HTTPD.LogEnabled = testing.Verbose()
c.HTTPDInputs[0].Enabled = true
c.HTTPDInputs[0].BindAddress = "127.0.0.1:0"
c.HTTPDInputs[0].LogEnabled = testing.Verbose()

c.Monitor.StoreEnabled = false

Expand Down