Skip to content

Commit e3826fb

Browse files
authored
Merge pull request #11945 from irapandey/promtail-to-alloy-migration
🌱 Promtail to alloy migration
2 parents 6b98ba4 + 5622a19 commit e3826fb

File tree

10 files changed

+151
-47
lines changed

10 files changed

+151
-47
lines changed

Tiltfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,9 @@ def deploy_provider_crds():
420420
)
421421

422422
def deploy_observability():
423-
if "promtail" in settings.get("deploy_observability", []):
424-
k8s_yaml(read_file("./.tiltbuild/yaml/promtail.observability.yaml"), allow_duplicates = True)
425-
k8s_resource(workload = "promtail", extra_pod_selectors = [{"app": "promtail"}], labels = ["observability"], resource_deps = ["loki"], objects = ["promtail:serviceaccount"])
423+
if "alloy" in settings.get("deploy_observability", []):
424+
k8s_yaml(read_file("./.tiltbuild/yaml/alloy.observability.yaml"), allow_duplicates = True)
425+
k8s_resource(workload = "alloy", extra_pod_selectors = [{"app": "alloy"}], labels = ["observability"], resource_deps = ["loki"], objects = ["alloy:serviceaccount"])
426426

427427
if "loki" in settings.get("deploy_observability", []):
428428
k8s_yaml(read_file("./.tiltbuild/yaml/loki.observability.yaml"), allow_duplicates = True)

docs/book/src/developer/core/logging.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,19 @@ thorny parts of code. Over time, based on feedback from SRE/developers, more log
136136

137137
## Developing and testing logs
138138

139-
Our [Tilt](tilt.md) setup offers a batteries-included log suite based on [Promtail](https://grafana.com/docs/loki/latest/clients/promtail/), [Loki](https://grafana.com/docs/loki/latest/fundamentals/overview/) and [Grafana](https://grafana.com/docs/grafana/latest/explore/logs-integration/).
139+
Our [Tilt](tilt.md) setup offers a batteries-included log suite based on [alloy](https://grafana.com/docs/loki/latest/send-data/alloy/), [Loki](https://grafana.com/docs/loki/latest/fundamentals/overview/) and [Grafana](https://grafana.com/docs/grafana/latest/explore/logs-integration/).
140140

141141
We are working to continuously improving this experience, allowing Cluster API developers to use logs and improve them as part of their development process.
142142

143143
For the best experience exploring the logs using Tilt:
144144
1. Set `--logging-format=json`.
145145
2. Set a high log verbosity, e.g. `v=5`.
146-
3. Enable Promtail, Loki, and Grafana under `deploy_observability`.
146+
3. Enable alloy, Loki, and Grafana under `deploy_observability`.
147147

148148
A minimal example of a tilt-settings.yaml file that deploys a ready-to-use logging suite looks like:
149149
```yaml
150150
deploy_observability:
151-
- promtail
151+
- alloy
152152
- loki
153153
- grafana
154154
enable_providers:
@@ -209,7 +209,6 @@ Will return logs from the `capi-controller-manager`, associated with the Cluster
209209
Will return the logs from four CAPI providers - the Core provider, Kubeadm Control Plane provider, Kubeadm Bootstrap provider and the Docker infrastructure provider. It filters by the cluster name and the machine name and then formats the log lines to show just the source controller and the message. This allows us to correlate logs and see actions taken by each of these four providers related to the machine `my-cluster-linux-worker-1`.
210210
211211
For more information on formatting and filtering logs using Grafana and Loki see:
212-
- [json parsing](https://grafana.com/docs/loki/latest/clients/promtail/stages/json/)
213212
- [log queries](https://grafana.com/docs/loki/latest/logql/log_queries/)
214213
215214
## What about providers

docs/book/src/developer/core/testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ analyzing them via Grafana.
308308

309309
1. Start the development environment as described in [Developing Cluster API with Tilt](tilt.md).
310310
* Make sure to deploy Loki and Grafana via `deploy_observability`.
311-
* If you only want to see imported logs, don't deploy promtail (via `deploy_observability`).
311+
* If you only want to see imported logs, don't deploy alloy (via `deploy_observability`).
312312
* If you want to drop all logs from Loki, just delete the Loki Pod in the `observability` namespace.
313313
2. You can then import logs via the `Import Logs` button on the top right of the [Loki resource page](http://localhost:10350/r/loki/overview).
314314
Just click on the downwards arrow, enter either a ProwJob URL, a GCS path or a local folder and click on `Import Logs`.

docs/book/src/developer/core/tilt.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ Supported values are:
297297
* `loki`: To receive and store logs.
298298
* `metrics-server`: To enable `kubectl top node/pod`.
299299
* `prometheus`*: For collecting metrics from Kubernetes.
300-
* `promtail`: For providing pod logs to `loki`.
300+
* `alloy`: For providing pod logs to `loki`.
301301
* `parca`*: For visualizing profiling data.
302302
* `tempo`: To store traces.
303303
* `visualizer`*: Visualize Cluster API resources for each cluster, provide quick access to the specs and status of any resource.

docs/book/src/developer/core/tuning.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ When tuning controllers, both for scalability, performance or for reducing their
99

1010
Cluster API provides a full stack of tools for tuning its own controllers as well as controllers for all providers if developed using controller runtime. As a bonus, most of this tooling can be used with any other controller runtime based controllers.
1111

12-
With tilt, you can easily deploy a full observability stack with Grafana, Loki, promtail, Prometheus, kube-state-metrics, Parca and Tempo.
12+
With tilt, you can easily deploy a full observability stack with Grafana, Loki, alloy, Prometheus, kube-state-metrics, Parca and Tempo.
1313

1414
All tools are preconfigured, and most notably kube-state-metrics already collects CAPI metrics and Grafana is configured with a set of dashboards that we used in previous rounds of CAPI tuning. Overall, the CAPI dev environment offers a considerable amount of expertise, free to use and to improve for the entire community. We highly recommend to invest time in looking into those tools, learn and provide feedback.
1515

hack/observability/promtail/kustomization.yaml renamed to hack/observability/alloy/kustomization.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ resources:
22
- ../namespace.yaml
33

44
helmCharts:
5-
- name: promtail
5+
- name: alloy
66
repo: https://grafana.github.io/helm-charts
7-
releaseName: promtail
8-
namespace: observability
7+
releaseName: alloy
8+
version: 0.12.5
99
valuesFile: values.yaml
10-
version: 6.16.6
10+
namespace: observability
11+
12+
1113

1214
helmGlobals:
1315
# Store chart in ".charts" folder instead of "charts".

hack/observability/alloy/values.yaml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Configuration for alloy - https://github.com/grafana/alloy/blob/main/operations/helm/charts/alloy/values.yaml
2+
alloy:
3+
configMap:
4+
create: true
5+
content: |-
6+
discovery.kubernetes "kubernetes_pods" {
7+
role = "pod"
8+
}
9+
10+
discovery.relabel "kubernetes_pods" {
11+
targets = discovery.kubernetes.kubernetes_pods.targets
12+
13+
rule {
14+
source_labels = ["__meta_kubernetes_pod_controller_name"]
15+
regex = "([0-9a-z-.]+?)(-[0-9a-f]{8,10})?"
16+
target_label = "__tmp_controller_name"
17+
}
18+
19+
rule {
20+
source_labels = ["__meta_kubernetes_pod_label_app_kubernetes_io_name", "__meta_kubernetes_pod_label_app", "__tmp_controller_name", "__meta_kubernetes_pod_name"]
21+
regex = "^;*([^;]+)(;.*)?$"
22+
target_label = "app"
23+
}
24+
25+
rule {
26+
source_labels = ["__meta_kubernetes_pod_label_app_kubernetes_io_instance", "__meta_kubernetes_pod_label_instance"]
27+
regex = "^;*([^;]+)(;.*)?$"
28+
target_label = "instance"
29+
}
30+
31+
rule {
32+
source_labels = ["__meta_kubernetes_pod_label_app_kubernetes_io_component", "__meta_kubernetes_pod_label_component"]
33+
regex = "^;*([^;]+)(;.*)?$"
34+
target_label = "component"
35+
}
36+
37+
rule {
38+
source_labels = ["__meta_kubernetes_pod_node_name"]
39+
target_label = "node_name"
40+
}
41+
42+
rule {
43+
source_labels = ["__meta_kubernetes_namespace"]
44+
target_label = "namespace"
45+
}
46+
47+
rule {
48+
source_labels = ["namespace", "app"]
49+
separator = "/"
50+
target_label = "job"
51+
}
52+
53+
rule {
54+
source_labels = ["__meta_kubernetes_pod_name"]
55+
target_label = "pod"
56+
}
57+
58+
rule {
59+
source_labels = ["__meta_kubernetes_pod_container_name"]
60+
target_label = "container"
61+
}
62+
63+
rule {
64+
source_labels = ["__meta_kubernetes_pod_uid", "__meta_kubernetes_pod_container_name"]
65+
separator = "/"
66+
target_label = "__path__"
67+
replacement = "/var/log/pods/*$1/*.log"
68+
}
69+
70+
rule {
71+
source_labels = ["__meta_kubernetes_pod_annotationpresent_kubernetes_io_config_hash", "__meta_kubernetes_pod_annotation_kubernetes_io_config_hash", "__meta_kubernetes_pod_container_name"]
72+
separator = "/"
73+
regex = "true/(.*)"
74+
target_label = "__path__"
75+
replacement = "/var/log/pods/*$1/*.log"
76+
}
77+
}
78+
79+
local.file_match "kubernetes_pods" {
80+
path_targets = discovery.relabel.kubernetes_pods.output
81+
}
82+
83+
loki.process "kubernetes_pods" {
84+
forward_to = [loki.write.default.receiver]
85+
86+
stage.cri { }
87+
88+
stage.json {
89+
expressions = {
90+
Cluster = "join('/',[Cluster.namespace,Cluster.name])",
91+
KubeadmControlPlane = "join('/',[KubeadmControlPlane.namespace,KubeadmControlPlane.name])",
92+
Machine = "join('/',[Machine.namespace,Machine.name])",
93+
MachineDeployment = "join('/',[MachineDeployment.namespace,MachineDeployment.name])",
94+
MachinePool = "join('/',[MachinePool.namespace,MachinePool.name])",
95+
MachineSet = "join('/',[MachineSet.namespace,MachineSet.name])",
96+
controller = "",
97+
}
98+
}
99+
100+
stage.labels {
101+
values = {
102+
Cluster = null,
103+
KubeadmControlPlane = null,
104+
Machine = null,
105+
MachineDeployment = null,
106+
MachinePool = null,
107+
MachineSet = null,
108+
controller = null,
109+
}
110+
}
111+
}
112+
113+
loki.source.file "kubernetes_pods" {
114+
targets = local.file_match.kubernetes_pods.targets
115+
forward_to = [loki.process.kubernetes_pods.receiver]
116+
legacy_positions_file = "/run/promtail/positions.yaml"
117+
}
118+
119+
loki.write "default" {
120+
endpoint {
121+
url = "http://loki:3100/loki/api/v1/push"
122+
tenant_id = "1"
123+
}
124+
external_labels = {}
125+
}
126+
mounts:
127+
varlog: true
128+
run:
129+
enabled: true
130+
path: /run
131+
podSecurityContext:
132+
runAsUser: 0
133+
runAsGroup: 0
134+
fsGroup: 0

hack/observability/grafana/chart/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ datasources:
3030
isDefault: true
3131
editable: true
3232
# This header has to be set as we had to set an OrgID
33-
# in promtail to be able to push the logs to Loki.
33+
# in alloy to be able to push the logs to Loki.
3434
jsonData:
3535
maxLines: 1000
3636
derivedFields:

hack/observability/promtail/values.yaml

Lines changed: 0 additions & 31 deletions
This file was deleted.

test/framework/deployment_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ func (eh *watchPodLogsEventHandler) streamPodLogs(pod *corev1.Pod) {
328328
}
329329

330330
// logMetadata contains metadata about the logs.
331-
// The format is very similar to the one used by promtail.
331+
// The format is very similar to the one used by alloy.
332332
type logMetadata struct {
333333
Job string `json:"job"`
334334
Namespace string `json:"namespace"`

0 commit comments

Comments
 (0)