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

Remove Prometheus Metrics When Kubernetes Pods Are Deleted #1032

Open
borg-z opened this issue Oct 24, 2024 · 3 comments
Open

Remove Prometheus Metrics When Kubernetes Pods Are Deleted #1032

borg-z opened this issue Oct 24, 2024 · 3 comments
Assignees
Labels
kind/feature New feature or request
Milestone

Comments

@borg-z
Copy link

borg-z commented Oct 24, 2024

Motivation

Currently, Falcosidekick integrates with Prometheus to expose metrics related to Falco events. However, there is an issue where metrics associated with Kubernetes pods are not being cleaned up when those pods are deleted from the cluster. For example, when a pod named dns-cz89z is removed, the corresponding metric:

falco_events{k8s_ns_name="default", k8s_pod_name="dns-cz89z", rule="Exec from shell in container", tier="cluster"}

remains in Prometheus. Over time, this leads to an accumulation of metrics for pods that no longer exist, resulting in a cluttered metrics database and potential confusion when monitoring the cluster's state. This issue affects the reliability and accuracy of monitoring, making it difficult to distinguish between active and inactive resources.

Feature

Implement one of the following solutions:

  • Cleanup Mechanism:
    Automatically remove Prometheus metrics associated with Kubernetes pods when those pods are deleted from the cluster.

  • Change Metric Type:
    Modify the falco_events metric from a CounterVec to a GaugeVec

Alternatives

Additional context

Example of the issue in action:

After deleting the pod dns-cz89z, the following metric remains:

falco_events{k8s_ns_name="default", k8s_pod_name="dns-cz89z", rule="Exec from shell in container", tier="cluster"}

Over time, these stale metrics accumulate, leading to performance degradation and cluttered monitoring dashboards.

@borg-z borg-z added the kind/feature New feature or request label Oct 24, 2024
@Issif Issif self-assigned this Oct 24, 2024
@Issif Issif added this to the 2.30 milestone Oct 24, 2024
@Issif
Copy link
Member

Issif commented Oct 24, 2024

Hi,

I understand your point, but I don't see any way to tell falcosidekick that the source pod doesn't exist anymore. And I'll not change the metric type, to avoid any breaking change for the users. I don't know how other applications handle this situation.

@borg-z
Copy link
Author

borg-z commented Oct 24, 2024

Thanks for the quick reply! I will think of ways to solve the problem

@Issif
Copy link
Member

Issif commented Oct 24, 2024

Maybe a periodic restart might help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature or request
Projects
Status: To do
Development

No branches or pull requests

2 participants