Skip to content

Commit

Permalink
[Kubernetes]: Update Alloy configs
Browse files Browse the repository at this point in the history
Signed-off-by: Weifeng Wang <[email protected]>
  • Loading branch information
qclaogui committed Apr 24, 2024
1 parent fa90705 commit f3581b5
Show file tree
Hide file tree
Showing 35 changed files with 6,347 additions and 1,102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Module Components: annotations_scrape
Description: Scrapes targets for logs based on kubernetes Pod annotations

Annotations:
logs.grafana.com/ingest: true
logs.grafana.com/scrape: true
logs.grafana.com/tenant: "primary"
*/

Expand All @@ -22,11 +22,7 @@ declare "annotations_scrape" {
default = ".*"
}

// arguments for kubernetes discovery
argument "namespaces" {
comment = "The namespaces to look for targets in (default: [\"kube-system\"] is all namespaces)"
optional = true
}
argument "cluster" { }

argument "annotation_prefix" {
comment = "The annotation_prefix to use (default: logs.grafana.com)"
Expand All @@ -43,18 +39,14 @@ declare "annotations_scrape" {
// find all pods
discovery.kubernetes "annotation_logs" {
role = "pod"

namespaces {
names = coalesce(argument.namespaces.value, [])
}
}

// filter logs by kubernetes annotations
discovery.relabel "annotation_logs_filter" {
targets = discovery.kubernetes.annotation_logs.targets

// allow pods to declare their logs to be ingested or not, the default is true
// i.e. logs.grafana.com/ingest: false
// i.e. logs.grafana.com/scrape: false
rule {
action = "keep"
source_labels = [
Expand All @@ -80,6 +72,13 @@ declare "annotations_scrape" {
target_label = "instance"
}

// set the cluster label
rule {
action = "replace"
replacement = argument.cluster.value
target_label = "cluster"
}

// set the namespace label
rule {
source_labels = ["__meta_kubernetes_namespace"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ declare "kubernetes_cluster_events" {
optional = true
}

argument "cluster" {
optional = true
}
argument "cluster" { }

loki.source.kubernetes_events "cluster_events" {
job_name = coalesce(argument.job_label.value, "integrations/kubernetes/eventhandler")
Expand All @@ -28,7 +26,7 @@ declare "kubernetes_cluster_events" {
loki.process "logs_service" {
stage.static_labels {
values = {
cluster = coalesce(argument.cluster.value, "k3d"),
cluster = argument.cluster.value,
}
}
forward_to = argument.forward_to.value
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Module Components: rules_to_loki
Description: Auto discovers PrometheusRule Kubernetes resources and loads them into a Loki instance.
*/

declare "rules_to_loki" {

/*****************************************************************
* ARGUMENTS
*****************************************************************/
argument "address" {
comment = "URL of the Loki ruler. (default: http://nginx.gateway.svc:3100)"
optional = true
}

argument "tenant" {
comment = "Mimir tenant ID. (default: fake)"
optional = true
}

/********************************************
* Kubernetes Prometheus Rules To Loki
********************************************/
loki.rules.kubernetes "rules_to_loki" {
address = coalesce(argument.address.value, "http://nginx.gateway.svc:3100")
tenant_id = coalesce(argument.tenant.value, "anonymous")

// rule_namespace_selector {
// match_labels = {
// auto_rules_to_loki= "true",
// }
// }

rule_selector {
match_labels = {
auto_rules_to_loki = "true",
}
}
}
}
Loading

0 comments on commit f3581b5

Please sign in to comment.