1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00

metrics: improve nfr processing time metric

Change the metric from a simple gauge (that basically was a single value
for the whole cluster) into a HistogramVec, aligning with the feature
discovery duration metric in nfd-worker. This improved metric now has
prometheus labels for the NFR name and node name, i.e. it is tracking
per-NFR metric for each node being processed. Also, change the naming to
better comply with prometheus suggested conventions.
This commit is contained in:
Markus Lehtonen 2023-07-28 17:58:26 +03:00
parent e0f10a81de
commit 945e7fcb3f
2 changed files with 15 additions and 7 deletions

View file

@ -30,7 +30,7 @@ import (
const ( const (
buildInfoQuery = "nfd_master_build_info" buildInfoQuery = "nfd_master_build_info"
updatedNodesQuery = "nfd_updated_nodes" updatedNodesQuery = "nfd_updated_nodes"
crdProcessingTimeQuery = "nfd_crd_processing_time" nfrProcessingTimeQuery = "nfd_nodefeaturerule_processing_duration_seconds"
) )
var ( var (
@ -47,10 +47,17 @@ var (
Name: updatedNodesQuery, Name: updatedNodesQuery,
Help: "Number of nodes updated by the master.", Help: "Number of nodes updated by the master.",
}) })
crdProcessingTime = prometheus.NewGauge(prometheus.GaugeOpts{ nfrProcessingTime = prometheus.NewHistogramVec(
Name: crdProcessingTimeQuery, prometheus.HistogramOpts{
Help: "Time spent processing the NodeFeatureRule CRD.", Name: nfrProcessingTimeQuery,
}) Help: "Time processing time of NodeFeatureRule objects.",
Buckets: []float64{0.0001, 0.00025, 0.0005, 0.001, 0.0025, 0.005, 0.01},
},
[]string{
"name",
"node",
},
)
) )
// registerVersion exposes the Operator build version. // registerVersion exposes the Operator build version.
@ -63,7 +70,7 @@ func runMetricsServer(port int) {
r := prometheus.NewRegistry() r := prometheus.NewRegistry()
r.MustRegister(buildInfo, r.MustRegister(buildInfo,
updatedNodes, updatedNodes,
crdProcessingTime) nfrProcessingTime)
mux := http.NewServeMux() mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.HandlerFor(r, promhttp.HandlerOpts{})) mux.Handle("/metrics", promhttp.HandlerFor(r, promhttp.HandlerOpts{}))

View file

@ -980,6 +980,7 @@ func (m *nfdMaster) processNodeFeatureRule(nodeName string, features *nfdv1alpha
// Process all rule CRs // Process all rule CRs
processStart := time.Now() processStart := time.Now()
for _, spec := range ruleSpecs { for _, spec := range ruleSpecs {
t := time.Now()
switch { switch {
case klog.V(3).Enabled(): case klog.V(3).Enabled():
klog.InfoS("executing NodeFeatureRule", "nodefeaturerule", klog.KObj(spec), "nodeName", nodeName, "nodeFeatureRuleSpec", utils.DelayedDumper(spec.Spec)) klog.InfoS("executing NodeFeatureRule", "nodefeaturerule", klog.KObj(spec), "nodeName", nodeName, "nodeFeatureRuleSpec", utils.DelayedDumper(spec.Spec))
@ -1004,9 +1005,9 @@ func (m *nfdMaster) processNodeFeatureRule(nodeName string, features *nfdv1alpha
features.InsertAttributeFeatures(nfdv1alpha1.RuleBackrefDomain, nfdv1alpha1.RuleBackrefFeature, ruleOut.Labels) features.InsertAttributeFeatures(nfdv1alpha1.RuleBackrefDomain, nfdv1alpha1.RuleBackrefFeature, ruleOut.Labels)
features.InsertAttributeFeatures(nfdv1alpha1.RuleBackrefDomain, nfdv1alpha1.RuleBackrefFeature, ruleOut.Vars) features.InsertAttributeFeatures(nfdv1alpha1.RuleBackrefDomain, nfdv1alpha1.RuleBackrefFeature, ruleOut.Vars)
} }
nfrProcessingTime.WithLabelValues(spec.Name, nodeName).Observe(time.Since(t).Seconds())
} }
processingTime := time.Since(processStart) processingTime := time.Since(processStart)
crdProcessingTime.Set(float64(processingTime))
klog.V(2).InfoS("processed NodeFeatureRule objects", "nodeName", nodeName, "objectCount", len(ruleSpecs), "duration", processingTime) klog.V(2).InfoS("processed NodeFeatureRule objects", "nodeName", nodeName, "objectCount", len(ruleSpecs), "duration", processingTime)
return labels, extendedResources, taints return labels, extendedResources, taints