-
Notifications
You must be signed in to change notification settings - Fork 101
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
set service_name label for podLogs #1175
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Run make build
inside charts/k8s-monitoring
to update the generated files.
charts/k8s-monitoring/charts/feature-pod-logs/templates/_common_pod_discovery.alloy.tpl
Outdated
Show resolved
Hide resolved
2f134cb
to
6dc7369
Compare
de5ea21
to
f248799
Compare
// explicitly set service_name. if not set, loki will automatically try to populate a default. | ||
// see https://grafana.com/docs/loki/latest/get-started/labels/#default-labels-for-all-users | ||
// | ||
// choose the first value found from the following ordered list: | ||
// - pod.annotation[resource.opentelemetry.io/service.name] | ||
// - pod.label[app.kubernetes.io/name] | ||
// - k8s.pod.name | ||
// - k8s.container.name | ||
rule { | ||
action = "replace" | ||
source_labels = [ | ||
"__meta_kubernetes_pod_annotation_resource_opentelemetry_io_service_name", | ||
"__meta_kubernetes_pod_label_app_kubernetes_io_name", | ||
"__meta_kubernetes_pod_name", | ||
"__meta_kubernetes_pod_container_name", | ||
] | ||
separator = ";" | ||
regex = "^(?:;*)?([^;]+).*$" | ||
replacement = "$1" | ||
target_label = "service_name" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cyrille-leclerc do you mind taking a look at this?
I can't include other values used by the opentelemetry operator (statefulset, deployment, etc.) because they are not currently supported by prometheus kubernetes service discovery.
Signed-off-by: Robbie Lankford <[email protected]>
f248799
to
310a260
Compare
This PR sets
service_name
,service_namespace
,deployment_environment
, anddeployment_environment_name
labels on Loki pod logs. This works when sent to loki destinations. I'll follow this PR up with updates for pod logs sent to OTLP destinations.The labels are set according to the following rules:
service_name
label set by taking the first non-empty value from these Kubernetes metadata fields (in order): the pod annotationresource.opentelemetry.io/service.name
, the pod labelapp.kubernetes.io/name
, the pod’s name, or the container’s name.service_namespace
set byresource.opentelemetry.io/service.namespace
pod annotation.deployment_environment
set byresource.opentelemetry.io/deployment.environment
pod annotation.deployment_environment_name
set byresource.opentelemetry.io/deployment.environment.name
pod annotation.If not set, Loki will attempt to set a default value according to these rules: https://grafana.com/docs/loki/latest/get-started/labels/#default-labels-for-all-users