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

[lownodeutilization]: Actual utilization: integration with Prometheus #1533

Merged

Conversation

ingvagabund
Copy link
Contributor

@ingvagabund ingvagabund commented Oct 11, 2024

Extend the actual utilization awareness with Prometheus integration.

For testing purposes:

    apiVersion: "descheduler/v1alpha2"
    kind: "DeschedulerPolicy"
    metricsProviders:
    - source: Prometheus
      prometheus:
        url: http://prometheus-kube-prometheus-prometheus.prom.svc.cluster.local
        authToken:
          secretReference:
            namespace: "kube-system"
            name: "authtoken"
    profiles:
      - name: ProfileName
        pluginConfig:
        - name: "LowNodeUtilization"
          args:
            thresholds:
              "MetricResource": 20
            targetThresholds:
              "MetricResource": 70
            metricsUtilization:
              source: Prometheus
              prometheus:
                query: instance:node_cpu:rate:sum
        plugins:
          balance:
            enabled:
              - "LowNodeUtilization"

TODO:

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 11, 2024
@fanhaouu
Copy link
Contributor

Hello, master. Due to the company's busy schedule previously, I only managed to complete half of the related KEP. I'm glad to see that you're working on this. It looks like you're aiming to reuse the current Node utilization logic. I have a few suggestions:

It should support different data sources, similar to PayPal's load-watcher.
It should support various real-time data processing algorithms. For instance, real-time calculations, using rate averages, or predictions based on EWMA + P95, similar to the approach used by autoscaler.
If the goal is to address real-time CPU hotspots, perhaps there’s no need to calculate the number of nodes below or above a certain threshold. Of course, you could also provide a switch to control this behavior.

Hope these suggestions help!

@ingvagabund
Copy link
Contributor Author

Hello sir :)

thank you for taking part in composing the out-of-tree descheduling plugin KEP.

It should support different data sources, similar to PayPal's load-watcher.

You are on the right track here. I'd like to get in touch with load-watcher maintainers and extend the codebase to provide a generic interface for accessing metrics related to pod utilization as well. Currently, only actual node utilization gets collected. Meantime, I am forming the code here to be able to better integrate with other utilization sources like metrics.

It should support various real-time data processing algorithms. For instance, real-time calculations, using rate averages, or predictions based on EWMA + P95, similar to the approach used by autoscaler.

This is where we can debate more. Thank you for sharing the specifics. There's an open issue for the pod autoscaler suggesting to introduce EMA: kubernetes/kubernetes#62235. Are you aware if there's a similar issue or a discussion for the cluster autoscaler? I'd love to learn more about how it's implemented there. Ultimately, the current plugin just needs to know which pod, when evicted, will improve the overall node/workload utilization when properly re-scheduled. I could see various ways to produce the utilization snapshot using various methods.

If the goal is to address real-time CPU hotspots, perhaps there’s no need to calculate the number of nodes below or above a certain threshold. Of course, you could also provide a switch to control this behavior.

I can see how evicting hotspot pods is related to consuming the metrics/real-time node utilization. In the current plugin context this is more suitable for a new/different plugin. I can also see how RemoveDuplicates can be extended to evict based on overall node utilization instead of the current counting approach. Not every plugin will need to consume metrics. Though, there can be common pieces shared across them through the descheduling framework.

@ingvagabund ingvagabund force-pushed the node-utilization-util-snapshot branch from c889a53 to 1f55c4d Compare October 15, 2024 10:18
@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 5, 2024
@ingvagabund ingvagabund force-pushed the node-utilization-util-snapshot branch 3 times, most recently from d744a96 to 800c92c Compare November 6, 2024 18:34
@ingvagabund
Copy link
Contributor Author

kubernetes/kubernetes#128663 to address the discrepancy in the fake metrics client node/pod metricses resource name.

@ingvagabund ingvagabund force-pushed the node-utilization-util-snapshot branch from f30f8a1 to 2e63411 Compare November 7, 2024 15:40
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 7, 2024
@ingvagabund ingvagabund force-pushed the node-utilization-util-snapshot branch 4 times, most recently from 0330902 to baa6650 Compare November 8, 2024 15:52
@ingvagabund
Copy link
Contributor Author

/test pull-descheduler-verify-master

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 13, 2024
@ingvagabund
Copy link
Contributor Author

Integration with kubernetes metrics in #1555.

@ingvagabund ingvagabund force-pushed the node-utilization-util-snapshot branch from baa6650 to 2442967 Compare November 16, 2024 09:09
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 16, 2024
@ingvagabund ingvagabund force-pushed the node-utilization-util-snapshot branch 5 times, most recently from 477104c to e6e5bf9 Compare November 16, 2024 19:04
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 11, 2024
@ingvagabund ingvagabund force-pushed the node-utilization-util-snapshot branch from d143aad to 0f0c525 Compare March 11, 2025 14:05
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 11, 2025
@googs1025
Copy link
Member

/cc

@k8s-ci-robot k8s-ci-robot requested a review from googs1025 March 12, 2025 05:25
}, nil
if namespacedSharedInformerFactory != nil && deschedulerPolicy.Prometheus != nil {
namespacedSharedInformerFactory.Core().V1().Secrets().Informer().AddEventHandler(desch.eventHandler())
desch.namespacedSecretsLister = namespacedSharedInformerFactory.Core().V1().Secrets().Lister().Secrets(deschedulerPolicy.Prometheus.AuthToken.SecretReference.Namespace)

Choose a reason for hiding this comment

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

nil check for AuthToken?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -462,7 +604,19 @@ func RunDeschedulerStrategies(ctx context.Context, rs *options.DeschedulerServer
}
}

if namespacedSharedInformerFactory != nil {

Choose a reason for hiding this comment

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

Can we create an extra variable similar to reconcileInClusterSAToken to condition this? At this point it is not entirerly clean why it depends on namespacedSharedInformerFactory

Choose a reason for hiding this comment

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

Actually, sa token and secret reconciller are mutually exclusive. Can we use iota enum here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

README.md Outdated
metrics outside of the kubernetes metrics server. The query is expected to return a vector of values for
each node. The values are expected to be any real number within <0; 1> interval. During eviction only
a single pod is evicted at most from each overutilized node. There's currently no support for evicting
more. Kubernetes metric server takes precedence over Prometheus.

Choose a reason for hiding this comment

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

+1, we can update the text above now

client._nodeUtilization = make(map[string]map[v1.ResourceName]*resource.Quantity)
client._pods = make(map[string][]*v1.Pod)

results, warnings, err := promv1.NewAPI(client.promClient).Query(context.TODO(), client.promQuery, time.Now())

Choose a reason for hiding this comment

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

context passing could be still improved

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 13, 2025
@ingvagabund ingvagabund force-pushed the node-utilization-util-snapshot branch from 0f0c525 to 4a9a008 Compare March 14, 2025 14:21
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 14, 2025
@ingvagabund ingvagabund force-pushed the node-utilization-util-snapshot branch 3 times, most recently from 8085495 to d7421d7 Compare March 14, 2025 15:14
@ingvagabund ingvagabund force-pushed the node-utilization-util-snapshot branch from 1832705 to 893bda5 Compare March 15, 2025 12:14
pkg/api/types.go Outdated
URL string
// authToken used for authentication with the prometheus server.
// If not set the in cluster authentication token for the descheduler service
// account is read from the container's file system is read.

Choose a reason for hiding this comment

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

Suggested change
// account is read from the container's file system is read.
// account is read from the container's file system.


type Prometheus struct {
URL string `json:"url,omitempty"`
// If not set the in cluster authentication token from the container's file system is read.

Choose a reason for hiding this comment

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

needs update as well

if d.previousPrometheusClientTransport != nil {
d.previousPrometheusClientTransport.CloseIdleConnections()
}
d.previousPrometheusClientTransport = nil

Choose a reason for hiding this comment

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

@ingvagabund ingvagabund force-pushed the node-utilization-util-snapshot branch from 893bda5 to d365253 Compare March 17, 2025 15:21
@atiratree
Copy link

LGTM

@ingvagabund
Copy link
Contributor Author

@atiratree thank you for your patience and expertise. Making the code much more better.

Squashing the comments before the final merge.

@ingvagabund ingvagabund force-pushed the node-utilization-util-snapshot branch from d365253 to e283c31 Compare March 17, 2025 15:26
@ingvagabund ingvagabund added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Mar 17, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

This pull-request has been approved by:

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 merged commit 6ab73d6 into kubernetes-sigs:master Mar 17, 2025
9 checks passed
@ingvagabund ingvagabund deleted the node-utilization-util-snapshot branch March 17, 2025 15:53
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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.

5 participants