-
Notifications
You must be signed in to change notification settings - Fork 806
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create new histogram to track the size of the encoded responses from …
…QF to Querier Signed-off-by: alanprot <[email protected]>
- Loading branch information
Showing
3 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package codec | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
v1 "github.com/prometheus/prometheus/web/api/v1" | ||
"github.com/weaveworks/common/middleware" | ||
) | ||
|
||
type InstrumentedCodecMetrics struct { | ||
responseSizeHistogram *prometheus.HistogramVec | ||
} | ||
|
||
func NewInstrumentedCodecMetrics(reg prometheus.Registerer) *InstrumentedCodecMetrics { | ||
return &InstrumentedCodecMetrics{ | ||
responseSizeHistogram: promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{ | ||
Namespace: "cortex", | ||
Name: "querier_codec_response_size", | ||
Help: "Size of the encoded prometheus response from the queriers.", | ||
Buckets: middleware.BodySizeBuckets, | ||
NativeHistogramBucketFactor: 1.1, | ||
NativeHistogramMaxBucketNumber: 100, | ||
NativeHistogramMinResetDuration: time.Hour, | ||
}, []string{"content_type"}), | ||
} | ||
} | ||
|
||
type InstrumentedCodec struct { | ||
uc v1.Codec | ||
|
||
metrics *InstrumentedCodecMetrics | ||
} | ||
|
||
func (c *InstrumentedCodec) ContentType() v1.MIMEType { | ||
return c.uc.ContentType() | ||
} | ||
|
||
func (c *InstrumentedCodec) CanEncode(resp *v1.Response) bool { | ||
return c.uc.CanEncode(resp) | ||
} | ||
|
||
func (c *InstrumentedCodec) Encode(resp *v1.Response) ([]byte, error) { | ||
b, err := c.uc.Encode(resp) | ||
if err == nil { | ||
c.metrics.responseSizeHistogram.WithLabelValues(c.uc.ContentType().String()).Observe(float64(len((b)))) | ||
} | ||
return b, err | ||
} | ||
|
||
func NewInstrumentedCodec(uc v1.Codec, m *InstrumentedCodecMetrics) v1.Codec { | ||
return &InstrumentedCodec{ | ||
uc: uc, | ||
metrics: m, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters