Skip to content

Commit

Permalink
Update collector metric counters to have a name (#886)
Browse files Browse the repository at this point in the history
  • Loading branch information
black-adder committed Jun 25, 2018
1 parent c19b6b0 commit 50429cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
18 changes: 10 additions & 8 deletions cmd/collector/app/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type countsBySvc struct {
factory metrics.Factory
lock *sync.Mutex
maxServiceNames int
category string
}

type metricsBySvc struct {
Expand Down Expand Up @@ -94,25 +95,26 @@ func NewSpanProcessorMetrics(serviceMetrics metrics.Factory, hostMetrics metrics
}

func newMetricsBySvc(factory metrics.Factory, category string) metricsBySvc {
spansFactory := factory.Namespace("spans."+category, nil)
tracesFactory := factory.Namespace("traces."+category, nil)
spansFactory := factory.Namespace("spans", nil)
tracesFactory := factory.Namespace("traces", nil)
return metricsBySvc{
spans: newCountsBySvc(spansFactory, maxServiceNames),
traces: newCountsBySvc(tracesFactory, maxServiceNames),
spans: newCountsBySvc(spansFactory, category, maxServiceNames),
traces: newCountsBySvc(tracesFactory, category, maxServiceNames),
}
}

func newCountsBySvc(factory metrics.Factory, maxServiceNames int) countsBySvc {
func newCountsBySvc(factory metrics.Factory, category string, maxServiceNames int) countsBySvc {
return countsBySvc{
counts: map[string]metrics.Counter{
otherServices: factory.Counter("", map[string]string{"svc": otherServices, "debug": "false"}),
otherServices: factory.Counter(category, map[string]string{"svc": otherServices, "debug": "false"}),
},
debugCounts: map[string]metrics.Counter{
otherServices: factory.Counter("", map[string]string{"svc": otherServices, "debug": "true"}),
otherServices: factory.Counter(category, map[string]string{"svc": otherServices, "debug": "true"}),
},
factory: factory,
lock: &sync.Mutex{},
maxServiceNames: maxServiceNames,
category: category,
}
}

Expand Down Expand Up @@ -181,7 +183,7 @@ func (m *countsBySvc) countByServiceName(serviceName string, isDebug bool) {
if isDebug {
debugStr = "true"
}
c := m.factory.Counter("", map[string]string{"svc": serviceName, "debug": debugStr})
c := m.factory.Counter(m.category, map[string]string{"svc": serviceName, "debug": debugStr})
counts[serviceName] = c
counter = c
} else {
Expand Down
14 changes: 7 additions & 7 deletions cmd/collector/app/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,25 @@ func TestProcessorMetrics(t *testing.T) {

func TestNewCountsBySvc(t *testing.T) {
baseMetrics := jaegerM.NewLocalFactory(time.Hour)
metrics := newCountsBySvc(baseMetrics, 3)
metrics := newCountsBySvc(baseMetrics, "not_on_my_level", 3)

metrics.countByServiceName("fry", false)
metrics.countByServiceName("leela", false)
metrics.countByServiceName("bender", false)
metrics.countByServiceName("zoidberg", false)

counters, _ := baseMetrics.LocalBackend.Snapshot()
assert.EqualValues(t, 1, counters["|debug=false|svc=fry"])
assert.EqualValues(t, 1, counters["|debug=false|svc=leela"])
assert.EqualValues(t, 2, counters["|debug=false|svc=other-services"])
assert.EqualValues(t, 1, counters["not_on_my_level|debug=false|svc=fry"])
assert.EqualValues(t, 1, counters["not_on_my_level|debug=false|svc=leela"])
assert.EqualValues(t, 2, counters["not_on_my_level|debug=false|svc=other-services"])

metrics.countByServiceName("zoidberg", true)
metrics.countByServiceName("bender", true)
metrics.countByServiceName("leela", true)
metrics.countByServiceName("fry", true)

counters, _ = baseMetrics.LocalBackend.Snapshot()
assert.EqualValues(t, 1, counters["|debug=true|svc=zoidberg"])
assert.EqualValues(t, 1, counters["|debug=true|svc=bender"])
assert.EqualValues(t, 2, counters["|debug=true|svc=other-services"])
assert.EqualValues(t, 1, counters["not_on_my_level|debug=true|svc=zoidberg"])
assert.EqualValues(t, 1, counters["not_on_my_level|debug=true|svc=bender"])
assert.EqualValues(t, 2, counters["not_on_my_level|debug=true|svc=other-services"])
}

0 comments on commit 50429cb

Please sign in to comment.