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 label propagation metrics calculation logic #2077

Merged
merged 2 commits into from
Apr 17, 2023

Conversation

ruixiansong
Copy link
Contributor

/assign @swetharepakula

@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 Apr 14, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @songrx1997. Thanks for your PR.

I'm waiting for a kubernetes 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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 14, 2023
@swetharepakula
Copy link
Member

/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. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 14, 2023
@ruixiansong
Copy link
Contributor Author

/retest

@@ -109,6 +110,16 @@ func (sm *SyncerMetrics) SetSyncerEPMetrics(key negtypes.NegSyncerKey, endpointS
sm.syncerEPSStateMap[key] = endpointStat.EndpointSliceStateCount
}

func (sm *SyncerMetrics) SetLabelMetrics(key negtypes.NegSyncerKey, labelstatLabelPropagationStats LabelPropagationStats) {
Copy link
Member

Choose a reason for hiding this comment

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

rename to labelPropagationStats

@@ -95,8 +102,20 @@ func truncatePodLabel(key, label string, maxTotalSize int) (string, error) {
return label, nil
}
if len(keyBytes)+minLabelLength > maxTotalSize {
metrics.PublishLabelPropagationError(TruncationFailure)
Copy link
Member

Choose a reason for hiding this comment

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

similar to logging, pull this out to the caller

return "", fmt.Errorf("%w: `%s:%s` truncation failed because the key exceeded the limit, length: %d, limit %d", ErrLabelTruncationFailed, key, label, len(keyBytes)+minLabelLength, maxTotalSize)
}
truncatedVal := string(labelBytes[:maxTotalSize-len(keyBytes)])
metrics.PublishLabelPropagationError(Truncated)
Copy link
Member

Choose a reason for hiding this comment

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

same comment as above

logger.Error(nil, "expected type *v1.Pod", "pod", key, "type", fmt.Sprintf("%T", obj))
continue
}
labelMap, err := labels.GetPodLabelMap(pod, lpConfig)
if err != nil {
recorder.Eventf(pod, apiv1.EventTypeWarning, "LabelsExceededLimit", "Label Propagation Error: %v", err)
}
metrics.PublishAnnotationMetrics(labels.GetPodLabelMapSize(labelMap), len(labelMap))
Copy link
Member

Choose a reason for hiding this comment

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

move this to the caller. we shouldn't have metrics in helper methods unless the helper function is for the 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 should also move events to the caller as well for the same reason

pkg/neg/syncers/utils_test.go Show resolved Hide resolved
@ruixiansong ruixiansong force-pushed the label-propagation-metrics branch from 770e6d8 to 9b62af3 Compare April 14, 2023 23:14
annotationSize = "annotation_size_per_endpoint"
labelErrorNumber = "label_propagation_error_count"
numberOfEndpoints = "number_of_endpoints"
epWithAnnotation = "with_annoatation"
Copy link
Member

Choose a reason for hiding this comment

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

typo: annotation

labelErrorNumber = "label_propagation_error_count"
numberOfEndpoints = "number_of_endpoints"
epWithAnnotation = "with_annoatation"
epWithoutAnnotation = "without_annotation"
Copy link
Member

Choose a reason for hiding this comment

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

we don't need this one. we can calculate with number of endpoints and without_annotation

@@ -79,6 +80,10 @@ func (sm *SyncerMetrics) Run(stopCh <-chan struct{}) {

// export exports syncer metrics.
func (sm *SyncerMetrics) export() {
lpMetrics := sm.computeLabelMetrics()
NumberOfEndpoints.WithLabelValues(epWithoutAnnotation).Set(float64(lpMetrics.NumberOfEndpoints - lpMetrics.EndpointsWithAnnotation))
Copy link
Member

Choose a reason for hiding this comment

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

let's remove this one. if we need this, we can calculate when we consume the metrics

annotationSize = "annotation_size_per_endpoint"
labelErrorNumber = "label_propagation_error_count"
numberOfEndpoints = "number_of_endpoints"
epWithAnnotation = "with_annoatation"
Copy link
Member

Choose a reason for hiding this comment

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

github won't let me comment on parts that aren't part of the diff. For the endpointAnnotationLabels, that should be changed to feature and then the value will be with_annotation

Comment on lines 80 to 79
if errors.Is(err, ErrLabelTruncated) {
metrics.PublishLabelPropagationError(Truncated)
} else if errors.Is(err, ErrLabelTruncationFailed) {
metrics.PublishLabelPropagationError(TruncationFailure)
}
Copy link
Member

Choose a reason for hiding this comment

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

pull this out into its own helper: publishLabelPropagationTruncationMetrics

pkg/neg/syncers/utils_test.go Show resolved Hide resolved
@ruixiansong ruixiansong force-pushed the label-propagation-metrics branch from 9b62af3 to a915ae2 Compare April 14, 2023 23:54
@swetharepakula
Copy link
Member

/retest

@ruixiansong ruixiansong force-pushed the label-propagation-metrics branch 3 times, most recently from 528e53e to 279fc57 Compare April 17, 2023 15:43
@ruixiansong ruixiansong changed the title Add label propagation calculation logic Add label propagation metrics calculation logic Apr 17, 2023
} {
out := collectLabelStats(tc.curLabelMap, tc.addLabelMap, tc.targetEndpointMap)
if diff := cmp.Diff(out, tc.expect); diff != "" {
t.Errorf("For test case %s: got %+v, want %+v, diff %s", tc.desc, out, tc.expect, diff)
Copy link
Member

Choose a reason for hiding this comment

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

nit: remove got %+v, want %+v and add the -want, +got

@ruixiansong ruixiansong force-pushed the label-propagation-metrics branch from 279fc57 to 2a56103 Compare April 17, 2023 16:00
Copy link
Member

@swetharepakula swetharepakula left a comment

Choose a reason for hiding this comment

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

/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 Apr 17, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: songrx1997, swetharepakula

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 Apr 17, 2023
@k8s-ci-robot k8s-ci-robot merged commit 6080857 into kubernetes:master Apr 17, 2023
@ruixiansong ruixiansong deleted the label-propagation-metrics branch May 2, 2023 19:33
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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.

3 participants