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

[kwok] Provide generic functions that enable it to simulate data for any indicator (Node) #555

Merged

Conversation

nikola-jokic
Copy link
Contributor

@nikola-jokic nikola-jokic commented Apr 28, 2023

What type of PR is this?

/kind feature

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #199

Does this PR introduce a user-facing change?

[kwok] Provide generic functions that enable it to simulate data for any indicator

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 28, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @nikola-jokic. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 28, 2023
@netlify
Copy link

netlify bot commented Apr 28, 2023

Deploy Preview for k8s-kwok canceled.

Name Link
🔨 Latest commit a7fa8aa
🔍 Latest deploy log https://app.netlify.com/sites/k8s-kwok/deploys/648931c7fcba070008bbe5ba

@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Apr 28, 2023
@nikola-jokic
Copy link
Contributor Author

This is currently just a proposed way of exposing metrics from the controller, to make sure package structure is okay.
Looking forward to your suggestions @wzshiming 😄

@wzshiming
Copy link
Member

wzshiming commented May 1, 2023

The package structure is good to me,
I would like to minimize hard-coded metrics and use configuration whenever possible 😄

@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 4, 2023
@wzshiming
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 4, 2023
@nikola-jokic nikola-jokic force-pushed the nikola-jokic/metrics branch from 7330ed0 to 99456b1 Compare May 12, 2023 09:14
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 12, 2023
@@ -277,6 +284,7 @@ func (c *NodeController) watchResources(ctx context.Context, opt metav1.ListOpti
node := event.Object.(*corev1.Node)
if c.need(node) {
c.putNodeInfo(node)
c.applyMetrics(ctx, node)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we delete the registry when the node is deleted, or should we set values to 0?

@nikola-jokic
Copy link
Contributor Author

nikola-jokic commented May 12, 2023

startedContainersTotal is kind of tricky. The fastest approach is to do it on the Pod Controller. Basically, this function would evaluate to true if node.metadata.name is pod's NodeName, and then increase counter on true.
Is there a better way I'm not seeing?

Update:
My first suggestion would not really work in case we have startedContainersTotal used as a part of the expression... We can have a counter per node to hold a state and then apply it for a node. Querying the API would be really expensive

@nikola-jokic nikola-jokic changed the title Nikola jokic/metrics [kwok] Provide generic functions that enable it to simulate data for any indicator (Node) May 12, 2023
@nikola-jokic
Copy link
Contributor Author

/cc @wzshiming
This is what I have so far, and it was working fine locally (manually tested) 😄
Need to add tests and hopefully find places to refactor, but I would appreciate your review! ☺️

@k8s-ci-robot k8s-ci-robot requested a review from wzshiming May 17, 2023 15:34
}

// Set is used to increment value at le bucket and add val to the sum.
func (h *Histogram) Set(le string, val float64) (err error) {
Copy link
Member

@wzshiming wzshiming Jun 9, 2023

Choose a reason for hiding this comment

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

I tested it and it didn't behave as I expected, so I refactored it and wzshiming@e4f49e3 it meets expectations 😄.

Apply my patch git apply <(curl https://github.com/wzshiming/kwok/commit/e4f49e3acf3ae0915cb3898e8f9cbf326888aa93.patch)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Amazing, sorry I could not make it work right away, I did not exactly know how it should behave 😄
I tried applying patch but it produced an error
Do you mind pushing on the branch 😄

Copy link
Member

Choose a reason for hiding this comment

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

BTY, I added auto docs for API, so this PR needs to rebase then exec ./hack/update-api-docs.sh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rebased and executed
I'll apply the patch by hand. git shows error (patch does not apply)

@nikola-jokic nikola-jokic force-pushed the nikola-jokic/metrics branch from 34e0a90 to e120819 Compare June 9, 2023 17:44
@nikola-jokic
Copy link
Contributor Author

/retest

// MetricSpec holds spec for metrics.
type MetricSpec struct {
// Path is a restful service path.
Path string `json:"path"`
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion, if kwokctl is using this configuration, we should add this Path to the Prometheus collection target, so we can open the web of Prometheus and see the chart of the configured metrics.

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sounds great as long as we keep it static
If you see it become dynamic (having route like /nodes/{nodeName}) in the future, is it okay to opt-out of the prometheus collection targets?

Copy link
Member

@wzshiming wzshiming Jun 12, 2023

Choose a reason for hiding this comment

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

Don't worry, Prometheus supports rules for dynamically discovered targets.

https://prometheus.io/docs/prometheus/latest/configuration/configuration/#http_sd_config

test/kwokctl/metric.yaml Outdated Show resolved Hide resolved
}

// EvaluateMetric evaluates a cel program and returns a metric value
func (e *Evaluator) EvaluateMetric(node *corev1.Node) (float64, error) {
Copy link
Member

@wzshiming wzshiming Jun 12, 2023

Choose a reason for hiding this comment

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

Let's keep it in the same style as EvaluateString.

// gen-crd-api-reference-docs
_ "github.com/ahmetb/gen-crd-api-reference-docs"
// code-generator
Copy link
Member

Choose a reason for hiding this comment

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

Revert this file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh sure, sorry about that

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 12, 2023
@nikola-jokic nikola-jokic force-pushed the nikola-jokic/metrics branch from 5ef07f7 to 077008e Compare June 12, 2023 13:17
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 12, 2023
help: "[ALPHA] Cumulative number of containers started"
kind: counter
value: 'startedContainersTotal( node.metadata.name )'
- name: kubelet_pleg_relist_duration_seconds
Copy link
Member

Choose a reason for hiding this comment

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

Look nice 😄

image

pkg/kwok/controllers/pod_controller.go Show resolved Hide resolved
hack/tools/tools.go Outdated Show resolved Hide resolved
@wzshiming
Copy link
Member

BTY, commits are too much, squash it 😄

@nikola-jokic nikola-jokic force-pushed the nikola-jokic/metrics branch from 08ccda5 to bb96667 Compare June 13, 2023 15:10
@wzshiming wzshiming force-pushed the nikola-jokic/metrics branch 2 times, most recently from 0c3021c to ac3cefd Compare June 14, 2023 03:17
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 14, 2023
Co-authored-by: Shiming Zhang <wzshiming@foxmail.com>
@wzshiming wzshiming force-pushed the nikola-jokic/metrics branch from ac3cefd to a7fa8aa Compare June 14, 2023 03:19
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 14, 2023
Copy link
Member

@wzshiming wzshiming left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm

Thank you for your contribution!

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: nikola-jokic, wzshiming

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 Jun 14, 2023
@nikola-jokic
Copy link
Contributor Author

Thank you for doing many reviews and improvements!

@k8s-ci-robot k8s-ci-robot merged commit e619889 into kubernetes-sigs:main Jun 14, 2023
@nikola-jokic nikola-jokic deleted the nikola-jokic/metrics branch June 14, 2023 07:00
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[kwok] Provide Kubelet metrics
3 participants