Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Append the labels that don't exist in metricStringKeys #124

Merged
merged 3 commits into from
Apr 3, 2022

Conversation

pingsutw
Copy link
Member

@pingsutw pingsutw commented Apr 1, 2022

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:

 Failed to register metrics. Error: descriptor Desc{fqName: \"datacatalog:datacatalog:storage:read_failure\", help: 
\"Indicates failure in GET for a given reference\", constLabels: {}, variableLabels: [app_name project domain exec_id wf 
node task tasktype runtime_type runtime_version failure_type failure_type]} is invalid: duplicate label names [goroutine 83 
[running]:\nruntime/debug.Stack()\n\t/usr/local/go/src/runtime/debug/stack.go:24 
+0x65\ngithub.com/flyteorg/datacatalog/pkg/rpc/datacatalogservice.NewDataCatalogService.func

Type

  • Bug Fix
  • Feature
  • Plugin

Are all requirements met?

  • Code completed
  • Smoke tested
  • Unit tests added
  • Code documentation added
  • Any pending items have an associated Issue

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

@codecov
Copy link

codecov bot commented Apr 1, 2022

Codecov Report

Merging #124 (80f6e41) into master (2937b8e) will increase coverage by 0.34%.
The diff coverage is 100.00%.

@@            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     
Flag Coverage Δ
unittests 67.65% <100.00%> (+0.36%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
promutils/labeled/counter.go 58.33% <100.00%> (+15.47%) ⬆️
promutils/labeled/gauge.go 45.61% <100.00%> (-2.61%) ⬇️
promutils/labeled/stopwatch.go 78.94% <100.00%> (+11.37%) ⬆️
promutils/labeled/summary.go 80.95% <100.00%> (+0.95%) ⬆️
cache/auto_refresh.go 72.72% <0.00%> (-5.79%) ⬇️
storage/stow_store.go 80.67% <0.00%> (+5.79%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2937b8e...80f6e41. Read the comment docs.

Comment on lines 71 to 76
var labels []string
for _, label := range additionalLabels.Labels {
if contains(metricStringKeys, label) == false {
labels = append(labels, label)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit:

Suggested change
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)
}
}

Copy link
Contributor

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

Copy link
Member Author

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]>
EngHabu
EngHabu previously approved these changes Apr 2, 2022
Signed-off-by: Kevin Su <[email protected]>
Copy link
Contributor

@EngHabu EngHabu left a comment

Choose a reason for hiding this comment

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

Thank you!

@EngHabu EngHabu merged commit 1ef3a07 into flyteorg:master Apr 3, 2022
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...)...)
Copy link
Member

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

Copy link
Member

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. :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants