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

feat: add volume attachment time & csi grpc execution time metrics #1142

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

iltyty
Copy link
Contributor

@iltyty iltyty commented Aug 23, 2024

What type of PR is this?

/kind feature

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?


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


@k8s-ci-robot k8s-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Aug 23, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: iltyty
Once this PR has been reviewed and has the lgtm label, please assign mowangdk for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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 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 Aug 23, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @iltyty. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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-sigs/prow repository.

@iltyty iltyty marked this pull request as draft August 23, 2024 05:41
@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 23, 2024
@mowangdk
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 23, 2024
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 29, 2024
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 9, 2024
@iltyty iltyty marked this pull request as ready for review September 9, 2024 02:32
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 9, 2024
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 23, 2024
return fullName[i+1:]
}

func observeExecTime(time int64, method, driverType, volumeId string, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func observeExecTime(time int64, method, driverType, volumeId string, err error) {
func observeExecTime(time time.Duration, method, driverType, volumeId string, err error) {

Just pass in the Duration to avoid any ambiguous about unit.

case ControllerPublish, ControllerUnpublish, NodeStage, NodeUnstage, NodeUnpublish:
start := time.Now()
resp, err := handler(ctx, req)
execTime := time.Since(start).Milliseconds()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
execTime := time.Since(start).Milliseconds()
execTime := time.Since(start).Seconds()

Use seconds as it already returns a float64.

Comment on lines 34 to 42
func NewCsiGrpcExecTimeCollector() (Collector, error) {
return &CsiGrpcExecTimeCollector, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is confusing. It is named New but returns an existing object.

const (
VolumeStatsCollectorName = "volume_stats"
VolumeStatsLabelType = "type"
VolumeStatsLabelId = "id"
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove ID as we discussed. We don't expect unbounded number of label values.

Comment on lines 104 to 107
if !strings.Contains(fullName, "/") || i == len(fullName)-1 {
return ""
}
return fullName[i+1:]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is not needed? If "/" is not in fullName, LastIndex will return -1, and fullName[i+1:] should become the fullName.
If i == len(fullName)-1, fullName[i+1:] will become empty string automatically.

return codes.Unknown
}

func observeVolumeAttachmentTime(curTime int64, req *csi.NodePublishVolumeRequest, driverType string, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func observeVolumeAttachmentTime(curTime int64, req *csi.NodePublishVolumeRequest, driverType string, err error) {
func observeVolumeAttachmentTime(curTime time.Time, req *csi.NodePublishVolumeRequest, driverType string, err error) {

Again, to avoid ambiguity.


func observeVolumeAttachmentTime(curTime int64, req *csi.NodePublishVolumeRequest, driverType string, err error) {
if client == nil {
if client = getK8sClient(); client == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not thread safe. And please try to avoid global variable.

log.Warnf("observeVolumeAttachmentTime: empty pod name/namespace: %s, %s", podName, podNamespace)
return
}
pod, err := client.CoreV1().Pods(podNamespace).Get(context.Background(), podName, metav1.GetOptions{})
Copy link
Contributor

Choose a reason for hiding this comment

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

Additional API server invocation. This can hinder the overall throughput of CSI. We should try to avoid this. Combine it to the runtime class detection?

execTime := time.Since(start).Milliseconds()
observeExecTime(execTime, method, driverType, volumeId, err)
return resp, err
case NodePublish:
Copy link
Contributor

Choose a reason for hiding this comment

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

How about add this one to a real NodePublishVolume handler? We should avoid string comparisons and prefer strongly typed handler generally.

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants