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

VolumeManager mount/unmount volume metrics #57766

Closed
wants to merge 12 commits into from

Conversation

dvonthenen
Copy link

@dvonthenen dvonthenen commented Jan 2, 2018

What this PR does / why we need it:
Starts to implement VolumeManager storage metrics as defined in the Metrics Spec (https://docs.google.com/document/d/1Fh0T60T_y888LsRwC51CQHO75b2IZ3A34ZQS71s_F0g/edit#heading=h.ys6pjpbasqdu)

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Partial fix kubernetes/enhancements#496

Special notes for your reviewer:
Implements mount/unmount volume metrics only. Will have subsequent PRs for additional metrics.

Release note:

Intended for post-1.9

@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/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. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 2, 2018
@gnufied
Copy link
Member

gnufied commented Jan 2, 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 Jan 2, 2018
@gnufied
Copy link
Member

gnufied commented Jan 2, 2018

/assign

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dvonthenen
We suggest the following additional approvers: gnufied, vishh

Assign the PR to them by writing /assign @gnufied @vishh in a comment when ready.

Associated issue: #496

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@@ -258,10 +272,16 @@ func (dsw *desiredStateOfWorld) MarkVolumesReportedInUse(
}

func (dsw *desiredStateOfWorld) DeletePodFromVolume(
podName types.UniquePodName, volumeName v1.UniqueVolumeName) {
podName types.UniquePodName, volumeName v1.UniqueVolumeName, volumeSpec *volume.Spec) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this volumeSpec parameter necessary here? Maybe we can get it from the podToMount struct, see the code here.

Copy link
Author

@dvonthenen dvonthenen Jan 5, 2018

Choose a reason for hiding this comment

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

Will look into it, but this is for an unmount operation.

Copy link
Author

Choose a reason for hiding this comment

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

The calling function is grabbing the volumeSpec from podToMount. The issue is that the desired_state_of_world_populator doesnt have access to the volumePluginMgr which is why the plugin lookup happens in DeletePodFromVolume.
https://github.com/kubernetes/kubernetes/pull/57766/files#diff-94e527d26427ceb4f990f05f76952656R246

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if I understand what you mean. I mean we can find the podToMount object in here, then we can use podToMount.spec instead of the volumeSpec parameter of DeletePodFromVolume .
The benefit of this approach is we needn't to change the signature of DesiredStateOfWorld.DeletePodFromVolume, which will reduce some work.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @mlmhl. The volumeSpec is already available in the cache, it doesn't need to be passed in.

Copy link
Author

Choose a reason for hiding this comment

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

Maybe I am misunderstanding something. Will take another look.

Copy link
Author

Choose a reason for hiding this comment

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

My bad... that's what happens when you drop something before a 2 week Christmas break and come back to it afterward. Will have a fix for this.

@@ -278,6 +298,9 @@ func (dsw *desiredStateOfWorld) DeletePodFromVolume(
// Delete volume if no child pods left
delete(dsw.volumesToMount, volumeName)
}

// create metric for volume unmount
dsw.volumesToUnmount[volumeName] = metrics.VolumeManagerOperationCompleteHook(volumePluginName, "volume_unmount")
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to add pod name as a dimension? As this umount operation is just umount volume from pod, not umount the volume device from node.

Copy link
Member

Choose a reason for hiding this comment

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

We generally never want to add pod names as a dimension because in a large enough cluster, it will cause blowing up of cardinality of metrics

Copy link
Member

Choose a reason for hiding this comment

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

we need to make sure that - we aren't leaking memory from volumesToUnmount map. Are we ever removing elements from this map? I don't see it.

Copy link
Author

Choose a reason for hiding this comment

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

Yup, will update and perform the delete.

Copy link
Author

@dvonthenen dvonthenen Jan 5, 2018

Choose a reason for hiding this comment

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

You can find the delete here:
https://github.com/kubernetes/kubernetes/pull/57766/files#diff-d905eaaa258ac0c788ec26e31079ce60R371

Delete from the map just prior to invoking the callback

@mlmhl
Copy link
Contributor

mlmhl commented Jan 3, 2018

Hi @gnufied , I have doubts about the definition of mount/unmount time, as we have two mount/umount operations: mount/umount the volume device to/from the node, and mount/umount the volume to/from a specific pod. Do we need to add metrics for each operation, or just use a same metric?

@@ -278,6 +298,9 @@ func (dsw *desiredStateOfWorld) DeletePodFromVolume(
// Delete volume if no child pods left
delete(dsw.volumesToMount, volumeName)
}

// create metric for volume unmount
dsw.volumesToUnmount[volumeName] = metrics.VolumeManagerOperationCompleteHook(volumePluginName, "volume_unmount")
Copy link
Member

Choose a reason for hiding this comment

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

We generally never want to add pod names as a dimension because in a large enough cluster, it will cause blowing up of cardinality of metrics

dsw.Lock()
defer dsw.Unlock()

volumePluginName := "plugin_unknown"
Copy link
Member

Choose a reason for hiding this comment

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

If a value is unknown the convention is to use <n/a>

Copy link
Author

Choose a reason for hiding this comment

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

Will update to change the default.

}
}
return volumesToMount
}

func (dsw *desiredStateOfWorld) GetVolumeUnmountMetric(volumeName v1.UniqueVolumeName) func(error) {
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 rename this function because it does not exactly return the metric itself, but it returns a callback which can be called to emit the metric.

@gnufied
Copy link
Member

gnufied commented Jan 5, 2018

@mlmhl yeah I think this PR only captures mount volume and umount volume... which is fine. mount volume and mount device operation is in particular tricky because - both operations happen inside one function.

We can probably refactor this PR to report umount_volume and umount_device metrics though, but we can do that in a follow up PR too.

@gnufied
Copy link
Member

gnufied commented Jan 5, 2018

W0105 17:48:42.079] 2018/01/05 17:48:41 error running compiler: exit status 1
I0105 17:48:42.180] pkg/kubelet/volumemanager/cache/desired_state_of_world_test.go:157:25: not enough arguments in call to dsw.DeletePodFromVolume
I0105 17:48:42.181] 	have ("k8s.io/kubernetes/pkg/volume/util/types".UniquePodName, "k8s.io/api/core/v1".UniqueVolumeName)
I0105 17:48:42.182] 	want ("k8s.io/kubernetes/pkg/volume/util/types".UniquePodName, "k8s.io/api/core/v1".UniqueVolumeName, *volume.Spec)
I0105 17:48:42.224] //cmd/cloud-controller-manager/app/options:go_default_test            NO STATUS
I0105 17:48:42.225] //cmd/genkubedocs:go_default_test                         

@dvonthenen you probably need to fix that.

@@ -47,6 +47,9 @@ const (
// Metrics keys of device plugin operations
DevicePluginRegistrationCountKey = "device_plugin_registration_count"
DevicePluginAllocationLatencyKey = "device_plugin_alloc_latency_microseconds"
// Metrics keys of volume operations
VolumeManagerOpeationsKey = "volumemanager_operation_duration_seconds"
Copy link
Contributor

Choose a reason for hiding this comment

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

typo

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

@@ -283,3 +304,18 @@ func (pc *podAndContainerCollector) Collect(ch chan<- prometheus.Metric) {
prometheus.GaugeValue,
float64(runningContainers))
}

// VolumeManagerOperationCompleteHook returns a hook to call when an operation is completed
func VolumeManagerOperationCompleteHook(plugin, operationName string) func(error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could the OperationCompleteHook in pkg/volume/util/metrics.go be reused?

Copy link
Author

Choose a reason for hiding this comment

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

The callback in pkg/volume/util/metrics.go represent the volume operation only. These metrics are at the volume manager view/perspective. We don't want to put both sets of data into the same bucket.

Copy link
Contributor

Choose a reason for hiding this comment

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

ACK

@@ -120,6 +126,9 @@ type desiredStateOfWorld struct {
// the map is the name of the volume and the value is a volume object
// containing more information about the volume.
volumesToMount map[v1.UniqueVolumeName]volumeToMount
// volumesToUnmount is a map containing callback functions to record metrics
// for a given Volume's unmount operation
volumesToUnmount map[v1.UniqueVolumeName]func(error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Use a different name? The map values aren't exactly volumes. Or the function can be wrapped in a volumeToUnmount struct

Copy link
Member

@gnufied gnufied Jan 6, 2018

Choose a reason for hiding this comment

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

Yeah I agree. may be call this - unmountCompletionCallbackMap ?

Copy link
Author

Choose a reason for hiding this comment

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

Renamed.

@@ -94,6 +95,10 @@ type DesiredStateOfWorld interface {
// current desired state of the world.
GetVolumesToMount() []VolumeToMount

// GetVolumeUnmountMetricCallback retreives the associated metric callback for a given
Copy link
Contributor

Choose a reason for hiding this comment

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

typo

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

func (dsw *desiredStateOfWorld) GetVolumeUnmountMetricCallback(volumeName v1.UniqueVolumeName) func(error) {
operationComplete := dsw.volumesToUnmount[volumeName]
delete(dsw.volumesToUnmount, volumeName)
return operationComplete
Copy link
Member

Choose a reason for hiding this comment

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

Don't we need to protect this with mutex?

Copy link
Author

Choose a reason for hiding this comment

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

Yup. Will add.

@gnufied
Copy link
Member

gnufied commented Jan 9, 2018

Looks like failure is from:

W0109 16:21:37.006] 2018/01/09 16:21:36 error running compiler: exit status 1
I0109 16:21:37.107] pkg/kubelet/volumemanager/reconciler/reconciler_test.go:334:25: not enough arguments in call to dsw.DeletePodFromVolume
I0109 16:21:37.108] 	have ("k8s.io/kubernetes/pkg/volume/util/types".UniquePodName, "k8s.io/api/core/v1".UniqueVolumeName)
I0109 16:21:37.108] 	want ("k8s.io/kubernetes/pkg/volume/util/types".UniquePodName, "k8s.io/api/core/v1".UniqueVolumeName, *volume.Spec)
I0109 16:21:37.109] pkg/kubelet/volumemanager/reconciler/reconciler_test.go:426:25: not enough arguments in call to dsw.DeletePodFromVolume
I0109 16:21:37.110] 	have ("k8s.io/kubernetes/pkg/volume/util/types".UniquePodName, "k8s.io/api/core/v1".UniqueVolumeName)
I0109 16:21:37.110] 	want ("k8s.io/kubernetes/pkg/volume/util/types".UniquePodName, "k8s.io/api/core/v1".UniqueVolumeName, *volume.Spec)
I0109 16:21:37.111] pkg/kubelet/volumemanager/reconciler/reconciler_test.go:704:25: not enough arguments in call to dsw.DeletePodFromVolume
I0109 16:21:37.111] 	have ("k8s.io/kubernetes/pkg/volume/util/types".UniquePodName, "k8s.io/api/core/v1".UniqueVolumeName)
I0109 16:21:37.112] 	want ("k8s.io/kubernetes/pkg/volume/util/types".UniquePodName, "k8s.io/api/core/v1".UniqueVolumeName, *volume.Spec)
I0109 16:21:37.112] pkg/kubelet/volumemanager/reconciler/reconciler_test.go:808:25: not enough arguments in call to dsw.DeletePodFromVolume
I0109 16:21:37.113] 	have ("k8s.io/kubernetes/pkg/volume/util/types".UniquePodName, "k8s.io/api/core/v1".UniqueVolumeName)
I0109 16:21:37.113] 	want ("k8s.io/kubernetes/pkg/volume/util/types".UniquePodName, "k8s.io/api/core/v1".UniqueVolumeName, *volume.Spec)
I0109 16:21:37.129] //cmd/cloud-controller-manager/app/options:go_default_test            NO STATUS
I0109 16:21:37.131] //cmd/genkubedocs:go_default_test                                     NO STATUS
I0109 16:21:37.131] //cmd/gke-certificates-controller/app:go_default_test                 NO STATUS
I0109 16:21:37.131] //cmd/hyperkube:go_default_test                                       NO STATUS
I0109 16:21:37.132] //cmd/kube-apiserver/app/options:go_default_test                      NO STATUS

Can you check the test logs? https://k8s-gubernator.appspot.com/build/kubernetes-jenkins/pr-logs/pull/57766/pull-kubernetes-bazel-test/24789/ ?

@saad-ali saad-ali added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Jan 10, 2018
@@ -258,10 +272,16 @@ func (dsw *desiredStateOfWorld) MarkVolumesReportedInUse(
}

func (dsw *desiredStateOfWorld) DeletePodFromVolume(
podName types.UniquePodName, volumeName v1.UniqueVolumeName) {
podName types.UniquePodName, volumeName v1.UniqueVolumeName, volumeSpec *volume.Spec) {
Copy link
Member

Choose a reason for hiding this comment

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

I agree with @mlmhl. The volumeSpec is already available in the cache, it doesn't need to be passed in.

@@ -278,6 +298,9 @@ func (dsw *desiredStateOfWorld) DeletePodFromVolume(
// Delete volume if no child pods left
delete(dsw.volumesToMount, volumeName)
}

// create metric for volume unmount
dsw.unmountCompletionCallbackMap[volumeName] = metrics.VolumeManagerOperationCompleteHook(volumePluginName, "volume_unmount")
Copy link
Member

Choose a reason for hiding this comment

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

This is not the right place to add metrics. This code is responsible for updating internal state. Which is one step of the operation. We should be adding metrics at the operation executor layer.

@davidz627 recently added common event logic and did a good job of factoring. His code may be worth a look. Will add him as a reviewer on this PR.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback. I am not familiar with the event logic functionality. Will dig into it.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can take a look at #56872, it touches most of the places where events and metrics are being generated in the operation executor.

Specifically : https://github.com/kubernetes/kubernetes/pull/56872/files#diff-450e811a4953f760ff1594ede8b2037eR344 if you take a look at the "CompleteFunc's" they handle some sort of metric generation already, maybe you can augment those.

Copy link
Member

Choose a reason for hiding this comment

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

This is bit tricky. @davidz627 the operation hooks you linked are used for tracking operation level metrics once operation has already started.

This PR is for metrics that try to cover entirety of mount or umount operation (please refer to linked Google Doc for more details). Having a operation hook on umount on its own is not useful, we need a way to store that hook at the time when volume is removed from desired_state_of_world and we need to call the hook when umount actually finishes. The goal of these metrics is to measure - total time spent inside these controllers.

Copy link
Author

Choose a reason for hiding this comment

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

The only other thing that I could/might do is wrap the callback in a volumesToUnmount struct in the event there is more information/state we need to carry forward for other operations then rename unmountCompletionCallbackMap map[v1.UniqueVolumeName]func(error) to something like volumesToUnmount map[v1.UniqueVolumeName]volumeToUnmount. I just started with the basic/simple case (just the callback itself) until we actually need to carry more state forward.

@gnufied @davidz627 @saad-ali Please advise on how you want to move forward.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation @gnufied. Now that I understand the use cases better, I understand why the code is structured this way. So next question: is it worth the added complexity in the code (and potential bugs; another data structure, unmountCompletionCallbackMap, that may get out of sync) to add this metric?

@k8s-github-robot
Copy link

@dvonthenen PR needs rebase

@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 13, 2018
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 14, 2018
@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


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. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 14, 2018
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten
/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jun 13, 2018
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note-none Denotes a PR that doesn't merit a release note. 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.

Detailed storage metrics of internal state
10 participants