Skip to content

Commit

Permalink
Merge pull request #32 from dbecorp/inject-labels-from-env
Browse files Browse the repository at this point in the history
Inject global labels from env var
  • Loading branch information
jakthom authored Oct 23, 2024
2 parents 67240d8 + 430e645 commit 14458da
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions hercules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ debug: false
port: 9100

globalLabels:
- cell: ausw1
- env: dev
- cell: ausw1 # Inject prometheus labels from config
- env: $ENV # Inject prometheus labels from env var

packages:
- location: hercules-packages/snowflake/performance/1.0.yml
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (c *Config) InstanceLabels() labels.GlobalLabels {
globalLabels := labels.GlobalLabels{}
globalLabels[HERCULES_NAME_LABEL] = c.Name
for k, v := range c.GlobalLabels {
globalLabels[k] = v
globalLabels[k] = labels.InjectLabelFromEnv(v)
}
return globalLabels
}
Expand Down
12 changes: 11 additions & 1 deletion pkg/labels/labels.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package labels

import "maps"
import (
"maps"
"os"
)

type GlobalLabels map[string]string

func InjectLabelFromEnv(labelVal string) string {
if string(labelVal[0]) == "$" {
return os.Getenv(string(labelVal[1:]))
}
return labelVal
}

func (l GlobalLabels) LabelNames() []string {
var labelNames []string
for k := range l {
Expand Down

0 comments on commit 14458da

Please sign in to comment.