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

enhancement(http-server): add response_body_key for setting http response body #21028

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

frankh
Copy link
Contributor

@frankh frankh commented Aug 8, 2024

backwards compatible change to add a response_body_key option for the http-server source.

If specified, returns the json encoding of the given key in the event as the response body

fixes #21013

@frankh frankh requested a review from a team as a code owner August 8, 2024 14:03
@bits-bot
Copy link

bits-bot commented Aug 8, 2024

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the domain: sources Anything related to the Vector's sources label Aug 8, 2024
@frankh
Copy link
Contributor Author

frankh commented Aug 14, 2024

@jszwedko any interest in this PR?

we want this to be able to return a uuid to the client to be able to track an event, feels like a reasonably common use-case

@frankh frankh force-pushed the feat/http-source-response-body-key branch from dedc0a1 to e3787c6 Compare August 14, 2024 14:35
Copy link
Member

@jszwedko jszwedko left a comment

Choose a reason for hiding this comment

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

Thanks for opening this PR @frankh !

Thinking about it a bit more, I think it'd be more flexible to let users specify a VRL program to generate the response. I think what you have here is pretty specific in that it pulls the field from the first event and then returns it as JSON.

I'm imagining, instead, that users could provide a VRL program that receives as input the entire series of input events and then can craft a response. For example:

ids = map_values!(.) -> |event| { event.id }

json_encode!({ ids: ids })

This would return [<list of ids from events>] as the response.

You could still return just the first field like you are doing here with something like:

json_encode!(.[0].id)

Granted, this is also a medium-sized change to Vector's UX. I don't think we have any precedent for it so I'd like to get some input from other maintainers. Before I do that, I'm curious if my suggestion would meet your need?

We could enable even more response customization by letting users return an object from the VRL program that includes things like Content-Type like:

ids = map_values!(.) -> |event| { event.id }

{
  headers: {
    "Content-Type": "application/json",
  },
  body: json_encode!({ ids: ids }),
  status_code: 200
}

(this is all VRL pseudocode)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain: sources Anything related to the Vector's sources
Projects
None yet
Development

Successfully merging this pull request may close these issues.

http sources should be able to customise the response sent back to clients
3 participants