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

exp/api: Add experimental exp module; Add remote API with write client and handler. #1658

Merged
merged 7 commits into from
Feb 25, 2025

Conversation

bwplotka
Copy link
Member

@bwplotka bwplotka commented Oct 21, 2024

This proposes Remote Write API directly in client_golang main module. No dependency added (some new small packages are added under the internal vendored code).

Old attempt: #1656

Both API (client) and handler supports 1.0 and 2.0 Proto messages, but I intentionally only host writev2.Request generated Go code as we plan to deprecate 1.0 and users should use writev2 now. Both API and handler also will work against protobuf message types that use custom generators e.g. with gogoproto or anything else.

TODO:

  • Add examples, documentation
  • Open PR that uses it on Prometheus

@bwplotka
Copy link
Member Author

Example use of handler in sink project: https://github.com/bwplotka/sink/blob/main/go/sink/main.go#L51

Copy link
Member

@cstyan cstyan left a comment

Choose a reason for hiding this comment

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

Both API (client) and handler supports 1.0 and 2.0 Proto messages, but I intentionally only host writev2.Request generated Go code as we plan to deprecate 1.0 and users should use writev2 now. Both API and handler also will work against protobuf message types that use custom generators e.g. with gogoproto or anything else.

Given that the spec is only just finalized recently and (afaik) still no receivers like Mimir support v2, we should include v1 request code imo.

return &handler{logger: logger, store: store}
}

func parseProtoMsg(contentType string) (WriteProtoFullName, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this something we can expose?

Copy link
Member

Choose a reason for hiding this comment

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

+1 to exposing this

h.logger.Error("Error decompressing remote write request", "err", err.Error())
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we can expose a hook for the logic of decoding and decompressing part so that downstream project can just use their existing code without many adjustment.

func decodeRequestBody(r *http.Request) (body []byte, err error)

The main logic that can benefit us is handling v1 and v2 proto and response headers. It would be nice to still reuse the other code.

Copy link
Member

Choose a reason for hiding this comment

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

Yup some requestValidatorDecoder interface that can be overridden downstream would be cool to have.

h.logger.Error("Error decompressing remote write request", "err", err.Error())
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
Copy link
Member

Choose a reason for hiding this comment

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

Yup some requestValidatorDecoder interface that can be overridden downstream would be cool to have.

return &handler{logger: logger, store: store}
}

func parseProtoMsg(contentType string) (WriteProtoFullName, error) {
Copy link
Member

Choose a reason for hiding this comment

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

+1 to exposing this

* Address remaining feedback

Signed-off-by: Saswata Mukherjee <[email protected]>

* Make Write message type more flexible

Signed-off-by: Saswata Mukherjee <[email protected]>

---------

Signed-off-by: Saswata Mukherjee <[email protected]>
* Move remote write API to client_golang/exp

Signed-off-by: Saswata Mukherjee <[email protected]>

* Don't use api.Client structs, add options for middleware

Signed-off-by: Saswata Mukherjee <[email protected]>

* Fix reqBuf usage

Signed-off-by: Saswata Mukherjee <[email protected]>

* Fix url path

Signed-off-by: Saswata Mukherjee <[email protected]>

* Add separate mod file (and workspace file)

Signed-off-by: Saswata Mukherjee <[email protected]>

* Hook exp tests fmt; Test handler error case; Configure backoff

Signed-off-by: Saswata Mukherjee <[email protected]>

---------

Signed-off-by: Saswata Mukherjee <[email protected]>
@bwplotka bwplotka changed the title api: Add remote API with write client; add remote handler. exp/api: Add experimental exp module; Add remote API with write client and handler. Jan 31, 2025
Signed-off-by: Bartlomiej Plotka <[email protected]>
@bwplotka bwplotka marked this pull request as ready for review February 3, 2025 10:50
Copy link
Member Author

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Thanks @saswatamcode for helping a lot. Let's get those last things to this branch + quick README and let's get it merged in the experimental module!

* Implement suggestion for Store interface and contentType

Signed-off-by: Saswata Mukherjee <[email protected]>

* Add README

Signed-off-by: Saswata Mukherjee <[email protected]>

* Use sync.Pool

Signed-off-by: Saswata Mukherjee <[email protected]>

* Implement review suggestions

Signed-off-by: Saswata Mukherjee <[email protected]>

* Release bufs right after compressPayload

Signed-off-by: Saswata Mukherjee <[email protected]>

---------

Signed-off-by: Saswata Mukherjee <[email protected]>
@bwplotka
Copy link
Member Author

bwplotka commented Feb 25, 2025

@saswatamcode addressed most if not all comments and we should be good for an experimental module here 💪🏽

@saswatamcode do you mind checking last lint issues? You can push straight to the branch if you want

@bwplotka bwplotka merged commit 248c3f7 into main Feb 25, 2025
11 checks passed
@bwplotka bwplotka deleted the prwclient-em branch February 25, 2025 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants