Skip to content

Commit b05f189

Browse files
committed
Change to tagged metrics in agent
Signed-off-by: Eundoo Song <[email protected]>
1 parent 933efb3 commit b05f189

File tree

3 files changed

+14
-25
lines changed

3 files changed

+14
-25
lines changed

Diff for: cmd/agent/app/processors/thrift_processor_test.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package processors
1616

1717
import (
1818
"errors"
19-
"fmt"
2019
"testing"
2120
"time"
2221

@@ -196,7 +195,7 @@ func assertProcessorCorrectness(
196195
metricsFactory *metrics.LocalFactory,
197196
sizeF func() int,
198197
nameF func() string,
199-
counterType string,
198+
format string,
200199
) {
201200
// wait for server to receive
202201
for i := 0; i < 1000; i++ {
@@ -219,11 +218,9 @@ func assertProcessorCorrectness(
219218
}
220219

221220
// agentReporter must emit metrics
222-
batchesSubmittedCounter := fmt.Sprintf("tc-reporter.%s.batches.submitted", counterType)
223-
spansSubmittedCounter := fmt.Sprintf("tc-reporter.%s.spans.submitted", counterType)
224221
mTestutils.AssertCounterMetrics(t, metricsFactory, []mTestutils.ExpectedMetric{
225-
{Name: batchesSubmittedCounter, Value: 1},
226-
{Name: spansSubmittedCounter, Value: 1},
222+
{Name: "tc-reporter.batches.submitted", Tags: map[string]string{"format": format}, Value: 1},
223+
{Name: "tc-reporter.spans.submitted", Tags: map[string]string{"format": format}, Value: 1},
227224
{Name: "thrift.udp.server.packets.processed", Value: 1},
228225
}...)
229226
}

Diff for: cmd/agent/app/reporter/tchannel/reporter.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ const (
3434

3535
type batchMetrics struct {
3636
// Number of successful batch submissions to collector
37-
BatchesSubmitted metrics.Counter `metric:"batches.submitted"`
37+
BatchesSubmitted metrics.Counter `metric:"tc-reporter.batches.submitted"`
3838

3939
// Number of failed batch submissions to collector
40-
BatchesFailures metrics.Counter `metric:"batches.failures"`
40+
BatchesFailures metrics.Counter `metric:"tc-reporter.batches.failures"`
4141

4242
// Number of spans in a batch submitted to collector
43-
BatchSize metrics.Gauge `metric:"batch_size"`
43+
BatchSize metrics.Gauge `metric:"tc-reporter.batch_size"`
4444

4545
// Number of successful span submissions to collector
46-
SpansSubmitted metrics.Counter `metric:"spans.submitted"`
46+
SpansSubmitted metrics.Counter `metric:"tc-reporter.spans.submitted"`
4747

4848
// Number of failed span submissions to collector
49-
SpansFailures metrics.Counter `metric:"spans.failures"`
49+
SpansFailures metrics.Counter `metric:"tc-reporter.spans.failures"`
5050
}
5151

5252
// Reporter forwards received spans to central collector tier over TChannel.
@@ -71,11 +71,9 @@ func New(
7171
zClient := zipkincore.NewTChanZipkinCollectorClient(thriftClient)
7272
jClient := jaeger.NewTChanCollectorClient(thriftClient)
7373
batchesMetrics := map[string]batchMetrics{}
74-
tcReporterNS := mFactory.Namespace("tc-reporter", nil)
7574
for _, s := range []string{zipkinBatches, jaegerBatches} {
76-
nsByType := tcReporterNS.Namespace(s, nil)
7775
bm := batchMetrics{}
78-
metrics.Init(&bm, nsByType, nil)
76+
metrics.Init(&bm, mFactory.Namespace("", map[string]string{"format": s}), nil)
7977
batchesMetrics[s] = bm
8078
}
8179
return &Reporter{

Diff for: cmd/agent/app/reporter/tchannel/reporter_test.go

+5-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package tchannel
1616

1717
import (
18-
"fmt"
1918
"testing"
2019
"time"
2120

@@ -105,16 +104,11 @@ func submitTestJaegerBatch(reporter *Reporter) error {
105104
return reporter.EmitBatch(batch)
106105
}
107106

108-
func checkCounters(t *testing.T, mf *metrics.LocalFactory, batchesSubmitted, spansSubmitted, batchesFailures, spansFailures int, prefix string) {
109-
batchesCounter := fmt.Sprintf("tc-reporter.%s.batches.submitted", prefix)
110-
batchesFailureCounter := fmt.Sprintf("tc-reporter.%s.batches.failures", prefix)
111-
spansCounter := fmt.Sprintf("tc-reporter.%s.spans.submitted", prefix)
112-
spansFailureCounter := fmt.Sprintf("tc-reporter.%s.spans.failures", prefix)
113-
107+
func checkCounters(t *testing.T, mf *metrics.LocalFactory, batchesSubmitted, spansSubmitted, batchesFailures, spansFailures int, format string) {
114108
mTestutils.AssertCounterMetrics(t, mf, []mTestutils.ExpectedMetric{
115-
{Name: batchesCounter, Value: batchesSubmitted},
116-
{Name: spansCounter, Value: spansSubmitted},
117-
{Name: batchesFailureCounter, Value: batchesFailures},
118-
{Name: spansFailureCounter, Value: spansFailures},
109+
{Name: "tc-reporter.batches.submitted", Tags: map[string]string{"format": format}, Value: batchesSubmitted},
110+
{Name: "tc-reporter.spans.submitted", Tags: map[string]string{"format": format}, Value: spansSubmitted},
111+
{Name: "tc-reporter.batches.failures", Tags: map[string]string{"format": format}, Value: batchesFailures},
112+
{Name: "tc-reporter.spans.failures", Tags: map[string]string{"format": format}, Value: spansFailures},
119113
}...)
120114
}

0 commit comments

Comments
 (0)