Skip to content

Commit

Permalink
Add a metric to measure how long resolving policy templates take
Browse files Browse the repository at this point in the history
Signed-off-by: Chunxi Luo <chuluo@redhat.com>
  • Loading branch information
ChunxiAlexLuo committed Nov 29, 2022
1 parent 3ef4232 commit 873cd66
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions controllers/configurationpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,24 @@ var policyEvalCounter = prometheus.NewCounterVec(
[]string{"name"},
)

var plcTempsProcessSecondsCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "config_policy_templates_process_seconds_total",
Help: "The total seconds taken while processing the configuration policy templates. Use this alongside " +
"config_policy_templates_process_total.",
},
[]string{"name"},
)

var plcTempsProcessCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "config_policy_templates_process_total",
Help: "The total number of processes of the configuration policy templates. Use this alongside " +
"config_policy_templates_process_seconds_total.",
},
[]string{"name"},
)

var compareObjSecondsCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "compare_objects_seconds_total",
Expand All @@ -117,6 +135,8 @@ func init() {
metrics.Registry.MustRegister(evalLoopHistogram)
metrics.Registry.MustRegister(policyEvalSecondsCounter)
metrics.Registry.MustRegister(policyEvalCounter)
metrics.Registry.MustRegister(plcTempsProcessSecondsCounter)
metrics.Registry.MustRegister(plcTempsProcessCounter)
metrics.Registry.MustRegister(compareObjSecondsCounter)
metrics.Registry.MustRegister(compareObjEvalCounter)
}
Expand Down Expand Up @@ -179,6 +199,8 @@ func (r *ConfigurationPolicyReconciler) Reconcile(ctx context.Context, request c
// If the metric was not deleted, that means the policy was never evaluated so it can be ignored.
_ = policyEvalSecondsCounter.DeleteLabelValues(request.Name)
_ = policyEvalCounter.DeleteLabelValues(request.Name)
_ = plcTempsProcessSecondsCounter.DeleteLabelValues(request.Name)
_ = plcTempsProcessCounter.DeleteLabelValues(request.Name)
_ = compareObjEvalCounter.DeletePartialMatch(prometheus.Labels{"config_policy_name": request.Name})
_ = compareObjSecondsCounter.DeletePartialMatch(prometheus.Labels{"config_policy_name": request.Name})
}
Expand Down Expand Up @@ -760,6 +782,8 @@ func (r *ConfigurationPolicyReconciler) handleObjectTemplates(plc policyv1.Confi
log.V(2).Info("Processing the object templates", "count", len(plc.Spec.ObjectTemplates))

if !disableTemplates {
startTime := time.Now().UTC()

for _, objectT := range plc.Spec.ObjectTemplates {
// first check to make sure there are no hub-templates with delimiter - {{hub
// if one exists, it means the template resolution on the hub did not succeed.
Expand Down Expand Up @@ -853,6 +877,11 @@ func (r *ConfigurationPolicyReconciler) handleObjectTemplates(plc policyv1.Confi
objectT.ObjectDefinition.Raw = resolvedTemplate.ResolvedJSON
}
}

endTime := time.Now().UTC()
durationSeconds := float64(endTime.Sub(startTime)) / float64(time.Second)
plcTempsProcessSecondsCounter.WithLabelValues(plc.GetName()).Add(durationSeconds)
plcTempsProcessCounter.WithLabelValues(plc.GetName()).Inc()
}

// Parse and fetch details from each object in each objectTemplate, and gather namespaces if required
Expand Down

0 comments on commit 873cd66

Please sign in to comment.