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

[BUG] Using additional labels in prometheus metrics can cause panic #2597

Closed
2 tasks done
hamersaw opened this issue Jun 7, 2022 · 0 comments · Fixed by flyteorg/flytestdlib#136
Closed
2 tasks done
Assignees
Labels
bug Something isn't working
Milestone

Comments

@hamersaw
Copy link
Contributor

hamersaw commented Jun 7, 2022

Describe the bug

Creating multiple metrics with additional labels may cause the Inc function to panic. This is contingent on the number of metric keys set at the global level.

Expected behavior

Metric labels should be set and maintained independent of each other so that additional metrics do not cause panics.

Additional context to reproduce

package main

import (
	"context"

	"github.com/flyteorg/flytestdlib/contextutils"
	"github.com/flyteorg/flytestdlib/promutils"
 	"github.com/flyteorg/flytestdlib/promutils/labeled"
)

func main() {
	labeled.UnsetMetricKeys()
	labeled.SetMetricKeys(contextutils.ProjectKey, contextutils.DomainKey, contextutils.WorkflowIDKey)

	scope := promutils.NewTestScope()
	c1 := labeled.NewCounter(
		"handle_count1",
		"c1",
		scope,
		labeled.AdditionalLabelsOption{Labels: []string{"foo"}},
	)
	c2 := labeled.NewCounter(
		"handle_count2",
		"c2",
		scope,
		labeled.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)
}

Screenshots

No response

Are you sure this issue hasn't been raised already?

  • Yes

Have you read the Code of Conduct?

  • Yes
@hamersaw hamersaw added bug Something isn't working untriaged This issues has not yet been looked at by the Maintainers labels Jun 7, 2022
@hamersaw hamersaw self-assigned this Jun 7, 2022
@hamersaw hamersaw removed the untriaged This issues has not yet been looked at by the Maintainers label Jun 7, 2022
@hamersaw hamersaw added this to the 1.1.0 - Hawk milestone Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant