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

[target-allocator] Add a pre-hook to the allocator to filter out dropped targets #1127

Merged
merged 5 commits into from
Nov 4, 2022

Conversation

moh-osman3
Copy link
Contributor

@moh-osman3 moh-osman3 commented Sep 26, 2022

PR to resolve #1064

The goal of this PR is to drop targets before targets are assigned to the collectors by the allocator. Not necessary to allocate targets that will be dropped in the relabel step.

Now the Allocator will check if there is a Filter set and apply it to filter down the list of targets.

filterStrategy=relabel-config drops targets based on Prometheus relabel_config
No filtering is the default.

@moh-osman3 moh-osman3 marked this pull request as ready for review October 4, 2022 19:34
@moh-osman3 moh-osman3 requested a review from a team October 4, 2022 19:34
Copy link
Contributor

@jaronoff97 jaronoff97 left a comment

Choose a reason for hiding this comment

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

Left a few thoughts

cmd/otel-allocator/allocation/strategy.go Outdated Show resolved Hide resolved
cmd/otel-allocator/discovery/discovery.go Outdated Show resolved Hide resolved
cmd/otel-allocator/prehooktargetfilter/no_op_filter.go Outdated Show resolved Hide resolved
cmd/otel-allocator/prehooktargetfilter/no_op_filter.go Outdated Show resolved Hide resolved
cmd/otel-allocator/prehooktargetfilter/no_op_filter.go Outdated Show resolved Hide resolved
cmd/otel-allocator/targetscommon/targets.go Outdated Show resolved Hide resolved
cmd/otel-allocator/allocation/least_weighted.go Outdated Show resolved Hide resolved
cmd/otel-allocator/allocation/consistent_hashing.go Outdated Show resolved Hide resolved
cmd/otel-allocator/prehook/relabel.go Outdated Show resolved Hide resolved
cmd/otel-allocator/prehook/relabel.go Outdated Show resolved Hide resolved
cmd/otel-allocator/prehook/relabel.go Outdated Show resolved Hide resolved
cmd/otel-allocator/prehook/relabel_test.go Outdated Show resolved Hide resolved
cmd/otel-allocator/prehook/relabel_test.go Show resolved Hide resolved
cmd/otel-allocator/prehook/relabel_test.go Outdated Show resolved Hide resolved
cmd/otel-allocator/prehook/relabel_test.go Outdated Show resolved Hide resolved
Copy link
Member

@Aneurysm9 Aneurysm9 left a comment

Choose a reason for hiding this comment

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

I think this is definitely moving in the right direction. A few comments and questions.

cmd/otel-allocator/allocation/consistent_hashing.go Outdated Show resolved Hide resolved
cmd/otel-allocator/allocation/least_weighted.go Outdated Show resolved Hide resolved
Comment on lines 36 to 42
func (hook mockHook) SetConfig(map[string][]*relabel.Config) {
}

func (hook mockHook) GetConfig() map[string][]*relabel.Config {
dummyRet := map[string][]*relabel.Config{}
return dummyRet
}
Copy link
Member

Choose a reason for hiding this comment

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

These don't seem to be at all relevant to the use of the prehook.Hook type here. Can that interface have just the Apply() method and leave [SG]etConfig() to the concrete implementation of the relabeling hook?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I'm still unsure the best way to implement this suggestion. I agree that [SG}etConfig() methods are specific to relabeling filter but therelabelCfg gets set in discovery. So I'm actually unsure if I'm able to get access to the concrete struct's method, when I only pass in the allocator interface.

cmd/otel-allocator/prehook/relabel.go Outdated Show resolved Hide resolved
cmd/otel-allocator/prehook/relabel.go Outdated Show resolved Hide resolved
cmd/otel-allocator/prehook/relabel.go Outdated Show resolved Hide resolved
@moh-osman3 moh-osman3 requested a review from a team October 25, 2022 00:48
Copy link
Contributor

@jaronoff97 jaronoff97 left a comment

Choose a reason for hiding this comment

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

Found one potential problem, otherwise this looks great!

cmd/otel-allocator/prehook/relabel.go Show resolved Hide resolved
cmd/otel-allocator/prehook/prehook.go Outdated Show resolved Hide resolved
Copy link
Contributor

@kristinapathak kristinapathak left a comment

Choose a reason for hiding this comment

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

Left a few suggestions for having smaller, more specific interfaces with their caller code. In general, we could define smaller interfaces in the prehook package but I'm not sure how useful that would be. I would rather define smaller interfaces in the packages that use them, especially if the prehook package must define an interface with all functions in order to allow for the injection of custom hooks.

I thought these were some interesting reads:
https://stackoverflow.com/questions/73954228/in-golang-how-can-a-consumer-define-an-interface-for-a-function-that-accepts-an
https://dave.cheney.net/practical-go/presentations/gophercon-israel.html#_let_callers_define_the_interface_they_require

I also expanded on my example playground code just for fun 🙂 https://go.dev/play/p/fQU_JdouqT-

cmd/otel-allocator/discovery/discovery.go Outdated Show resolved Hide resolved
cmd/otel-allocator/allocation/strategy.go Outdated Show resolved Hide resolved
cmd/otel-allocator/allocation/least_weighted.go Outdated Show resolved Hide resolved
cmd/otel-allocator/allocation/consistent_hashing.go Outdated Show resolved Hide resolved
cmd/otel-allocator/allocation/least_weighted.go Outdated Show resolved Hide resolved
cmd/otel-allocator/allocation/strategy.go Outdated Show resolved Hide resolved
cmd/otel-allocator/allocation/strategy.go Outdated Show resolved Hide resolved
SetConfig(map[string][]*relabel.Config)
}

func NewManager(log logr.Logger, ctx context.Context, logger log.Logger, hook discoveryHook, options ...func(*discovery.Manager)) *Manager {
Copy link
Member

Choose a reason for hiding this comment

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

This function signature needs some love, but that can probably be handled in a separate issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made a note to create an issue to refactor this function signature.

cmd/otel-allocator/prehook/prehook.go Outdated Show resolved Hide resolved
cmd/otel-allocator/prehook/prehook.go Outdated Show resolved Hide resolved
cmd/otel-allocator/allocation/least_weighted.go Outdated Show resolved Hide resolved
@moh-osman3 moh-osman3 requested review from Aneurysm9 and secustor and removed request for secustor and Aneurysm9 November 2, 2022 09:37
@pavolloffay pavolloffay merged commit 854eb67 into open-telemetry:main Nov 4, 2022
ItielOlenick pushed a commit to ItielOlenick/opentelemetry-operator that referenced this pull request May 1, 2024
…ped targets (open-telemetry#1127)

* Adding prehook allocator filter to reduce assigned targets

* add metrics to track number of targets kept after filtering

* add smaller interfaces local to packages using them

* address review feedback

* remove outdated references
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.

[target-allocator] Apply relabel configs to targets prior to allocation
6 participants