Logs

The line every decision writes, and the fields it carries.

Admitik writes one JSON line per decision: a policy of a kind, over an object, in an operation, with a result and, when there is something to say, a message.

{"level":"info","msg":"policy decision","policy":"require-limits","policyKind":"validate","operation":"CREATE","object":{"apiVersion":"apps/v1","kind":"Deployment","namespace":"team-a","name":"checkout"},"result":"denied","reason":"conditions","message":"the container 'api' must declare a cpu limit"}

This page is the contract. The code lives in internal/telemetry/log.go and its tests in internal/telemetry/log_test.go.

Fields

FieldTypeMeaning
msgstringpolicy decision, always. It is how a decision line is found
policystringThe policy that was involved
policyKindstringvalidate, mutate or generate
operationstringCREATE, UPDATE or DELETE
objectobjectThe object the policy acted on: apiVersion, kind, name, and namespace when it is namespaced
resultstringWhat came out, see below
reasonstringWhy, in a closed set: none, sources, conditions, template, patch, apply
messagestringOptional. Why, in words. Only when there is something to say

When the object a policy acts on is not the one that woke it up, the line adds one field:

FieldTypeMeaning
triggerobjectThe object that woke the policy up, same shape as object

Generation writes it, because a Namespace wakes a policy that writes a NetworkPolicy. A cleanup policy will not, because it removes the object that triggered it: object and trigger would be the same thing. Cloning writes it, because the source and the copy are different objects.

Lines may also carry duration and, for generated objects, created. They are informative and may be absent.

Results

resultLevelMeaning
deniedinfoThe policy rejected the object
permissiveinfoThe policy found the object non compliant and let it pass
patchedinfoThe policy changed the object
generatedinfoThe policy wrote an object
failederrorThe policy could not be applied. error carries what went wrong
alloweddebugThe policy evaluated the object and had nothing to say
skippeddebugThe policy did not apply, by its conditions or because the object exists

info is for what changed something. A policy that did nothing only appears with --zap-log-level=debug.

Compatibility

  • Fields are added, never renamed or removed. Adding a field is a minor change; renaming or removing one is a breaking change and needs a release note.
  • New values of result and reason are added to their sets. Neither accepts free text: the message carries that.
  • Both are checked by tests. If a test in internal/telemetry/log_test.go fails, the contract changed on purpose or by accident: decide which, and update this file in the same change.

Writing a decision

Decisions are written by telemetry.LogDecision, which is the only place that knows the shape of the line. A new kind of policy or a new place that decides something must use it:

telemetry.LogDecision(logger, telemetry.DecisionLine{
	Policy:    policy.Name,
	Kind:      telemetry.KindValidate,
	Object:    common.ObjectRefOfAdmission(request.Kind, request.Namespace, request.Name),
	Operation: string(request.Operation),
	Result:    result.Outcome,
	Reason:    result.Reason,
	Message:   result.Message,
	Err:       result.Err,
})

The logger is the root one: the function adds every field of the line.