local_reply_config : support content-type in SubstitutionFormatString#13019
Conversation
Signed-off-by: Devesh Kandpal <devesh.kandpal@dkandpal-ltm.internal.salesforce.com>
Signed-off-by: Devesh Kandpal <devesh.kandpal@dkandpal-ltm.internal.salesforce.com>
Signed-off-by: Devesh Kandpal <devesh.kandpal@dkandpal-ltm.internal.salesforce.com>
Signed-off-by: Devesh Kandpal <devesh.kandpal@dkandpal-ltm.internal.salesforce.com>
|
/retest |
|
Retrying Azure Pipelines, to retry CircleCI checks, use |
ramaraochavali
left a comment
There was a problem hiding this comment.
looks good high level,
Update docs https://github.com/envoyproxy/envoy/blob/master/docs/root/configuration/http/http_conn_man/local_reply.rst#local-reply-format-modification
and add release notes
| auto local = Factory::create(config_, context_); | ||
|
|
||
| // code=400 matches the first filter; rewrite code and body | ||
| // has its own formatter |
|
Instead of this, WDYT of adding a facility to override |
|
Sure. Is there any benefit of doing that rather than this? I could see one benefit i.e. not polluting |
|
@ramaraochavali I think that could be a reason, and setting content-type seems one of the mentioned suggestion here: #11313 (comment). And perhaps we can stay to have "structured" via JSON and "unstructured" via text (it seems |
|
Sure. I am fine with that. @deveshkandpal24121990 WDYT? |
| google.protobuf.Struct json_format = 2 [(validate.rules).message = {required: true}]; | ||
|
|
||
| // Specify a format with command operators to form a html string. | ||
| // Its details is described in :ref:`format string<config_access_log_format_strings>`. |
There was a problem hiding this comment.
Please update these docs with a description of HTML format.
| // | ||
| // .. code-block:: | ||
| // | ||
| // html_format: <p>%LOCAL_REPLY_BODY%:%RESPONSE_CODE%:path=$REQ(:path)%</p> |
There was a problem hiding this comment.
IIUC, the only difference is that you are setting content type? Would it be preferable to be able to just specify the content-type?
There was a problem hiding this comment.
@htuch - do you mean adding just content-type to ResponseMapper as is suggested here -> #13019 (comment) ?
There was a problem hiding this comment.
Yeah. I'm thinking there's probably a lot of different variations on content type that might be asked for over time, so adding a special purpose field here is limiting. It makes sense to distinguish text/JSON, since they are structurally different.
Signed-off-by: Devesh Kandpal <devesh.kandpal@dkandpal-ltm.internal.salesforce.com>
Signed-off-by: Devesh Kandpal <devesh.kandpal@dkandpal-ltm.internal.salesforce.com>
ramaraochavali
left a comment
There was a problem hiding this comment.
Few comments. @htuch PTAL
| // * for ``json_format`` the keys with null values are omitted in the output structure. | ||
| bool omit_empty_values = 3; | ||
|
|
||
| // Specify a content_type for text_format. This will be ignored for json_format |
| // | ||
| // content_type: "text/html; charset=UTF-8" | ||
| // | ||
| string content_type = 4 [(validate.rules).string = {min_bytes: 1}]; |
There was a problem hiding this comment.
Do we need this validation since it is only valid for text_format?
There was a problem hiding this comment.
Also specify currently supported content type values are text/html; charset=UTF-8 and text/plain defaulted to text/plain ?
| * access log: added support for :ref:`%DOWNSTREAM_PEER_FINGERPRINT_1% <config_access_log_format_response_flags>` as a response flag. | ||
| * access log: added support for nested objects in :ref:`JSON logging mode <config_access_log_format_dictionaries>`. | ||
| * access log: added :ref:`omit_empty_values<envoy_v3_api_field_config.core.v3.SubstitutionFormatString.omit_empty_values>` option to omit unset value from formatted log. | ||
| * access log: added :ref:`content_type<envoy_v3_api_field_config.core.v3.SubstitutionFormatString.content_type>` option to set content-type for textformat. |
There was a problem hiding this comment.
I think this is applicable for local reply (not so for access log) - so may be we should release note it under local_reply config?
|
|
||
| absl::string_view SubstitutionFormatStringUtils::getContentType( | ||
| const envoy::config::core::v3::SubstitutionFormatString& config) { | ||
| const std::string contentType = config.content_type(); |
There was a problem hiding this comment.
Simplify this as follows as those are the only ones supported now ?
if (contentType == Http::Headers::get().ContentTypeValues.Html)
return Http::Headers::get().ContentTypeValues.Html;
else
return Http::Headers::get().ContentTypeValues.Text;
There was a problem hiding this comment.
Why can't we plumb through the content type directly, without having to rely on well-known values?
Signed-off-by: Devesh Kandpal <devesh.kandpal@dkandpal-ltm.internal.salesforce.com>
Signed-off-by: Devesh Kandpal <devesh.kandpal@dkandpal-ltm.internal.salesforce.com>
|
addressed comments. @ramaraochavali @htuch PTAL. Thanks! |
Signed-off-by: Devesh Kandpal <devesh.kandpal@dkandpal-ltm.internal.salesforce.com>
Signed-off-by: Devesh Kandpal <devesh.kandpal@dkandpal-ltm.internal.salesforce.com>
|
/retest |
|
Retrying Azure Pipelines, to retry CircleCI checks, use |
|
the integration test logs complains about |
|
/retest |
|
Retrying Azure Pipelines, to retry CircleCI checks, use |
| if (config.content_type() == Http::Headers::get().ContentTypeValues.Html) { | ||
| return Http::Headers::get().ContentTypeValues.Html; | ||
| } |
There was a problem hiding this comment.
Not sure, but can we pass config.content_type() value as is? And yes, when it is not set and it is not JSON we return text/plain. WDYT @htuch?
There was a problem hiding this comment.
@dio - I tried doing that initially, however config.content_type() returns std:string& and after the value would get assigned to absl:string_view content_type_ , the address it points to is not valid anymore after the scope of the method is over. My understanding about string_view is that it's a read-only pointer to the string object being assigned. One way to fix that was to change the datatype of content_type_ to std::string, however I wasn't sure if that is encouraged ? Any other ideas ?
There was a problem hiding this comment.
Sure, make content_type_ a std::string.
| envoy::config::core::v3::SubstitutionFormatString::FormatCase::kJsonFormat | ||
| ? Http::Headers::get().ContentTypeValues.Json | ||
| : Http::Headers::get().ContentTypeValues.Text) {} | ||
| : Formatter::SubstitutionFormatStringUtils::getContentType(config)) {} |
There was a problem hiding this comment.
So, given: https://github.com/envoyproxy/envoy/pull/13019/files#r488273786, here we can have: config.content_type().empty() ? Http::Headers::get().ContentTypeValues.Text : config.content_type().
htuch
left a comment
There was a problem hiding this comment.
Thanks, API LGTM modulo comments.
/wait
|
|
||
| // Specify a content_type for text_format. This will be ignored for json_format. | ||
| // Currently supported content-type value includes ``text/html; charset=UTF-8`` and ``text/plain`` | ||
| // with default value being ``text/plain``. |
There was a problem hiding this comment.
I think we can avoid relying on well-known values, see below comments. Other than this, this API is fine.
| // * for ``json_format`` the keys with null values are omitted in the output structure. | ||
| bool omit_empty_values = 3; | ||
|
|
||
| // Specify a content_type for text_format. This will be ignored for json_format. |
There was a problem hiding this comment.
Please specify defaults when no content_type is specified.
| // * for ``json_format`` the keys with null values are omitted in the output structure. | ||
| bool omit_empty_values = 3; | ||
|
|
||
| // Specify a content_type for text_format. This will be ignored for json_format. |
There was a problem hiding this comment.
Nit: *content_type* for *text_format*
| // * for ``json_format`` the keys with null values are omitted in the output structure. | ||
| bool omit_empty_values = 3; | ||
|
|
||
| // Specify a content_type for text_format. This will be ignored for json_format. |
There was a problem hiding this comment.
Why ignore for JSON? I feel there are JSON content type variants you might want to support, e.g. https://stackoverflow.com/questions/477816/what-is-the-correct-json-content-type
Signed-off-by: Devesh Kandpal <devesh.kandpal@dkandpal-ltm.internal.salesforce.com>
|
@htuch @ramaraochavali @dio - PTAL. Thanks! |
ramaraochavali
left a comment
There was a problem hiding this comment.
LGTM with minor nits
| envoy::config::core::v3::SubstitutionFormatString::FormatCase::kJsonFormat | ||
| ? Http::Headers::get().ContentTypeValues.Json | ||
| : Http::Headers::get().ContentTypeValues.Text) {} | ||
| content_type_(Formatter::SubstitutionFormatStringUtils::getContentType(config)) {} |
There was a problem hiding this comment.
nit: may be you can inline this initialization
!config.content_type().empty()? config.content_type() : config.format_case() ==
envoy::config::core::v3::SubstitutionFormatString::FormatCase::kJsonFormat
? Http::Headers::get().ContentTypeValues.Json
: Http::Headers::get().ContentTypeValues.Text;
and avoid the method?
| * load balancer: added a :ref:`configuration<envoy_v3_api_msg_config.cluster.v3.Cluster.LeastRequestLbConfig>` option to specify the active request bias used by the least request load balancer. | ||
| * load balancer: added an :ref:`option <envoy_v3_api_field_config.cluster.v3.Cluster.LbSubsetConfig.LbSubsetSelector.single_host_per_subset>` to optimize subset load balancing when there is only one host per subset. | ||
| * load balancer: added support for bounded load per host for consistent hash load balancers via :ref:`hash_balance_factor <envoy_api_field_Cluster.CommonLbConfig.consistent_hashing_lb_config>`. | ||
| * local_reply config: added :ref:`content_type<envoy_v3_api_field_config.core.v3.SubstitutionFormatString.content_type>` option to set appropriate content-type for text_format or json_format. |
There was a problem hiding this comment.
nit: suggestion
added :ref:content_type<envoy_v3_api_field_config.core.v3.SubstitutionFormatString.content_type> option to set content-type.
Specifying text_format or json_format here is redundant here as we support for all formats now.
Signed-off-by: Devesh Kandpal <devesh.kandpal@dkandpal-ltm.internal.salesforce.com>
|
@htuch - whenever you get a chance, could you PTAL ? Thanks in advance! |
…envoyproxy#13019) Prior to this fix only text_format and json_format were supported which would result in text/plain or application/json content-type. This Introduces content_type field which supports setting content-type for body_format / body_format_override in local_reply_config. Risk Level: low Testing: Unit Testing, Manual Testing Docs Changes: Introduces new field content_type in substitution_format_string.proto that supports setting content-type for body_format / body_format_override in local_reply_config. Release Notes: Added release notes. Fixes envoyproxy#11313 Co-authored-by: Devesh Kandpal <devesh.kandpal@dkandpal-ltm.internal.salesforce.com> (cherry picked from commit a8b946e)
…envoyproxy#13019) Prior to this fix only text_format and json_format were supported which would result in text/plain or application/json content-type. This Introduces content_type field which supports setting content-type for body_format / body_format_override in local_reply_config. Risk Level: low Testing: Unit Testing, Manual Testing Docs Changes: Introduces new field content_type in substitution_format_string.proto that supports setting content-type for body_format / body_format_override in local_reply_config. Release Notes: Added release notes. Fixes envoyproxy#11313 Co-authored-by: Devesh Kandpal <devesh.kandpal@dkandpal-ltm.internal.salesforce.com> (cherry picked from commit a8b946e)
…envoyproxy#13019) Prior to this fix only text_format and json_format were supported which would result in text/plain or application/json content-type. This Introduces content_type field which supports setting content-type for body_format / body_format_override in local_reply_config. Risk Level: low Testing: Unit Testing, Manual Testing Docs Changes: Introduces new field content_type in substitution_format_string.proto that supports setting content-type for body_format / body_format_override in local_reply_config. Release Notes: Added release notes. Fixes envoyproxy#11313 Co-authored-by: Devesh Kandpal <devesh.kandpal@dkandpal-ltm.internal.salesforce.com> (cherry picked from commit a8b946e)
…envoyproxy#13019) Prior to this fix only text_format and json_format were supported which would result in text/plain or application/json content-type. This Introduces content_type field which supports setting content-type for body_format / body_format_override in local_reply_config. Risk Level: low Testing: Unit Testing, Manual Testing Docs Changes: Introduces new field content_type in substitution_format_string.proto that supports setting content-type for body_format / body_format_override in local_reply_config. Release Notes: Added release notes. Fixes envoyproxy#11313 Co-authored-by: Devesh Kandpal <devesh.kandpal@dkandpal-ltm.internal.salesforce.com> (cherry picked from commit a8b946e)
For an explanation of how to fill out the fields, please see the relevant section
in PULL_REQUESTS.md
Commit Message: local_reply_config : support content-type in SubstitutionFormatString
Additional Description: Prior to this fix only
text_formatandjson_formatwere supported which would result intext/plainorapplication/jsoncontent-type. This Introducescontent_typefield which supports settingcontent-typeforbody_format / body_format_overrideinlocal_reply_config.Risk Level: low
Testing: Unit Testing, Manual Testing
Docs Changes: Introduces new field
content_typeinsubstitution_format_string.protothat supports setting content-type forbody_format / body_format_overrideinlocal_reply_config.Release Notes: Added release notes.
[Optional Fixes #Issue] Fixes #11313