Skip to content

Enable wrapping of distributor push. #3755

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

Merged
merged 2 commits into from
Jan 29, 2021

Conversation

jeschkies
Copy link
Contributor

@jeschkies jeschkies commented Jan 28, 2021

Summary:
Introduces PushFunc and PushWrapper types which are used to defined a
configurable wrapper around the push function of the distributor. It is
similar to an HTTP middleware but receives the already deserialized
write request.

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@jeschkies jeschkies force-pushed the karsten/push-wrapper branch 2 times, most recently from e1b3788 to 299d0ad Compare January 28, 2021 17:18
@jeschkies jeschkies changed the title Enable wrapping of dsitributor push. Enable wrapping of distributor push. Jan 28, 2021
@jeschkies jeschkies force-pushed the karsten/push-wrapper branch from 299d0ad to 9e74266 Compare January 28, 2021 17:24
@pstibrany
Copy link
Contributor

Would it make sense to reuse recently introduced PushOnlyIngesterServer instead?

Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

LGTM to me. Just left minor comments.

Would it make sense to reuse recently introduced PushOnlyIngesterServer instead?

@pstibrany I'm not sure. I talked to Karsten offline and the use case here is to run the distributor as is but being able, in a downstream project, to access the WriteRequest before (or after) it has been handled by the Distributor.Push(). I think a wrapper here is what we want. WDYT?

@jeschkies jeschkies force-pushed the karsten/push-wrapper branch 3 times, most recently from c43a8cb to 3d54f41 Compare January 29, 2021 12:38
@jeschkies jeschkies marked this pull request as ready for review January 29, 2021 12:38
@jeschkies jeschkies requested a review from pracucci January 29, 2021 12:38
@pstibrany
Copy link
Contributor

pstibrany commented Jan 29, 2021

@pstibrany I'm not sure. I talked to Karsten offline and the use case here is to run the distributor as is but being able, in a downstream project, to access the WriteRequest before (or after) it has been handled by the Distributor.Push(). I think a wrapper here is what we want. WDYT?

What I meant was to modify util/push.Handler like this:

func Handler(cfg distributor.Config int, sourceIPs *middleware.SourceIPExtractor, push client.PushOnlyIngesterServer) http.Handler

Which would work and wouldn't introduce new dependencies, but it doesn't really solve the problem this PR is solving.

While working on this, we I'd suggest we reduce the dependency from util/push to distributor package, by

  1. moving DistributorPushFunc to util/push (interfaces are typically declared at place where they are "consumed", ie. called)
  2. applying the push wrapper before calling util/push.Handler, and
  3. passing cfg.MaxRecvMsgSize as separate parameter to Handler.

WDYT?

@jeschkies
Copy link
Contributor Author

@pracucci the linter complains

pkg/distributor/distributor.go:399:6: type name will be used as distributor.DistributorPushFunc by other packages, and that stutters; consider calling this PushFunc (golint)
type DistributorPushFunc func(context.Context, *ingester_client.WriteRequest) (*ingester_client.WriteResponse, error)
     ^

Should I ignore it?

@jeschkies
Copy link
Contributor Author

jeschkies commented Jan 29, 2021

moving DistributorPushFunc to util/push (interfaces are typically declared at place where they are "consumed", ie. called)

@pstibrany, I've tried that but it introduces a circular dependency since the config in distrobutor.go must know the type DistributorPushWrapper.

applying the push wrapper before calling util/push.Handler, and

I was thinking about this. However, the wrapper is defined in the config. Since the config is passed to the handler why not evaluate it there?

passing cfg.MaxRecvMsgSize as separate parameter to Handler.

Ah, I start to understand. You don't want the dependency on config and thus avoid the circular dependency. I'm open to that. @pracucci, what's your take?

@pracucci
Copy link
Contributor

Ah, I start to understand. You don't want the dependency on config and thus avoid the circular dependency. I'm open to that. @pracucci, what's your take?

@jeschkies I'm fine with Peter's suggestion 👍

@pracucci
Copy link
Contributor

type DistributorPushFunc func(context.Context, *ingester_client.WriteRequest) (*ingester_client.WriteResponse, error)
Should I ignore it?

Once you will move it to pkg/util you can just name it PushFunc because it will be a generic utility there with no "knowledge" of the distributor.

@jeschkies jeschkies force-pushed the karsten/push-wrapper branch from 3d54f41 to 71f2866 Compare January 29, 2021 14:58
@jeschkies
Copy link
Contributor Author

Once you will move it to pkg/util you can just name it PushFunc because it will be a generic utility there with no "knowledge" of the distributor.

I called it Func because the linter would complain about stuttering. Unfortunately my tests don't make any sense anymore. How can I test the logic in the RegisterDistributor method?

@jeschkies jeschkies force-pushed the karsten/push-wrapper branch 4 times, most recently from fa59a1b to 990458a Compare January 29, 2021 15:48
Copy link
Contributor

@pstibrany pstibrany 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 addressing our feedback!

@jeschkies jeschkies force-pushed the karsten/push-wrapper branch from 990458a to 53365f2 Compare January 29, 2021 16:00
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

LGTM (modulo a couple of nits). Thanks!

Summary:
Introduces PushFunc and PushWrapper types which are used to defined a
configurable wrapper around the push function of the distributor. It is
similar to an HTTP middleware but receives the already deserialized
write request.

Co-authored-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: Karsten Jeschkies <k@jeschkies.xyz>
@jeschkies jeschkies force-pushed the karsten/push-wrapper branch from 53365f2 to 9ba2e56 Compare January 29, 2021 16:30
@pracucci pracucci merged commit 0976147 into cortexproject:master Jan 29, 2021
@jeschkies jeschkies deleted the karsten/push-wrapper branch January 29, 2021 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants