Skip to content

Commit

Permalink
Make it configurable to whether emit metrics with host tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuntao Lu committed Feb 16, 2019
1 parent 67bd14a commit 737584e
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion config/production.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/example-gateway/config/production.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions examples/example-gateway/config/production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/example-gateway/config/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions examples/example-gateway/config/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions runtime/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
}
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/endpoints/bar/bar_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestCallMetrics(t *testing.T) {
},
)

numMetrics := 13
numMetrics := 12
cg := gateway.(*testGateway.ChildProcessGateway)
cg.MetricsWaitGroup.Add(numMetrics)

Expand Down
2 changes: 1 addition & 1 deletion test/endpoints/baz/baz_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion test/endpoints/tchannel/baz/baz_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestCallMetrics(t *testing.T) {
)
assert.NoError(t, err)

numMetrics := 10
numMetrics := 9
cg.MetricsWaitGroup.Add(numMetrics)

ctx := context.Background()
Expand Down
15 changes: 8 additions & 7 deletions test/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
1 change: 1 addition & 0 deletions test/lib/bench_gateway/bench_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 1 addition & 0 deletions test/lib/test_gateway/test_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/lib/test_gateway/test_gateway_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
}

Expand Down

0 comments on commit 737584e

Please sign in to comment.