-
Notifications
You must be signed in to change notification settings - Fork 303
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
Add label propagation metrics calculation logic #2077
Conversation
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 Once the patch is verified, the new status will be reflected by the 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. |
/ok-to-test |
/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) { |
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.
rename to labelPropagationStats
pkg/neg/syncers/labels/labels.go
Outdated
@@ -95,8 +102,20 @@ func truncatePodLabel(key, label string, maxTotalSize int) (string, error) { | |||
return label, nil | |||
} | |||
if len(keyBytes)+minLabelLength > maxTotalSize { | |||
metrics.PublishLabelPropagationError(TruncationFailure) |
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.
similar to logging, pull this out to the caller
pkg/neg/syncers/labels/labels.go
Outdated
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) |
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.
same comment as above
pkg/neg/syncers/transaction.go
Outdated
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)) |
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.
move this to the caller. we shouldn't have metrics in helper methods unless the helper function is for the 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 should also move events to the caller as well for the same reason
770e6d8
to
9b62af3
Compare
annotationSize = "annotation_size_per_endpoint" | ||
labelErrorNumber = "label_propagation_error_count" | ||
numberOfEndpoints = "number_of_endpoints" | ||
epWithAnnotation = "with_annoatation" |
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: annotation
labelErrorNumber = "label_propagation_error_count" | ||
numberOfEndpoints = "number_of_endpoints" | ||
epWithAnnotation = "with_annoatation" | ||
epWithoutAnnotation = "without_annotation" |
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 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)) |
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.
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" |
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.
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
pkg/neg/syncers/labels/labels.go
Outdated
if errors.Is(err, ErrLabelTruncated) { | ||
metrics.PublishLabelPropagationError(Truncated) | ||
} else if errors.Is(err, ErrLabelTruncationFailed) { | ||
metrics.PublishLabelPropagationError(TruncationFailure) | ||
} |
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.
pull this out into its own helper: publishLabelPropagationTruncationMetrics
9b62af3
to
a915ae2
Compare
/retest |
528e53e
to
279fc57
Compare
pkg/neg/syncers/transaction_test.go
Outdated
} { | ||
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) |
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.
nit: remove got %+v, want %+v
and add the -want, +got
279fc57
to
2a56103
Compare
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.
/lgtm
/approve
[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 |
/assign @swetharepakula