[FLINK-39368][connector-http] Add User-Agent configuration support for HTTP sink and lookup#34
Conversation
a6f4c6a to
5e11e4b
Compare
5e11e4b to
0c95cb3
Compare
davidradl
left a comment
There was a problem hiding this comment.
please add documentation
|
Hi @davidradl, I've added comprehensive documentation for the What's Added:
The documentation now includes:
Please let me know if you'd like any additional documentation or clarification! |
dddfa5b to
e4c988d
Compare
|
Thanks for the review. Pushed a rebuilt commit that squashes the history into a single clean commit on top of current
Local |
Introduce a new `http.user.agent` option for both the HTTP lookup source and the HTTP sink so that every outgoing request carries an identifiable User-Agent header by default. Behaviour: * Default value is `flink-connector-http` (matches the connector artifact identifier). * Setting User-Agent simultaneously via `http.user.agent` and via the existing per-prefix header option (`http.source.lookup.header.User-Agent` or `http.sink.header.User-Agent`) is rejected at table creation time with an IllegalArgumentException, to avoid silently losing one of the two values. Documentation: * Add the new option to the lookup and sink options tables. * Add a dedicated `User-Agent` subsection with an example DDL. Tests: * `JavaNetSinkHttpClientTest` and `JavaNetHttpPollingClientTest` cover the default value, a custom value and the conflict path.
e4c988d to
31fc409
Compare
|
Correction on my previous comment: the force-pushed commit is now properly based on the current |
|
Hi @davidradl, friendly ping — all three of your review threads on this PR are now marked as resolved and the latest commit (
Plus: documentation rows + a CI (GitHub Actions Java 11 + 17) is green. PR is |
|
|
||
| Setting `User-Agent` through both `http.user.agent` and `http.source.lookup.header.User-Agent` | ||
| (or `http.sink.header.User-Agent` for the sink) is ambiguous and is rejected at table creation time | ||
| with an `IllegalArgumentException`. Configure it through exactly one of the two options. |
There was a problem hiding this comment.
nit: remove the word exactly
| | http.request.query-param-fields-with-key | optional | A map of column names to query parameter keys. See the [Query Parameter Mapping](#query-parameter-mapping) section for details and examples. | | ||
| | http.request.body-template | optional | Used for the `http-generic-json-url` query creator. A JSON template string for constructing the request body for PUT and POST operations. Use `{{fieldName}}` placeholders to reference top-level columns from the lookup table. Supports creating complex nested JSON structures with both placeholders and literal values. See the [Body Template](#body-template) section for details and examples. | | ||
| | http.request.url-map | optional | Used for the `http-generic-json-url` query creator. The map of insert names to column names used as url segments. Parses a string as a map of strings. For example if there are table columns called `customerId` and `orderId`, then specifying value `customerId:cid,orderID:oid` and a url of https://myendpoint/customers/{cid}/orders/{oid} will mean that the url used for the lookup query will dynamically pickup the values for `customerId`, `orderId` and use them in the url e.g. https://myendpoint/customers/cid1/orders/oid1. The expected format of the map is: `key1:value1,key2:value2`. | | ||
| | http.user.agent | optional | The value of the `User-Agent` HTTP header sent with every lookup request. Defaults to `flink-connector-http`. Setting this option together with `http.source.lookup.header.User-Agent` is not allowed and will fail with a configuration error. | |
There was a problem hiding this comment.
I think we should put the new option near the top around url, so we start with all the common configuration options then specialize to the sink or lookup appropriately when we list them
| properties.getProperty( | ||
| HttpDynamicSinkConnectorOptions.USER_AGENT.key(), | ||
| HttpDynamicSinkConnectorOptions.USER_AGENT.defaultValue()); | ||
| if (userAgent != null && !userAgent.isEmpty()) { |
There was a problem hiding this comment.
userAgent will always have a value here - as it will be the user specified one or the default. So there is no way to specify http.sink.header.User-Agent and have it work after this change
What is the purpose of the change
Add a dedicated
http.user.agentoption so that requests issued by theHTTP connector carry an identifiable
User-Agentheader out of the box,for both the lookup source and the async sink.
Without this option, the underlying Java
HttpClientsends requestswithout any
User-Agentheader, which makes server-side logging,rate limiting and access auditing harder. Users could already override
the header via
http.source.lookup.header.User-Agent/http.sink.header.User-Agent, but there was no sensible default.Brief change log
http.user.agentConfigOption toHttpLookupConnectorOptionsand
HttpDynamicSinkConnectorOptions. Default value isflink-connector-http(matches the connector artifact identifier).RequestFactoryBase(lookup) andJavaNetSinkHttpClient(sink).User-Agentsimultaneously viahttp.user.agentandvia the corresponding
http.*.header.User-Agententry with a clearIllegalArgumentException.SINK_HEADERS/SOURCE_LOOKUP_HEADERS(fromFLINK-HTTP-3) and the new
USER_AGENToption in the factoryoptionalOptions()lists.add a short
User-Agentsubsection with an example DDL.Verifying this change
JavaNetSinkHttpClientTest#shouldBuildClientWithoutHeadersnowasserts that the default
User-Agent: flink-connector-httpisattached when no header configuration is given.
JavaNetSinkHttpClientTest#shouldBuildClientWithCustomUserAgentandJavaNetHttpPollingClientTest#shouldBuildClientWithCustomUserAgentassert that a user-provided value is honoured.
JavaNetSinkHttpClientTest#shouldThrowErrorWhenUserAgentConflictand the lookup counterpart assert that the conflict detection fires
with a helpful message.
Does this pull request potentially affect one of the following parts:
http.user.agentConfigOptionheader to outgoing requests
Documentation
docs/content/docs/connectors/table/http.mdand thecontent.zhequivalent, under the lookup options table, sink options table and
a dedicated
User-Agentsubsection