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

cleanup(scheduler): move metricRecorder to metrics package #115519

Merged
merged 1 commit into from Feb 16, 2023

Conversation

sanposhiho
Copy link
Member

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

#115083 wants to record plugin_execution_duration_seconds metric for PreEnqueue in the scheduling queue.
Currently, all extension points record plugin_execution_duration_seconds via metricsRecorder which records the metrics in a separate goroutine. Then, it's better to utilize this for PreEnqueue as well for better performance.

The scheduling queue package ("k8s.io/kubernetes/pkg/scheduler/internal/queue") is outside of the framework package and the metricsRecorder in the frameworkImpl struct isn't callable from the scheduling queue.

This PR just moves it to pkg/scheduler/metrics/metric_recorder.go with renaming it to MetricsAsyncRecorder so that we can initialize MetricsAsyncRecorder outside the framework and use the same MetricsAsyncRecorder object both in the framework and the scheduling queue (will be done in another PR).

Which issue(s) this PR fixes:

Related to #115083

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

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


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/L Denotes a PR that changes 100-499 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. labels Feb 4, 2023
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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 needs-priority Indicates a PR lacks a `priority/foo` label and requires one. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Feb 4, 2023
@sanposhiho sanposhiho force-pushed the move-metric-recorder branch 2 times, most recently from 4ab9d46 to 18ef9d6 Compare February 5, 2023 00:58

// ObservePluginDurationAsync observes the plugin_execution_duration_seconds metric.
// The metric will be flushed to Prometheus asynchronously.
func (r *MetricAsyncRecorder) ObservePluginDurationAsync(extensionPoint, pluginName, status string, value float64) {
Copy link
Member

Choose a reason for hiding this comment

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

is it intentional to change the type of status from Status to string?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. We cannot use k8s.io/kubernetes/pkg/scheduler/framework here due to the import cycle.

# When we import k8s.io/kubernetes/pkg/scheduler/framework here,
# and build the scheduler.

package k8s.io/kubernetes/pkg/scheduler/metrics
	imports k8s.io/kubernetes/pkg/scheduler/framework
	imports k8s.io/kubernetes/pkg/scheduler/framework/parallelize
	imports k8s.io/kubernetes/pkg/scheduler/metrics: import cycle not allowed

@Huang-Wei
Copy link
Member

/lgtm
/approve

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

LGTM label has been added.

Git tree hash: c3e6307bdb5f86d612868cd1ce7c3f537334d52e

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Huang-Wei, sanposhiho

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 Feb 16, 2023
"k8s.io/component-base/metrics"
"time"

k8smetrics "k8s.io/component-base/metrics"
Copy link
Member

Choose a reason for hiding this comment

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

/hold
can we use metrics directly here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. Fixed.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 16, 2023
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 16, 2023
@kerthcet
Copy link
Member

What do you mean use the same MetricsAsyncRecorder object both in the framework and the scheduling queue, they're different recorder. @sanposhiho

@sanposhiho
Copy link
Member Author

I'm not sure I understood correctly what you mean but I'd like to do (in the next PR) is:

  • store the same MetricsAsyncRecorder object in PriorityQueue struct.
  • run priorityqueue.metricsRecorder.ObservePluginDurationAsync("PreEnqueue", pl.Name(), status.Code().String(), metrics.SinceInSeconds(startTime)) in runPreEnqueuePlugins.

@sanposhiho
Copy link
Member Author

Why the "same" MetricsAsyncRecorder object? -> Each MetricsAsyncRecorder object has one goroutine to flush metrics periodically. To reduce the num of goroutines working in the scheduler, it's better to use the same MetricsAsyncRecorder object in both the framework and the priorityqueue.

@kerthcet
Copy link
Member

Got the idea, I thought the same record was

activeQ: heap.NewWithRecorder(podInfoKeyFunc, comp, metrics.NewActivePodsRecorder()),

/lgtm
/hold cancel
/retest

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 16, 2023
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 16, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: a1086fa25a7c36e54d9981960677cd682a6f8b3c

@k8s-ci-robot k8s-ci-robot merged commit 77af0be into kubernetes:master Feb 16, 2023
@k8s-ci-robot k8s-ci-robot added this to the v1.27 milestone Feb 16, 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/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants