Skip to content

Commit

Permalink
Change to tagged metrics in agent (#950)
Browse files Browse the repository at this point in the history
Use tags in agent metrics
  • Loading branch information
eundoosong authored and yurishkuro committed Jul 24, 2018
1 parent df4a5e0 commit ba7d9b8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
9 changes: 3 additions & 6 deletions cmd/agent/app/processors/thrift_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package processors

import (
"errors"
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -196,7 +195,7 @@ func assertProcessorCorrectness(
metricsFactory *metrics.LocalFactory,
sizeF func() int,
nameF func() string,
counterType string,
format string,
) {
// wait for server to receive
for i := 0; i < 1000; i++ {
Expand All @@ -219,11 +218,9 @@ func assertProcessorCorrectness(
}

// agentReporter must emit metrics
batchesSubmittedCounter := fmt.Sprintf("tc-reporter.%s.batches.submitted", counterType)
spansSubmittedCounter := fmt.Sprintf("tc-reporter.%s.spans.submitted", counterType)
mTestutils.AssertCounterMetrics(t, metricsFactory, []mTestutils.ExpectedMetric{
{Name: batchesSubmittedCounter, Value: 1},
{Name: spansSubmittedCounter, Value: 1},
{Name: "tchannel-reporter.batches.submitted", Tags: map[string]string{"format": format}, Value: 1},
{Name: "tchannel-reporter.spans.submitted", Tags: map[string]string{"format": format}, Value: 1},
{Name: "thrift.udp.server.packets.processed", Value: 1},
}...)
}
4 changes: 1 addition & 3 deletions cmd/agent/app/reporter/tchannel/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,9 @@ func New(
zClient := zipkincore.NewTChanZipkinCollectorClient(thriftClient)
jClient := jaeger.NewTChanCollectorClient(thriftClient)
batchesMetrics := map[string]batchMetrics{}
tcReporterNS := mFactory.Namespace("tc-reporter", nil)
for _, s := range []string{zipkinBatches, jaegerBatches} {
nsByType := tcReporterNS.Namespace(s, nil)
bm := batchMetrics{}
metrics.Init(&bm, nsByType, nil)
metrics.Init(&bm, mFactory.Namespace("tchannel-reporter", map[string]string{"format": s}), nil)
batchesMetrics[s] = bm
}
return &Reporter{
Expand Down
16 changes: 5 additions & 11 deletions cmd/agent/app/reporter/tchannel/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package tchannel

import (
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -105,16 +104,11 @@ func submitTestJaegerBatch(reporter *Reporter) error {
return reporter.EmitBatch(batch)
}

func checkCounters(t *testing.T, mf *metrics.LocalFactory, batchesSubmitted, spansSubmitted, batchesFailures, spansFailures int, prefix string) {
batchesCounter := fmt.Sprintf("tc-reporter.%s.batches.submitted", prefix)
batchesFailureCounter := fmt.Sprintf("tc-reporter.%s.batches.failures", prefix)
spansCounter := fmt.Sprintf("tc-reporter.%s.spans.submitted", prefix)
spansFailureCounter := fmt.Sprintf("tc-reporter.%s.spans.failures", prefix)

func checkCounters(t *testing.T, mf *metrics.LocalFactory, batchesSubmitted, spansSubmitted, batchesFailures, spansFailures int, format string) {
mTestutils.AssertCounterMetrics(t, mf, []mTestutils.ExpectedMetric{
{Name: batchesCounter, Value: batchesSubmitted},
{Name: spansCounter, Value: spansSubmitted},
{Name: batchesFailureCounter, Value: batchesFailures},
{Name: spansFailureCounter, Value: spansFailures},
{Name: "tchannel-reporter.batches.submitted", Tags: map[string]string{"format": format}, Value: batchesSubmitted},
{Name: "tchannel-reporter.spans.submitted", Tags: map[string]string{"format": format}, Value: spansSubmitted},
{Name: "tchannel-reporter.batches.failures", Tags: map[string]string{"format": format}, Value: batchesFailures},
{Name: "tchannel-reporter.spans.failures", Tags: map[string]string{"format": format}, Value: spansFailures},
}...)
}

0 comments on commit ba7d9b8

Please sign in to comment.