Skip to content

Commit

Permalink
Add tags to project metrics (#2623)
Browse files Browse the repository at this point in the history
* Add tags to project metrics

This adds a few tags that I've found useful for our monitoring of a
many-project terraform repository. There are likely more tags that can
be added in other areas, but I figured I'd start small and get feedback
before increasing the blast radius

* Add labels, handle nils, alphabetize

* Move //nolint to line of assignment
  • Loading branch information
TylerLubeck authored Oct 28, 2022
1 parent 117ce59 commit 9ab3fd2
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion server/events/command/project_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package command

import (
"fmt"
"strconv"
"strings"

"github.com/hashicorp/go-version"
Expand Down Expand Up @@ -96,7 +97,18 @@ type ProjectContext struct {
// SetScope sets the scope of the stats object field. Note: we deliberately set this on the value
// instead of a pointer since we want scopes to mirror our function stack
func (p ProjectContext) SetScope(scope string) {
p.Scope = p.Scope.SubScope(scope) //nolint
v := ""
if p.TerraformVersion != nil {
v = p.TerraformVersion.String()
}
p.Scope = p.Scope.SubScope(scope).Tagged(map[string]string{ //nolint
"base_repo": p.BaseRepo.FullName,
"pr_number": strconv.Itoa(p.Pull.Num),
"project": p.ProjectName,
"project_path": p.RepoRelDir,
"terraform_version": v,
"workspace": p.Workspace,
})
}

// GetShowResultFileName returns the filename (not the path) to store the tf show result
Expand Down

0 comments on commit 9ab3fd2

Please sign in to comment.