Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ tasks:
# fail to build.
#
# Those fixtures and every kustomization under config/ and deploy/,
# except Components, are rendered and checked for a LOG_LEVEL,
# LOG_FORMAT, --log-level or --log-format that internal/logging rejects.
# except Components, are rendered and checked for a LOG_LEVEL or
# --log-level that internal/logging rejects, and for the removed
# LOG_FORMAT and --log-format or the local-only --zap-devel.
# The containerlab overlays under deploy/containerlab/resources build
# only once the lab scripts copy config/ onto a node, so they are not
# rendered here; their source YAML, inline patches included, is checked
Expand All @@ -250,11 +251,11 @@ tasks:
echo "FAIL: $dir does not build"; status=1; continue
fi
if ! printf '%s\n' "$out" | {{.LOCALBIN}}/check-log-settings -label "$dir" -; then
echo "FAIL: $dir sets an unsupported log level or format"; status=1
echo "FAIL: $dir sets an unsupported log setting"; status=1
fi
done
if ! find config deploy tests/manifests -name '*.yaml' -print0 | xargs -0 {{.LOCALBIN}}/check-log-settings; then
echo "FAIL: source YAML sets an unsupported log level or format"; status=1
echo "FAIL: source YAML sets an unsupported log setting"; status=1
fi
for dir in tests/manifests/invalid/*/; do
if {{.KUSTOMIZE}} build "$dir" > /dev/null 2>&1; then
Expand Down
2 changes: 1 addition & 1 deletion cmd/fabric-api/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ func runGateway(parent context.Context, o *gatewayOptions) error {
// manager shuts down.
defer context.AfterFunc(ctx, gs.Stop)()

slog.Info("starting fabric-api gateway", "version", metadata.Version, "site", o.site, "cluster", o.clusterName,
slog.Info("starting fabric-api gateway", "version", metadata.Version, "site", o.site, "clusterName", o.clusterName,
"cell", o.cell, "debug", debugAddr)
return mgr.Start(ctx)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/fabric-api/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func runNode(parent context.Context, o *nodeOptions) error {
stopMetrics := serveMetrics(metricsAddr, metrics.Handler())
defer stopMetrics()

slog.Info("starting fabric-api node", "version", metadata.Version, "node", o.nodeName, "site", o.site,
slog.Info("starting fabric-api node", "version", metadata.Version, "nodeName", o.nodeName, "site", o.site,
"listen", addr, "metrics", metricsAddr, "probeSources", sources, "expensiveQueries", o.enableExpensive)
errc := make(chan error, 1)
go func() { errc <- gs.Serve(lis) }()
Expand Down
2 changes: 1 addition & 1 deletion cmd/fabric-config-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func run(parent context.Context, opts *options, fn func(*fabricconfig.Agent, con

opts.restCfg = restCfg

slog.Info("starting "+appName, "version", metadata.Version, "node", opts.nodeName, "namespace", opts.namespace,
slog.Info("starting "+appName, "version", metadata.Version, "nodeName", opts.nodeName, "podNamespace", opts.namespace,
"activation", opts.activation, "configMaps", opts.configMaps)
return fn(agent, ctx)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/galactic-edge/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func run(parent context.Context, o *options) error {
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
return err
}
slog.Info("starting galactic-edge", "node", o.nodeName, "owner", a.Owner,
slog.Info("starting galactic-edge", "nodeName", o.nodeName, "owner", a.Owner,
"version", metadata.Version)
return mgr.Start(ctx)
}
4 changes: 2 additions & 2 deletions cmd/galactic-gateway/encapsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ func resolveEncapSource(ctx context.Context, reader client.Reader, nodeName, con
switch {
case errors.As(err, &listRoutersError{}):
slog.Warn("Listing BGPRouters to derive the edge gateway SRv6 encapsulation source failed; retrying",
"node", nodeName, "retryIn", delay, "error", err)
"nodeName", nodeName, "retryIn", delay, "error", err)
case errors.As(err, &noRouterYetError{}):
slog.Info("Waiting for this node's BGPRouter to derive the edge gateway SRv6 encapsulation source",
"node", nodeName, "retryIn", delay)
"nodeName", nodeName, "retryIn", delay)
default:
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion deploy/containerlab/scripts/verify-fabric-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ node_targets() {
echo "${node} $(awk -v n="${node}" '$1 == n {print $2}' <<<"${certs}") ${hostip} ${frpod}"
done
}
q() { "${FA}" --log-format text --log-level warn query --cell "${site}" --operator lab-verify \
q() { "${FA}" --log-level warn query --cell "${site}" --operator lab-verify \
--tls-cert "${creds}/tls.crt" --tls-key "${creds}/tls.key" --tls-ca "${creds}/ca.crt" "$@"; }

# wait_info prints a node's Info, retrying for up to 90s: right after a
Expand Down
2 changes: 1 addition & 1 deletion docs/controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CLI defaults below describe the binary. Deployment overlays may override them; f
| `--health-probe-bind-address` | `:8081` | Health and readiness listener |
| `--leader-elect` | `true` | Elect one reconciler; cell webhook replicas all serve admission |

Logging takes `--log-level` (`LOG_LEVEL`) and `--log-format` (`LOG_FORMAT`); see [Logging](../observability/logging.md).
Logging takes `--log-level` (`LOG_LEVEL`) and the standard `--zap-*` flags; see [Logging](../observability/logging.md).

## Cell flags

Expand Down
16 changes: 8 additions & 8 deletions docs/fabric-api/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ syntax (`10m`).

### Global (all subcommands)

| Flag | Env | Default | Meaning |
| ----------------- | ------------ | ------- | -------------------------------------------- |
| `--log-level` | `LOG_LEVEL` | `info` | `debug`, `info`, `warn` or `error` |
| `--log-format` | `LOG_FORMAT` | `json` | `json` or `text` |
| `--version`, `-V` | | | Print the version and exit (root only) |
| `--build-info` | | | Print build information and exit (root only) |

[Logging](../observability/logging.md) describes what these two flags cover.
| Flag | Env | Default | Meaning |
| ----------------- | ----------- | ------- | -------------------------------------------- |
| `--log-level` | `LOG_LEVEL` | `info` | `debug`, `info`, `warn` or `error` |
| `--zap-*` | | | Standard zap flags, such as `--zap-devel` |
| `--version`, `-V` | | | Print the version and exit (root only) |
| `--build-info` | | | Print build information and exit (root only) |

[Logging](../observability/logging.md) describes what the logging flags cover.

Tracing is enabled only when `OTEL_EXPORTER_OTLP_ENDPOINT` or
`OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` is set; the standard OpenTelemetry exporter
Expand Down
2 changes: 1 addition & 1 deletion docs/gateway/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ flags, or a combination of both (CLI flags take precedence), with the
`GALACTIC_GATEWAY` env prefix — the same three-tier precedence pattern
`galactic-router` uses (see [docs/router/configuration.md](../router/configuration.md)).

Logging takes `--log-level` (`LOG_LEVEL`) and `--log-format` (`LOG_FORMAT`), without the `GALACTIC_GATEWAY` prefix; see [Logging](../observability/logging.md).
Logging takes `--log-level` (`LOG_LEVEL`), without the `GALACTIC_GATEWAY` prefix and the standard `--zap-*` flags; see [Logging](../observability/logging.md).

| Option | Environment Variable | CLI Flag | Default | Required |
| ------------------- | -------------------------------------- | ------------------------------- | ----------- | ------------- |
Expand Down
2 changes: 1 addition & 1 deletion docs/nat/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ flags, or a combination of both (CLI flags take precedence), with the
`galactic-router` and `galactic-gateway` use (see
[docs/router/configuration.md](../router/configuration.md)).

Logging takes `--log-level` (`LOG_LEVEL`) and `--log-format` (`LOG_FORMAT`), without the `GALACTIC_NAT` prefix; see [Logging](../observability/logging.md).
Logging takes `--log-level` (`LOG_LEVEL`), without the `GALACTIC_NAT` prefix and the standard `--zap-*` flags; see [Logging](../observability/logging.md).

| Option | Environment Variable | CLI Flag | Default | Required |
| ------------------ | -------------------------------- | ------------------------- | ------------- | -------- |
Expand Down
132 changes: 95 additions & 37 deletions docs/observability/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,40 @@ Every long-running Galactic binary (`galactic-router`, `galactic-gateway`,
`galactic-nat`, `galactic-vrf`, `galactic-controller`, `galactic-edge`,
`galactic-cni`, `fabric-router-controller`, `fabric-api` and
`fabric-config-agent`) installs one logger at startup through
`internal/logging`. The same handler writes the binary's own `slog` lines, the
standard `log` package, controller-runtime (reconciler errors, cache and leader
election) and klog (client-go), so every line has one format and one level
threshold. For `galactic-cni` that covers the `install-cni` init container and
the `credential-refresh` daemon; for `fabric-config-agent`, the `frr-init` init
container and the `config-agent` sidecar.

| Flag | Env | Default | Meaning |
| -------------- | ------------ | ------- | ---------------------------------- |
| `--log-level` | `LOG_LEVEL` | `info` | `debug`, `info`, `warn` or `error` |
| `--log-format` | `LOG_FORMAT` | `json` | `json` or `text` |

An explicit flag wins over the environment variable. `--log-level` also
accepts what Go's `slog` parses beyond the four names: any case, and an offset
such as `info+2`.
`internal/logging`, which builds it with the shared Milo instrumentation
library ([`go.miloapis.com/instrumentation/logging`](https://github.com/milo-os/instrumentation)).
The same logger writes the binary's own `slog` lines, the standard `log`
package, controller-runtime (reconciler errors, cache and leader election),
klog (client-go) and the embedded GoBGP server in `galactic-router`, so every
line has one format and one level threshold. For `galactic-cni` that covers
the `install-cni` init container and the `credential-refresh` daemon; for
`fabric-config-agent`, the `frr-init` init container and the `config-agent`
sidecar.

| Flag | Env | Default | Meaning |
| ------------------------ | ----------- | ------- | ----------------------------------------------- |
| `--log-level` | `LOG_LEVEL` | `info` | `debug`, `info`, `warn` or `error` |
| `--zap-devel` | | off | Console output for local runs |
| `--zap-log-level` | | | zap's level; overrides `--log-level` when given |
| `--zap-encoder` | | `json` | `json` or `console` |
| `--zap-stacktrace-level` | | `error` | Lowest level that carries a stack trace |
| `--zap-time-encoding` | | RFC3339 | zap's time encoding |

The `--zap-*` flags are controller-runtime's standard zap flags, the same in
every Milo service. An explicit `--log-level` wins over `LOG_LEVEL`.
`--log-level` also accepts what Go's `slog` parses beyond the four names: any
case, and an offset such as `info+2`.

An unsupported value stops the binary at startup, before it does anything
else, whether it comes from the flag or the environment variable. A DaemonSet
with one crash-loops on every node. `task test:manifests`, which CI runs,
renders every kustomization under `config/` and `deploy/` and fails on an
unsupported value for a container running one of these binaries.
`hack/check-log-settings` applies the same rules (`internal/logging`'s
`ValidateLevel` and `ValidateFormat`) to any YAML, so downstream manifests
should run it on their rendered output, with a Galactic release that includes
it:
unsupported level for a container running one of these binaries. It also fails
on `--zap-devel`, which is for local runs only, and on the removed
`--log-format` flag and `LOG_FORMAT` variable. `hack/check-log-settings`
applies the same rules (`internal/logging`'s `ValidateLevel`) to any YAML, so
downstream manifests should run it on their rendered output, with a Galactic
release that includes it:

```sh
kustomize build <overlay> | go run go.datum.net/galactic/hack/check-log-settings@<version> -
Expand All @@ -37,31 +46,80 @@ kustomize build <overlay> | go run go.datum.net/galactic/hack/check-log-settings
It recognizes a Galactic container by its image repository name, or by a
command that runs one of these binaries: `fabric-config-agent` ships in the
`fabric-router` image, run directly by `config-agent` and from a shell script
by `frr-init`. It checks only literal values, not ones read from a ConfigMap or Secret. An empty
`LOG_LEVEL` or `LOG_FORMAT` counts as unset. In source YAML that isn't
by `frr-init`. It checks only literal values, not ones read from a ConfigMap or
Secret. An empty `LOG_LEVEL` counts as unset. In source YAML that isn't
rendered, such as the containerlab overlays, it reads strategic-merge patches
but not JSON 6902 patches.

Production runs the defaults: one JSON object per line on stderr, with
`time`, `level` and `msg` keys. controller-runtime's lines also carry a
`logger` key naming the component. Its verbose lines (`V(1)` and up) appear
only at `--log-level=debug`. klog keeps its own verbosity setting, which these
flags don't change, so client-go's `klog.V(n)` lines stay off.
## Output

Production runs the defaults: one JSON object per line on stderr. Every line
has these keys:

| Key | Value |
| ------------------------- | ------------------------------------------------------------ |
| `ts` | RFC 3339 timestamp in UTC, to the nanosecond |
| `level` | `debug`, `info`, `warn` or `error` |
| `msg` | The message |
| `build_version` | The binary's release tag, from `internal/metadata.Version` |
| `instrumentation_version` | The instrumentation library's version linked into the binary |

Lines may also carry `logger` (the component, such as controller-runtime's
`controller-runtime.client.config` or `gobgp`), `caller` (file and line of a
`slog` call), `error`, and `stacktrace` on `error` lines. controller-runtime's
verbose lines (`V(1)` and up) and `slog.Debug` lines appear only at
`--log-level=debug`, with level `debug`. klog keeps its own verbosity setting,
which these flags don't change, so client-go's `klog.V(n)` lines stay off.

Galactic's own log keys avoid the names the collection pipeline reserves for
its labels, such as `node`, `namespace`, `pod` and `service`. A Kubernetes
object a line is about is `resource_name` and `resource_namespace`; other
values use specific names such as `nodeName` or `podNamespace`.
controller-runtime's reconciler lines still carry its own `namespace` and
`name` keys.

A binary that fails after reading its flags logs the error as one `error`
line through the same handler, then exits 1. A bad flag or an invalid
`--log-level` or `--log-format` fails before the handler exists, so that one
line is Go's default text.
line through the same logger, then exits 1. A bad flag or an invalid
`--log-level` fails before the logger exists, so that one line is Go's default
text.

For local runs, `--log-format=text --log-level=debug` gives readable output
with the verbose lines. No binary enables controller-runtime's zap development
mode: `internal/logging`'s `TestBinariesUseThisPackage` fails when a command
under `cmd/` imports controller-runtime's zap package or calls `SetLogger`
itself, and `TestLongRunningBinariesInstallTheHandler` fails when a command
under `cmd/` doesn't import `internal/logging` at all.
For local runs, `--zap-devel --log-level=debug` gives console output with the
verbose lines. No binary turns on development mode itself:
`internal/logging`'s `TestLoggerAdopted` runs the instrumentation library's
logger check over the whole module, which fails on any logger not built by the
library and on development mode turned on in source.
`TestBinariesUseThisPackage` fails when a command under `cmd/` imports
controller-runtime's zap package or calls `SetLogger` itself, and
`TestLongRunningBinariesInstallTheHandler` fails when a command under `cmd/`
doesn't import `internal/logging` at all.

Two kinds of command are exempt. The CNI plugins (`galactic-veth`,
`galactic-tap`, `galactic-ipam`, `galactic-bgp` and `galactic-route`) run once
per CNI call and write JSON to their own log file; see the
per CNI call and write the same JSON lines to their own log file, through
`internal/logging.SetupFile`; see the
[CNI environment variables](../cni/environment-variables.md).
`galactic-usid` is a one-shot codec command in the debug image.

## Changes from the slog format

Releases before the instrumentation library wrote lines with Go's `slog` JSON
handler. Queries that read log fields need these changes:

| Before | Now |
| ---------------------------------------- | ------------------------------------------------------------------- |
| `time`, local time zone | `ts`, UTC |
| `level` `DEBUG`, `INFO`, `WARN`, `ERROR` | `level` `debug`, `info`, `warn`, `error` |
| controller-runtime `err` | `error` |
| controller-runtime `logger` with `/` | `logger` with `.`, such as `controller-runtime.webhook` |
| no version | `build_version` and `instrumentation_version` |
| no source location or stack trace | `caller` on `slog` lines, `stacktrace` on `error` lines |
| `node` | `nodeName` |
| `namespace` | `resource_namespace`, or `podNamespace` for a pod's |
| `name` beside `namespace` | `resource_name` |
| `pod` | `podRef` or `podName` |
| `service` | `serviceName`, `serviceUID`, or `caller` for a Looking Glass caller |
| `endpoint` | `serviceEndpoint` |
| `instance` | `instanceName` |
| `cluster` | `clusterName` |
| `--log-format`, `LOG_FORMAT` | removed; `--zap-devel` for local console output |
| GoBGP lines discarded | GoBGP lines at the binary's level, logger `gobgp` |
2 changes: 1 addition & 1 deletion docs/router/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ flag name — the mapping is defined in `internal/config` (see `RouterConfig`
and the `EnvRouter*` constants). Always use the exact name from the table
below.

Logging takes `--log-level` (`LOG_LEVEL`) and `--log-format` (`LOG_FORMAT`), without the `GALACTIC_ROUTER` prefix; see [Logging](../observability/logging.md).
Logging takes `--log-level` (`LOG_LEVEL`), without the `GALACTIC_ROUTER` prefix and the standard `--zap-*` flags; see [Logging](../observability/logging.md).

| Option | Environment Variable | CLI Flag | Default |
| ------------------------ | ------------------------------------------ | ---------------------------- | --------------------------- |
Expand Down
Loading
Loading