Skip to content

Commit

Permalink
Add support for prometheus with exemplars
Browse files Browse the repository at this point in the history
- Pull in latest v1.4.1 prometheus client
- Add WithExemplar methods to counters and histograms
  • Loading branch information
shreyassrivatsan committed Feb 28, 2020
1 parent a87ae9d commit fbb8fae
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 41 deletions.
86 changes: 46 additions & 40 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

[[constraint]]
name = "github.com/prometheus/client_golang"
version = "1.1.0"
version = "1.4.1"

[[constraint]]
name = "github.com/stretchr/testify"
Expand Down
3 changes: 3 additions & 0 deletions metrics/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package metrics
type Counter interface {
// Inc adds the given value to the counter.
Inc(int64)
IncWithExemplar(int64, string)
}

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

func (nullCounter) Inc(int64) {}

func (n nullCounter) IncWithExemplar(int64, string) {}
15 changes: 15 additions & 0 deletions metrics/go-kit/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ func (c *Counter) Inc(delta int64) {
c.counter.Add(float64(delta))
}

// IncWithExemplar adds the given value alongwith the trace ID provided.
func (c *Counter) IncWithExemplar(int64, string) {
panic("not implemented")
}

// Gauge is an adapter from go-kit Gauge to jaeger-lib Gauge
type Gauge struct {
gauge kit.Gauge
Expand Down Expand Up @@ -65,6 +70,11 @@ func (t *Timer) Record(delta time.Duration) {
t.hist.Observe(delta.Seconds())
}

// RecordWithExemplar saves the time passed in with the trace ID provided.
func (t *Timer) RecordWithExemplar(time.Duration, string) {
panic("not implemented")
}

// Histogram is an adapter from go-kit Histogram to jaeger-lib Histogram
type Histogram struct {
hist kit.Histogram
Expand All @@ -79,3 +89,8 @@ func NewHistogram(hist kit.Histogram) *Histogram {
func (t *Histogram) Record(value float64) {
t.hist.Observe(value)
}

// RecordWithExemplar saves the time passed in with the trace ID provided.
func (t *Histogram) RecordWithExemplar(float64, string) {
panic("not implemented")
}
3 changes: 3 additions & 0 deletions metrics/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package metrics
type Histogram interface {
// Records the value passed in.
Record(float64)
RecordWithExemplar(float64, string)
}

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

func (nullHistogram) Record(float64) {}

func (n nullHistogram) RecordWithExemplar(float64, string) {}
12 changes: 12 additions & 0 deletions metrics/metricstest/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ func (l *localTimer) Record(d time.Duration) {
l.localBackend.RecordTimer(l.name, l.tags, d)
}

func (l *localTimer) RecordWithExemplar(d time.Duration, t string) {
l.localBackend.RecordTimer(l.name, l.tags, d)
}

type localHistogram struct {
stats
}
Expand All @@ -284,6 +288,10 @@ func (l *localHistogram) Record(v float64) {
l.localBackend.RecordHistogram(l.name, l.tags, v)
}

func (l *localHistogram) RecordWithExemplar(v float64, t string) {
l.localBackend.RecordHistogram(l.name, l.tags, v)
}

type localCounter struct {
stats
}
Expand All @@ -292,6 +300,10 @@ func (l *localCounter) Inc(delta int64) {
l.localBackend.IncCounter(l.name, l.tags, delta)
}

func (l *localCounter) IncWithExemplar(delta int64, t string) {
l.localBackend.IncCounter(l.name, l.tags, delta)
}

type localGauge struct {
stats
}
Expand Down
18 changes: 18 additions & 0 deletions metrics/multi/multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ func (c *counter) Inc(delta int64) {
}
}

func (c *counter) IncWithExemplar(delta int64, t string) {
for _, counter := range c.counters {
counter.Inc(delta)
}
}

// Counter implements metrics.Factory interface
func (f *Factory) Counter(options metrics.Options) metrics.Counter {
counter := &counter{
Expand All @@ -63,6 +69,12 @@ func (t *timer) Record(delta time.Duration) {
}
}

func (t *timer) RecordWithExemplar(delta time.Duration, traceID string) {
for _, timer := range t.timers {
timer.Record(delta)
}
}

// Timer implements metrics.Factory interface
func (f *Factory) Timer(options metrics.TimerOptions) metrics.Timer {
timer := &timer{
Expand All @@ -84,6 +96,12 @@ func (h *histogram) Record(value float64) {
}
}

func (h *histogram) RecordWithExemplar(value float64, t string) {
for _, histogram := range h.histograms {
histogram.Record(value)
}
}

// Histogram implements metrics.Factory interface
func (f *Factory) Histogram(options metrics.HistogramOptions) metrics.Histogram {
histogram := &histogram{
Expand Down
Loading

0 comments on commit fbb8fae

Please sign in to comment.