vectordotdev / vector

A high-performance observability data pipeline.
https://vector.dev
Mozilla Public License 2.0
17.53k stars 1.54k forks source link

Get all query parameters from http server source #21321

Open uricorin opened 5 days ago

uricorin commented 5 days ago

Use cases

Hi everyone. We're using vector to aggregate HTTP requests. Currently, query parameters must be specified, by name, or they won't be outputted.

There's no easy way to support requests with varying arguments.

References

Discussion on a similar issue #16396

Solution

I've updated the code to output all query parameters, as a string, to field query_parameters_string. A configuration variable, all_qp, enables this functionality - It's off by default.

Here's an example configuration:

  sources:
    http:
      type: http_server
      address: 127.0.0.1:8080
      encoding: json
      headers:
        - "*"
      method: POST
      path: /mypath/
      response_code: 200
      all_qp: true # Toggle on

  transforms:
    enriched_http:
      type: remap
      inputs:
        - http
      source: |-
        .params = parse_query_string!(.query_parameters_string)
  sinks:
    # Debug http
    stdout:
      type: console
      inputs: [enriched_http]
      encoding:
        codec: json    

Proposal

I'd like to contribute this change back to the upstream project. If you approve opening a PR I'd appreciate suggestions regarding functionality and testing.

Notes

The Heroku Logplex and http server sources reuse functions so this change will add the capability to both.

jszwedko commented 1 day ago

Thanks for opening this request @uricorin ! I agree it would be useful functionality. Rather than adding a new config option, all_qp, I'd suggest we model it like headers which accepts wildcards so that you could just configure it like:

query_paramaters:
  - '*'

Happy to see a PR!