Add prometheus metric requests_total with headers
Co-authored-by: Julien Salleyron <julien.salleyron@gmail.com>
This commit is contained in:
parent
4bc2305ed3
commit
c823879097
20 changed files with 295 additions and 90 deletions
|
@ -2,6 +2,7 @@ package metrics
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -37,12 +38,12 @@ func TestNewMultiRegistry(t *testing.T) {
|
|||
registries := []Registry{newCollectingRetryMetrics(), newCollectingRetryMetrics()}
|
||||
registry := NewMultiRegistry(registries)
|
||||
|
||||
registry.ServiceReqsCounter().With("key", "requests").Add(1)
|
||||
registry.ServiceReqsCounter().With(nil, "key", "requests").Add(1)
|
||||
registry.ServiceReqDurationHistogram().With("key", "durations").Observe(float64(2))
|
||||
registry.ServiceRetriesCounter().With("key", "retries").Add(3)
|
||||
|
||||
for _, collectingRegistry := range registries {
|
||||
cReqsCounter := collectingRegistry.ServiceReqsCounter().(*counterMock)
|
||||
cReqsCounter := collectingRegistry.ServiceReqsCounter().(*counterWithHeadersMock)
|
||||
cReqDurationHistogram := collectingRegistry.ServiceReqDurationHistogram().(*histogramMock)
|
||||
cRetriesCounter := collectingRegistry.ServiceRetriesCounter().(*counterMock)
|
||||
|
||||
|
@ -67,7 +68,7 @@ func TestNewMultiRegistry(t *testing.T) {
|
|||
|
||||
func newCollectingRetryMetrics() Registry {
|
||||
return &standardRegistry{
|
||||
serviceReqsCounter: &counterMock{},
|
||||
serviceReqsCounter: &counterWithHeadersMock{},
|
||||
serviceReqDurationHistogram: &histogramMock{},
|
||||
serviceRetriesCounter: &counterMock{},
|
||||
}
|
||||
|
@ -87,6 +88,20 @@ func (c *counterMock) Add(delta float64) {
|
|||
c.counterValue += delta
|
||||
}
|
||||
|
||||
type counterWithHeadersMock struct {
|
||||
counterValue float64
|
||||
lastLabelValues []string
|
||||
}
|
||||
|
||||
func (c *counterWithHeadersMock) With(_ http.Header, labelValues ...string) CounterWithHeaders {
|
||||
c.lastLabelValues = labelValues
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *counterWithHeadersMock) Add(delta float64) {
|
||||
c.counterValue += delta
|
||||
}
|
||||
|
||||
type histogramMock struct {
|
||||
lastHistogramValue float64
|
||||
lastLabelValues []string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue