Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix metrics collection in case of duplicate policy names #3006

Merged
merged 3 commits into from
Oct 17, 2024

Conversation

lambdanis
Copy link
Contributor

@lambdanis lambdanis commented Oct 16, 2024

This fixes a metrics collection error that was occurring in case there were
multiple namespaced policies with the same name. The metrics collector is
iterating over all policies and reports tetragon_tracingpolicy_kernel_memory_bytes
metric for each of them. The metric used to be labeled only with the policy
name, so in case there was a second policy with the same name, the collector
reported a duplicate what causes the entire metrics collection job to fail.
Adding a policy_namespace label should prevent duplicates.

There is an underlying assumption that each policy returned by
ListTracingPolicies has a unique (name, namespace) tuple - if it's not the
case, then metrics collection might fail again. Also, I'm not sure if
per-policy memory metrics should be reported for policies in states different
than loaded. Currently they are - I didn't change that behaviour, but it's now
covered by tests.

Fixes: a5301b8 ("pkg/metrics: add metrics for policy kernel memory us")

Despite the name, it's identical to TestingEnableAndReset and unused.

Signed-off-by: Anna Kapuscinska <anna@isovalent.com>
@lambdanis lambdanis added kind/bug Something isn't working release-note/misc This PR makes changes that have no direct user impact. labels Oct 16, 2024
@lambdanis lambdanis requested review from mtardy and a team as code owners October 16, 2024 23:56
@lambdanis lambdanis force-pushed the pr/lambdanis/fix-policymetrics branch from e95d6e4 to 5130118 Compare October 16, 2024 23:57
Copy link
Contributor

@kkourt kkourt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! Left a minor comment which would be great if fixed before merging.

pkg/testutils/sensors/sensors.go Outdated Show resolved Hide resolved
Add GetTestSensorManagerWithDummyPF function to testutils/sensors, that creates
a dummy policy filter instead of using the global one. The only difference
between dummy and disabled policy filter is that dummy doesn't return an error
when adding/deleting a policy, so it allows to load a namespaced policy without
maintaining the policy state. This can be useful to test functionalities that
depend on the sensor manager but not on the policy filter state, e.g. policy
metrics.

Signed-off-by: Anna Kapuscinska <anna@isovalent.com>
This fixes a metrics collection error that was occurring in case there were
multiple namespaced policies with the same name. The metrics collector is
iterating over all policies and reports tetragon_tracingpolicy_kernel_memory_bytes
metric for each of them. The metric used to be labeled only with the policy
name, so in case there was a second policy with the same name, the collector
reported a duplicate what causes the entire metrics collection job to fail.
Adding a policy_namespace label should prevent duplicates.

There is an underlying assumption that each policy returned by
ListTracingPolicies has a unique (name, namespace) tuple - if it's not the
case, then metrics collection might fail again. Also, I'm not sure if
per-policy memory metrics should be reported for policies in states different
than loaded. Currently they are - I didn't change that behaviour, but it's now
covered by tests.

Fixes: a5301b8 ("pkg/metrics: add metrics for policy kernel memory us")

Signed-off-by: Anna Kapuscinska <anna@isovalent.com>
@lambdanis lambdanis force-pushed the pr/lambdanis/fix-policymetrics branch from 5130118 to 10ed475 Compare October 17, 2024 17:16
Copy link

netlify bot commented Oct 17, 2024

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit 10ed475
🔍 Latest deploy log https://app.netlify.com/sites/tetragon/deploys/67114687a1bb5d0008c721ef
😎 Deploy Preview https://deploy-preview-3006--tetragon.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@lambdanis lambdanis merged commit 80ee2a1 into cilium:main Oct 17, 2024
46 checks passed
@mtardy
Copy link
Member

mtardy commented Oct 18, 2024

oh thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working release-note/misc This PR makes changes that have no direct user impact.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants