Skip to content
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

Support custom JSON fields for Envoy access logs #3032

Closed
mike1808 opened this issue Oct 14, 2020 · 10 comments · Fixed by #3059
Closed

Support custom JSON fields for Envoy access logs #3032

mike1808 opened this issue Oct 14, 2020 · 10 comments · Fixed by #3059
Assignees
Labels
area/deployment Issues or PRs related to deployment tooling or infrastructure. area/operational Issues or PRs about making Contour easier to operate as a production service. kind/feature Categorizes issue or PR as related to a new feature. lifecycle/accepted Denotes an issue that has been triaged and determined to be valid.

Comments

@mike1808
Copy link
Contributor

mike1808 commented Oct 14, 2020

We want to be able to configure Contour to have custom JSON access log fields, such as custom_field: %REQ(OUR-CUSTOM-HEADER)%.

We are thinking that this can be achieved by having a new property with the JSON fields mapping like for DefaultField in the Contour config. For example:

accesslog-format: json
json-fields:
  - "@timestamp"
  - custom_field
extra-json-fields:
  custom_field:  "%REQ(X-CUSTOM-HEADER)%",

We @cloudfoundry/cf-for-k8s-networking are happy to contribute this feature to upstream.

@mike1808 mike1808 added the kind/feature Categorizes issue or PR as related to a new feature. label Oct 14, 2020
@xcrezd
Copy link

xcrezd commented Oct 15, 2020

+1

@jpeach jpeach added lifecycle/needs-triage Indicates that an issue needs to be triaged by a project contributor. area/deployment Issues or PRs related to deployment tooling or infrastructure. area/operational Issues or PRs about making Contour easier to operate as a production service. labels Oct 15, 2020
@jpeach
Copy link
Contributor

jpeach commented Oct 16, 2020

Historically, new fields were added to the internal list, see #1734. I think that customizing the fields is a reasonable need, however IIUC there's always been a concern that directly exposing the envoy config is too risky because an invalid config would break the envoy config, and we don't have good ways to surface the error.

Maybe we can address this without directly exposing the envoy config, or maybe it's time to just accept the risk 🤷

@mike1808
Copy link
Contributor Author

mike1808 commented Oct 16, 2020

@jpeach do you think restricting fields to only take custom headers names will increase the chances of accepting this feature? For example:

json-fields:
  - "@timestamp"
  - custom_field
extra-json-fields-headers:
  custom_field:  "X-CUSTOM-HEADER"

So it won't be the exact Envoy config, and will help Contour to keep this API in future if Envoy decides to change it.

@xcrezd
Copy link

xcrezd commented Oct 17, 2020

This is the only thing that stops us to move from nginx-controller to contour, the ability to add headers to log

@jpeach
Copy link
Contributor

jpeach commented Oct 18, 2020

xref #1507, #2523

@jpeach
Copy link
Contributor

jpeach commented Oct 19, 2020

When we send an unsupported log token, the listener resource is rejected:

ERRO[0004] Error adding/updating listener(s) ingress_http: Not supported field in StreamInfo: JPEACH  code=13 connection=4 context=xds node_id=envoy-f2lvb node_version=v1.16.0 response_nonce=1 version_info=1

Neither Contour nor go-control-plane recover gracefully from a rejected update, so we want to be careful to only push valid configuration.

envoyproxy/envoy#13620

@jpeach
Copy link
Contributor

jpeach commented Oct 19, 2020

@jpeach do you think restricting fields to only take custom headers names will increase the chances of accepting this feature?

I'm not sure that we need to be as restrictive as that. What if we allow known-good envoy log tokens within the same json-fields syntax? Maybe:

json-fields:
- "@timestamp"
- "flags=%RESPONSE_FLAGS%"
- "other_field="some literal string"

We can validate the right hand-side of the key=value pair against the internal list of non-parameterized log tokens. For parameterized tokens, we ought to be able to validate %RESP()%, %REQ()% and %TRAILER()% with a regex. I'm not sure that the other parameterized tokens are all that useful in a Contour deployment.

If the field name conflicts with a built-in field name, we probably should treat this as an override (e.g. it would make sense for many organizations to override the request_id field to use a different header).

@youngnick
Copy link
Member

youngnick commented Oct 19, 2020

Yes, to put this another way, the risk of accepting config directly from users is that the failure case is really bad. One typo, and your Envoys will stop accepting config from Contour, until they are restarted, even if you fix the issue. (!) This is not handled well in either the original Contour xDS implementation (#1176) or the go-control-plane one (envoyproxy/go-control-plane#46).

@jpeach's suggestion seems reasonable, I'd like to see a design proposal for something similar (That is, a PR to /design using https://github.com/projectcontour/contour/blob/main/design/design-document-tmpl.md as a base), or at least a detailed description in here of how we could handle the use cases @jpeach mentioned above.

@mike1808
Copy link
Contributor Author

@youngnick I'll open a PR for a design. Also, just curious why the Envoy JSON logging proposal is still in a draft stage?

@youngnick
Copy link
Member

It's probably still in draft because we forgot to update it to final, oops. Thanks for pointing that out.

@jpeach jpeach added lifecycle/accepted Denotes an issue that has been triaged and determined to be valid. and removed lifecycle/needs-triage Indicates that an issue needs to be triaged by a project contributor. labels Oct 21, 2020
@jpeach jpeach added this to Unprioritized in Contour Project Board via automation Oct 21, 2020
@jpeach jpeach moved this from Unprioritized to In progress in Contour Project Board Oct 21, 2020
mike1808 pushed a commit to cf-routing/contour that referenced this issue Oct 23, 2020
Add support for custon Envoy JSON fields via use of `=` in the field
name.

See [design doc](design/envoy-json-logging-custom-fields-design.md) for
more information.

Fixes projectcontour#3032

Signed-off-by: Mikael Manukyan <mmanukyan@vmware.com>
mike1808 added a commit to cf-routing/contour that referenced this issue Oct 23, 2020
Fixes projectcontour#3032, projectcontour#1507

Signed-off-by: Clay Kauzlaric <ckauzlaric@vmware.com>
mike1808 pushed a commit to cf-routing/contour that referenced this issue Oct 23, 2020
Add support for custon Envoy JSON fields via use of `=` in the field
name.

See [design doc](design/envoy-json-logging-custom-fields-design.md) for
more information.

Fixes projectcontour#3032

Signed-off-by: Mikael Manukyan <mmanukyan@vmware.com>
Co-authored-by: Clay Kauzlaric KauzClay <ckauzlaric@vmware.com>
mike1808 added a commit to cf-routing/contour that referenced this issue Oct 23, 2020
Fixes projectcontour#3032, projectcontour#1507

Signed-off-by: Clay Kauzlaric <ckauzlaric@vmware.com>
Co-authored-by: Mikael Manukyan <mmanukyan@vmware.com>
mike1808 added a commit to cf-routing/contour that referenced this issue Oct 23, 2020
Add support for custon Envoy JSON fields via use of `=` in the field
name.

See [design doc](design/envoy-json-logging-custom-fields-design.md) for
more information.

Fixes projectcontour#3032

Signed-off-by: Mikael Manukyan <mmanukyan@vmware.com>
Co-authored-by: Mikael Manukyan <mmanukyan@vmware.com>
mike1808 added a commit to cf-routing/contour that referenced this issue Oct 23, 2020
Fixes projectcontour#3032, projectcontour#1507

Signed-off-by: Clay Kauzlaric <ckauzlaric@vmware.com>
Co-authored-by: Mikael Manukyan <mmanukyan@vmware.com>
mike1808 added a commit to cf-routing/contour that referenced this issue Oct 23, 2020
Add support for custon Envoy JSON fields via use of `=` in the field
name.

See [design doc](design/envoy-json-logging-custom-fields-design.md) for
more information.

Fixes projectcontour#3032

Signed-off-by: Mikael Manukyan <mmanukyan@vmware.com>
Co-authored-by: Mikael Manukyan <mmanukyan@vmware.com>
mike1808 added a commit to cf-routing/contour that referenced this issue Oct 23, 2020
Fixes projectcontour#3032, projectcontour#1507

Signed-off-by: Clay Kauzlaric <ckauzlaric@vmware.com>
Co-authored-by: Clay Kauzlaric <ckauzlaric@vmware.com>
XanderStrike pushed a commit to cf-routing/contour that referenced this issue Oct 26, 2020
Add support for custon Envoy JSON fields via use of `=` in the field
name.

See [design doc](design/envoy-json-logging-custom-fields-design.md) for
more information.

Fixes projectcontour#3032

Signed-off-by: Mikael Manukyan <mmanukyan@vmware.com>
Co-authored-by: Mikael Manukyan <mmanukyan@vmware.com>
Co-authored-by: Alexander Standke <astandke@vmware.com>
XanderStrike pushed a commit to cf-routing/contour that referenced this issue Oct 26, 2020
Fixes projectcontour#3032, projectcontour#1507

Signed-off-by: Clay Kauzlaric <ckauzlaric@vmware.com>
Co-authored-by: Clay Kauzlaric <ckauzlaric@vmware.com>
Co-authored-by: Alexander Standke <astandke@vmware.com>
XanderStrike pushed a commit to cf-routing/contour that referenced this issue Oct 27, 2020
Add support for custon Envoy JSON fields via use of `=` in the field
name.

See [design doc](design/envoy-json-logging-custom-fields-design.md) for
more information.

Fixes projectcontour#3032, projectcontour#1507

Signed-off-by: Mikael Manukyan <mmanukyan@vmware.com>
Co-authored-by: Mikael Manukyan <mmanukyan@vmware.com>
Co-authored-by: Alexander Standke <astandke@vmware.com>
XanderStrike pushed a commit to cf-routing/contour that referenced this issue Oct 27, 2020
Add support for custon Envoy JSON fields via use of `=` in the field
name.

See [design doc](design/envoy-json-logging-custom-fields-design.md) for
more information.

Fixes projectcontour#3032, projectcontour#1507

Signed-off-by: Mikael Manukyan <mmanukyan@vmware.com>
Co-authored-by: Clay Kauzlaric <ckauzlaric@vmware.com>
Co-authored-by: Alexander Standke <astandke@vmware.com>
XanderStrike pushed a commit to cf-routing/contour that referenced this issue Oct 27, 2020
Add support for custon Envoy JSON fields via use of `=` in the field
name.

See [design doc](design/envoy-json-logging-custom-fields-design.md) for
more information.

Fixes projectcontour#3032, projectcontour#1507

Signed-off-by: Mikael Manukyan <mmanukyan@vmware.com>
Co-authored-by: Clay Kauzlaric <ckauzlaric@vmware.com>
Co-authored-by: Alexander Standke <astandke@vmware.com>
XanderStrike pushed a commit to cf-routing/contour that referenced this issue Oct 27, 2020
Add support for custon Envoy JSON fields via use of `=` in the field
name.

See [design doc](design/envoy-json-logging-custom-fields-design.md) for
more information.

Fixes projectcontour#3032, projectcontour#1507

Signed-off-by: Mikael Manukyan <mmanukyan@vmware.com>
Co-authored-by: Clay Kauzlaric <ckauzlaric@vmware.com>
Co-authored-by: Alexander Standke <astandke@vmware.com>
Contour Project Board automation moved this from In progress to 1.10 Release Oct 27, 2020
jpeach pushed a commit that referenced this issue Oct 27, 2020
Add support for custon Envoy JSON fields via use of `=` in the field
name.

See [design doc](design/envoy-json-logging-custom-fields-design.md) for
more information.

Fixes #3032, #1507

Signed-off-by: Mikael Manukyan <mmanukyan@vmware.com>
Co-authored-by: Clay Kauzlaric <ckauzlaric@vmware.com>
Co-authored-by: Alexander Standke <astandke@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/deployment Issues or PRs related to deployment tooling or infrastructure. area/operational Issues or PRs about making Contour easier to operate as a production service. kind/feature Categorizes issue or PR as related to a new feature. lifecycle/accepted Denotes an issue that has been triaged and determined to be valid.
Projects
None yet
4 participants