fix inconsistent-label-cardinality for prometheus metrics: nginx_ingress_controller_requests (#8225)
* fix inconsistent-label-cardinality for prometheus metrics: nginx_ingress_controller_requests * add host to collectorLabels only if metricsPerHost is true
This commit is contained in:
parent
53a232f829
commit
86964b15a8
2 changed files with 42 additions and 4 deletions
|
|
@ -217,6 +217,7 @@ func NewSocketCollector(pod, namespace, class string, metricsPerHost bool, bucke
|
|||
}
|
||||
|
||||
sc.metricMapping = map[string]interface{}{
|
||||
prometheus.BuildFQName(PrometheusNamespace, "", "requests"): sc.requests,
|
||||
prometheus.BuildFQName(PrometheusNamespace, "", "request_duration_seconds"): sc.requestTime,
|
||||
prometheus.BuildFQName(PrometheusNamespace, "", "request_size"): sc.requestLength,
|
||||
|
||||
|
|
@ -258,9 +259,6 @@ func (sc *SocketCollector) handleMessage(msg []byte) {
|
|||
"service": stats.Service,
|
||||
"canary": stats.Canary,
|
||||
}
|
||||
if sc.metricsPerHost {
|
||||
requestLabels["host"] = stats.Host
|
||||
}
|
||||
|
||||
collectorLabels := prometheus.Labels{
|
||||
"namespace": stats.Namespace,
|
||||
|
|
@ -268,6 +266,12 @@ func (sc *SocketCollector) handleMessage(msg []byte) {
|
|||
"status": stats.Status,
|
||||
"service": stats.Service,
|
||||
"canary": stats.Canary,
|
||||
"method": stats.Method,
|
||||
"path": stats.Path,
|
||||
}
|
||||
if sc.metricsPerHost {
|
||||
requestLabels["host"] = stats.Host
|
||||
collectorLabels["host"] = stats.Host
|
||||
}
|
||||
|
||||
latencyLabels := prometheus.Labels{
|
||||
|
|
@ -415,6 +419,12 @@ func (sc *SocketCollector) RemoveMetrics(ingresses []string, registry prometheus
|
|||
klog.V(2).InfoS("metric not removed", "name", metricName, "ingress", ingKey, "labels", labels)
|
||||
}
|
||||
}
|
||||
|
||||
if c, ok := metric.(*prometheus.CounterVec); ok {
|
||||
if removed := c.Delete(labels); !removed {
|
||||
klog.V(2).InfoS("metric not removed", "name", metricName, "ingress", ingKey, "labels", labels)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue