-
Notifications
You must be signed in to change notification settings - Fork 67
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
Prometheus Exemplars Support #448
Changes from 3 commits
200bb33
587a5d7
e92ba95
f183540
2d3c3e8
43002eb
e9f654d
40eae9e
b19e769
2cee064
cd67c81
d4b073c
a6324be
cadf753
40691fb
a0fad1b
60554ab
409dede
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ package es | |
import ( | ||
"bytes" | ||
"fmt" | ||
"github.com/uber/jaeger-client-go" | ||
"io/ioutil" | ||
"net/http" | ||
"net/url" | ||
|
@@ -13,12 +12,14 @@ import ( | |
"strings" | ||
"time" | ||
|
||
"github.com/uber/jaeger-client-go" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. empty line |
||
"github.com/beatlabs/patron/log" | ||
"github.com/beatlabs/patron/trace" | ||
elasticsearch "github.com/elastic/go-elasticsearch/v8" | ||
"github.com/elastic/go-elasticsearch/v8/esapi" | ||
"github.com/elastic/go-elasticsearch/v8/estransport" | ||
opentracing "github.com/opentracing/opentracing-go" | ||
"github.com/opentracing/opentracing-go" | ||
"github.com/opentracing/opentracing-go/ext" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
@@ -125,7 +126,7 @@ func observeResponse(req *http.Request, sp opentracing.Span, rsp *http.Response, | |
|
||
if sctx, ok := sp.Context().(jaeger.SpanContext); ok { | ||
durationHistogram.(prometheus.ExemplarObserver).ObserveWithExemplar( | ||
time.Since(start).Seconds(), prometheus.Labels{"traceID": sctx.TraceID().String()}, | ||
time.Since(start).Seconds(), prometheus.Labels{trace.TraceID: sctx.TraceID().String()}, | ||
) | ||
} else { | ||
durationHistogram.Observe(time.Since(start).Seconds()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,10 @@ package grpc | |
|
||
import ( | ||
"context" | ||
"github.com/uber/jaeger-client-go" | ||
"time" | ||
|
||
"github.com/uber/jaeger-client-go" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
"github.com/beatlabs/patron/correlation" | ||
"github.com/beatlabs/patron/log" | ||
"github.com/beatlabs/patron/trace" | ||
|
@@ -91,7 +92,7 @@ func unaryInterceptor(target string) grpc.UnaryClientInterceptor { | |
durationHistogram := rpcDurationMetrics.WithLabelValues(unary, target, method, rpcStatus.Code().String()) | ||
if sctx, ok := span.Context().(jaeger.SpanContext); ok { | ||
durationHistogram.(prometheus.ExemplarObserver).ObserveWithExemplar( | ||
invokeDuration.Seconds(), prometheus.Labels{"traceID": sctx.TraceID().String()}, | ||
invokeDuration.Seconds(), prometheus.Labels{trace.TraceID: sctx.TraceID().String()}, | ||
) | ||
} else { | ||
durationHistogram.Observe(invokeDuration.Seconds()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,13 @@ package http | |
import ( | ||
"compress/flate" | ||
"compress/gzip" | ||
"github.com/uber/jaeger-client-go" | ||
"io" | ||
"net/http" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/uber/jaeger-client-go" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
"github.com/opentracing-contrib/go-stdlib/nethttp" | ||
"github.com/opentracing/opentracing-go" | ||
"github.com/opentracing/opentracing-go/ext" | ||
|
@@ -98,7 +99,7 @@ func (tc *TracedClient) Do(req *http.Request) (*http.Response, error) { | |
|
||
if sctx, ok := ht.Span().Context().(jaeger.SpanContext); ok { | ||
durationHistogram.(prometheus.ExemplarObserver).ObserveWithExemplar( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a way to type assert safely which is: |
||
time.Since(start).Seconds(), prometheus.Labels{"traceID": sctx.TraceID().String()}, | ||
time.Since(start).Seconds(), prometheus.Labels{trace.TraceID: sctx.TraceID().String()}, | ||
) | ||
} else { | ||
durationHistogram.Observe(time.Since(start).Seconds()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
package v2 | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/beatlabs/patron/trace" | ||
"github.com/opentracing/opentracing-go" | ||
"github.com/uber/jaeger-client-go" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. empty line |
||
"github.com/Shopify/sarama" | ||
patronerrors "github.com/beatlabs/patron/errors" | ||
"github.com/beatlabs/patron/internal/validation" | ||
|
@@ -41,6 +46,22 @@ func init() { | |
prometheus.MustRegister(messageStatus) | ||
} | ||
|
||
func statusCountAddWithExemplars(ctx context.Context, deliveryType string, status deliveryStatus, topic string, cnt int) { | ||
messageStatusCounter := messageStatus.WithLabelValues(string(status), topic, deliveryType) | ||
spanFromCtx := opentracing.SpanFromContext(ctx) | ||
if spanFromCtx != nil { | ||
if sctx, ok := spanFromCtx.Context().(jaeger.SpanContext); ok { | ||
messageStatusCounter.(prometheus.ExemplarAdder).AddWithExemplar( | ||
float64(cnt), prometheus.Labels{trace.TraceID: sctx.TraceID().String()}, | ||
) | ||
} else { | ||
messageStatusCounter.Add(float64(cnt)) | ||
} | ||
} else { | ||
messageStatusCounter.Add(float64(cnt)) | ||
} | ||
} | ||
|
||
func statusCountAdd(deliveryType string, status deliveryStatus, topic string, cnt int) { | ||
messageStatus.WithLabelValues(string(status), topic, deliveryType).Add(float64(cnt)) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,11 @@ import ( | |
"context" | ||
"errors" | ||
"fmt" | ||
"github.com/uber/jaeger-client-go" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/uber/jaeger-client-go" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/sns" | ||
"github.com/aws/aws-sdk-go/service/sns/snsiface" | ||
|
@@ -131,7 +132,7 @@ func observePublish(span opentracing.Span, start time.Time, topic string, err er | |
|
||
if sctx, ok := span.Context().(jaeger.SpanContext); ok { | ||
durationHistogram.(prometheus.ExemplarObserver).ObserveWithExemplar( | ||
time.Since(start).Seconds(), prometheus.Labels{"traceID": sctx.TraceID().String()}, | ||
time.Since(start).Seconds(), prometheus.Labels{trace.TraceID: sctx.TraceID().String()}, | ||
) | ||
} else { | ||
durationHistogram.Observe(time.Since(start).Seconds()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty line should be removed