Skip to content

Commit

Permalink
feat: add the ability to customize the format of the job label
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhackl committed Jan 8, 2025
1 parent 32aeea4 commit 9dee128
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 9 additions & 3 deletions modules/kubernetes/annotations/logs/logs.alloy
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ declare "pods" {
default = ".*"
}

argument "job_format" {
comment = "Format of the job label. Default is namespace/pod name as $1/$2"
optional = true
default = "$1/$2"
}

/*
Hidden Arguments
These arguments are used to set reusable variables to avoid repeating logic
Expand Down Expand Up @@ -190,11 +196,11 @@ declare "pods" {
rule {
action = "replace"
source_labels = [
"workload",
"__meta_kubernetes_namespace",
"workload",
]
regex = ".+\\/(.+);(.+)"
replacement = "$2/$1"
regex = "(.+);.+\\/(.+)"
replacement = argument.job_format.value
target_label = "job"
}
}
Expand Down
10 changes: 8 additions & 2 deletions modules/kubernetes/annotations/metrics.alloy
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ declare "kubernetes" {
optional = true
}

argument "job_format" {
comment = "Format of the job label. Default is namespace/pod_controller_name as $1/$2"
optional = true
default = "$1/$2"
}

/*
Hidden Arguments
These arguments are used to set reusable variables to avoid repeating logic
Expand Down Expand Up @@ -394,7 +400,7 @@ declare "kubernetes" {
]
separator = ";"
regex = "^([^;]+)(?:;*)?([^;]+).*$"
replacement = "$1/$2"
replacement = argument.job_format.value
target_label = "job"
}

Expand All @@ -408,7 +414,7 @@ declare "kubernetes" {
]
separator = ";"
regex = "^(?:ReplicaSet);([^;]+);([^;]+)-.+$"
replacement = "$1/$2"
replacement = argument.job_format.value
target_label = "job"
}

Expand Down

0 comments on commit 9dee128

Please sign in to comment.