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

Delete pod stats on pod deleted #153

Merged
merged 1 commit into from
Nov 2, 2022
Merged

Conversation

roivaz
Copy link
Member

@roivaz roivaz commented Oct 31, 2022

This PR adds a garbage collector to delete stats of pods that have been deleted. It is basically a k8s informer that reacts to pod deletion events by removing all the stats related to the pod from the stats cache.

The PR also removes all stats that had information about the grpc stream_id. This was previously used to cleanup stats but it was producing inconsistent results .

/kind bug
/priority important-soon
/assign

@3scale-robot 3scale-robot added kind/bug Categorizes issue or PR as related to a bug. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next sprint. needs-size Indicates a PR or issue lacks a `size/foo` label and requires one. labels Oct 31, 2022
@3scale-robot 3scale-robot added size/M Requires about a day to complete the PR or the issue. and removed needs-size Indicates a PR or issue lacks a `size/foo` label and requires one. labels Oct 31, 2022
Comment on lines 13 to 41
func (s *Stats) RunGC(client kubernetes.Interface, namespace string, stopCh <-chan struct{}) error {

factory := informers.NewSharedInformerFactoryWithOptions(client, time.Hour*24, informers.WithNamespace(namespace))
podInformer := factory.Core().V1().Pods()
podInformer.Informer().AddEventHandler(
cache.ResourceEventHandlerFuncs{
DeleteFunc: deleteStatsForDeletedPodsFn(s),
},
)

factory.Start(stopCh)
// wait for the initial synchronization of the local cache.
if !cache.WaitForCacheSync(stopCh, podInformer.Informer().HasSynced) {
return errors.New("failed to sync")
}

return nil

}

func deleteStatsForDeletedPodsFn(s *Stats) func(obj interface{}) {

return func(obj interface{}) {
switch o := obj.(type) {
case *corev1.Pod:
s.DeleteKeysByFilter(o.GetName())
}
}

}
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the relevant code that deletes the pod related stats when a pod is deleted.

@slopezz
Copy link
Member

slopezz commented Oct 31, 2022

/lgtm

@3scale-robot 3scale-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 31, 2022
@3scale-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 66624cecbcedd5867bb20434503c03be7bc7651f

@raelga
Copy link
Contributor

raelga commented Oct 31, 2022

/lgtm

@roivaz
Copy link
Member Author

roivaz commented Oct 31, 2022

/approve

@3scale-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: roivaz

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@3scale-robot 3scale-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 31, 2022
@roivaz
Copy link
Member Author

roivaz commented Oct 31, 2022

/ok-to-test

@3scale-robot 3scale-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Oct 31, 2022
@roivaz roivaz removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 31, 2022
@3scale-robot 3scale-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed lgtm Indicates that a PR is ready to be merged. labels Nov 2, 2022
@roivaz roivaz added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed ok-to-test Indicates a non-member PR verified by an org member that is safe to test. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Nov 2, 2022
@3scale-robot 3scale-robot merged commit 4eae756 into main Nov 2, 2022
@3scale-robot 3scale-robot deleted the fix/pod-stats-cleanup branch November 2, 2022 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next sprint. size/M Requires about a day to complete the PR or the issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants