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

bugfix: Initialize metrics with empty tags #2847

Merged
merged 3 commits into from
Dec 21, 2022

Conversation

Fabianoshz
Copy link
Contributor

@Fabianoshz Fabianoshz commented Dec 21, 2022

what

Added empty tags to metrics initialization to avoid errors when running commands.

Tried to hide the implementation behind the ProjectScopeTags so we can have an easy way to implement empty tags like this:

	projectTags := command.ProjectScopeTags{}
	scope = metrics.SetScopeTags(scope.SubScope("project"), projectTags.Loadtags())

Instead of this:

	scope = scope.SubScope("project")
	scope = scope.Tagged(map[string]string{
		"base_repo":         "",
		"pr_number":         "",
		"project":           "",
		"project_path":      "",
		"terraform_version": "",
		"workspace":         "",
	})

This should ensure that in the future if someone adds new tags to the ProjectScopeTags they still will be initialized empty while still can use the SetProjectScopeTags to add the values.

why

references

@Fabianoshz Fabianoshz requested a review from a team as a code owner December 21, 2022 15:29
Workspace string
}

func (s ProjectScopeTags) Loadtags() map[string]string {
Copy link
Member

Choose a reason for hiding this comment

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

Should this be named like this?

Suggested change
func (s ProjectScopeTags) Loadtags() map[string]string {
func (s ProjectScopeTags) loadTags() map[string]string {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately I think we have to keep this public since it is used on server/events/instrumented_project_command_runner.go, maybe the function name choice wasn't clear enough?

I guess that to make this private I could make an ScopeTags interface on the metrics package, and call the loadTags from there. Then ProjectScopeTags would be an implementation of that interface passed as argument to a function that load the tags on the scope. I'm not so sure this would work though, but I can give a try.

Copy link
Member

Choose a reason for hiding this comment

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

That's ok, this was a nitpick.

Copy link
Member

@nitrocode nitrocode left a comment

Choose a reason for hiding this comment

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

Looks good. Left one nitpick.

@nitrocode nitrocode changed the title fix: Initialize metrics with empty tags bugfix: Initialize metrics with empty tags Dec 21, 2022
@nitrocode nitrocode merged commit 9a38e35 into runatlantis:main Dec 21, 2022
@nitrocode nitrocode added this to the 0.22.0 milestone Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

potential tally.Scope() vs Prometheus usage contract mismatch
2 participants