Skip to content

[RW] Use remoteapi.Write function to sendSamplesWithBackoff#17373

Closed
pipiland2612 wants to merge 11 commits intoprometheus:mainfrom
pipiland2612:replace_que_func
Closed

[RW] Use remoteapi.Write function to sendSamplesWithBackoff#17373
pipiland2612 wants to merge 11 commits intoprometheus:mainfrom
pipiland2612:replace_que_func

Conversation

@pipiland2612
Copy link
Copy Markdown
Contributor

@pipiland2612 pipiland2612 commented Oct 20, 2025

Which issue(s) does the PR fix:

Does this PR introduce a user-facing change?

NONE

Signed-off-by: pipiland2612 <[email protected]>
Signed-off-by: pipiland2612 <[email protected]>
Signed-off-by: pipiland2612 <[email protected]>
Signed-off-by: pipiland2612 <[email protected]>
Signed-off-by: pipiland2612 <[email protected]>
Signed-off-by: pipiland2612 <[email protected]>
Signed-off-by: pipiland2612 <[email protected]>
Signed-off-by: pipiland2612 <[email protected]>
Signed-off-by: pipiland2612 <[email protected]>
@pipiland2612 pipiland2612 marked this pull request as draft October 20, 2025 14:06
@pipiland2612
Copy link
Copy Markdown
Contributor Author

This is just an overall idea of what would look liek if we want to use Write function for sendsSampleWithBackOff. The test I will fix later if the overall method is good.

cc @bwplotka @saswatamcode

@bwplotka bwplotka marked this pull request as ready for review October 20, 2025 18:29
Signed-off-by: pipiland2612 <[email protected]>
Signed-off-by: pipiland2612 <[email protected]>
@@ -459,37 +489,42 @@ func TestSampleDeliveryOrder(t *testing.T) {

func TestShutdown(t *testing.T) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This changed version of the test is flaky

externalLabels: extLabelsSlice,
relabelConfigs: relabelConfigs,
storeClient: client,
remoteAPI: nil, // Will be set below after QueueManager is created
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
remoteAPI: nil, // Will be set below after QueueManager is created

backoffCfg := remoteapi.BackoffConfig{
Min: time.Duration(t.cfg.MinBackoff),
Max: time.Duration(t.cfg.MaxBackoff),
MaxRetries: 0,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is noop

Suggested change
MaxRetries: 0,

var err error
t.remoteAPI, err = remoteapi.NewAPI(client.Endpoint(), apiOpts...)
if err != nil {
logger.Error("Failed to create remote API client", "endpoint", client.Endpoint(), "err", err)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why not failing?

logger.Error("Failed to create remote API client", "endpoint", client.Endpoint(), "err", err)
}

return t
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
return t
return t, err


// Initialize remoteAPI now that QueueManager is fully created
// Configure backoff to match queue manager config
backoffCfg := remoteapi.BackoffConfig{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not just do t.SetClient(....)

@@ -1048,8 +1073,29 @@ func (t *QueueManager) SeriesReset(index int) {
// fields are updated to avoid restarting the queue.
func (t *QueueManager) SetClient(c WriteClient) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
func (t *QueueManager) SetClient(c WriteClient) {
func (t *QueueManager) SetClient(c WriteClient) error {

if isSampleOld(currentTime, time.Duration(s.qm.cfg.SampleAgeLimit), lowest) {
// Data became stale - cancel the Write to stop retrying stale data.
s.qm.logger.Debug("data became stale during Write retries, canceling",
"refresh_attempt", refreshAttempt,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's ensure we have a test for refreshed retries.

@pipiland2612 pipiland2612 marked this pull request as draft October 29, 2025 08:36
return accumulatedStats, err
s.qm.metrics.sentBatchDuration.Observe(time.Since(begin).Seconds())

// Convert client_golang stats to Prometheus stats.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to convert things? I wonder why we still need to use private field here. Is this enough to convince us to make this field public or are we missing helper function?

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.

2 participants