Implement reporting status classes in metrics (#8548)

This commit introduces a backwards compatible command line option
--report-status-classes which will enable reporting response status classes
(2xx, 3xx..) instead of status codes in exported metrics.
This commit is contained in:
Filip Petkovski 2022-05-21 20:18:00 +02:00 committed by GitHub
parent 0240dd3fba
commit 4da96ea26a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 71 additions and 16 deletions

View file

@ -85,7 +85,8 @@ type SocketCollector struct {
hosts sets.String
metricsPerHost bool
metricsPerHost bool
reportStatusClasses bool
buckets HistogramBuckets
}
@ -110,7 +111,7 @@ var defObjectives = map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}
// NewSocketCollector creates a new SocketCollector instance using
// the ingress watch namespace and class used by the controller
func NewSocketCollector(pod, namespace, class string, metricsPerHost bool, buckets HistogramBuckets) (*SocketCollector, error) {
func NewSocketCollector(pod, namespace, class string, metricsPerHost, reportStatusClasses bool, buckets HistogramBuckets) (*SocketCollector, error) {
socket := "/tmp/nginx/prometheus-nginx.socket"
// unix sockets must be unlink()ed before being used
_ = syscall.Unlink(socket)
@ -139,7 +140,8 @@ func NewSocketCollector(pod, namespace, class string, metricsPerHost bool, bucke
sc := &SocketCollector{
listener: listener,
metricsPerHost: metricsPerHost,
metricsPerHost: metricsPerHost,
reportStatusClasses: reportStatusClasses,
responseTime: prometheus.NewHistogramVec(
prometheus.HistogramOpts{
@ -249,6 +251,10 @@ func (sc *SocketCollector) handleMessage(msg []byte) {
continue
}
if sc.reportStatusClasses && len(stats.Status) > 0 {
stats.Status = fmt.Sprintf("%cxx", stats.Status[0])
}
// Note these must match the order in requestTags at the top
requestLabels := prometheus.Labels{
"status": stats.Status,