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

Add metrics for volume scheduling operations #59529

Merged
merged 1 commit into from
Oct 23, 2018

Conversation

wackxu
Copy link
Contributor

@wackxu wackxu commented Feb 8, 2018

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes # #56162

Special notes for your reviewer:
/assign @msau42
Release note:

Add metrics for volume scheduling operations

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 8, 2018
@msau42
Copy link
Member

msau42 commented Feb 8, 2018

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Feb 8, 2018
Buckets: prometheus.ExponentialBuckets(1000, 2, 15),
},
)
VolumeBindingPredicateLatency = prometheus.NewHistogram(
Copy link
Member

Choose a reason for hiding this comment

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

@bsalamat, what do you think about having a metric on a specific predicate? This predicate does have the potential to be slow because it has to iterative through all PVs.

Copy link
Member

Choose a reason for hiding this comment

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

Having metrics for a specific predicate is not consistent with the rest of our code base, but it's fine for now while we are finding a better solution for dynamic resource binding.

@@ -87,6 +87,30 @@ var (
Name: "total_preemption_attempts",
Help: "Total preemption attempts in the cluster till now",
})
AssumeBindVolumesLatency = prometheus.NewHistogram(
Copy link
Member

Choose a reason for hiding this comment

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

I know the function name is assume and bind, but I think it makes more sense for the metric to be named just "AssumeVolumesLatency" because the function doesn't actually do the bind operation, it just queues it.

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

@@ -350,6 +352,8 @@ func (sched *Scheduler) bindVolumesWorker() {
Status: v1.ConditionFalse,
Reason: reason,
})

metrics.BindPodVolumeLatency.Observe(metrics.SinceInMicroseconds(start))
Copy link
Member

Choose a reason for hiding this comment

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

It may also be good to add a metric to count VolumeBindingFailed. I don't expect it to happen often.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@msau42 Done

@wackxu
Copy link
Contributor Author

wackxu commented Feb 9, 2018

I do not know why verify import boss failure, It is so strange.

errors in package "k8s.io/kubernetes/pkg/kubectl/cmd/resource":
import k8s.io/kubernetes/pkg/scheduler/metrics did not match any allowed prefix

errors in package "k8s.io/kubernetes/pkg/kubectl/cmd/set":
import k8s.io/kubernetes/pkg/scheduler/metrics did not match any allowed prefix

errors in package "k8s.io/kubernetes/pkg/kubectl/cmd/testing":
import k8s.io/kubernetes/pkg/scheduler/metrics did not match any allowed prefix

errors in package "k8s.io/kubernetes/pkg/kubectl/cmd":
import k8s.io/kubernetes/pkg/scheduler/metrics did not match any allowed prefix

errors in package "k8s.io/kubernetes/pkg/kubectl/cmd/config":
import k8s.io/kubernetes/pkg/scheduler/metrics did not match any allowed prefix

@msau42
Copy link
Member

msau42 commented Feb 9, 2018

@wackxu can you also add metrics to pkg/controller/volume/persistentvolume/scheduler_binder_cache.go? I want to track how many times a binding was added to the cache, and how many times it was removed from the cache. This could help detect potential memory leaks.

@msau42
Copy link
Member

msau42 commented Feb 9, 2018

regarding your import failures, I think because the change is adding an import to the predicates pkg, it will trigger some allowed import check. You can modify the import restrictions file, like this

@wackxu wackxu force-pushed the addmetricvol branch 3 times, most recently from 25ec499 to e4e0612 Compare February 11, 2018 02:27
@wackxu
Copy link
Contributor Author

wackxu commented Feb 11, 2018

@msau42 Done, PTAL

@@ -59,6 +60,8 @@ func (c *podBindingCache) DeleteBindings(pod *v1.Pod) {

podName := getPodName(pod)
delete(c.bindings, podName)

metrics.VolumeBindingDeleteFromSchedulerBinderCache.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 think it would be better to only record when it's actually removed (it could have already been removed previously)

@@ -72,6 +75,8 @@ func (c *podBindingCache) UpdateBindings(pod *v1.Pod, node string, bindings []*b
c.bindings[podName] = nodeBinding
}
nodeBinding[node] = bindings

metrics.VolumeBindingAddToSchedulerBinderCache.Inc()
Copy link
Member

Choose a reason for hiding this comment

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

And here, only record when it's actually added.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 14, 2018
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 26, 2018
@wackxu
Copy link
Contributor Author

wackxu commented Feb 26, 2018

@msau42 Done, PTAL

@@ -71,6 +75,10 @@ func (c *podBindingCache) UpdateBindings(pod *v1.Pod, node string, bindings []*b
nodeBinding = nodeBindings{}
c.bindings[podName] = nodeBinding
}
if _, ok := nodeBinding[node]; !ok {
metrics.VolumeBindingAddToSchedulerBinderCache.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 think this can just be updated in the block above, since the metrics is based on the pod name, not 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.

Done

@@ -1588,6 +1591,7 @@ func (c *VolumeBindingChecker) predicate(pod *v1.Pod, meta algorithm.PredicateMe
return false, failReasons, nil
}

metrics.VolumeBindingPredicateLatency.Observe(metrics.SinceInMicroseconds(start))
Copy link
Member

Choose a reason for hiding this comment

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

I think we should also record latency when predicate returns failReasons because it still has to do lots of calculations in FindPodVolumes.

VolumeBindingFailed = prometheus.NewCounter(
prometheus.CounterOpts{
Subsystem: schedulerSubsystem,
Name: "total_volume_binding_failed",
Copy link
Member

Choose a reason for hiding this comment

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

I think the convention is to have count or latency at the end of the name, so something like "volume_binding_error_count"

@@ -298,6 +299,7 @@ func (sched *Scheduler) assumeAndBindVolumes(assumed *v1.Pod, host string) error
}
return err
}
metrics.AssumeVolumesLatency.Observe(metrics.SinceInMicroseconds(start))
Copy link
Member

Choose a reason for hiding this comment

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

We should observe latency even when error

@@ -56,6 +73,8 @@ type PVCLister interface {
func Register(pvLister PVLister, pvcLister PVCLister) {
registerMetrics.Do(func() {
prometheus.MustRegister(newPVAndPVCCountCollector(pvLister, pvcLister))
prometheus.MustRegister(VolumeBindingAddToSchedulerBinderCache)
Copy link
Member

Choose a reason for hiding this comment

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

I think the registration here is not going to work. This registration is called in PV controller process, but the volume binding cache is a library used by scheduler process. So I think the library needs export a register method that the scheduler will call.

Copy link
Member

Choose a reason for hiding this comment

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

These registration calls should be removed from this file, because this is called for PV controller process, not scheduler process.

@msau42
Copy link
Member

msau42 commented Mar 24, 2018

@wackxu thanks for working on this. I just wanted to check if you will still have time to continue on this?

@wackxu
Copy link
Contributor Author

wackxu commented Mar 24, 2018

@msau42 Sorry for the delay, will update later

Copy link
Member

@msau42 msau42 left a comment

Choose a reason for hiding this comment

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

This is looking really good thanks! Just one minor nit


// RegisterForScheduler is used for scheduler, because the volume binding cache is a library
// used by scheduler process.
func RegisterForScheduler() {
Copy link
Member

Choose a reason for hiding this comment

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

Can you call this "RegisterVolumeSchedulingMetrics" to be more clear?

@msau42
Copy link
Member

msau42 commented Jul 23, 2018

/lgtm
/retest

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 23, 2018
@msau42
Copy link
Member

msau42 commented Jul 27, 2018

/assign @bsalamat

@@ -21,6 +21,7 @@ import (
"time"

"github.com/prometheus/client_golang/prometheus"
"k8s.io/kubernetes/pkg/controller/volume/persistentvolume"
Copy link
Member

Choose a reason for hiding this comment

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

Any chance we could separate the metrics in a different package and import only the metrics package instead of the whole persistent volume controller?

Copy link
Member

Choose a reason for hiding this comment

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

@wackxu would you be able to look into this?

Copy link
Contributor Author

@wackxu wackxu Oct 12, 2018

Choose a reason for hiding this comment

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

We have already import k8s.io/kubernetes/pkg/controller/volume/persistentvolume in the scheduler and the metric is used only for scheduler like scheduler_binder files. I think we can extract a separate dir for those files in a follow pr

Copy link
Member

Choose a reason for hiding this comment

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

That sounds reasonable.

@k8s-github-robot
Copy link

/test all

Tests are more than 96 hours old. Re-running tests.

@msau42
Copy link
Member

msau42 commented Oct 3, 2018

@wackxu a lot of refactoring has gone in 1.12, so this change needs to be rebased. Do you still have time to work on this?

@wackxu
Copy link
Contributor Author

wackxu commented Oct 12, 2018

@msau42 Sorry for the delay, will update today

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 12, 2018
Copy link
Member

@bsalamat bsalamat left a comment

Choose a reason for hiding this comment

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

/approve

VolumeBindingFailed = prometheus.NewCounter(
prometheus.CounterOpts{
Subsystem: VolumeSchedulerSubsystem,
Name: "binding_error_total",
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 also have error count for assume and predicates too? (similar to stage latency)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the delay, updated

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Oct 23, 2018
@wackxu wackxu changed the title Add metrics to volume scheduling operations Add metrics for volume scheduling operations Oct 23, 2018
@msau42
Copy link
Member

msau42 commented Oct 23, 2018

/lgtm
/approve

Thanks for continuing to work on this!

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bsalamat, msau42, wackxu

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 Oct 23, 2018
@msau42
Copy link
Member

msau42 commented Oct 23, 2018

/retest

1 similar comment
@msau42
Copy link
Member

msau42 commented Oct 23, 2018

/retest

@k8s-ci-robot k8s-ci-robot merged commit 101d26c into kubernetes:master Oct 23, 2018
@wackxu wackxu deleted the addmetricvol branch October 24, 2018 01:10
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. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants