Repository navigation
Description
What happened
ProxyAccessLogFormat.Type is optional. The CEL rule on the type only requires that
something is set when the type is omitted:
// api/v1alpha1/envoyproxy_accesslogging_types.go
// +kubebuilder:validation:XValidation:rule="!has(self.type) ? (has(self.text) || has(self.json)) : true",message="If AccessLogFormat type is unset, at least one of text or json must be set."
So format: {text: "..."} with no type is accepted by the API server for any sink type.
The OpenTelemetry sink honors it. File and ALS do not: the text is dropped and the built-in
default JSON fields are emitted instead. No error, no status condition.
Config that gets dropped
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyProxy
metadata:
name: custom-proxy-config
namespace: envoy-gateway-system
spec:
telemetry:
accessLog:
settings:
- format:
text: |
custom %START_TIME% %REQ(:METHOD)% %RESPONSE_CODE%
sinks:
- type: File
file:
path: /dev/stdout
Expected: the file sink logs with that format string. Actual: the proxy logs the default
JSON access log fields.
Where
internal/gatewayapi/listener.go
File sink, line 899:
if format.Type != nil && *format.Type == egv1a1.ProxyAccessLogFormatTypeText {
ALS sink, line 963: same test.
With format.Type == nil both fall to the else branch, which builds an ir.JSONAccessLog
from format.JSON. format.JSON is nil here, and ir.MapToSlice(nil) returns nil, so the
IR carries an empty field list. internal/xds/translator/accesslog.go lines 159-163 then
substitutes the defaults:
if json.JSON != nil {
jsonLogFields = json.JSON
} else {
jsonLogFields = ir.MapToSlice(EnvoyJSONLogFields)
}
The OpenTelemetry sink at line 1015 uses a different test and does handle the nil type:
if format.Type == nil || *format.Type == egv1a1.ProxyAccessLogFormatTypeText {
al.Text = format.Text
}
There is a third path with the same outcome: when len(accessLog.Sinks) == 0, lines 882-890
build a JSONAccessLog on /dev/stdout unconditionally. There is no text branch at all, so
a type-less text format is dropped there too, and so is format: {type: Text, text: "..."}
with no sinks.
Confirmed by
Calling processAccessLog directly with the EnvoyProxy above (type-less text format, one
File sink) returns an ir.AccessLog with 0 entries in Text and 1 in JSON, whose JSON
field list is empty. That is the input to the xds default substitution above.
Question
The type-less format looks like it was added for the OpenTelemetry sink, where text (body)
and attributes are both meaningful. Two directions:
- Make the File and ALS paths (and the no-sink stdout path) honor a type-less text format,
matching the OTel behavior. - Add a CEL rule rejecting a type-less format when a non-OTel sink is configured, so the
config is refused instead of silently ignored.
Which do you prefer? Happy to send a PR either way.
Environment
main at f1d26db.
Activity
fix: honor access log text format when format.type is unset (envoypro…
fix: honor access log text format when format.type is unset (envoypro…
[release/v1.9] cherry pick for v1.9.1 (#9872)
[release-1.8] Cherry pick for v1.8.4 (#9877)