defenseunicorns / uds-core

A secure runtime platform for mission-critical capabilities
https://uds.defenseunicorns.com
Apache License 2.0
38 stars 15 forks source link

Add consistent (typed) log metadata #549

Open rjferguson21 opened 1 week ago

rjferguson21 commented 1 week ago

With the addition of https://github.com/defenseunicorns/uds-core/pull/533, we will be using child loggers which allow adding metadata to each log line which is very useful for filtering by a particular uds-operator component in Loki (or other log parsers).

It would also be beneficial to try to standardize the objects that we are logging using pino so that we can go a step further and potentially filter by other metadata for example showing all operator reconcile logs related to a particular Package.

The change would end up taking log lines that looked like:

 log.info(
    `Processing Package ${namespace}/${name}, status.phase: ${pkg.status?.phase}, observedGeneration: ${pkg.status?.observedGeneration}, retryAttempt: ${pkg.status?.retryAttempt}`,
  );

and converting them to something like:

 // note this is K8s Metadata but it could include anything
 type UDSReconcileLogMetadata = {
  name: string;
  namespace: string;
};

log.info<UDSReconcileLogMetadata>(
  { name, namespace },
  `Processing Package ${namespace}/${name}, status.phase: ${pkg.status?.phase}, observedGeneration: ${pkg.status?.observedGeneration}, retryAttempt: ${pkg.status?.retryAttempt}`,
);

The value of this would be that instead of you could consistently search for logs relating to a particular Package without relying on the log message alone.

UnicornChance commented 1 week ago

also worth capturing in this issue could be the confusing nature of the pepr policies and the naming conventions there. The /policies/index.ts logs are under the policies component but technically refer to the operator.exemptions, maybe a restructuring of the files or renaming the components.