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: implement backoff for snowpipe streaming authorization errors #5399

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

shekhar-rudder
Copy link
Member

@shekhar-rudder shekhar-rudder commented Dec 27, 2024

Description

This PR introduces a backoff mechanism when creating channels in the Snowpipe streaming destination. If an authorization error is encountered at the schema, table, or column level, the backoff ensures that we avoid repeatedly attempting to connect to Snowflake unnecessarily.

  • Added a new struct authzBackoff in manager to store backoff related state
  • Refactoring: Added managerCreator as a field in the manager for making the code testable.
  • Until now, any error encountered while creating the channel for the discards table resulted in the job being marked as aborted. In this PR, the behavior has been updated to mark the job as failed, allowing it to be retried.
  • Backoff is applied whenever an authorization error is encountered.
  • Backoff is being cleared whenver channels for all the tables are being created without any authz error

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

@@ -26,6 +26,9 @@ import (
warehouseutils "github.com/rudderlabs/rudder-server/warehouse/utils"
)

// Creating an alias since "model.TableSchema" is defined in an internal module
type ModelTableSchema = model.TableSchema
Copy link
Member Author

@shekhar-rudder shekhar-rudder Dec 27, 2024

Choose a reason for hiding this comment

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

Any alternatives ? I can't import model.TableSchema in the snowpipestreaming test since it is in an internal module.

Copy link
Member

Choose a reason for hiding this comment

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

We can use whutils.ModelTableSchema

Copy link

codecov bot commented Dec 27, 2024

Codecov Report

Attention: Patch coverage is 89.02439% with 9 lines in your changes missing coverage. Please review.

Project coverage is 74.80%. Comparing base (8a186e5) to head (e268f73).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...tionmanager/snowpipestreaming/snowpipestreaming.go 86.36% 4 Missing and 2 partials ⚠️
...yncdestinationmanager/snowpipestreaming/channel.go 80.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5399      +/-   ##
==========================================
- Coverage   74.82%   74.80%   -0.03%     
==========================================
  Files         438      438              
  Lines       61331    61404      +73     
==========================================
+ Hits        45893    45933      +40     
- Misses      12895    12932      +37     
+ Partials     2543     2539       -4     

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

@@ -26,6 +26,9 @@ import (
warehouseutils "github.com/rudderlabs/rudder-server/warehouse/utils"
)

// Creating an alias since "model.TableSchema" is defined in an internal module
type ModelTableSchema = model.TableSchema
Copy link
Member

Choose a reason for hiding this comment

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

We can use whutils.ModelTableSchema

@@ -43,6 +48,29 @@ func (m *mockAPI) GetStatus(_ context.Context, channelID string) (*model.StatusR
return m.getStatusOutputMap[channelID]()
}

type mockManager struct {
manager.Manager
throwSchemaErr bool
Copy link
Member

Choose a reason for hiding this comment

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

Instead of a boolean, we can set the following error like createSchemaErr, createTableErr.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Comment on lines 140 to 141
backoffDuration time.Duration
initialBackoffDuration time.Duration
Copy link
Member

Choose a reason for hiding this comment

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

Can we use github.com/cenkalti/backoff/v4 instead of implementing this logic?

Copy link
Member Author

Choose a reason for hiding this comment

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

Replaced the custom implementation with the library

Comment on lines 217 to 222
var authzErr *snowpipeAuthzError
if errors.As(err, &authzErr) {
if shouldResetBackoff {
shouldResetBackoff = false
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var authzErr *snowpipeAuthzError
if errors.As(err, &authzErr) {
if shouldResetBackoff {
shouldResetBackoff = false
}
}
if errors.As(err, &authzErr) && !shouldResetBackoff {
shouldResetBackoff = false
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed shouldResetBackoff since it was unnecessary

whutils "github.com/rudderlabs/rudder-server/warehouse/utils"
)

var json = jsoniter.ConfigCompatibleWithStandardLibrary

func New(
conf *config.Config,
logger logger.Logger,
mLogger logger.Logger,
Copy link
Member

Choose a reason for hiding this comment

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

mLogger Do you mean module logger? Can we rename it as log?

Copy link
Member Author

Choose a reason for hiding this comment

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

I had renamed it to mLogger since managerCreator had an argument of type logger.Logger. Renaming it to log

logger.NewStringField("table", discardsTable()),
obskit.Error(err),
)
shouldResetBackoff = false
Copy link
Member

@achettyiitr achettyiitr Dec 30, 2024

Choose a reason for hiding this comment

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

We can return from here itself. No point in going forward.

Suggested change
shouldResetBackoff = false
m.stats.jobs.failed.Count(len(asyncDest.ImportingJobIDs))
return common.AsyncUploadOutput{
FailedJobIDs: asyncDest.ImportingJobIDs,
FailedCount: len(asyncDest.ImportingJobIDs),
FailedReason: fmt.Errorf("failed to initialize channel with schema: %w", err).Error(),
DestinationID: asyncDest.Destination.ID,
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Added an early return with failed job reporting

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.

2 participants