Skip to content

Commit 9850b7f

Browse files
committed
feat: deploy grafana alloy
1 parent 7b50a3a commit 9850b7f

File tree

6 files changed

+218
-0
lines changed

6 files changed

+218
-0
lines changed

apps/alloy/alloy.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
apiVersion: helm.toolkit.fluxcd.io/v2
3+
kind: HelmRelease
4+
metadata:
5+
name: alloy
6+
spec:
7+
interval: 5m
8+
timeout: 15m
9+
chart:
10+
spec:
11+
chart: alloy
12+
version: '0.6.0'
13+
sourceRef:
14+
kind: HelmRepository
15+
name: grafana-charts
16+
namespace: apps
17+
maxHistory: 5
18+
install:
19+
crds: CreateReplace
20+
remediation:
21+
retries: 4
22+
upgrade:
23+
crds: CreateReplace
24+
timeout: 15m
25+
remediation:
26+
remediateLastFailure: true
27+
uninstall:
28+
keepHistory: false
29+
values:
30+
alloy:
31+
extraEnv:
32+
- name: GRAFANA_CLOUD_API_KEY
33+
valueFrom:
34+
secretKeyRef:
35+
name: grafana-cloud-secrets
36+
key: API_KEY
37+
- name: GRAFANA_CLOUD_LOGS_USER
38+
value: '967489'
39+
configMap:
40+
create: false
41+
name: alloy-config
42+
key: config.alloy

apps/alloy/kustomization.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
namespace: apps
4+
resources:
5+
- ./alloy.yaml
6+
- ./secret.yaml
7+
configMapGenerator:
8+
- name: alloy-config
9+
files:
10+
- config.alloy=./resources/config.alloy
11+
generatorOptions:
12+
disableNameSuffixHash: true

apps/alloy/resources/config.alloy

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// discovery.kubernetes allows you to find scrape targets from Kubernetes resources.
2+
// It watches cluster state and ensures targets are continually synced with what is currently running in your cluster.
3+
discovery.kubernetes "pod" {
4+
role = "pod"
5+
}
6+
7+
// discovery.relabel rewrites the label set of the input targets by applying one or more relabeling rules.
8+
// If no rules are defined, then the input targets are exported as-is.
9+
discovery.relabel "pod_logs" {
10+
targets = discovery.kubernetes.pod.targets
11+
12+
// Label creation - "namespace" field from "__meta_kubernetes_namespace"
13+
rule {
14+
source_labels = ["__meta_kubernetes_namespace"]
15+
action = "replace"
16+
target_label = "namespace"
17+
}
18+
19+
// Label creation - "pod" field from "__meta_kubernetes_pod_name"
20+
rule {
21+
source_labels = ["__meta_kubernetes_pod_name"]
22+
action = "replace"
23+
target_label = "pod"
24+
}
25+
26+
// Label creation - "container" field from "__meta_kubernetes_pod_container_name"
27+
rule {
28+
source_labels = ["__meta_kubernetes_pod_container_name"]
29+
action = "replace"
30+
target_label = "container"
31+
}
32+
33+
// Label creation - "app" field from "__meta_kubernetes_pod_label_app_kubernetes_io_name"
34+
rule {
35+
source_labels = ["__meta_kubernetes_pod_label_app_kubernetes_io_name"]
36+
action = "replace"
37+
target_label = "app"
38+
}
39+
40+
// Label creation - "job" field from "__meta_kubernetes_namespace" and "__meta_kubernetes_pod_container_name"
41+
// Concatenate values __meta_kubernetes_namespace/__meta_kubernetes_pod_container_name
42+
rule {
43+
source_labels = ["__meta_kubernetes_namespace", "__meta_kubernetes_pod_container_name"]
44+
action = "replace"
45+
target_label = "job"
46+
separator = "/"
47+
replacement = "$1"
48+
}
49+
50+
// Label creation - "container" field from "__meta_kubernetes_pod_uid" and "__meta_kubernetes_pod_container_name"
51+
// Concatenate values __meta_kubernetes_pod_uid/__meta_kubernetes_pod_container_name.log
52+
rule {
53+
source_labels = ["__meta_kubernetes_pod_uid", "__meta_kubernetes_pod_container_name"]
54+
action = "replace"
55+
target_label = "__path__"
56+
separator = "/"
57+
replacement = "/var/log/pods/*$1/*.log"
58+
}
59+
60+
// Label creation - "container_runtime" field from "__meta_kubernetes_pod_container_id"
61+
rule {
62+
source_labels = ["__meta_kubernetes_pod_container_id"]
63+
action = "replace"
64+
target_label = "container_runtime"
65+
regex = "^(\\S+):\\/\\/.+$"
66+
replacement = "$1"
67+
}
68+
}
69+
70+
// loki.source.kubernetes tails logs from Kubernetes containers using the Kubernetes API.
71+
loki.source.kubernetes "pod_logs" {
72+
targets = discovery.relabel.pod_logs.output
73+
forward_to = [loki.process.pod_logs.receiver]
74+
}
75+
76+
// loki.process receives log entries from other Loki components, applies one or more processing stages,
77+
// and forwards the results to the list of receivers in the component’s arguments.
78+
loki.process "pod_logs" {
79+
stage.static_labels {
80+
values = {
81+
cluster = "anton",
82+
}
83+
}
84+
85+
forward_to = [loki.write.grafana_cloud.receiver]
86+
}
87+
88+
// loki.source.kubernetes_events tails events from the Kubernetes API and converts them
89+
// into log lines to forward to other Loki components.
90+
loki.source.kubernetes_events "cluster_events" {
91+
job_name = "integrations/kubernetes/eventhandler"
92+
log_format = "logfmt"
93+
forward_to = [
94+
loki.process.cluster_events.receiver,
95+
]
96+
}
97+
98+
loki.process "cluster_events" {
99+
forward_to = [loki.write.grafana_cloud.receiver]
100+
101+
stage.static_labels {
102+
values = {
103+
cluster = "anton",
104+
}
105+
}
106+
107+
stage.labels {
108+
values = {
109+
kubernetes_cluster_events = "job",
110+
}
111+
}
112+
}
113+
114+
loki.write "grafana_cloud" {
115+
endpoint {
116+
url = "https://logs-prod-012.grafana.net/loki/api/v1/push"
117+
basic_auth {
118+
username = env("GRAFANA_CLOUD_LOGS_USER")
119+
password = env("GRAFANA_CLOUD_API_KEY")
120+
}
121+
}
122+
}

apps/alloy/secret.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: grafana-cloud-secrets
5+
namespace: apps
6+
stringData:
7+
API_KEY: ENC[AES256_GCM,data:+ypERtzqL2ZUTh/r2Iw5QncgMoMB1TCDunWHTQmd057xdSRUJlXpplzX+K/kSedRVGnvin17q2YZdMqMX6nbXAqZoho2SUMbtm+pC8fK/ZSGB9DGNqMfDaObuDBKpaDNGqdjDIFjeZd0J+j3nmPSVvtBLJRNFb0v5DOcTWioCFaDUYSm0qUJSd2N6AKvoGOcRDgx2ZCIPzdUa8nOgGZMfw==,iv:59JBsXIf0P3oHKaUGaNXYtUuazfcGR5Lxy2G1y+rIT4=,tag:r+2GZ9MO+zIumZ2h0KSM/w==,type:str]
8+
sops:
9+
kms: []
10+
gcp_kms: []
11+
azure_kv: []
12+
hc_vault: []
13+
age:
14+
- recipient: age194r4u78jlkcg3waxh5ddpwe6y0pwenuhk9avnkmc3huzcpf26d0spa3ggf
15+
enc: |
16+
-----BEGIN AGE ENCRYPTED FILE-----
17+
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSA5RXo1K2RXcU5CRXprLys3
18+
OVB2TXVnbi92ZEVsRzVQV0Z6WnRTbU5rbm5ZCjREdVdmLy8xZTZlWkFLWWJvcVpQ
19+
OHcvN2FKaEN1VWRoaUtrTmJ4MWY3aTgKLS0tIDlWSEdqd0JzeVp6SXFXek1nckdI
20+
U25MMXJudFMxbithTnZhT3MrYzJiT3MKUHZft0byZa+HiQygo351g6jngg4YIaK0
21+
UowhOtDmxVRskpML+4jemYBhA8I0Ek39EDBhfzj0vI67qAH4IeUM/g==
22+
-----END AGE ENCRYPTED FILE-----
23+
lastmodified: "2024-08-16T19:06:36Z"
24+
mac: ENC[AES256_GCM,data:/iub7WT94FmlVN2OBJ+CAxVtGJ26h51tzTSAY0ktkRgGkkkDIWbk0UbiHdZzP/ic++/p8pW7yBCkmybIhO6Z/fgGcLtxvq7IsH0nu77Y2C7qUJM3qBmGng8Lc/LacGVFE0ppUFTTvENaC1tCDZePCilNAOfN/krmMp1bb1ehlIk=,iv:VeL3jzD1ZO722y2NjTJdyprFgzrY1udonYGQcEzfc7E=,tag:xyf5HjIJLHOqi2xjw2hquw==,type:str]
25+
pgp: []
26+
encrypted_regex: ((?i)(pass($|word)|claim|secret($|[^N])|key|token|^data$|^stringData|^databaseUrl))
27+
version: 3.9.0

clusters/anton/apps/alloy.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: kustomize.toolkit.fluxcd.io/v1
2+
kind: Kustomization
3+
metadata:
4+
name: alloy
5+
namespace: flux-system
6+
spec:
7+
interval: 10m0s
8+
sourceRef:
9+
kind: GitRepository
10+
name: flux-system
11+
path: ./apps/alloy
12+
prune: true
13+
dependsOn:
14+
- name: apps-base

clusters/anton/apps/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ resources:
2727
- ./homepage.yaml
2828
- ./unpackerr.yaml
2929
- ./windmill.yaml
30+
- ./alloy.yaml

0 commit comments

Comments
 (0)