Skip to content

Commit

Permalink
ignore config policy with no parent for metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Will Kutler <wkutler@redhat.com>
  • Loading branch information
willkutler committed Dec 6, 2022
1 parent 0ef5339 commit 1b8207e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions controllers/configurationpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,10 @@ func (r *ConfigurationPolicyReconciler) handleObjectTemplates(plc policyv1.Confi

r.checkRelatedAndUpdate(plc, relatedObjects, oldRelated, statusChanged)

parent := plc.OwnerReferences[0]
policyUserErrorsGauge.WithLabelValues(parent.Name, plc.GetName(), "invalid-template").Add(1)
if len(plc.OwnerReferences) > 0 {
parent := plc.OwnerReferences[0]
policyUserErrorsGauge.WithLabelValues(parent.Name, plc.GetName(), "invalid-template").Add(1)
}

return
}
Expand Down Expand Up @@ -1631,8 +1633,10 @@ func (r *ConfigurationPolicyReconciler) getMapping(

log.Error(err, "Could not map resource, do you have the CRD deployed?", "kind", kind)

parent := policy.OwnerReferences[0]
policyUserErrorsGauge.WithLabelValues(parent.Name, policy.GetName(), "no-object-CRD").Add(1)
if len(policy.OwnerReferences) > 0 {
parent := policy.OwnerReferences[0]
policyUserErrorsGauge.WithLabelValues(parent.Name, policy.GetName(), "no-object-CRD").Add(1)
}
}

errMsg := err.Error()
Expand Down Expand Up @@ -2455,8 +2459,10 @@ func (r *ConfigurationPolicyReconciler) addForUpdate(policy *policyv1.Configurat
} else if err != nil {
policyLog.Error(err, "Could not update status, retrying next loop")

parent := policy.OwnerReferences[0]
policySystemErrorsGauge.WithLabelValues(parent.Name, policy.GetName(), "status-update-failed").Add(1)
if len(policy.OwnerReferences) > 0 {
parent := policy.OwnerReferences[0]
policySystemErrorsGauge.WithLabelValues(parent.Name, policy.GetName(), "status-update-failed").Add(1)
}
}
}

Expand Down

0 comments on commit 1b8207e

Please sign in to comment.