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
Conversation
/ok-to-test |
/assign |
803d67b
to
84632d7
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dvonthenen Assign the PR to them by writing 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 |
@@ -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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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") |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
@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. |
@dvonthenen you probably need to fix that. |
pkg/kubelet/metrics/metrics.go
Outdated
@@ -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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. Will add.
Looks like failure is from:
Can you check the test logs? https://k8s-gubernator.appspot.com/build/kubernetes-jenkins/pr-logs/pull/57766/pull-kubernetes-bazel-test/24789/ ? |
@@ -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) { |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
8452301
to
232c156
Compare
@dvonthenen PR needs rebase |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
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. |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Rotten issues close after 30d of inactivity. Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
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: