diff --git a/pkg/metrics/policyfiltermetrics/policyfiltermetrics.go b/pkg/metrics/policyfiltermetrics/policyfiltermetrics.go index 0f3b8693734..d27e363a915 100644 --- a/pkg/metrics/policyfiltermetrics/policyfiltermetrics.go +++ b/pkg/metrics/policyfiltermetrics/policyfiltermetrics.go @@ -53,8 +53,17 @@ var ( }, []string{"subsys", "op"}) ) +var ( + PolicyFilterHookContainerNameMissingMetrics = prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: consts.MetricsNamespace, + Name: "policyfilter_hook_container_name_missing_total", + Help: "The total number of operations when the container name was missing in the OCI hook", + ConstLabels: nil, + }) +) + func InitMetrics(registry *prometheus.Registry) { - registry.MustRegister(PolicyFilterOpMetrics) + registry.MustRegister(PolicyFilterOpMetrics, PolicyFilterHookContainerNameMissingMetrics) // Initialize metrics with labels PolicyFilterOpMetrics.WithLabelValues(RTHooksSubsys.String(), AddContainerOperation.String()).Add(0) @@ -73,3 +82,7 @@ func OpInc(subsys Subsys, op Operation) { subsys.String(), op.String(), ).Inc() } + +func ContNameMissInc() { + PolicyFilterHookContainerNameMissingMetrics.Inc() +} diff --git a/pkg/policyfilter/rthooks/rthooks.go b/pkg/policyfilter/rthooks/rthooks.go index 65c6d1eac5b..8a97d16041e 100644 --- a/pkg/policyfilter/rthooks/rthooks.go +++ b/pkg/policyfilter/rthooks/rthooks.go @@ -97,6 +97,7 @@ func createContainerHook(_ context.Context, arg *rthooks.CreateContainerArg) err containerName := arg.Req.ContainerName if containerName == "" { log.Warnf("failed to find container information for %s, but will continue", containerID) + policyfiltermetrics.ContNameMissInc() } log.WithFields(logrus.Fields{ @@ -107,10 +108,13 @@ func createContainerHook(_ context.Context, arg *rthooks.CreateContainerArg) err "container-name": containerName, }).Trace("policyfilter: add pod container") cgid := policyfilter.CgroupID(cgID) - if err := pfState.AddPodContainer(policyfilter.PodID(podID), namespace, pod.Labels, containerID, cgid, containerName); err != nil { + err = pfState.AddPodContainer(policyfilter.PodID(podID), namespace, pod.Labels, containerID, cgid, containerName) + policyfiltermetrics.OpInc(policyfiltermetrics.RTHooksSubsys, policyfiltermetrics.AddContainerOperation) + + if err != nil { log.WithError(err).Warn("failed to update policy filter, aborting hook.") + return err } - policyfiltermetrics.OpInc(policyfiltermetrics.RTHooksSubsys, policyfiltermetrics.AddContainerOperation) return nil }