From 0d860f0350eff4e7ed60d1179eade1a104aab5a5 Mon Sep 17 00:00:00 2001 From: gunnaraasen Date: Thu, 7 Apr 2016 09:57:54 -0700 Subject: [PATCH] Support multiple http inputs --- CHANGELOG.md | 1 + cmd/influxd/run/config.go | 11 +++--- cmd/influxd/run/config_test.go | 55 ++++++++++++++++++++------ cmd/influxd/run/server.go | 31 +++++++++------ cmd/influxd/run/server_helpers_test.go | 6 +-- 5 files changed, 72 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22c76525e7b..03e82f1a752 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. ### Bugfixes diff --git a/cmd/influxd/run/config.go b/cmd/influxd/run/config.go index e8816533c6a..65b5eb32e75 100644 --- a/cmd/influxd/run/config.go +++ b/cmd/influxd/run/config.go @@ -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"` @@ -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()} diff --git a/cmd/influxd/run/config_test.go b/cmd/influxd/run/config_test.go index 17bdc4f381f..2c9e4c9792b 100644 --- a/cmd/influxd/run/config_test.go +++ b/cmd/influxd/run/config_test.go @@ -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" @@ -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 { @@ -117,7 +130,7 @@ dir = "/tmp/data" [admin] bind-address = ":8083" -[http] +[[http]] bind-address = ":8087" [[graphite]] @@ -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) } @@ -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) } diff --git a/cmd/influxd/run/server.go b/cmd/influxd/run/server.go index cc1591219c7..61e841fb304 100644 --- a/cmd/influxd/run/server.go +++ b/cmd/influxd/run/server.go @@ -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 != "" { + 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 { @@ -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 diff --git a/cmd/influxd/run/server_helpers_test.go b/cmd/influxd/run/server_helpers_test.go index b46176851ef..835635744f4 100644 --- a/cmd/influxd/run/server_helpers_test.go +++ b/cmd/influxd/run/server_helpers_test.go @@ -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