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

feat(processor): preserve auth in batch processor #10002

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

grandwizard28
Copy link

Description

This PR preserves the authData in the client context after the batch processor. The idea is that the auth data can be used after the batch processor in subsequent processors and exporters.

Testing

  • Current unit tests modified to include the context
  • Need help with adding unit tests which choose auth is preserved.

@grandwizard28 grandwizard28 requested a review from a team as a code owner April 19, 2024 12:43
@mx-psi mx-psi requested a review from jpkrohling April 19, 2024 14:04
@mx-psi
Copy link
Member

mx-psi commented Apr 19, 2024

@grandwizard28 Thanks for the PR! Are there any related issues to this?

Copy link

codecov bot commented Apr 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.78%. Comparing base (4a58092) to head (45f83ea).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #10002   +/-   ##
=======================================
  Coverage   91.77%   91.78%           
=======================================
  Files         360      360           
  Lines       16641    16643    +2     
=======================================
+ Hits        15273    15275    +2     
  Misses       1041     1041           
  Partials      327      327           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@grandwizard28
Copy link
Author

Hey @mx-psi,
There are no current issues related to this. The background is while using any auth extension, we generally want to propagate some data (for example user_id) across processors and exporters but the batch processor is dropping the clientInfo.Auth struct.

I thought this would make a nice edition to the core since the batch processor is widely used.

Do let me know your thoughts on the above hypothesis :)

@grandwizard28
Copy link
Author

Hey @jpkrohling @mx-psi,
Any thoughts here?

Copy link
Member

@jpkrohling jpkrohling left a comment

Choose a reason for hiding this comment

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

I'm not sure this is accurate. I believe this feature exists already, and was implemented by @jmacd on #7578. If that's not working for some reason, I'd be interested in hearing about that in an issue.

@@ -129,7 +129,9 @@ func newBatchProcessor(set processor.CreateSettings, cfg *Config, batchFunc func
metadataLimit: int(cfg.MetadataCardinalityLimit),
}
if len(bp.metadataKeys) == 0 {
s := bp.newShard(nil)
// Retrieve info from the context and preserve Auth
info := client.FromContext(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

The context at this level doesn't have auth data, as newBatchProcessor isn't called in response to incoming data, but during the startup of the collector.

Copy link
Author

Choose a reason for hiding this comment

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

Understood! The idea is to propogate the existing context in all shards created.

The newShard function is the same regardless of whether we want to start at startup with a single shard or start multiple shards as per the metadata. I figured we just need to amend the signature of newShard to give it an existing (if present) AuthData.

Is my understanding fair?

@grandwizard28
Copy link
Author

If you look at the exportCtx @jpkrohling, it looks like the following:

exportCtx := client.NewContext(context.Background(), client.Info{
		Metadata: client.NewMetadata(md),
	})

There is no AuthData preservation happening here at all. We are creating a new context altogether.

Do you want me to still create an issue?

@jpkrohling
Copy link
Member

No, the code you are looking for is here:

b, loaded = mb.batchers.LoadOrStore(aset, mb.newShard(md))

This will create a new shard based on the context for that is available in the consume function, which does have client metadata.

@grandwizard28
Copy link
Author

Hey @jpkrohling,
Created an issue for this: #10093

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.

None yet

3 participants