diff --git a/CHANGELOG.md b/CHANGELOG.md index eb5648495f61..d57ff5aa69e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ this platform. FreeBSD builds will return in a future release. - [ENHANCEMENT] agentctl will now be installed by the rpm and deb packages as `grafana-agentctl`. (@rfratto) + +- [BUGFIX] Integrations will now function if the HTTP listen address was set to a value other than the default. + [206](https://github.com/grafana/agent/issues/206) (@mattdurham) # v0.9.0 (2020-12-10) diff --git a/pkg/client/grafanacloud/client_test.go b/pkg/client/grafanacloud/client_test.go index 62386a9ae588..e3d918103811 100644 --- a/pkg/client/grafanacloud/client_test.go +++ b/pkg/client/grafanacloud/client_test.go @@ -27,7 +27,8 @@ func TestClient_AgentConfig(t *testing.T) { "status": "success", "data": { "server": { - "http_listen_port": 12345 + "http_listen_port": 12345, + "http_listen_address" : "127.0.0.1" }, "integrations": { "agent": { @@ -47,6 +48,7 @@ func TestClient_AgentConfig(t *testing.T) { expect := ` server: http_listen_port: 12345 + http_listen_address: 127.0.0.1 integrations: agent: enabled: true diff --git a/pkg/config/config.go b/pkg/config/config.go index d29ac3088762..f4e56d863582 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -51,6 +51,7 @@ func (c *Config) ApplyDefaults() error { if c.Integrations.Enabled { c.Integrations.ListenPort = &c.Server.HTTPListenPort + c.Integrations.ListenHost = &c.Server.HTTPListenAddress } return nil diff --git a/pkg/integrations/manager.go b/pkg/integrations/manager.go index 7d4cf3c50abe..1df71561e670 100644 --- a/pkg/integrations/manager.go +++ b/pkg/integrations/manager.go @@ -64,6 +64,10 @@ type ManagerConfig struct { // ListenPort tells the integration Manager which port the Agent is // listening on for generating Prometheus instance configs. ListenPort *int `yaml:"-"` + + // ListenHost tells the integration Manager which port the Agent is + // listening on for generating Prometheus instance configs + ListenHost *string `yaml:"-"` } // MarshalYAML implements yaml.Marshaler for ManagerConfig. @@ -252,8 +256,8 @@ func (m *Manager) instanceConfigForIntegration(cfg Config, i Integration) instan } func (m *Manager) scrapeServiceDiscovery() discovery.Configs { - localAddr := fmt.Sprintf("127.0.0.1:%d", *m.c.ListenPort) + localAddr := fmt.Sprintf("%s:%d", *m.c.ListenHost, *m.c.ListenPort) labels := model.LabelSet{} if m.c.UseHostnameLabel { labels[model.LabelName("agent_hostname")] = model.LabelValue(m.hostname) diff --git a/pkg/integrations/manager_test.go b/pkg/integrations/manager_test.go index 9e1d7ae7e7d7..ec8e781cde31 100644 --- a/pkg/integrations/manager_test.go +++ b/pkg/integrations/manager_test.go @@ -36,13 +36,15 @@ test: ` var ( cfg ManagerConfig - listenPort int = 12345 + listenPort int = 12345 + listenHost string = "127.0.0.1" ) require.NoError(t, yaml.Unmarshal([]byte(cfgText), &cfg)) // Listen port must be set before applying defaults. Normally applied by the // config package. cfg.ListenPort = &listenPort + cfg.ListenHost = &listenHost outBytes, err := yaml.Marshal(cfg) require.NoError(t, err) @@ -58,13 +60,15 @@ agent: var ( cfg ManagerConfig - listenPort int = 12345 + listenPort int = 12345 + listenHost string = "127.0.0.1" ) require.NoError(t, yaml.Unmarshal([]byte(cfgText), &cfg)) // Listen port must be set before applying defaults. Normally applied by the // config package. cfg.ListenPort = &listenPort + cfg.ListenHost = &listenHost relabels, err := cfg.DefaultRelabelConfigs() require.NoError(t, err) @@ -285,9 +289,11 @@ func mockInstanceFactory(_ instance.Config) (instance.ManagedInstance, error) { func mockManagerConfig() ManagerConfig { listenPort := 0 + listenHost := "127.0.0.1" return ManagerConfig{ ScrapeIntegrations: true, IntegrationRestartBackoff: 0, ListenPort: &listenPort, + ListenHost: &listenHost, } }