-
Notifications
You must be signed in to change notification settings - Fork 23
Append the labels that don't exist in metricStringKeys #124
Conversation
Signed-off-by: Kevin Su <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #124 +/- ##
==========================================
+ Coverage 68.54% 68.89% +0.34%
==========================================
Files 68 68
Lines 3332 3343 +11
==========================================
+ Hits 2284 2303 +19
+ Misses 882 871 -11
- Partials 166 169 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
promutils/labeled/counter.go
Outdated
var labels []string | ||
for _, label := range additionalLabels.Labels { | ||
if contains(metricStringKeys, label) == false { | ||
labels = append(labels, label) | ||
} | ||
} |
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:
var labels []string | |
for _, label := range additionalLabels.Labels { | |
if contains(metricStringKeys, label) == false { | |
labels = append(labels, label) | |
} | |
} | |
labels := make([]string, 0, len(additionalLabels.Labels) | |
metricKeysSet := sets.NewString(metricStringKeys...) | |
for _, label := range additionalLabels.Labels { | |
if !metricKeysSet.Contains(label) { | |
labels = append(labels, label) | |
} | |
} |
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.
And then we can delete the contains function
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.
updated it, thank you @EngHabu
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
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.
Thank you!
c.additionalLabels = contextutils.MetricKeysFromStrings(additionalLabels.Labels) | ||
labels := GetUniqueLabels(metricStringKeys, additionalLabels.Labels) | ||
// Here we only append the labels that don't exist in metricStringKeys | ||
c.CounterVec = scope.MustNewCounterVec(name, description, append(metricStringKeys, labels...)...) |
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 append
here may modify the same underly array backing up metricStringKeys
and cause corruption for a counter that was created previously.
A repro:
package labeled
import (
"context"
"testing"
"github.com/flyteorg/flytestdlib/contextutils"
"github.com/flyteorg/flytestdlib/promutils"
"github.com/stretchr/testify/assert"
)
func TestLabeledCounter(t *testing.T) {
UnsetMetricKeys()
assert.NotPanics(t, func() {
SetMetricKeys(contextutils.ProjectKey, contextutils.DomainKey, contextutils.WorkflowIDKey)
})
scope := promutils.NewTestScope()
c1 := NewCounter(
"handle_count1",
"c1",
/*scope=*/ scope,
/*opts=*/ AdditionalLabelsOption{Labels: []string{"foo"}},
)
c2 := NewCounter(
"handle_count2",
"c2",
/*scope=*/ scope,
/*opts=*/ AdditionalLabelsOption{Labels: []string{"tasktype"}}, // this corrupts c1
)
ctx := context.TODO()
ctx = contextutils.WithProjectDomain(ctx, "project", "domain")
ctx = contextutils.WithWorkflowID(ctx, "workflow")
ctx = contextutils.WithTaskID(ctx, "task")
ctx = contextutils.WithTaskType(ctx, "type")
ctx = context.WithValue(ctx, "foo", "foo")
c1.Inc(ctx) // <--- panic here
c2.Inc(ctx)
}
cc @hamersaw
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.
It was not introduced by this PR though, the last change of this was ages ago in pingsutw@c811acb. :)
Signed-off-by: Kevin Su [email protected]
TL;DR
We should append the labels that don't exist in metricStringKeys
Failed to start datacatalog in single binary because we attempted to register the same metric key.
Error message:
Type
Are all requirements met?
Complete description
How did you fix the bug, make the feature etc. Link to any design docs etc
Tracking Issue
flyteorg/flyte#2266
Follow-up issue
NA