-
Notifications
You must be signed in to change notification settings - Fork 789
fix: otel sink json access logging without text field #5498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4bb15af
5ea3f3b
fac129c
2153e2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -336,10 +336,10 @@ func buildXdsAccessLog(al *ir.AccessLog, accessLogType ir.ProxyAccessLogType) ([ | |
| ResourceAttributes: convertToKeyValueList(otel.Resources, false), | ||
| } | ||
|
|
||
| if otel.Text == nil { | ||
| return nil, errors.New("otel.Text is nil") | ||
| var format string | ||
| if otel.Text != nil && *otel.Text != "" { | ||
| format = *otel.Text | ||
|
Comment on lines
340
to
341
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also do a separate check for JSON logging? I.e. check if JSON attributes are defined or not, and in case not, default to Something along the lines if len(otel.Attributes) != 0 {
al.Attributes = convertToKeyValueList(otel.Attributes, true)
formatters = accessLogOpenTelemetryFormatters(format, otel.Attributes)
} else {
// if there are no attributes, use the default EnvoyJSONLogFields
al.Attributes = convertToKeyValueList(EnvoyJSONLogFields, true)
formatters = accessLogOpenTelemetryFormatters(format, EnvoyJSONLogFields)
}
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds goo to me, cc @guydc
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry this took a bit of time. Went through the OpenTelemetry specs and documentation on the field. Implemented following:
The JSON fields are populated to the accessLog |
||
| } | ||
| format := *otel.Text | ||
|
|
||
| if format != "" { | ||
| al.Body = &otlpcommonv1.AnyValue{ | ||
|
|
@@ -349,9 +349,17 @@ func buildXdsAccessLog(al *ir.AccessLog, accessLogType ir.ProxyAccessLogType) ([ | |
| } | ||
| } | ||
|
|
||
| al.Attributes = convertToKeyValueList(otel.Attributes, true) | ||
| var attrs map[string]string | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesnt this feel weird, if we have a format its part of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we move this to another GH issue and only have the fix around in this PR so we can add it into v1.3.2 , releasing soon
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be done! Only concern is, how does this behave in case no output type or format/attributes are defined? As JSON logging is now default, does it render logs empty for users who have neither defined? Previously in v1.3.0, the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this looks good, sorry for the confusion |
||
| if len(otel.Attributes) != 0 { | ||
| attrs = otel.Attributes | ||
| } else if len(otel.Attributes) == 0 && format == "" { | ||
| // if there are no attributes and text format is unset, use the default EnvoyJSONLogFields | ||
| attrs = EnvoyJSONLogFields | ||
| } | ||
|
|
||
| al.Attributes = convertToKeyValueList(attrs, true) | ||
| formatters := accessLogOpenTelemetryFormatters(format, attrs) | ||
|
|
||
| formatters := accessLogOpenTelemetryFormatters(format, otel.Attributes) | ||
| if len(formatters) != 0 { | ||
| al.Formatters = formatters | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| apiVersion: gateway.networking.k8s.io/v1 | ||
| kind: Gateway | ||
| metadata: | ||
| name: accesslog-gtw | ||
| namespace: gateway-conformance-infra | ||
| spec: | ||
| gatewayClassName: {GATEWAY_CLASS_NAME} | ||
| listeners: | ||
| - name: http | ||
| port: 80 | ||
| protocol: HTTP | ||
| allowedRoutes: | ||
| namespaces: | ||
| from: Same | ||
| infrastructure: | ||
| parametersRef: | ||
| group: gateway.envoyproxy.io | ||
| kind: EnvoyProxy | ||
| name: accesslog-otel | ||
| --- | ||
| apiVersion: gateway.envoyproxy.io/v1alpha1 | ||
| kind: EnvoyProxy | ||
| metadata: | ||
| name: accesslog-otel | ||
| namespace: gateway-conformance-infra | ||
| spec: | ||
| ipFamily: IPv4 | ||
| telemetry: | ||
| accessLog: | ||
| settings: | ||
| - matches: | ||
| - "'x-envoy-logged' in request.headers" | ||
| sinks: | ||
| - type: OpenTelemetry | ||
| openTelemetry: | ||
| backendRefs: | ||
| - name: otel-collector | ||
| namespace: monitoring | ||
| port: 4317 | ||
| resources: | ||
| k8s.cluster.name: "envoy-gateway" | ||
| shutdown: | ||
| drainTimeout: 5s | ||
| minDrainDuration: 1s | ||
| --- | ||
| apiVersion: gateway.networking.k8s.io/v1 | ||
| kind: HTTPRoute | ||
| metadata: | ||
| name: accesslog-otel | ||
| namespace: gateway-conformance-infra | ||
| spec: | ||
| parentRefs: | ||
| - name: accesslog-gtw | ||
| rules: | ||
| - matches: | ||
| - path: | ||
| type: PathPrefix | ||
| value: /otel | ||
| backendRefs: | ||
| - name: infra-backend-v2 | ||
| port: 8080 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| apiVersion: gateway.networking.k8s.io/v1 | ||
| kind: Gateway | ||
| metadata: | ||
| name: accesslog-gtw | ||
| namespace: gateway-conformance-infra | ||
| spec: | ||
| gatewayClassName: {GATEWAY_CLASS_NAME} | ||
| listeners: | ||
| - name: http | ||
| port: 80 | ||
| protocol: HTTP | ||
| allowedRoutes: | ||
| namespaces: | ||
| from: Same | ||
| infrastructure: | ||
| parametersRef: | ||
| group: gateway.envoyproxy.io | ||
| kind: EnvoyProxy | ||
| name: accesslog-otel | ||
| --- | ||
| apiVersion: gateway.envoyproxy.io/v1alpha1 | ||
| kind: EnvoyProxy | ||
| metadata: | ||
| name: accesslog-otel | ||
| namespace: gateway-conformance-infra | ||
| spec: | ||
| ipFamily: IPv4 | ||
| telemetry: | ||
| accessLog: | ||
| settings: | ||
| - format: | ||
| type: JSON | ||
| json: | ||
| time: "%START_TIME%" | ||
| method: "%REQ(:METHOD)%" | ||
| metadata: "%METADATA(ROUTE:envoy-gateway:resources)%" | ||
| x-envoy-original-path: "%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%" | ||
| protocol: "%PROTOCOL%" | ||
| responseCode: "%RESPONSE_CODE%" | ||
| responseFlags: "%RESPONSE_FLAGS%" | ||
| bytesReceived: "%BYTES_RECEIVED%" | ||
| bytesSent: "%BYTES_SENT%" | ||
| duration: "%DURATION%" | ||
| x-forwarded-for: "%REQ(X-FORWARDED-FOR)%" | ||
| user-agent: "%REQ(USER-AGENT)%" | ||
| x-request-id: "%REQ(X-REQUEST-ID)%" | ||
| authority: "%REQ(:AUTHORITY)%" | ||
| upstreamHost: "%UPSTREAM_HOST%" | ||
| matches: | ||
| - "'x-envoy-logged' in request.headers" | ||
| sinks: | ||
| - type: OpenTelemetry | ||
| openTelemetry: | ||
| backendRefs: | ||
| - name: otel-collector | ||
| namespace: monitoring | ||
| port: 4317 | ||
| resources: | ||
| k8s.cluster.name: "envoy-gateway" | ||
| shutdown: | ||
| drainTimeout: 5s | ||
| minDrainDuration: 1s | ||
| --- | ||
| apiVersion: gateway.networking.k8s.io/v1 | ||
| kind: HTTPRoute | ||
| metadata: | ||
| name: accesslog-otel | ||
| namespace: gateway-conformance-infra | ||
| spec: | ||
| parentRefs: | ||
| - name: accesslog-gtw | ||
| rules: | ||
| - matches: | ||
| - path: | ||
| type: PathPrefix | ||
| value: /otel | ||
| backendRefs: | ||
| - name: infra-backend-v2 | ||
| port: 8080 |
Uh oh!
There was an error while loading. Please reload this page.