diff --git a/modules/kubernetes/annotations/logs/logs.alloy b/modules/kubernetes/annotations/logs/logs.alloy index b403700..2e43fc1 100644 --- a/modules/kubernetes/annotations/logs/logs.alloy +++ b/modules/kubernetes/annotations/logs/logs.alloy @@ -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 @@ -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" } } diff --git a/modules/kubernetes/annotations/metrics.alloy b/modules/kubernetes/annotations/metrics.alloy index 6b6890b..43ce000 100644 --- a/modules/kubernetes/annotations/metrics.alloy +++ b/modules/kubernetes/annotations/metrics.alloy @@ -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 @@ -394,7 +400,7 @@ declare "kubernetes" { ] separator = ";" regex = "^([^;]+)(?:;*)?([^;]+).*$" - replacement = "$1/$2" + replacement = argument.job_format.value target_label = "job" } @@ -408,7 +414,7 @@ declare "kubernetes" { ] separator = ";" regex = "^(?:ReplicaSet);([^;]+);([^;]+)-.+$" - replacement = "$1/$2" + replacement = argument.job_format.value target_label = "job" }