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

podgc metrics should count all pod deletion behaviors #118480

Merged
merged 1 commit into from Jul 13, 2023

Conversation

carlory
Copy link
Member

@carlory carlory commented Jun 6, 2023

What type of PR is this?

/kind feature

What this PR does / why we need it:

Literally, force_delete_pods_total and force_delete_pod_errors_total metrics should count all the behaviors of the gc controller that forcefully delete pods.

The reason label indicates the reason why the pod was forcibly deleted by GC

Special notes for your reviewer:

Does this PR introduce a user-facing change?

`force_delete_pods_total ` and `force_delete_pod_errors_total ` metrics count all pod deletion behaviors.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

- [KEP]: https://github.com/kubernetes/enhancements/issues/2268

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jun 6, 2023
@k8s-ci-robot k8s-ci-robot added sig/apps Categorizes an issue or PR as relevant to SIG Apps. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jun 6, 2023
@carlory carlory changed the title gc metrics should count all pod deletion behaviors podgc metrics should count all pod deletion behaviors Jun 6, 2023
@carlory
Copy link
Member Author

carlory commented Jun 6, 2023

/cc @xing-yang

if err != nil {
t.Errorf("Error getting actualDeletingPodsTotal")
}
if actualDeletingPodsTotal != float64(inputDeletingPodsTotal) {
t.Errorf("Expected desiredDeletingPodsTotal to be %d, got %v", inputDeletingPodsTotal, actualDeletingPodsTotal)
}

actualDeletingPodsErrorTotal, err := metricstestutil.GetCounterMetricValue(deletingPodsErrorTotal.WithLabelValues())
actualDeletingPodsErrorTotal, err := metricstestutil.GetCounterMetricValue(deletingPodsErrorTotal.WithLabelValues("out-of-service"))
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add unit tests for all the other labels?

Copy link
Member Author

Choose a reason for hiding this comment

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

added.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 6, 2023
@carlory
Copy link
Member Author

carlory commented Jun 12, 2023

/cc @xing-yang @jpbetz @gnufied

@carlory
Copy link
Member Author

carlory commented Jun 13, 2023

/triage accepted
/assign @janetkuo

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 13, 2023
@carlory
Copy link
Member Author

carlory commented Jun 14, 2023

/check-cla

@carlory
Copy link
Member Author

carlory commented Jun 14, 2023

/easycla

@xing-yang
Copy link
Contributor

/assign @gnufied

@@ -179,11 +179,11 @@ func (gcc *PodGCController) gcTerminating(ctx context.Context, pods []*v1.Pod) {
wait.Add(1)
go func(pod *v1.Pod) {
defer wait.Done()
deletingPodsTotal.WithLabelValues().Inc()
deletingPodsTotal.WithLabelValues("out-of-service").Inc()
Copy link
Member

Choose a reason for hiding this comment

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

Can we move these dimensions such as out-of-service, terminated etc in well defined constants, so as it gets easier to reuse them without potentially having typos in the code?

Copy link
Member Author

Choose a reason for hiding this comment

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

@gnufied updated.

@@ -213,9 +213,11 @@ func (gcc *PodGCController) gcTerminated(ctx context.Context, pods []*v1.Pod) {
wait.Add(1)
go func(pod *v1.Pod) {
defer wait.Done()
deletingPodsTotal.WithLabelValues("terminated").Inc()
Copy link
Member

Choose a reason for hiding this comment

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

I am thinking, if we should emit this metric before or after the completion of delete operation. As it stands, we emit when we start deleting.

Also, I think we should add namespace to these metrics, so as if we force deleted pods from a particular namespace, a k8s admin can investigate why that happened. @msau42 what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Waiting for a feedback from @msau42

Copy link
Member

Choose a reason for hiding this comment

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

namespace would be good to add. I have a slight preference to add the metric after completion. Do we care about deletion errors?

Copy link
Member Author

Choose a reason for hiding this comment

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

@xing-yang what do you think?

@carlory carlory force-pushed the gc_metrics branch 3 times, most recently from b09a043 to 04ac55e Compare July 3, 2023 02:32
@carlory
Copy link
Member Author

carlory commented Jul 3, 2023

@xing-yang @msau42 @gnufied the namespace label is added.

@carlory
Copy link
Member Author

carlory commented Jul 3, 2023

/test pull-kubernetes-node-e2e-containerd

t.Helper()

actualDeletingPodsTotal, err := metricstestutil.GetCounterMetricValue(deletingPodsTotal.WithLabelValues())
actualDeletingPodsTotal, err := metricstestutil.GetCounterMetricValue(metrics.DeletingPodsTotal.WithLabelValues("", reason))
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the namespace for these pods?

Copy link
Member Author

Choose a reason for hiding this comment

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

@gnufied
Copy link
Member

gnufied commented Jul 6, 2023

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 6, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: b87e82ce5aab1c88b98e1351fc76a6dd201c19ed

@carlory
Copy link
Member Author

carlory commented Jul 7, 2023

/assign @janetkuo

@xing-yang
Copy link
Contributor

/lgtm

@xing-yang
Copy link
Contributor

/assign @andrewsykim

@xing-yang
Copy link
Contributor

/assign @soltysh

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: carlory, soltysh

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 13, 2023
@soltysh
Copy link
Contributor

soltysh commented Jul 13, 2023

/priority important-longterm

@k8s-ci-robot k8s-ci-robot added priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jul 13, 2023
@k8s-ci-robot k8s-ci-robot merged commit cd92159 into kubernetes:master Jul 13, 2023
11 of 12 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.28 milestone Jul 13, 2023
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/apps Categorizes an issue or PR as relevant to SIG Apps. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants