Skip to content

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

Merged
merged 4 commits into from
Mar 22, 2025

Conversation

kraashen
Copy link
Contributor

What type of PR is this?

This PR attempts to fix issue #5481 by passing only the JSON attributes to the otel formatter builder. It does this by leaving the text format empty when JSON type is specified but text is not.

What this PR does / why we need it:

As described in the linked issue, this leads to a situation where HTTPRoutes are not registering to listeners due to error returned in situations where JSON logging is used. This issue seemed to be rising when OpenTelemetry sink type is used without text field in the configuration.

Tested this in a local cluster calling the test API, and logs seemed to be produced in Loki when queried with exporter=OTEL label.
image

Which issue(s) this PR fixes:

Fixes #5481

Release Notes: Yes

Note

I have little to none prior experience of Envoy Gateway development. Went through the guidelines with best effort, but I'm a bit unsure if there are any possible other downstream consequences to this change. Any advice would be appreciated!

@kraashen kraashen requested a review from a team as a code owner March 14, 2025 09:03
Copy link

codecov bot commented Mar 14, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 4 lines in your changes missing coverage. Please review.

Project coverage is 65.26%. Comparing base (580686a) to head (2153e2d).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/xds/translator/accesslog.go 66.66% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5498      +/-   ##
==========================================
+ Coverage   65.25%   65.26%   +0.01%     
==========================================
  Files         213      213              
  Lines       34063    34069       +6     
==========================================
+ Hits        22228    22236       +8     
+ Misses      10500    10499       -1     
+ Partials     1335     1334       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@arkodg arkodg requested review from zirain and guydc March 15, 2025 02:30
@zirain zirain force-pushed the fix/otel-json-accesslog branch from ece73ca to 43133c3 Compare March 15, 2025 10:25
Copy link
Member

@zirain zirain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, defer to @guydc

Comment on lines +340 to +341
if otel.Text != nil && *otel.Text != "" {
format = *otel.Text
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 EnvoyJSONLogFields?

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)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds goo to me, cc @guydc

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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:

  • When no text or JSON type is set, default to EnvoyJSONLogFields, similar to previous implementation with the respective text format prior to v1.3.1/v1.2.7

The JSON fields are populated to the accessLog Attributes field as before with the JSON fields. Went through the OpenTelemetry specification discussion on this and relevant docs and to me it seems that this should be an OK way to go.

@kraashen kraashen force-pushed the fix/otel-json-accesslog branch from 9381a23 to 5ea3f3b Compare March 20, 2025 07:32
Copy link
Contributor

@guydc guydc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for fixing this and adding a test!

@@ -349,9 +349,17 @@ func buildXdsAccessLog(al *ir.AccessLog, accessLogType ir.ProxyAccessLogType) ([
}
}

al.Attributes = convertToKeyValueList(otel.Attributes, true)
var attrs map[string]string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesnt this feel weird, if we have a format its part of Body, else Attributes

Copy link
Contributor

Choose a reason for hiding this comment

The 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

		if otel.Text != nil && *otel.Text != "" {
			format = *otel.Text

in this PR so we can add it into v1.3.2 , releasing soon

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 EnvoyTextLogFormat was set as default and then it was checked if log format was defined. https://github.com/envoyproxy/gateway/blob/v1.3.0/internal/xds/translator/accesslog.go#L325-L336

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks good, sorry for the confusion

Copy link
Contributor

@arkodg arkodg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks !

@arkodg
Copy link
Contributor

arkodg commented Mar 22, 2025

@kraashen can you fix DCO and force push

@kraashen kraashen force-pushed the fix/otel-json-accesslog branch from f7c0dbf to fac129c Compare March 22, 2025 18:59
@arkodg arkodg merged commit cb3ffd2 into envoyproxy:main Mar 22, 2025
9 checks passed
zhaohuabing pushed a commit to zhaohuabing/gateway that referenced this pull request Mar 23, 2025
* fix otel sink json access logging without text field

Signed-off-by: Tomi Juntunen <[email protected]>

* use json format as default when format or type is not set

Signed-off-by: Tomi Juntunen <[email protected]>

* set formatters only if the slice of formatters is not empty

Signed-off-by: Tomi Juntunen <[email protected]>

---------

Signed-off-by: Tomi Juntunen <[email protected]>
Co-authored-by: Arko Dasgupta <[email protected]>
(cherry picked from commit cb3ffd2)
Signed-off-by: Huabing (Robin) Zhao <[email protected]>
guydc pushed a commit to guydc/gateway that referenced this pull request Mar 23, 2025
* fix otel sink json access logging without text field

Signed-off-by: Tomi Juntunen <[email protected]>

* use json format as default when format or type is not set

Signed-off-by: Tomi Juntunen <[email protected]>

* set formatters only if the slice of formatters is not empty

Signed-off-by: Tomi Juntunen <[email protected]>

---------

Signed-off-by: Tomi Juntunen <[email protected]>
Co-authored-by: Arko Dasgupta <[email protected]>
(cherry picked from commit cb3ffd2)
Signed-off-by: Guy Daich <[email protected]>
guydc added a commit that referenced this pull request Mar 24, 2025
* load BackendTLSPolicy in standalone mode (#5431)

Signed-off-by: Arko Dasgupta <[email protected]>
(cherry picked from commit 4d914ae)
Signed-off-by: Guy Daich <[email protected]>

* Wasm: cache Wasm OCI image permission check results (#5358)

* add TTL for wasm permission check

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* fix test

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* change

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* refresh the cache

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* purge the cache

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* refactor

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* on retry on retriable errors

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* add release note

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

---------

Signed-off-by: Huabing (Robin) Zhao <[email protected]>
(cherry picked from commit 672de8a)
Signed-off-by: Guy Daich <[email protected]>

* Load EnvoyExtensionPolicy in standalone mode (#5460)

* load EnvoyExtensionPolicy in standalone mode

Signed-off-by: Takeshi Yoneda <[email protected]>

* more

Signed-off-by: Takeshi Yoneda <[email protected]>

* release note

Signed-off-by: Takeshi Yoneda <[email protected]>

* review: use a valid target name instead of myapp

Signed-off-by: Takeshi Yoneda <[email protected]>

* gen

Signed-off-by: Takeshi Yoneda <[email protected]>

---------

Signed-off-by: Takeshi Yoneda <[email protected]>
(cherry picked from commit 4be098d)
Signed-off-by: Guy Daich <[email protected]>

* fix: check for mirror backendRef in httproute index (#5497)

* check for mirror backendRef

Signed-off-by: mark winter <[email protected]>
(cherry picked from commit 72b72c4)
Signed-off-by: Guy Daich <[email protected]>

* fix: dont return an err when gatewayclass is not accepted (#5524)

* bug: dont return an err when gatewayclass is not accepted

this is a user generated error, we shouldnt log it as
a system error, and return with an error

Signed-off-by: Arko Dasgupta <[email protected]>

* release notes

Signed-off-by: Arko Dasgupta <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
(cherry picked from commit 51e87ca)
Signed-off-by: Guy Daich <[email protected]>

* fix: host header should not be allowed to modify (#5533)

* host header is not allowed to be modified

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* address comment

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

---------

Signed-off-by: Huabing (Robin) Zhao <[email protected]>
(cherry picked from commit 54efa34)
Signed-off-by: Guy Daich <[email protected]>

* fix: retrigger reconciliation when backendRef of type ServiceImport is updated (#5461)

* fix: retrigger reconilation when backendRef of type ServiceImport is updated

Signed-off-by: Teju Nareddy <[email protected]>
(cherry picked from commit e2f8978)
Signed-off-by: Guy Daich <[email protected]>

* pin envoy and ratelimit

Signed-off-by: Guy Daich <[email protected]>

* fix: otel sink json access logging without text field (#5498)

* fix otel sink json access logging without text field

Signed-off-by: Tomi Juntunen <[email protected]>

* use json format as default when format or type is not set

Signed-off-by: Tomi Juntunen <[email protected]>

* set formatters only if the slice of formatters is not empty

Signed-off-by: Tomi Juntunen <[email protected]>

---------

Signed-off-by: Tomi Juntunen <[email protected]>
Co-authored-by: Arko Dasgupta <[email protected]>
(cherry picked from commit cb3ffd2)
Signed-off-by: Guy Daich <[email protected]>

* [release/v1.3] v1.3.2 release notes (#5584)

v1.3.2 release notes

Signed-off-by: Guy Daich <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: Guy Daich <[email protected]>
Signed-off-by: Huabing (Robin) Zhao <[email protected]>
Signed-off-by: Takeshi Yoneda <[email protected]>
Signed-off-by: mark winter <[email protected]>
Signed-off-by: Teju Nareddy <[email protected]>
Signed-off-by: Tomi Juntunen <[email protected]>
Co-authored-by: Arko Dasgupta <[email protected]>
Co-authored-by: Huabing (Robin) Zhao <[email protected]>
Co-authored-by: Takeshi Yoneda <[email protected]>
Co-authored-by: Mark Winter <[email protected]>
Co-authored-by: Teju Nareddy <[email protected]>
Co-authored-by: Tomi Juntunen <[email protected]>
arkodg added a commit that referenced this pull request Mar 25, 2025
* bump envoy to v1.32.4

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* fix: host header should not be allowed to modify (#5533)

* host header is not allowed to be modified

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* address comment

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

---------

Signed-off-by: Huabing (Robin) Zhao <[email protected]>
(cherry picked from commit 54efa34)
Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* add release note

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* bump ratelimit to 0141a24

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* Wasm: cache Wasm OCI image permission check results (#5358)

* add TTL for wasm permission check

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* fix test

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* change

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* refresh the cache

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* purge the cache

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* refactor

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* on retry on retriable errors

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* add release note

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

---------

Signed-off-by: Huabing (Robin) Zhao <[email protected]>
(cherry picked from commit 672de8a)
Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* load BackendTLSPolicy in standalone mode (#5431)

Signed-off-by: Arko Dasgupta <[email protected]>
(cherry picked from commit 4d914ae)
Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* fix: check for mirror backendRef in httproute index (#5497)

* check for mirror backendRef

Signed-off-by: mark winter <[email protected]>
(cherry picked from commit 72b72c4)
Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* fix: dont return an err when gatewayclass is not accepted (#5524)

* bug: dont return an err when gatewayclass is not accepted

this is a user generated error, we shouldnt log it as
a system error, and return with an error

Signed-off-by: Arko Dasgupta <[email protected]>

* release notes

Signed-off-by: Arko Dasgupta <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
(cherry picked from commit 51e87ca)
Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* update release note

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* update reatelimit

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* fix gen

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* Load EnvoyExtensionPolicy in standalone mode (#5460)

* load EnvoyExtensionPolicy in standalone mode

Signed-off-by: Takeshi Yoneda <[email protected]>

* more

Signed-off-by: Takeshi Yoneda <[email protected]>

* release note

Signed-off-by: Takeshi Yoneda <[email protected]>

* review: use a valid target name instead of myapp

Signed-off-by: Takeshi Yoneda <[email protected]>

* gen

Signed-off-by: Takeshi Yoneda <[email protected]>

---------

Signed-off-by: Takeshi Yoneda <[email protected]>
(cherry picked from commit 4be098d)
Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* add security update to release note

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* fix: otel sink json access logging without text field (#5498)

* fix otel sink json access logging without text field

Signed-off-by: Tomi Juntunen <[email protected]>

* use json format as default when format or type is not set

Signed-off-by: Tomi Juntunen <[email protected]>

* set formatters only if the slice of formatters is not empty

Signed-off-by: Tomi Juntunen <[email protected]>

---------

Signed-off-by: Tomi Juntunen <[email protected]>
Co-authored-by: Arko Dasgupta <[email protected]>
(cherry picked from commit cb3ffd2)
Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* update release date

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* update release date

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

---------

Signed-off-by: Huabing (Robin) Zhao <[email protected]>
Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: mark winter <[email protected]>
Signed-off-by: Takeshi Yoneda <[email protected]>
Signed-off-by: Tomi Juntunen <[email protected]>
Co-authored-by: Arko Dasgupta <[email protected]>
Co-authored-by: Mark Winter <[email protected]>
Co-authored-by: Takeshi Yoneda <[email protected]>
Co-authored-by: Tomi Juntunen <[email protected]>
zhaohuabing pushed a commit to zhaohuabing/gateway that referenced this pull request Mar 25, 2025
* fix otel sink json access logging without text field

Signed-off-by: Tomi Juntunen <[email protected]>

* use json format as default when format or type is not set

Signed-off-by: Tomi Juntunen <[email protected]>

* set formatters only if the slice of formatters is not empty

Signed-off-by: Tomi Juntunen <[email protected]>

---------

Signed-off-by: Tomi Juntunen <[email protected]>
Co-authored-by: Arko Dasgupta <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenTelemetry access log sink failure with "otel.Text is nil" error (EG v1.3.1)
4 participants