Skip to content

Commit e8d7544

Browse files
committed
Add new host extraction for NGINX Gateway Fabric in Alloy
1 parent 6b51b39 commit e8d7544

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎kubernetes/namespaces/loki/alloy/alloy_values.yml‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,40 @@ alloy:
7171
// Write all values into the Loki receiver
7272
loki.source.kubernetes "pods" {
7373
targets = discovery.relabel.pods.output
74+
forward_to = [loki.process.nginx_gateway.receiver]
75+
}
76+
77+
loki.process "nginx_gateway" {
7478
forward_to = [loki.write.local.receiver]
79+
80+
stage.match {
81+
selector = `{namespace="nginx-gateway", app_container="/nginx"}`
82+
83+
// Set the default first
84+
stage.static_labels {
85+
values = {
86+
ngf_host = "unknown",
87+
}
88+
}
89+
90+
// Try to extract host from JSON
91+
stage.json {
92+
expressions = { ngf_host = "host" }
93+
}
94+
95+
// Only overwrites ngf_host if the JSON extraction actually populated it
96+
stage.labels {
97+
values = {
98+
ngf_host = "",
99+
}
100+
}
101+
102+
stage.drop {
103+
source = "__error__"
104+
value = "JSONParserErr"
105+
drop_counter_reason = "non_json_nginx_log"
106+
}
107+
}
75108
}
76109
77110
loki.write "local" {

0 commit comments

Comments
 (0)