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

Make Write message type more flexble, address some feedback #1710

Merged
merged 2 commits into from
Jan 17, 2025

Conversation

saswatamcode
Copy link

@saswatamcode saswatamcode commented Jan 16, 2025

Addresses a few comments from PR
Also imports v1, as a convenience package as well (we can keep until we deprecate fully?)

Also makes Write marshaling more flexible with any type and gogo marshaling. Generics don't really seem to fit as you can't have multiple interface constraints on them.

Might be worth, merging with merge commit to keep original PR commits clear

cc: @bwplotka

Signed-off-by: Saswata Mukherjee <[email protected]>
// Under any marshaling scheme, v2 requests have a `Symbols` field of type []string.
// So would always have a `GetSymbols()` method which doesn't rely on any other types.
type v2Request interface {
GetSymbols() []string
Copy link
Author

Choose a reason for hiding this comment

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

This seems a bit hacky, but need it for the contentType detection. I wonder if there is a better way here

Copy link
Member

Choose a reason for hiding this comment

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

Interesting. I think this is acceptable for now.

Copy link
Member

@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! Good progress, some comments. I planned to move it to client_golang/exp which would allow us to experiment on main. Want to help with that in the next PR, if not I will do it one day (no pressure!)

// Under any marshaling scheme, v2 requests have a `Symbols` field of type []string.
// So would always have a `GetSymbols()` method which doesn't rely on any other types.
type v2Request interface {
GetSymbols() []string
Copy link
Member

Choose a reason for hiding this comment

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

Interesting. I think this is acceptable for now.

api/prometheus/v1/remote/remote_api.go Show resolved Hide resolved
@@ -74,6 +75,22 @@ func WithAPILogger(logger *slog.Logger) APIOption {
}
}

// WithAPIEndpoint returns APIOption that allows providing endpoint.
func WithAPIEndpoint(endpoint string) APIOption {
Copy link
Member

Choose a reason for hiding this comment

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

You mean path? Using it in URL will mean path. Either we rename to path or not use client.URL or not use client structs at all.

I wanted to move this lib to separate client_golang/exp/ module for now, so we might want to get rid of client (improve it). Can do in my PR, but let's just switch to path here for now?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah it hit me after, let me update

Copy link
Author

Choose a reason for hiding this comment

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

Switched to path, I can do exp module in next PR

}

// NewRemoteWriteHandler returns HTTP handler that receives Remote Write 2.0
// protocol https://prometheus.io/docs/specs/remote_write_spec_2_0/.
func NewRemoteWriteHandler(logger *slog.Logger, store writeStorage) http.Handler {
return &handler{logger: logger, store: store}
func NewRemoteWriteHandler(logger *slog.Logger, store writeStorage, decompressor remoteWriteDecompressor) http.Handler {
Copy link
Member

Choose a reason for hiding this comment

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

We might need opts here as well, separate ones 🤔

Copy link
Author

Choose a reason for hiding this comment

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

Let me add!

Copy link
Author

Choose a reason for hiding this comment

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

Added for logger and decompressor

@@ -279,18 +327,32 @@ type writeStorage interface {
Store(ctx context.Context, proto WriteProtoFullName, serializedRequest []byte) (_ WriteResponseStats, code int, _ error)
}

// remoteWriteDecompressor is an interface that allows decompressing the body of the request.
type remoteWriteDecompressor interface {
Copy link
Member

Choose a reason for hiding this comment

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

can you remind me why we need this?

Another option is to use server middleware interface for this. There are common middlewares for this work ppl use e.g. Otel

Copy link
Author

Choose a reason for hiding this comment

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

Some downstream users have their own request body size limiter+instrumentaion impls, that they would probably want to use. I know Thanos and Cortex have them #1658 (comment)

I don't think compression-wise things would be too different (maybe using s2).

Copy link
Member

Choose a reason for hiding this comment

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

Cool, I will merge for now, but we need to switch to middleware injection technique

api/prometheus/v1/remote/genproto/buf.gen.yaml Outdated Show resolved Hide resolved
Signed-off-by: Saswata Mukherjee <[email protected]>
@bwplotka bwplotka merged commit e0800f5 into prometheus:prwclient-em Jan 17, 2025
8 checks passed
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.

2 participants