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

[chore] [exporterhelper] Refactor queue initialization #8284

Merged
merged 2 commits into from
Aug 30, 2023

Conversation

dmitryax
Copy link
Member

@dmitryax dmitryax commented Aug 25, 2023

Make the queue initialization process consistent for both queue types. Instead of having different workflows for memory and persistent queues, this change breaks the initialization of both into two generic steps:

  1. Queue factory: NewBoundedMemoryQueue, NewPersistentQueue
  2. Start method: queue.Start(context.Context, component.Host, QueueSettings)

This change:

  • reduces coupling between queuedRetrySender and the queues;
  • allows future refactoring of queuedRetrySender;
  • allows future extraction of the queue package from the exporterhelper;
  • makes it possible to have WithRequestQueue option for the new exporter helper API as drafted in [exporterhelper] Add WithRequestQueue option to the exporter #8275.

@dmitryax dmitryax requested review from a team and codeboten August 25, 2023 07:00
@dmitryax dmitryax changed the title [exporterhelper] Refactor queue initialization [chore] [exporterhelper] Refactor queue initialization Aug 25, 2023
@dmitryax dmitryax added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Aug 25, 2023
@dmitryax dmitryax force-pushed the refactor-queu-creation branch 2 times, most recently from 3390d83 to 25e16d6 Compare August 25, 2023 07:23
@dmitryax
Copy link
Member Author

Hi @swiatekm-sumo, can you please take a look at this PR?

@dmitryax dmitryax force-pushed the refactor-queu-creation branch 6 times, most recently from 5920592 to 23d1e4d Compare August 26, 2023 03:41
}
}

// StartConsumers starts a given number of goroutines consuming items from the queue
// and passing them into the consumer callback.
func (q *boundedMemoryQueue) StartConsumers(numWorkers int, callback func(item Request)) {
func (q *boundedMemoryQueue) Start(_ context.Context, _ component.Host, set QueueSettings) error {
Copy link
Member

Choose a reason for hiding this comment

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

Why not passing the callback as well in the ctor vs passing set here?

Comment on lines +143 to +148
CreateSettings: set,
DataType: qrs.signal,
Callback: func(item internal.Request) {
_ = qrs.consumerSender.send(item)
item.OnProcessingFinished()
},
Copy link
Member

Choose a reason for hiding this comment

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

Same as previous comment, better to pass all of these in the ctor if possible or at least pass only the callback.

Copy link
Member Author

Choose a reason for hiding this comment

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

The idea is to expose the constructors to the user, as you suggested in #8248 (comment). I wanted to reuse the same structures in the public and private packages. If we want to move all these arguments that users should not be providing, we will need different public structs encapsulating the internal ones. Also, we would likely need to change the signature of the Option from type Option func(*baseSettings) to type Option func(*baseExporter), which should not be considered as a breaking change I believe. Let me try this out

Copy link
Member Author

@dmitryax dmitryax Aug 30, 2023

Choose a reason for hiding this comment

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

This involves too many additional changes. I would like to merge this one and try it in a separate PR. This PR essentially doesn't change the way how the Callback argument is passed anyway

exporter/exporterhelper/queued_retry.go Show resolved Hide resolved
@@ -294,7 +240,7 @@ func createSampledLogger(logger *zap.Logger) *zap.Logger {

// send implements the requestSender interface
func (qrs *queuedRetrySender) send(req internal.Request) error {
if !qrs.queueSettings.config.Enabled {
Copy link
Member

Choose a reason for hiding this comment

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

In a separate PR, I think we should always have a "queue" instead of all these if nil checks, and use a "direct call queue" that just pass to the callback.

Make the queue initialization process consistent for both queue types. Instead of different workflows for memory and persistent queues, this change breaks it into two generic steps:
1. Queue factory
2. Start method

This change:
- reduces coupling;
- allows future refactoring of queuedRetrySender;
- allows extracting of the queue package from the exporterhelper;
- makes it possible to have `WithRequestQueue` option for the new exporter helper API.
@dmitryax dmitryax merged commit 7030388 into open-telemetry:main Aug 30, 2023
30 checks passed
@github-actions github-actions bot added this to the next release milestone Aug 30, 2023
@dmitryax dmitryax deleted the refactor-queu-creation branch August 30, 2023 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants