Skip to content
This repository was archived by the owner on Aug 17, 2025. It is now read-only.

Commit 720c498

Browse files
Add support for prometheus with exemplars
- Pull in latest v1.4.1 prometheus client - Add WithExemplar methods to counters and histograms Signed-off-by: Shreyas Srivatsan <[email protected]>
1 parent a87ae9d commit 720c498

File tree

10 files changed

+172
-41
lines changed

10 files changed

+172
-41
lines changed

Gopkg.lock

Lines changed: 46 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
[[constraint]]
1414
name = "github.com/prometheus/client_golang"
15-
version = "1.1.0"
15+
version = "1.4.1"
1616

1717
[[constraint]]
1818
name = "github.com/stretchr/testify"

metrics/counter.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package metrics
1818
type Counter interface {
1919
// Inc adds the given value to the counter.
2020
Inc(int64)
21+
IncWithExemplar(int64, string)
2122
}
2223

2324
// NullCounter counter that does nothing
@@ -26,3 +27,5 @@ var NullCounter Counter = nullCounter{}
2627
type nullCounter struct{}
2728

2829
func (nullCounter) Inc(int64) {}
30+
31+
func (n nullCounter) IncWithExemplar(int64, string) {}

metrics/go-kit/metrics.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ func (c *Counter) Inc(delta int64) {
3535
c.counter.Add(float64(delta))
3636
}
3737

38+
// IncWithExemplar adds the given value alongwith the trace ID provided.
39+
func (c *Counter) IncWithExemplar(int64, string) {
40+
panic("not implemented")
41+
}
42+
3843
// Gauge is an adapter from go-kit Gauge to jaeger-lib Gauge
3944
type Gauge struct {
4045
gauge kit.Gauge
@@ -65,6 +70,11 @@ func (t *Timer) Record(delta time.Duration) {
6570
t.hist.Observe(delta.Seconds())
6671
}
6772

73+
// RecordWithExemplar saves the time passed in with the trace ID provided.
74+
func (t *Timer) RecordWithExemplar(time.Duration, string) {
75+
panic("not implemented")
76+
}
77+
6878
// Histogram is an adapter from go-kit Histogram to jaeger-lib Histogram
6979
type Histogram struct {
7080
hist kit.Histogram
@@ -79,3 +89,8 @@ func NewHistogram(hist kit.Histogram) *Histogram {
7989
func (t *Histogram) Record(value float64) {
8090
t.hist.Observe(value)
8191
}
92+
93+
// RecordWithExemplar saves the time passed in with the trace ID provided.
94+
func (t *Histogram) RecordWithExemplar(float64, string) {
95+
panic("not implemented")
96+
}

metrics/histogram.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package metrics
1818
type Histogram interface {
1919
// Records the value passed in.
2020
Record(float64)
21+
RecordWithExemplar(float64, string)
2122
}
2223

2324
// NullHistogram that does nothing
@@ -26,3 +27,5 @@ var NullHistogram Histogram = nullHistogram{}
2627
type nullHistogram struct{}
2728

2829
func (nullHistogram) Record(float64) {}
30+
31+
func (n nullHistogram) RecordWithExemplar(float64, string) {}

metrics/metricstest/local.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ func (l *localTimer) Record(d time.Duration) {
276276
l.localBackend.RecordTimer(l.name, l.tags, d)
277277
}
278278

279+
func (l *localTimer) RecordWithExemplar(d time.Duration, t string) {
280+
l.localBackend.RecordTimer(l.name, l.tags, d)
281+
}
282+
279283
type localHistogram struct {
280284
stats
281285
}
@@ -284,6 +288,10 @@ func (l *localHistogram) Record(v float64) {
284288
l.localBackend.RecordHistogram(l.name, l.tags, v)
285289
}
286290

291+
func (l *localHistogram) RecordWithExemplar(v float64, t string) {
292+
l.localBackend.RecordHistogram(l.name, l.tags, v)
293+
}
294+
287295
type localCounter struct {
288296
stats
289297
}
@@ -292,6 +300,10 @@ func (l *localCounter) Inc(delta int64) {
292300
l.localBackend.IncCounter(l.name, l.tags, delta)
293301
}
294302

303+
func (l *localCounter) IncWithExemplar(delta int64, t string) {
304+
l.localBackend.IncCounter(l.name, l.tags, delta)
305+
}
306+
295307
type localGauge struct {
296308
stats
297309
}

metrics/multi/multi.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ func (c *counter) Inc(delta int64) {
4242
}
4343
}
4444

45+
func (c *counter) IncWithExemplar(delta int64, t string) {
46+
for _, counter := range c.counters {
47+
counter.Inc(delta)
48+
}
49+
}
50+
4551
// Counter implements metrics.Factory interface
4652
func (f *Factory) Counter(options metrics.Options) metrics.Counter {
4753
counter := &counter{
@@ -63,6 +69,12 @@ func (t *timer) Record(delta time.Duration) {
6369
}
6470
}
6571

72+
func (t *timer) RecordWithExemplar(delta time.Duration, traceID string) {
73+
for _, timer := range t.timers {
74+
timer.Record(delta)
75+
}
76+
}
77+
6678
// Timer implements metrics.Factory interface
6779
func (f *Factory) Timer(options metrics.TimerOptions) metrics.Timer {
6880
timer := &timer{
@@ -84,6 +96,12 @@ func (h *histogram) Record(value float64) {
8496
}
8597
}
8698

99+
func (h *histogram) RecordWithExemplar(value float64, t string) {
100+
for _, histogram := range h.histograms {
101+
histogram.Record(value)
102+
}
103+
}
104+
87105
// Histogram implements metrics.Factory interface
88106
func (f *Factory) Histogram(options metrics.HistogramOptions) metrics.Histogram {
89107
histogram := &histogram{

0 commit comments

Comments
 (0)