Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate query metrics and include result tag #1075

Merged
merged 3 commits into from
Sep 28, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions storage/spanstore/metrics/decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@ type ReadMetricsDecorator struct {
}

type queryMetrics struct {
Errors metrics.Counter `metric:"errors"`
Attempts metrics.Counter `metric:"attempts"`
Successes metrics.Counter `metric:"successes"`
Responses metrics.Timer `metric:"responses"` //used as a histogram, not necessary for GetTrace
ErrLatency metrics.Timer `metric:"errLatency"`
OKLatency metrics.Timer `metric:"okLatency"`
Errors metrics.Counter
Attempts metrics.Counter
Successes metrics.Counter
Responses metrics.Timer //used as a histogram, not necessary for GetTrace
ErrLatency metrics.Timer
OKLatency metrics.Timer
}

func (q *queryMetrics) emit(err error, latency time.Duration, responses int) {
q.Attempts.Inc(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Attempts being used elsewhere?

if err != nil {
q.Errors.Inc(1)
q.ErrLatency.Record(latency)
Expand All @@ -66,9 +65,14 @@ func NewReadMetricsDecorator(spanReader spanstore.Reader, metricsFactory metrics
}

func buildQueryMetrics(namespace string, metricsFactory metrics.Factory) *queryMetrics {
qMetrics := &queryMetrics{}
scoped := metricsFactory.Namespace(namespace, nil)
metrics.Init(qMetrics, scoped, nil)
qMetrics := &queryMetrics{
Errors: scoped.Counter("requests", map[string]string{"result": "err"}),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better name than requests and/or responses?
requests = number of query operations performed
responses = number of items returned per request

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

responses = number of items returned per request

what items? traces, spans?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on which operation: find traces, get operations, get services and get trace.
So jaeger_find_traces_responses would be tracking the number of traces returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On reflection, requests and responses is probably ok - the requests is a counter, so should be obvious relates to number of requests. responses is a histogram to represent the number of items in each response.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems this discussion has finished already, but how about "operations" and "results"?

Even though "requests/responses" is probably OK as well, I would avoid it as it's a bit of a loaded term.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have removed the additional part of the name for those counters, so now it is just:

jaeger_query_find_traces{result="err"} 0
jaeger_query_find_traces{result="ok"} 1
jaeger_query_find_traces_latency_bucket{result="err",le="0.005"} 0
jaeger_query_find_traces_latency_bucket{result="ok",le="0.005"} 1
jaeger_query_find_traces_responses_bucket{le="0.005"} 1

Successes: scoped.Counter("requests", map[string]string{"result": "ok"}),
Responses: scoped.Timer("responses", nil),
ErrLatency: scoped.Timer("latency", map[string]string{"result": "err"}),
OKLatency: scoped.Timer("latency", map[string]string{"result": "ok"}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use the annotation-based initialization as before? It keeps declaration of the struct and metrics name in a single place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #1096

}
return qMetrics
}

Expand Down
52 changes: 22 additions & 30 deletions storage/spanstore/metrics/decorator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,23 @@ func TestSuccessfulUnderlyingCalls(t *testing.T) {
mrs.FindTraces(context.Background(), &spanstore.TraceQueryParameters{})
counters, gauges := mf.Snapshot()
expecteds := map[string]int64{
"get_operations.attempts": 1,
"get_operations.successes": 1,
"get_operations.errors": 0,
"get_trace.attempts": 1,
"get_trace.successes": 1,
"get_trace.errors": 0,
"find_traces.attempts": 1,
"find_traces.successes": 1,
"find_traces.errors": 0,
"get_services.attempts": 1,
"get_services.successes": 1,
"get_services.errors": 0,
"get_operations.requests|result=ok": 1,
"get_operations.requests|result=err": 0,
"get_trace.requests|result=ok": 1,
"get_trace.requests|result=err": 0,
"find_traces.requests|result=ok": 1,
"find_traces.requests|result=err": 0,
"get_services.requests|result=ok": 1,
"get_services.requests|result=err": 0,
}

existingKeys := []string{
"get_operations.okLatency.P50",
"get_operations.latency|result=ok.P50",
"get_trace.responses.P50",
"find_traces.okLatency.P50", // this is not exhaustive
"find_traces.latency|result=ok.P50", // this is not exhaustive
}
nonExistentKeys := []string{
"get_operations.errLatency.P50",
"get_operations.latency|result=err.P50",
}

checkExpectedExistingAndNonExistentCounters(t, counters, expecteds, gauges, existingKeys, nonExistentKeys)
Expand Down Expand Up @@ -100,28 +96,24 @@ func TestFailingUnderlyingCalls(t *testing.T) {
mrs.FindTraces(context.Background(), &spanstore.TraceQueryParameters{})
counters, gauges := mf.Snapshot()
expecteds := map[string]int64{
"get_operations.attempts": 1,
"get_operations.successes": 0,
"get_operations.errors": 1,
"get_trace.attempts": 1,
"get_trace.successes": 0,
"get_trace.errors": 1,
"find_traces.attempts": 1,
"find_traces.successes": 0,
"find_traces.errors": 1,
"get_services.attempts": 1,
"get_services.successes": 0,
"get_services.errors": 1,
"get_operations.requests|result=ok": 0,
"get_operations.requests|result=err": 1,
"get_trace.requests|result=ok": 0,
"get_trace.requests|result=err": 1,
"find_traces.requests|result=ok": 0,
"find_traces.requests|result=err": 1,
"get_services.requests|result=ok": 0,
"get_services.requests|result=err": 1,
}

existingKeys := []string{
"get_operations.errLatency.P50",
"get_operations.latency|result=err.P50",
}

nonExistentKeys := []string{
"get_operations.okLatency.P50",
"get_operations.latency|result=ok.P50",
"get_trace.responses.P50",
"query.okLatency.P50", // this is not exhaustive
"query.latency|result=ok.P50", // this is not exhaustive
}

checkExpectedExistingAndNonExistentCounters(t, counters, expecteds, gauges, existingKeys, nonExistentKeys)
Expand Down