Allow user override of proxy telemetry config

This commit is contained in:
Paul Banks 2018-06-13 16:53:44 +01:00 committed by Jack Pearkes
parent 530d4acc57
commit fd3681f35b
2 changed files with 33 additions and 3 deletions

View File

@ -1067,8 +1067,21 @@ func (s *HTTPServer) AgentConnectProxyConfig(resp http.ResponseWriter, req *http
// Rely on the fact that TelemetryConfig makes a new map each call to
// override the prefix here without affecting other callers.
telemetry["MetricsPrefix"] = "consul.proxy." + target.ID
// Merge with any config passed by the user to allow service definition
// to override.
if userRaw, ok := config["telemetry"]; ok {
if userT, ok := userRaw.(map[string]interface{}); ok {
for k, v := range telemetry {
if _, ok := userT[k]; !ok {
userT[k] = v
}
}
}
} else {
config["telemetry"] = telemetry
}
}
reply := &api.ConnectProxyConfig{
ProxyServiceID: proxy.Proxy.ProxyService.ID,

View File

@ -3386,6 +3386,9 @@ func TestAgentConnectProxyConfig_ConfigHandling(t *testing.T) {
proxy_min_port = 10000
proxy_max_port = 10000
}
telemetry {
statsite_address = "localhost:8989"
}
`,
proxy: structs.ServiceDefinitionConnectProxy{
Config: map[string]interface{}{
@ -3400,7 +3403,11 @@ func TestAgentConnectProxyConfig_ConfigHandling(t *testing.T) {
"local_service_address": "127.0.0.1:8000", // port from service reg
"connect_timeout_ms": 1000,
"foo": "bar",
"telemetry": makeTelemetryDefaults(reg.ID),
"telemetry": map[string]interface{}{
"FilterDefault": true,
"MetricsPrefix": "consul.proxy." + reg.ID,
"StatsiteAddr": "localhost:8989",
},
},
},
{
@ -3425,6 +3432,9 @@ func TestAgentConnectProxyConfig_ConfigHandling(t *testing.T) {
proxy_min_port = 10000
proxy_max_port = 10000
}
telemetry {
statsite_address = "localhost:8989"
}
`,
proxy: structs.ServiceDefinitionConnectProxy{
ExecMode: "script",
@ -3434,6 +3444,9 @@ func TestAgentConnectProxyConfig_ConfigHandling(t *testing.T) {
"bind_address": "127.0.0.1",
"bind_port": 1024,
"local_service_address": "127.0.0.1:9191",
"telemetry": map[string]interface{}{
"StatsiteAddr": "stats.it:10101",
},
},
},
wantMode: api.ProxyExecModeScript,
@ -3443,7 +3456,11 @@ func TestAgentConnectProxyConfig_ConfigHandling(t *testing.T) {
"bind_port": float64(1024),
"local_service_address": "127.0.0.1:9191",
"connect_timeout_ms": float64(2000),
"telemetry": makeTelemetryDefaults(reg.ID),
"telemetry": map[string]interface{}{
"FilterDefault": true,
"MetricsPrefix": "consul.proxy." + reg.ID,
"StatsiteAddr": "stats.it:10101",
},
},
},
}