From 737584eb2bfe1c803a4eb19aa0b56deb28241d77 Mon Sep 17 00:00:00 2001 From: Chuntao Lu Date: Fri, 15 Feb 2019 23:19:23 -0800 Subject: [PATCH] Make it configurable to whether emit metrics with host tag --- CHANGELOG.md | 4 ++++ config/production.gen.go | 3 ++- config/production.yaml | 1 + config/test.yaml | 1 + examples/example-gateway/config/production.json | 1 + examples/example-gateway/config/production.yaml | 1 + examples/example-gateway/config/test.json | 1 + examples/example-gateway/config/test.yaml | 1 + runtime/gateway.go | 11 ++++------- test/endpoints/bar/bar_metrics_test.go | 2 +- test/endpoints/baz/baz_metrics_test.go | 2 +- test/endpoints/tchannel/baz/baz_metrics_test.go | 2 +- test/health_test.go | 15 ++++++++------- test/lib/bench_gateway/bench_gateway.go | 1 + test/lib/test_gateway/test_gateway.go | 1 + test/lib/test_gateway/test_gateway_process.go | 2 +- 16 files changed, 30 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45f51f463..e5c3cad81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## Unreleased +### Changed +- **BREAKING** It is now configurable whether to emit metrics with `host` tag or not. Runtime config now expects + the boolean field `metrics.m3.includeHost` to be set. +- Removed logger metrics since it is barely useful. ## 0.2.0 - 2019-01-17 ### Added diff --git a/config/production.gen.go b/config/production.gen.go index e74511083..bc6699b9f 100644 --- a/config/production.gen.go +++ b/config/production.gen.go @@ -73,6 +73,7 @@ jaeger.sampler.param: 0.001 jaeger.sampler.type: remote metrics.flushInterval: 1000 metrics.m3.hostPort: 127.0.0.1:9052 +metrics.m3.includeHost: true metrics.m3.maxPacketSizeBytes: 1440 metrics.m3.maxQueueSize: 10000 metrics.runtime.collectInterval: 1000 @@ -97,7 +98,7 @@ func productionYaml() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "production.yaml", size: 636, mode: os.FileMode(420), modTime: time.Unix(1, 0)} + info := bindataFileInfo{name: "production.yaml", size: 665, mode: os.FileMode(420), modTime: time.Unix(1, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/config/production.yaml b/config/production.yaml index 07a5fe67a..f8a8a147b 100644 --- a/config/production.yaml +++ b/config/production.yaml @@ -7,6 +7,7 @@ jaeger.sampler.param: 0.001 jaeger.sampler.type: remote metrics.flushInterval: 1000 metrics.m3.hostPort: 127.0.0.1:9052 +metrics.m3.includeHost: true metrics.m3.maxPacketSizeBytes: 1440 metrics.m3.maxQueueSize: 10000 metrics.runtime.collectInterval: 1000 diff --git a/config/test.yaml b/config/test.yaml index a93624d0d..1c43ae783 100644 --- a/config/test.yaml +++ b/config/test.yaml @@ -8,6 +8,7 @@ jaeger.sampler.param: 0.001 jaeger.sampler.type: remote metrics.flushInterval: 1000 metrics.m3.hostPort: 127.0.0.1:9052 +metrics.m3.includeHost: false metrics.m3.maxPacketSizeBytes: 1440 metrics.m3.maxQueueSize: 10000 metrics.runtime.collectInterval: 1000 diff --git a/examples/example-gateway/config/production.json b/examples/example-gateway/config/production.json index b215b9c04..454eded12 100644 --- a/examples/example-gateway/config/production.json +++ b/examples/example-gateway/config/production.json @@ -48,6 +48,7 @@ "logger.fileName": "/var/log/example-gateway/example-gateway.log", "logger.output": "disk", "metrics.serviceName": "example-gateway", + "metrics.m3.includeHost": true, "service.env.config": {}, "serviceName": "example-gateway", "sidecarRouter.default.http.ip": "127.0.0.1", diff --git a/examples/example-gateway/config/production.yaml b/examples/example-gateway/config/production.yaml index a38692b4d..00defdd37 100644 --- a/examples/example-gateway/config/production.yaml +++ b/examples/example-gateway/config/production.yaml @@ -45,6 +45,7 @@ http.port: 7783 logger.fileName: /var/log/example-gateway/example-gateway.log logger.output: disk metrics.serviceName: example-gateway +metrics.m3.includeHost: true service.env.config: {} serviceName: example-gateway sidecarRouter.default.http.calleeHeader: RPC-Service diff --git a/examples/example-gateway/config/test.json b/examples/example-gateway/config/test.json index f39fa285e..30ec2c69a 100644 --- a/examples/example-gateway/config/test.json +++ b/examples/example-gateway/config/test.json @@ -45,6 +45,7 @@ "logger.fileName": "/tmp/example-gateway.log", "logger.output": "disk", "metrics.serviceName": "example-gateway", + "metrics.m3.includeHost": true, "service.env.config": {}, "serviceName": "example-gateway", "sidecarRouter.default.http.ip": "127.0.0.1", diff --git a/examples/example-gateway/config/test.yaml b/examples/example-gateway/config/test.yaml index fd72756f6..3eefb450d 100644 --- a/examples/example-gateway/config/test.yaml +++ b/examples/example-gateway/config/test.yaml @@ -42,6 +42,7 @@ http.port: 0 logger.fileName: /tmp/example-gateway.log logger.output: disk metrics.serviceName: example-gateway +metrics.m3.includeHost: true service.env.config: {} serviceName: example-gateway shutdown.pollInterval: 10 diff --git a/runtime/gateway.go b/runtime/gateway.go index e17c0aa8c..3e846234e 100644 --- a/runtime/gateway.go +++ b/runtime/gateway.go @@ -444,15 +444,10 @@ func (gateway *Gateway) setupMetrics(config *StaticConfig) (err error) { panic("expected no metrics backend in gateway.") } - // TODO: Why aren't common tags emitted? - // NewReporter adds 'env' and 'service' common tags; and no 'host' tag. - commonTags := map[string]string{} opts := m3.Options{ HostPorts: []string{config.MustGetString("metrics.m3.hostPort")}, Service: service, Env: env, - CommonTags: commonTags, - IncludeHost: false, MaxQueueSize: int(config.MustGetInt("metrics.m3.maxQueueSize")), MaxPacketSizeBytes: int32(config.MustGetInt("metrics.m3.maxPacketSizeBytes")), } @@ -463,13 +458,15 @@ func (gateway *Gateway) setupMetrics(config *StaticConfig) (err error) { panic("expected gateway to have MetricsBackend in opts") } - // TODO: Remove 'env' and 'service' default tags once they are emitted by metrics backend. defaultTags := map[string]string{ "env": env, "service": service, - "host": GetHostname(), "dc": gateway.Config.MustGetString("datacenter"), } + if config.MustGetBoolean("metrics.m3.includeHost") { + defaultTags["host"] = GetHostname() + } + // Adds in any env variable variables specified in config envVarsToTagInRootScope := []string{} config.MustGetStruct("envVarsToTagInRootScope", &envVarsToTagInRootScope) diff --git a/test/endpoints/bar/bar_metrics_test.go b/test/endpoints/bar/bar_metrics_test.go index 8a18c643d..ca7cf8e49 100644 --- a/test/endpoints/bar/bar_metrics_test.go +++ b/test/endpoints/bar/bar_metrics_test.go @@ -62,7 +62,7 @@ func TestCallMetrics(t *testing.T) { }, ) - numMetrics := 13 + numMetrics := 12 cg := gateway.(*testGateway.ChildProcessGateway) cg.MetricsWaitGroup.Add(numMetrics) diff --git a/test/endpoints/baz/baz_metrics_test.go b/test/endpoints/baz/baz_metrics_test.go index c7c0ea488..b7a753eb9 100644 --- a/test/endpoints/baz/baz_metrics_test.go +++ b/test/endpoints/baz/baz_metrics_test.go @@ -77,7 +77,7 @@ func TestCallMetrics(t *testing.T) { headers["device"] = "ios" headers["deviceversion"] = "carbon" - numMetrics := 14 + numMetrics := 13 cg.MetricsWaitGroup.Add(numMetrics) _, err = gateway.MakeRequest( diff --git a/test/endpoints/tchannel/baz/baz_metrics_test.go b/test/endpoints/tchannel/baz/baz_metrics_test.go index 498d4aaf8..df1591f3a 100644 --- a/test/endpoints/tchannel/baz/baz_metrics_test.go +++ b/test/endpoints/tchannel/baz/baz_metrics_test.go @@ -74,7 +74,7 @@ func TestCallMetrics(t *testing.T) { ) assert.NoError(t, err) - numMetrics := 10 + numMetrics := 9 cg.MetricsWaitGroup.Add(numMetrics) ctx := context.Background() diff --git a/test/health_test.go b/test/health_test.go index 1798435e5..0dbd08f5b 100644 --- a/test/health_test.go +++ b/test/health_test.go @@ -200,13 +200,6 @@ func TestRuntimeMetrics(t *testing.T) { cgateway := gateway.(*testGateway.ChildProcessGateway) - // Expect 9 runtime metrics + 2 logged metric - numMetrics := 12 - cgateway.MetricsWaitGroup.Add(numMetrics) - cgateway.MetricsWaitGroup.Wait() - - metrics := cgateway.M3Service.GetMetrics() - assert.Equal(t, numMetrics, len(metrics), "expected 12 metrics") names := []string{ "runtime.num-cpu", "runtime.gomaxprocs", @@ -220,6 +213,14 @@ func TestRuntimeMetrics(t *testing.T) { "runtime.memory.num-gc", "runtime.memory.gc-pause-ms", } + // this is a shame because first GC takes 20s to kick in + // only then gc stats can be collected + // oh and the magic number 2 are 2 other stats produced + cgateway.MetricsWaitGroup.Add(len(names) + 2) + cgateway.MetricsWaitGroup.Wait() + + metrics := cgateway.M3Service.GetMetrics() + tags := map[string]string{ "env": "test", "service": "test-gateway", diff --git a/test/lib/bench_gateway/bench_gateway.go b/test/lib/bench_gateway/bench_gateway.go index c76b4dfaa..14f3ddab6 100644 --- a/test/lib/bench_gateway/bench_gateway.go +++ b/test/lib/bench_gateway/bench_gateway.go @@ -107,6 +107,7 @@ func CreateGateway( } seedConfig["tchannel.processName"] = "bench-gateway" seedConfig["metrics.serviceName"] = "bench-gateway" + seedConfig["metrics.m3.includeHost"] = true benchGateway := &BenchGateway{ httpClient: &http.Client{ diff --git a/test/lib/test_gateway/test_gateway.go b/test/lib/test_gateway/test_gateway.go index dcea1c91a..f43077c8f 100644 --- a/test/lib/test_gateway/test_gateway.go +++ b/test/lib/test_gateway/test_gateway.go @@ -276,6 +276,7 @@ func CreateGateway( composedConfig["metrics.serviceName"] = serviceName composedConfig["metrics.flushInterval"] = 10 composedConfig["metrics.m3.hostPort"] = testGateway.m3Server.Addr + composedConfig["metrics.m3.includeHost"] = true composedConfig["metrics.runtime.enableCPUMetrics"] = opts.EnableRuntimeMetrics composedConfig["metrics.runtime.enableMemMetrics"] = opts.EnableRuntimeMetrics composedConfig["metrics.runtime.enableGCMetrics"] = opts.EnableRuntimeMetrics diff --git a/test/lib/test_gateway/test_gateway_process.go b/test/lib/test_gateway/test_gateway_process.go index a0bab5598..29df638d2 100644 --- a/test/lib/test_gateway/test_gateway_process.go +++ b/test/lib/test_gateway/test_gateway_process.go @@ -219,7 +219,7 @@ func readAddrFromStdout(testGateway *ChildProcessGateway, reader *bufio.Reader) return &MalformedStdoutError{ Type: "malformed.stdout", StdoutLine: msg, - Message: "Could not find real http/tchannle address in server stdout", + Message: "Could not find real http/tchannel address in server stdout", } }