You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/book/src/developer/logging.md
+52-15Lines changed: 52 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -130,23 +130,25 @@ thorny parts of code. Over time, based on feedback from SRE/developers, more log
130
130
131
131
## Developing and testing logs
132
132
133
-
We are continuously improving our [Tilt](tilt.md) setup allowing Cluster API developers to use logs and improve them as part of
134
-
their development process.
135
-
136
-
Developers can deploy an entire log observability suite by simply setting the
137
-
`deploy_observability` value in your [tilt-setting.yaml](tilt.md#create-a-tilt-settings-file).
133
+
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/).
138
134
139
-
```yaml
140
-
deploy_observability:
141
-
- promtail
142
-
- loki
143
-
- grafana
144
-
```
135
+
We are working to continuously improving this experience, allowing Cluster API developers to use logs and improve them as part of their development process.
145
136
146
-
In order to test structured logging it is required to override some controller flags, and similar approach can be used
147
-
for increasing log verbosity, e.g.
137
+
For the best experience exploring the logs using Tilt:
138
+
1. Set `--logging-format=json`.
139
+
2. Set a high log verbosity, e.g. `v=5`.
140
+
3. Enable promtail, loki, and grafana under deploy_observability.
148
141
142
+
A minimal example of a tilt-settings.yaml file that deploys a ready-to-use logging suite looks like:
149
143
```yaml
144
+
deploy_observability:
145
+
- promtail
146
+
- loki
147
+
- grafana
148
+
enable_providers:
149
+
- docker
150
+
- kubeadm-bootstrap
151
+
- kubeadm-control-plane
150
152
extra_args:
151
153
core:
152
154
- "--logging-format=json"
@@ -161,9 +163,43 @@ extra_args:
161
163
- "--v=5"
162
164
- "--logging-format=json"
163
165
```
166
+
The above options can be combined with other settings from our [Tilt](tilt.md) setup. Once Tilt is is up and running with these settings users will be able to browse logs using the Grafana Explore UI.
167
+
168
+
This will normally be available on `localhost:3001`. To explore logs from Loki, open the Explore interface for the DataSource 'Loki'. [This link](http://localhost:3001/explore?datasource%22:%22Loki%22) should work as a shortcut with the default Tilt settings.
164
169
165
-
Over time, we would like to further improve this with the help of the community; feel free to open issues or propose
166
-
ideas!
170
+
### Example queries
171
+
172
+
In the Log browser the following queries can be used to browse logs by controller, and by specific Cluster API objects. For example:
173
+
```
174
+
{app="capi-controller-manager"} | json
175
+
```
176
+
Will return logs from the `capi-controller-manager` which are parsed in json. Passing the query through the json parser allows filtering by key-value pairs that are part of nested json objects. For example `.cluster.name` becomes `cluster_name`.
Will return logs from the `capi-controller-manager`, associated with the Cluster `my-cluster` and the Reconcile ID `6f6ad971-bdb6-4fa3-b803-xxxxxxxxxxxx`. Each reconcile loop will have a unique Reconcile ID.
Will return logs from the `capi-controller-manager`, associated with the Cluster `my-cluster` and the Reconcile ID `6f6ad971-bdb6-4fa3-b803-xxxxxxxxxxxx` it further selects only those logs which come from the Cluster controller. It will then format the logs so only the message is displayed.
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`.
199
+
200
+
For more information on formatting and filtering logs using Grafana and Loki see:
0 commit comments