Project | LXD |
Status | Implemented |
Author(s) | @monstermunchkin |
Approver(s) | @stgraber @tomp |
Release | LXD 5.6 |
Internal ID | LX025 |
Abstract
Allow LXD to stream lifecycle and log events to a Grafana Loki server.
Rationale
Currently, lifecycle and log events can be viewed by running lxc monitor
or querying /1.0/events
. If running multiple LXD servers (not clustered), there is no way of aggregating the logs of all servers. Streaming lifecycle and log events to a Grafana Loki server solves this problem, and also enables visualizing these on a dashboard.
Specification
Design
Streaming lifecycle and log events to a Grafana Loki server requires the loki.api.url
config key to be set which points to the Grafana Loki server. Should the Grafana Loki server require authentication, loki.auth.username
and loki.auth.password
need to be set for basic authentication. If a CA certificate is needed for the server, it can be specified in loki.api.ca_cert
.
The event type(s) and the minimum log level which are to be streamed can be configured using the loki.types
and loki.loglevel
config keys respectively.
Every streamed event will have two fixed labels app=lxd
and type=<lifecycle|logging>
. Additional labels can be specified using loki.labels
. If any of these labels are found in an LXD event, they will be added as a label to a Loki event, and removed from the log message. All other key-value pairs will be added to the log message like "key1=\"<value1>\" <key2>=\"<value2>\" <message>"
.
Labels at the metadata level do not have to be prefixed (level
, message
), the others do (context-class
, context-description
, context-operation
, context-project
). This is done to avoid keys of the same name on different levels.
Example:
loki.labels: [context-class, context-instance, context-project]
LXD Event:
location: none
metadata:
context:
class: task
description: Updating images
operation: 9007385a-4d34-46e3-a676-a4bc355319a5
project: ""
level: debug
message: Started operation
timestamp: "2022-09-02T10:21:42.886203976+02:00"
type: logging
Loki event:
{
"streams": [
{
"stream": {
"app": "lxd",
"type": "logging",
"context-class": "task",
},
"values": [
[
"1662106902886203976",
"context-description=\"Updating images\" context-operation=\"9007385a-4d34-46e3-a676-a4bc355319a5\" level=\"debug\" Started operation"
]
]
}
]
}
Here, context-class
is in loki.labels
and is therefore added as a label. The keys context-description
, context-operation
, and level
and their values are added to the log message.
API changes
No API changes.
CLI changes
No CLI changes.
Database changes
No database changes.
Upgrade handling
No upgrade handling.
Further information
No further information.