Skip to content

Switching emitter. This will allow for a per feed emitter designation.#13363

Merged
abhishekagarwal87 merged 8 commits intoapache:masterfrom
TSFenwick:feature-add-switching-emitter
Dec 5, 2022
Merged

Switching emitter. This will allow for a per feed emitter designation.#13363
abhishekagarwal87 merged 8 commits intoapache:masterfrom
TSFenwick:feature-add-switching-emitter

Conversation

@TSFenwick
Copy link
Contributor

@TSFenwick TSFenwick commented Nov 14, 2022

This will work by looking at an event's feed and direct it to a specific emitter. If no specific feed is specified for a feed. The emitter can direct the event to a default emitter.

Description

The goal of this PR is to allow there to be a way to filter events to a different emitter. For example druid cluster might be sending metrics with the statsd emitter, but we want to emit request log events to an http emitter. Currently in druid there is no way to do this without sending all the events to both of them. And each emitter doesn't necessarily have the ability to filter out events it doesn't want to send/hold onto in memory.

Create and Wire Up Switching Emitter ...

We chose to use a linear search for finding the correct emitter based on feed because the number emitters and feeds is likely to be low enough that a linear search will likely be the fastest.

Release note

New you can now use a specific emitter for each feed. For example this means that alerts can go to http emitter, metrics can go to statsd emitter, and requestLog events can go to a kafka emitter.


Key changed/added classes in this PR
  • SwitchingEmitter
  • SwitchingEmitterConfig
  • SwitchingEmitterModule

This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

This will work by looking at an event's feed and direct it to a specific emitter. If no specific feed is specified for a feed.
The emitter can direct the event to a default emitter.
public void flush() throws IOException
{
boolean fail = false;
log.info("Flushing Switching Emitter.");
Copy link
Contributor

Choose a reason for hiding this comment

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

what frequency is this logging going to be at?

|Property|Description|Default|
|--------|-----------|-------|
|`druid.emitter.switching.emitters`|Map of feed to list of emitter modules to load that will be used for each feed, e.g., {"metrics":["http"], "alerts":["logging"]}|{}|
|`druid.emitter.switching.defaultEmitters`|List of emitter modules to load that will be used if there is no emitter specifically designated to the event feed, e.g., ["logging","http"].|[]|
Copy link
Contributor

Choose a reason for hiding this comment

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

so that event feed will go to all the default emitters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this where naming gets weird. Default is probably the wrong name. since it could be read that no matter what every event goes to the default emitters but i see it as it as the list of emitters to use if there isn't a match for an event's feed

Example of how it's working as coded:
So with a hypothetical config and hypothetical event feed names, and emitters

druid.emitter.switching.defaultEmitters=[http, foo]
druid.emitter.switching.emitters={"metrics":["statsd", "logging"], "alerts":["bar"]}

if an event with feed metrics is emitted. it will only be emitted to statsd and logging emitters and will not go to the default emitters.
if an event with feed requestLog it would be emitted to the http and foo emitters
if an event with feed alerts it would be emitted to bar emitter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@abhishekagarwal87 One thing that can be done here is i add this per feed functionality onto the composing emitter instead of making a new one...

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the current structure is fine since the final JSON would get a bit unwieldy. what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, no complaints from me then

@abhishekagarwal87 abhishekagarwal87 merged commit 10bec54 into apache:master Dec 5, 2022
@abhishekagarwal87
Copy link
Contributor

Thank you @TSFenwick for the contribution.

@clintropolis clintropolis added this to the 26.0 milestone Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants