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

When metrics are counted, discard the wrong container StartTime metrics #110880

Merged
merged 1 commit into from Jul 15, 2022

Conversation

yangjunmyfm192085
Copy link
Contributor

@yangjunmyfm192085 yangjunmyfm192085 commented Jun 30, 2022

What type of PR is this?

/kind bug

What this PR does / why we need it:

Incorrect metrics of container might be generated when pod start or stop.
Need to filter out wrong metrics.

Which issue(s) this PR fixes:

Fixes #109679

Special notes for your reviewer:

Does this PR introduce a user-facing change?

When metrics are counted, discard the wrong container StartTime metrics

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


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. kind/bug Categorizes issue or PR as related to a bug. 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. area/kubelet sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. sig/node Categorizes an issue or PR as relevant to SIG Node. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jun 30, 2022
@k8s-ci-robot k8s-ci-robot requested review from odinuge and wzshiming Jun 30, 2022
Copy link
Member

@wzshiming wzshiming left a comment

/lgtm

/aasign @dashpole

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 30, 2022
@dgrisonnet
Copy link
Member

dgrisonnet commented Jun 30, 2022

/assign
/triage accepted
/priority important-soon

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed 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 30, 2022
@dgrisonnet
Copy link
Member

dgrisonnet commented Jun 30, 2022

/approve

@dgrisonnet
Copy link
Member

dgrisonnet commented Jun 30, 2022

Looks like only David can approve this. @dashpole should we perhaps take an action item to add sig-instrumentation approvers and reviewers to kubelet metrics owner file?

/assign @dashpole

@pacoxu pacoxu added this to Needs Reviewer in SIG Node PR Triage Jul 6, 2022
@yangjunmyfm192085 yangjunmyfm192085 moved this from Needs Reviewer to Needs Approver in SIG Node PR Triage Jul 7, 2022
@dashpole
Copy link
Contributor

dashpole commented Jul 11, 2022

Sorry, just getting back from vacation. Sig node owns these packages, and I am an approver based on my previous work in sig-node. Anyone with pkg/kubelet can also approve, so it isn't just me, but it might be nice for someone else who spans both sigs (maybe @ehashman) to be an approver here as well. Did we find the root cause of the negative start time? This change is unobjectionable, but is probably hiding a real issue. With just this change, we would end up dropping metrics that might be valid.

@249043822
Copy link
Member

249043822 commented Jul 14, 2022

The containerStats.StartTime comes from the container.spec.CreateTime which is collected by cadvisor, so if the containerStats.StartTime is not initialized, it means that the container.spec.CreateTime was not set by cadvisor while it created the containerData. But see the code, normaly it is not possible for the CreateTime not set except in some extreme case. @bobbypage did you ever meet that the container.spec.CreateTime was not set by cadvisor? thanks
https://github.com/google/cadvisor/blob/master/container/common/helpers.go#L74-L99

@yangjunmyfm192085
Copy link
Contributor Author

yangjunmyfm192085 commented Jul 14, 2022

@dashpole This issue occurs when the pod terminates.
According to @249043822 's analysis, normal data statistics will not be affected,Only happens when the container state changes
so merge this pr we would not end up dropping metrics that might be valid. but we still need to find the root cause .
/cc @249043822 @bobbypage

@odinuge
Copy link
Member

odinuge commented Jul 14, 2022

It looks like @AtkinsChang was right in his comment on May 23. This appear to be from an "empty" time object.

This code snippet return the same as seen in the issue;

package main

import (
	"fmt"
	"time"
)
func main() {
	t := time.Time{}
	fmt.Printf("metric: %e, %d", float64(t.UnixNano())/float64(time.Second), t.Unix()*1000+int64(t.Nanosecond()/1000000))
}

Running it returns metric: -6.795365e+09, -62135596800000.

Can you please describe more about your setup here @yangjunmyfm1920? Is this due to CRI metrics returning the wrong value, or some other thing? It would be nice to be able to reproduce it to be sure about what is causing it. I can't see how that referred cadvisor PR can result in such a time.Time value, so I suspect its something else...

Do you know more about the CRI metrics pipeline ref. the above @dashpole?

Lgtm as well, but think we should find the root cause for this!

/lgtm

@dashpole
Copy link
Contributor

dashpole commented Jul 14, 2022

I'm not aware of the current status of CRI-O, but it used to still use cAdvisor for metrics. If that is the case, then it would be the cAdvisor code responsible for detecting container start time in this case.

@yangjunmyfm192085
Copy link
Contributor Author

yangjunmyfm192085 commented Jul 14, 2022

It looks like @AtkinsChang was right in his comment on May 23. This appear to be from an "empty" time object.

This code snippet return the same as seen in the issue;

package main

import (
	"fmt"
	"time"
)
func main() {
	t := time.Time{}
	fmt.Printf("metric: %e, %d", float64(t.UnixNano())/float64(time.Second), t.Unix()*1000+int64(t.Nanosecond()/1000000))
}

Running it returns metric: -6.795365e+09, -62135596800000.

Can you please describe more about your setup here @yangjunmyfm1920? Is this due to CRI metrics returning the wrong value, or some other thing? It would be nice to be able to reproduce it to be sure about what is causing it. I can't see how that referred cadvisor PR can result in such a time.Time value, so I suspect its something else...

Do you know more about the CRI metrics pipeline ref. the above @dashpole?

Lgtm as well, but think we should find the root cause for this!

/lgtm

I agree with @dashpole

Copy link
Contributor Author

@yangjunmyfm192085 yangjunmyfm192085 left a comment

/retest

@yangjunmyfm192085
Copy link
Contributor Author

yangjunmyfm192085 commented Jul 14, 2022

/test pull-kubernetes-unit

@yangjunmyfm192085
Copy link
Contributor Author

yangjunmyfm192085 commented Jul 14, 2022

/test pull-kubernetes-e2e-gce-ubuntu-containerd

@yangjunmyfm192085
Copy link
Contributor Author

yangjunmyfm192085 commented Jul 14, 2022

/test pull-kubernetes-e2e-kind

@k8s-triage-robot
Copy link

k8s-triage-robot commented Jul 14, 2022

The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass.

This bot retests PRs for certain kubernetes repos according to the following rules:

  • The PR does have any do-not-merge/* labels
  • The PR does not have the needs-ok-to-test label
  • The PR is mergeable (does not have a needs-rebase label)
  • The PR is approved (has cncf-cla: yes, lgtm, approved labels)
  • The PR is failing tests required for merge

You can:

/retest

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 14, 2022
@249043822
Copy link
Member

249043822 commented Jul 15, 2022

@yangjunmyfm192085 pls rebase

@k8s-ci-robot k8s-ci-robot removed lgtm Indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jul 15, 2022
Copy link
Member

@249043822 249043822 left a comment

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 15, 2022
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Jul 15, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 249043822, dashpole, dgrisonnet, wzshiming, yangjunmyfm192085

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 removed the lgtm Indicates that a PR is ready to be merged. label Jul 15, 2022
@249043822
Copy link
Member

249043822 commented Jul 15, 2022

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 15, 2022
Copy link
Contributor Author

@yangjunmyfm192085 yangjunmyfm192085 left a comment

/test pull-kubernetes-unit

@249043822
Copy link
Member

249043822 commented Jul 15, 2022

/test pull-kubernetes-unit

@yangjunmyfm192085
Copy link
Contributor Author

yangjunmyfm192085 commented Jul 15, 2022

/test pull-kubernetes-e2e-kind

@k8s-ci-robot k8s-ci-robot merged commit 6382266 into kubernetes:master Jul 15, 2022
14 checks passed
SIG Node PR Triage automation moved this from Needs Approver to Done Jul 15, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.25 milestone Jul 15, 2022
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. area/kubelet cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. sig/node Categorizes an issue or PR as relevant to SIG Node. 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
Development

Successfully merging this pull request may close these issues.

Incorrect metrics of container might be generated when pod start or stop
8 participants