From d564bc8ccc71b4e60c9e29bbfd12a32624adbbbf Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 13 Jul 2026 19:48:01 +0000 Subject: [PATCH 01/28] chore(deps): update actions/checkout action to v7 (#433) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 40a49c3e..93bbf7b3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: name: lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 - uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0 with: @@ -27,7 +27,7 @@ jobs: name: test runs-on: ubuntu-latest steps: - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 - name: test run: make docker && make docker-test From 768a936eb3e8a9956cb8bd9855f0eb490120d85a Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Fri, 28 Aug 2026 15:54:07 -0500 Subject: [PATCH 02/28] chore(lint): fixes (#437) * chore(lint): ignore reassign on test table overrides * chore(lint): extract helpers to reduce nestif complexity * chore(lint): Fix modernize findings * chore(lint): Fix goimports findings * chore(lint): Fix nilnil findings * chore(lint): Fix golines findings * chore: fix typos in error messages --- command/command.go | 162 +++++++------- command/command_test.go | 2 +- command/device_limit.go | 3 +- command/item_size_monitor_test.go | 5 +- command/server_defined_unique_entity_test.go | 2 +- controller/controller_test.go | 2 +- datastore/item_count_test.go | 2 +- datastore/sync_entity.go | 219 ++++++++++--------- datastore/sync_entity_test.go | 4 +- 9 files changed, 211 insertions(+), 190 deletions(-) diff --git a/command/command.go b/command/command.go index dc272901..da5bc228 100644 --- a/command/command.go +++ b/command/command.go @@ -31,6 +31,58 @@ const ( normalCountTypeStr string = "normal" ) +func setupNewClient( + ctx context.Context, + db datastore.Datastore, + clientID string, +) (*sync_pb.SyncEnums_ErrorType, error) { + // Reject the request if client has >= 50 devices in the chain. + activeDevices := 0 + for { + hasChangesRemaining, syncEntities, err := db.GetUpdatesForType( + ctx, + deviceInfoTypeID, + 0, + false, + clientID, + maxGUBatchSize, + ) + if err != nil { + log.Error().Err(err).Msgf("db.GetUpdatesForType failed for type %v", deviceInfoTypeID) + errCode := sync_pb.SyncEnums_TRANSIENT_ERROR + return &errCode, + fmt.Errorf("error getting updates for type %v: %w", deviceInfoTypeID, err) + } + + for _, entity := range syncEntities { + if !*entity.Deleted { + activeDevices++ + } + + // Error out when device limit has been reached. + if hasReachedDeviceLimit(activeDevices, clientID) { + errCode := sync_pb.SyncEnums_THROTTLED + return &errCode, errors.New("exceed limit of active devices in a chain") + } + } + + // Run until all device records are checked. + if !hasChangesRemaining { + break + } + } + + // Insert initial records if needed. + err := InsertServerDefinedUniqueEntities(ctx, db, clientID) + if err != nil { + log.Error().Err(err).Msg("Create server defined unique entities failed") + errCode := sync_pb.SyncEnums_TRANSIENT_ERROR + return &errCode, fmt.Errorf("error creating server defined unique entities: %w", err) + } + success := sync_pb.SyncEnums_SUCCESS + return &success, nil +} + // handleGetUpdatesRequest handles GetUpdatesMessage and fills // GetUpdatesResponse. Target sync entities in the database will be updated or // deleted based on the client's requests. @@ -46,48 +98,8 @@ func handleGetUpdatesRequest( isNewClient := guMsg.GetUpdatesOrigin != nil && *guMsg.GetUpdatesOrigin == sync_pb.SyncEnums_NEW_CLIENT isPoll := guMsg.GetUpdatesOrigin != nil && *guMsg.GetUpdatesOrigin == sync_pb.SyncEnums_PERIODIC if isNewClient { - // Reject the request if client has >= 50 devices in the chain. - activeDevices := 0 - for { - hasChangesRemaining, syncEntities, err := db.GetUpdatesForType( - ctx, - deviceInfoTypeID, - 0, - false, - clientID, - maxGUBatchSize, - ) - if err != nil { - log.Error().Err(err).Msgf("db.GetUpdatesForType failed for type %v", deviceInfoTypeID) - errCode = sync_pb.SyncEnums_TRANSIENT_ERROR - return &errCode, - fmt.Errorf("error getting updates for type %v: %w", deviceInfoTypeID, err) - } - - for _, entity := range syncEntities { - if !*entity.Deleted { - activeDevices++ - } - - // Error out when device limit has been reached. - if hasReachedDeviceLimit(activeDevices, clientID) { - errCode = sync_pb.SyncEnums_THROTTLED - return &errCode, errors.New("exceed limit of active devices in a chain") - } - } - - // Run until all device records are checked. - if !hasChangesRemaining { - break - } - } - - // Insert initial records if needed. - err := InsertServerDefinedUniqueEntities(ctx, db, clientID) - if err != nil { - log.Error().Err(err).Msg("Create server defined unique entities failed") - errCode = sync_pb.SyncEnums_TRANSIENT_ERROR - return &errCode, fmt.Errorf("error creating server defined unique entitiies: %w", err) + if setupErrCode, err := setupNewClient(ctx, db, clientID); err != nil { + return setupErrCode, err } } @@ -492,6 +504,20 @@ func handleClearServerDataRequest( return &errCode, nil } +func applyHandlerError(pbRsp *sync_pb.ClientToServerResponse, err error, wrapMsg string) error { + if err == nil { + return nil + } + if pbRsp.ErrorCode != nil { + pbRsp.ErrorMessage = aws.String(err.Error()) + return nil + } + // In seldom error cases which are not temporary and will not go away + // when clients retry, we will not use defined sync error in the proto + // response, but use internal server error. + return fmt.Errorf("%s: %w", wrapMsg, err) +} + // HandleClientToServerMessage handles the protobuf ClientToServerMessage and // fills the protobuf ClientToServerResponse. func HandleClientToServerMessage( @@ -509,40 +535,27 @@ func HandleClientToServerMessage( SetSyncPollInterval: aws.Int32(setSyncPollInterval), MaxCommitBatchSize: aws.Int32(maxCommitBatchSize)} - var err error if pb.MessageContents == nil { return errors.New("nil pb.MessageContents received") - } else if *pb.MessageContents == sync_pb.ClientToServerMessage_GET_UPDATES { + } + + switch *pb.MessageContents { + case sync_pb.ClientToServerMessage_GET_UPDATES: guRsp := &sync_pb.GetUpdatesResponse{} pbRsp.GetUpdates = guRsp + var err error pbRsp.ErrorCode, err = handleGetUpdatesRequest(ctx, cache, pb.GetUpdates, guRsp, db, clientID) - if err != nil { - if pbRsp.ErrorCode != nil { - pbRsp.ErrorMessage = aws.String(err.Error()) - return nil - } - // In seledom error cases which are not temporary and will not go away - // when clients retry, we will not use defined sync error in the proto - // response, but use internal server error. - return fmt.Errorf("error handling GetUpdates request: %w", err) - } - } else if *pb.MessageContents == sync_pb.ClientToServerMessage_COMMIT { + return applyHandlerError(pbRsp, err, "error handling GetUpdates request") + case sync_pb.ClientToServerMessage_COMMIT: commitRsp := &sync_pb.CommitResponse{} pbRsp.Commit = commitRsp + var err error pbRsp.ErrorCode, err = handleCommitRequest(context.TODO(), cache, pb.Commit, commitRsp, db, clientID) - if err != nil { - if pbRsp.ErrorCode != nil { - pbRsp.ErrorMessage = aws.String(err.Error()) - return nil - } - // In seledom error cases which are not temporary and will not go away - // when clients retry, we will not use defined sync error in the proto - // response, but use internal server error. - return fmt.Errorf("error handling Commit request: %w", err) - } - } else if *pb.MessageContents == sync_pb.ClientToServerMessage_CLEAR_SERVER_DATA { + return applyHandlerError(pbRsp, err, "error handling Commit request") + case sync_pb.ClientToServerMessage_CLEAR_SERVER_DATA: csdRsp := &sync_pb.ClearServerDataResponse{} pbRsp.ClearServerData = csdRsp + var err error pbRsp.ErrorCode, err = handleClearServerDataRequest( context.Background(), cache, @@ -550,19 +563,10 @@ func HandleClientToServerMessage( pb.ClearServerData, clientID, ) - if err != nil { - if pbRsp.ErrorCode != nil { - pbRsp.ErrorMessage = aws.String(err.Error()) - return nil - } - // In seldom error cases which are not temporary and will not go away - // when clients retry, we will not use defined sync error in the proto - // response, but use internal server error. - return fmt.Errorf("error handling ClearServerData request: %w", err) - } - } else { + return applyHandlerError(pbRsp, err, "error handling ClearServerData request") + case sync_pb.ClientToServerMessage_DEPRECATED_3, sync_pb.ClientToServerMessage_DEPRECATED_4: + fallthrough + default: return errors.New("unsupported message type of ClientToServerMessage") } - - return nil } diff --git a/command/command_test.go b/command/command_test.go index b7d8f0d8..28d38610 100644 --- a/command/command_test.go +++ b/command/command_test.go @@ -68,7 +68,7 @@ func NewPBSyncAttrs( } func (suite *CommandTestSuite) SetupSuite() { - datastore.Table = "client-entity-test-command" + datastore.Table = "client-entity-test-command" //nolint:reassign // acceptable for tests var err error suite.dynamo, err = datastore.NewDynamo() suite.Require().NoError(err, "Failed to get dynamoDB session") diff --git a/command/device_limit.go b/command/device_limit.go index 15095054..1d517fb1 100644 --- a/command/device_limit.go +++ b/command/device_limit.go @@ -22,8 +22,7 @@ func init() { func LoadHighDeviceLimitClientIDs(clientIDList string) { highDeviceLimitClientIDs = make(map[string]bool) if clientIDList != "" { - ids := strings.Split(clientIDList, ",") - for _, id := range ids { + for id := range strings.SplitSeq(clientIDList, ",") { highDeviceLimitClientIDs[strings.ToLower(strings.TrimSpace(id))] = true } } diff --git a/command/item_size_monitor_test.go b/command/item_size_monitor_test.go index f451b758..231c3a5c 100644 --- a/command/item_size_monitor_test.go +++ b/command/item_size_monitor_test.go @@ -4,10 +4,11 @@ import ( "strings" "testing" - "github.com/brave/go-sync/command" - "github.com/brave/go-sync/schema/protobuf/sync_pb" "github.com/stretchr/testify/assert" "google.golang.org/protobuf/proto" + + "github.com/brave/go-sync/command" + "github.com/brave/go-sync/schema/protobuf/sync_pb" ) func makeEntity(size int) *sync_pb.SyncEntity { diff --git a/command/server_defined_unique_entity_test.go b/command/server_defined_unique_entity_test.go index 21f7b977..c792500e 100644 --- a/command/server_defined_unique_entity_test.go +++ b/command/server_defined_unique_entity_test.go @@ -30,7 +30,7 @@ type SyncAttrs struct { } func (suite *ServerDefinedUniqueEntityTestSuite) SetupSuite() { - datastore.Table = "client-entity-test-command" + datastore.Table = "client-entity-test-command" //nolint:reassign // acceptable for tests var err error suite.dynamo, err = datastore.NewDynamo() suite.Require().NoError(err, "Failed to get dynamoDB session") diff --git a/controller/controller_test.go b/controller/controller_test.go index 16ddd97f..75ceae01 100644 --- a/controller/controller_test.go +++ b/controller/controller_test.go @@ -30,7 +30,7 @@ type ControllerTestSuite struct { } func (suite *ControllerTestSuite) SetupSuite() { - datastore.Table = "client-entity-test-controllor" + datastore.Table = "client-entity-test-controllor" //nolint:reassign // acceptable for tests var err error suite.dynamo, err = datastore.NewDynamo() suite.Require().NoError(err, "Failed to get dynamoDB session") diff --git a/datastore/item_count_test.go b/datastore/item_count_test.go index 1122d845..db948ab3 100644 --- a/datastore/item_count_test.go +++ b/datastore/item_count_test.go @@ -18,7 +18,7 @@ type ItemCountTestSuite struct { } func (suite *ItemCountTestSuite) SetupSuite() { - datastore.Table = "client-entity-test-datastore" + datastore.Table = "client-entity-test-datastore" //nolint:reassign // acceptable for tests var err error suite.dynamo, err = datastore.NewDynamo() suite.Require().NoError(err, "Failed to get dynamoDB session") diff --git a/datastore/sync_entity.go b/datastore/sync_entity.go index 990c76a1..111d7832 100644 --- a/datastore/sync_entity.go +++ b/datastore/sync_entity.go @@ -170,59 +170,7 @@ func (dynamo *Dynamo) InsertSyncEntity(ctx context.Context, entity *SyncEntity) // Write tag item for all data types, except for // the history type, which does not use tag items. if entity.ClientDefinedUniqueTag != nil && *entity.DataType != HistoryTypeID { - items := make([]types.TransactWriteItem, 0, 2) - // Additional item for ensuring tag's uniqueness for a specific client. - item := NewServerClientUniqueTagItem(entity.ClientID, *entity.ClientDefinedUniqueTag, false) - av, err := attributevalue.MarshalMap(*item) - if err != nil { - return false, fmt.Errorf("error marshalling unique tag item to insert sync entity: %w", err) - } - tagItem := types.TransactWriteItem{ - Put: &types.Put{ - Item: av, - ExpressionAttributeNames: expr.Names(), - ExpressionAttributeValues: expr.Values(), - ConditionExpression: expr.Condition(), - TableName: aws.String(Table), - }, - } - - // Normal sync item - av, err = attributevalue.MarshalMap(*entity) - if err != nil { - return false, fmt.Errorf("error marshlling sync item to insert sync entity: %w", err) - } - syncItem := types.TransactWriteItem{ - Put: &types.Put{ - Item: av, - ExpressionAttributeNames: expr.Names(), - ExpressionAttributeValues: expr.Values(), - ConditionExpression: expr.Condition(), - TableName: aws.String(Table), - }, - } - items = append(items, tagItem) - items = append(items, syncItem) - - _, err = dynamo.TransactWriteItems(ctx, - &dynamodb.TransactWriteItemsInput{TransactItems: items}) - if err != nil { - // Return conflict if insert condition failed. - var canceledException *types.TransactionCanceledException - if errors.As(err, &canceledException) { - for _, reason := range canceledException.CancellationReasons { - if reason.Code != nil && *reason.Code == conditionalCheckFailed { - return true, fmt.Errorf("error inserting sync item with client tag: %w", err) - } - } - } - return false, fmt.Errorf( - "error writing tag item and sync item in a transaction to insert sync entity: %w", - err, - ) - } - - return false, nil + return dynamo.insertSyncEntityWithClientTag(ctx, entity, expr) } // Normal sync item @@ -244,6 +192,67 @@ func (dynamo *Dynamo) InsertSyncEntity(ctx context.Context, entity *SyncEntity) return false, nil } +func (dynamo *Dynamo) insertSyncEntityWithClientTag( + ctx context.Context, + entity *SyncEntity, + expr expression.Expression, +) (bool, error) { + item := NewServerClientUniqueTagItem(entity.ClientID, *entity.ClientDefinedUniqueTag, false) + av, err := attributevalue.MarshalMap(*item) + if err != nil { + return false, fmt.Errorf("error marshalling unique tag item to insert sync entity: %w", err) + } + tagItem := types.TransactWriteItem{ + Put: &types.Put{ + Item: av, + ExpressionAttributeNames: expr.Names(), + ExpressionAttributeValues: expr.Values(), + ConditionExpression: expr.Condition(), + TableName: aws.String(Table), + }, + } + + av, err = attributevalue.MarshalMap(*entity) + if err != nil { + return false, fmt.Errorf("error marshalling sync item to insert sync entity: %w", err) + } + syncItem := types.TransactWriteItem{ + Put: &types.Put{ + Item: av, + ExpressionAttributeNames: expr.Names(), + ExpressionAttributeValues: expr.Values(), + ConditionExpression: expr.Condition(), + TableName: aws.String(Table), + }, + } + + _, err = dynamo.TransactWriteItems(ctx, + &dynamodb.TransactWriteItemsInput{TransactItems: []types.TransactWriteItem{tagItem, syncItem}}) + if err != nil && isTransactConditionalCheckFailed(err) { + return true, fmt.Errorf("error inserting sync item with client tag: %w", err) + } + if err != nil { + return false, fmt.Errorf( + "error writing tag item and sync item in a transaction to insert sync entity: %w", + err, + ) + } + return false, nil +} + +func isTransactConditionalCheckFailed(err error) bool { + var canceledException *types.TransactionCanceledException + if !errors.As(err, &canceledException) { + return false + } + for _, reason := range canceledException.CancellationReasons { + if reason.Code != nil && *reason.Code == conditionalCheckFailed { + return true + } + } + return false +} + // HasServerDefinedUniqueTag check the tag item to see if there is already a // tag item exists with the tag value for a specific client. func (dynamo *Dynamo) HasServerDefinedUniqueTag(ctx context.Context, clientID string, tag string) (bool, error) { @@ -421,7 +430,11 @@ func (dynamo *Dynamo) ClearServerData(ctx context.Context, clientID string) ([]S syncEntities = append(syncEntities, pageEntities...) totalCount += page.Count - log.Info().Str("chainID", clientID).Int("page", pageIndex).Int32("count", page.Count).Msg("Queried sync entities for deletion") + log.Info(). + Str("chainID", clientID). + Int("page", pageIndex). + Int32("count", page.Count). + Msg("Queried sync entities for deletion") pageIndex++ for i := int32(0); i < page.Count; i += maxTransactDeleteItemSize { @@ -471,7 +484,10 @@ func (dynamo *Dynamo) ClearServerData(ctx context.Context, clientID string) ([]S continue } - if _, err := dynamo.TransactWriteItems(ctx, &dynamodb.TransactWriteItemsInput{TransactItems: items}); err != nil { + if _, err := dynamo.TransactWriteItems( + ctx, + &dynamodb.TransactWriteItemsInput{TransactItems: items}, + ); err != nil { return syncEntities, fmt.Errorf("error deleting sync entities for client %s: %w", clientID, err) } } @@ -554,52 +570,7 @@ func (dynamo *Dynamo) UpdateSyncEntity(ctx context.Context, entity *SyncEntity, // tag item too. if entity.Deleted != nil && entity.ClientDefinedUniqueTag != nil && *entity.Deleted && *entity.DataType != HistoryTypeID { - pk := PrimaryKey{ - ClientID: entity.ClientID, ID: clientTagItemPrefix + *entity.ClientDefinedUniqueTag} - tagItemKey, err := attributevalue.MarshalMap(pk) - if err != nil { - return false, false, fmt.Errorf("error marshalling key to update sync entity: %w", err) - } - - items := make([]types.TransactWriteItem, 0, 2) - updateSyncItem := types.TransactWriteItem{ - Update: &types.Update{ - Key: key, - ExpressionAttributeNames: expr.Names(), - ExpressionAttributeValues: expr.Values(), - ConditionExpression: expr.Condition(), - UpdateExpression: expr.Update(), - ReturnValuesOnConditionCheckFailure: types.ReturnValuesOnConditionCheckFailureAllOld, - TableName: aws.String(Table), - }, - } - deleteTagItem := types.TransactWriteItem{ - Delete: &types.Delete{ - Key: tagItemKey, - TableName: aws.String(Table), - }, - } - items = append(items, updateSyncItem) - items = append(items, deleteTagItem) - - _, err = dynamo.TransactWriteItems(ctx, - &dynamodb.TransactWriteItemsInput{TransactItems: items}) - if err != nil { - // Return conflict if the update condition fails. - var canceledException *types.TransactionCanceledException - if errors.As(err, &canceledException) { - for _, reason := range canceledException.CancellationReasons { - if reason.Code != nil && *reason.Code == conditionalCheckFailed { - return true, false, nil - } - } - } - - return false, false, fmt.Errorf("error deleting sync item and tag item in a transaction: %w", err) - } - - // Successfully soft-delete the sync item and delete the tag item. - return false, true, nil + return dynamo.softDeleteSyncEntityWithClientTag(ctx, entity, key, expr) } // Not deleting a sync item with a client tag, do a normal update on sync @@ -641,6 +612,52 @@ func (dynamo *Dynamo) UpdateSyncEntity(ctx context.Context, entity *SyncEntity, return false, deleted, nil } +func (dynamo *Dynamo) softDeleteSyncEntityWithClientTag( + ctx context.Context, + entity *SyncEntity, + key map[string]types.AttributeValue, + expr expression.Expression, +) (bool, bool, error) { + pk := PrimaryKey{ + ClientID: entity.ClientID, ID: clientTagItemPrefix + *entity.ClientDefinedUniqueTag} + tagItemKey, err := attributevalue.MarshalMap(pk) + if err != nil { + return false, false, fmt.Errorf("error marshalling key to update sync entity: %w", err) + } + + updateSyncItem := types.TransactWriteItem{ + Update: &types.Update{ + Key: key, + ExpressionAttributeNames: expr.Names(), + ExpressionAttributeValues: expr.Values(), + ConditionExpression: expr.Condition(), + UpdateExpression: expr.Update(), + ReturnValuesOnConditionCheckFailure: types.ReturnValuesOnConditionCheckFailureAllOld, + TableName: aws.String(Table), + }, + } + deleteTagItem := types.TransactWriteItem{ + Delete: &types.Delete{ + Key: tagItemKey, + TableName: aws.String(Table), + }, + } + + _, err = dynamo.TransactWriteItems(ctx, + &dynamodb.TransactWriteItemsInput{ + TransactItems: []types.TransactWriteItem{updateSyncItem, deleteTagItem}, + }) + if err != nil && isTransactConditionalCheckFailed(err) { + return true, false, nil + } + if err != nil { + return false, false, fmt.Errorf("error deleting sync item and tag item in a transaction: %w", err) + } + + // Successfully soft-delete the sync item and delete the tag item. + return false, true, nil +} + // GetUpdatesForType returns sync entities of a data type where it's mtime is // later than the client token. // To do this in dynamoDB, we use (ClientID, DataType#Mtime) as GSI to get a diff --git a/datastore/sync_entity_test.go b/datastore/sync_entity_test.go index 6759a462..330b3fdd 100644 --- a/datastore/sync_entity_test.go +++ b/datastore/sync_entity_test.go @@ -26,7 +26,7 @@ type SyncEntityTestSuite struct { } func (suite *SyncEntityTestSuite) SetupSuite() { - datastore.Table = "client-entity-test-datastore" + datastore.Table = "client-entity-test-datastore" //nolint:reassign // acceptable for tests var err error suite.dynamo, err = datastore.NewDynamo() suite.Require().NoError(err, "Failed to get dynamoDB session") @@ -1036,7 +1036,7 @@ func (suite *SyncEntityTestSuite) TestClearServerDataPagination() { otherClientID := "client-other" insert := func(cid string, count int, specifics []byte) { - for i := 0; i < count; i++ { + for i := range count { entity := datastore.SyncEntity{ ClientID: cid, ID: fmt.Sprintf("id-%04d", i), From 5046a930daa7d1f2a5b885b24dd7ba78dd8b8885 Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Fri, 28 Aug 2026 18:16:12 -0500 Subject: [PATCH 03/28] chore(lint): Fix dupl findings (#438) --- datastore/datastoretest/dynamo.go | 70 +++++++------------------------ 1 file changed, 16 insertions(+), 54 deletions(-) diff --git a/datastore/datastoretest/dynamo.go b/datastore/datastoretest/dynamo.go index 7cbbdc70..12f4aa3a 100644 --- a/datastore/datastoretest/dynamo.go +++ b/datastore/datastoretest/dynamo.go @@ -75,12 +75,10 @@ func ResetTable(dynamo *datastore.Dynamo) error { return CreateTable(dynamo) } -// ScanSyncEntities scans the dynamoDB table and returns all sync items. -func ScanSyncEntities(dynamo *datastore.Dynamo) ([]datastore.SyncEntity, error) { - filter := expression.AttributeExists(expression.Name("Version")) +func scanItems[T any](dynamo *datastore.Dynamo, filter expression.ConditionBuilder, kind string) ([]T, error) { expr, err := expression.NewBuilder().WithFilter(filter).Build() if err != nil { - return nil, fmt.Errorf("error building expression to scan sync entitites: %w", err) + return nil, fmt.Errorf("error building expression to scan %s: %w", kind, err) } input := &dynamodb.ScanInput{ @@ -91,15 +89,21 @@ func ScanSyncEntities(dynamo *datastore.Dynamo) ([]datastore.SyncEntity, error) } out, err := dynamo.Scan(context.Background(), input) if err != nil { - return nil, fmt.Errorf("error doing scan for sync entities: %w", err) + return nil, fmt.Errorf("error doing scan for %s: %w", kind, err) } - syncItems := []datastore.SyncEntity{} - err = attributevalue.UnmarshalListOfMaps(out.Items, &syncItems) + var items []T + err = attributevalue.UnmarshalListOfMaps(out.Items, &items) if err != nil { - return nil, fmt.Errorf("error unmarshalling sync entitites: %w", err) + return nil, fmt.Errorf("error unmarshalling %s: %w", kind, err) } - return syncItems, nil + return items, nil +} + +// ScanSyncEntities scans the dynamoDB table and returns all sync items. +func ScanSyncEntities(dynamo *datastore.Dynamo) ([]datastore.SyncEntity, error) { + return scanItems[datastore.SyncEntity]( + dynamo, expression.AttributeExists(expression.Name("Version")), "sync entities") } // ScanTagItems scans the dynamoDB table and returns all tag items. @@ -107,54 +111,12 @@ func ScanTagItems(dynamo *datastore.Dynamo) ([]datastore.ServerClientUniqueTagIt filter := expression.And( expression.AttributeNotExists(expression.Name("ExpireAt")), expression.AttributeNotExists(expression.Name("Version"))) - expr, err := expression.NewBuilder().WithFilter(filter).Build() - if err != nil { - return nil, fmt.Errorf("error building expression to scan tag items: %w", err) - } - - input := &dynamodb.ScanInput{ - ExpressionAttributeNames: expr.Names(), - ExpressionAttributeValues: expr.Values(), - FilterExpression: expr.Filter(), - TableName: aws.String(datastore.Table), - } - out, err := dynamo.Scan(context.Background(), input) - if err != nil { - return nil, fmt.Errorf("error doing scan for tag items: %w", err) - } - tagItems := []datastore.ServerClientUniqueTagItem{} - err = attributevalue.UnmarshalListOfMaps(out.Items, &tagItems) - if err != nil { - return nil, fmt.Errorf("error unmarshalling tag items: %w", err) - } - - return tagItems, nil + return scanItems[datastore.ServerClientUniqueTagItem](dynamo, filter, "tag items") } // ScanClientItemCounts scans the dynamoDB table and returns all client item // counts. func ScanClientItemCounts(dynamo *datastore.Dynamo) ([]datastore.ClientItemCounts, error) { - filter := expression.AttributeExists(expression.Name("ItemCount")) - expr, err := expression.NewBuilder().WithFilter(filter).Build() - if err != nil { - return nil, fmt.Errorf("error building expression to scan item counts: %w", err) - } - - input := &dynamodb.ScanInput{ - ExpressionAttributeNames: expr.Names(), - ExpressionAttributeValues: expr.Values(), - FilterExpression: expr.Filter(), - TableName: aws.String(datastore.Table), - } - out, err := dynamo.Scan(context.Background(), input) - if err != nil { - return nil, fmt.Errorf("error doing scan for item counts: %w", err) - } - clientItemCounts := []datastore.ClientItemCounts{} - err = attributevalue.UnmarshalListOfMaps(out.Items, &clientItemCounts) - if err != nil { - return nil, fmt.Errorf("error unmarshalling item counts: %w", err) - } - - return clientItemCounts, nil + return scanItems[datastore.ClientItemCounts]( + dynamo, expression.AttributeExists(expression.Name("ItemCount")), "item counts") } From 8b6e12fa79417e705c25e68a8f0fdfb4105f0f62 Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Fri, 28 Aug 2026 18:16:12 -0500 Subject: [PATCH 04/28] chore(lint): Fix govet shadowing findings (#440) --- auth/auth_test.go | 4 ++-- command/command.go | 28 ++++++++++++------------- command/server_defined_unique_entity.go | 2 +- datastore/sync_entity.go | 28 ++++++++++++------------- datastore/sync_entity_test.go | 4 ++-- middleware/disabled_chain.go | 6 +++--- 6 files changed, 36 insertions(+), 36 deletions(-) diff --git a/auth/auth_test.go b/auth/auth_test.go index 88e80b65..b7f6127b 100644 --- a/auth/auth_test.go +++ b/auth/auth_test.go @@ -112,8 +112,8 @@ func (suite *AuthTestSuite) TestAuthorize() { } for testName, test := range tests { req.Header.Set("Authorization", test.token) - clientID, err := auth.Authorize(req) - suite.Require().Equal(test.err, err, + clientID, authErr := auth.Authorize(req) + suite.Require().Equal(test.err, authErr, "error mismatched for %s test case", testName) suite.Require().Equal(test.clientID, clientID, "clientID mismatched for %s test case", testName) diff --git a/command/command.go b/command/command.go index da5bc228..2a02ed55 100644 --- a/command/command.go +++ b/command/command.go @@ -194,10 +194,10 @@ func handleGetUpdatesRequest( // Fill the PB entry from above DB entries until maxSize is reached. j := 0 for ; j < len(entities) && len(guRsp.Entries) < cap(guRsp.Entries); j++ { - entity, err := datastore.CreatePBSyncEntity(&entities[j]) - if err != nil { + entity, createErr := datastore.CreatePBSyncEntity(&entities[j]) + if createErr != nil { errCode = sync_pb.SyncEnums_TRANSIENT_ERROR - return &errCode, fmt.Errorf("error creating protobuf sync entity from DB entity: %w", err) + return &errCode, fmt.Errorf("error creating protobuf sync entity from DB entity: %w", createErr) } guRsp.Entries = append(guRsp.Entries, entity) } @@ -311,12 +311,12 @@ func handleCommitRequest( entryRsp := &sync_pb.CommitResponse_EntryResponse{} commitRsp.Entryresponse[i] = entryRsp - entityToCommit, err := datastore.CreateDBSyncEntity(v, commitMsg.CacheGuid, clientID) - if err != nil { // Can't unmarshal & marshal the message from PB into DB format + entityToCommit, createErr := datastore.CreateDBSyncEntity(v, commitMsg.CacheGuid, clientID) + if createErr != nil { // Can't unmarshal & marshal the message from PB into DB format rspType := sync_pb.CommitResponse_INVALID_MESSAGE entryRsp.ResponseType = &rspType entryRsp.ErrorMessage = aws.String( - fmt.Sprintf("Cannot convert protobuf sync entity to DB format: %v", err.Error()), + fmt.Sprintf("Cannot convert protobuf sync entity to DB format: %v", createErr.Error()), ) continue } @@ -366,15 +366,15 @@ func handleCommitRequest( // Insert all non-history items. For history items, ignore any items above history quoto // and lie to the client about the objects being synced instead of returning OVER_QUOTA // so the client can continue to sync other entities. - conflict, err := db.InsertSyncEntity(ctx, entityToCommit) - if err != nil { - log.Error().Err(err).Msg("Insert sync entity failed") + conflict, insertErr := db.InsertSyncEntity(ctx, entityToCommit) + if insertErr != nil { + log.Error().Err(insertErr).Msg("Insert sync entity failed") rspType := sync_pb.CommitResponse_TRANSIENT_ERROR if conflict { rspType = sync_pb.CommitResponse_CONFLICT } entryRsp.ResponseType = &rspType - entryRsp.ErrorMessage = aws.String(fmt.Sprintf("Insert sync entity failed: %v", err.Error())) + entryRsp.ErrorMessage = aws.String(fmt.Sprintf("Insert sync entity failed: %v", insertErr.Error())) continue } @@ -391,12 +391,12 @@ func handleCommitRequest( } } } else { // Update - conflict, deleted, err := db.UpdateSyncEntity(ctx, entityToCommit, oldVersion) - if err != nil { - log.Error().Err(err).Msg("Update sync entity failed") + conflict, deleted, updateErr := db.UpdateSyncEntity(ctx, entityToCommit, oldVersion) + if updateErr != nil { + log.Error().Err(updateErr).Msg("Update sync entity failed") rspType := sync_pb.CommitResponse_TRANSIENT_ERROR entryRsp.ResponseType = &rspType - entryRsp.ErrorMessage = aws.String(fmt.Sprintf("Update sync entity failed: %v", err.Error())) + entryRsp.ErrorMessage = aws.String(fmt.Sprintf("Update sync entity failed: %v", updateErr.Error())) continue } if conflict { diff --git a/command/server_defined_unique_entity.go b/command/server_defined_unique_entity.go index 825825a6..ff623529 100644 --- a/command/server_defined_unique_entity.go +++ b/command/server_defined_unique_entity.go @@ -88,7 +88,7 @@ func InsertServerDefinedUniqueEntities(ctx context.Context, db datastore.Datasto syncedBookmarksName: syncedBookmarksTag, bookmarkBarName: bookmarkBarTag} for name, tag := range bookmarkSecondLevelFolders { - entity, err := createServerDefinedUniqueEntity( + entity, err = createServerDefinedUniqueEntity( name, tag, clientID, bookmarkRootID, specifics) if err != nil { return fmt.Errorf("error creating entity with a server tag: %w", err) diff --git a/datastore/sync_entity.go b/datastore/sync_entity.go index 111d7832..5c211888 100644 --- a/datastore/sync_entity.go +++ b/datastore/sync_entity.go @@ -418,14 +418,14 @@ func (dynamo *Dynamo) ClearServerData(ctx context.Context, clientID string) ([]S var totalCount int32 var pageIndex int for paginator.HasMorePages() { - page, err := paginator.NextPage(ctx) - if err != nil { - return syncEntities, fmt.Errorf("error querying sync entities to clear: %w", err) + page, pageErr := paginator.NextPage(ctx) + if pageErr != nil { + return syncEntities, fmt.Errorf("error querying sync entities to clear: %w", pageErr) } var pageEntities []SyncEntity - if err := attributevalue.UnmarshalListOfMaps(page.Items, &pageEntities); err != nil { - return syncEntities, fmt.Errorf("error unmarshalling sync entities to clear: %w", err) + if unmarshalErr := attributevalue.UnmarshalListOfMaps(page.Items, &pageEntities); unmarshalErr != nil { + return syncEntities, fmt.Errorf("error unmarshalling sync entities to clear: %w", unmarshalErr) } syncEntities = append(syncEntities, pageEntities...) totalCount += page.Count @@ -449,9 +449,9 @@ func (dynamo *Dynamo) ClearServerData(ctx context.Context, clientID string) ([]S // Fail delete if race condition detected (modified time has changed). if item.Version != nil && item.Mtime != nil { cond := expression.Name("Mtime").Equal(expression.Value(*item.Mtime)) - condExpr, err := expression.NewBuilder().WithCondition(cond).Build() - if err != nil { - return syncEntities, fmt.Errorf("error deleting sync entities for client %s: %w", clientID, err) + condExpr, buildErr := expression.NewBuilder().WithCondition(cond).Build() + if buildErr != nil { + return syncEntities, fmt.Errorf("error deleting sync entities for client %s: %w", clientID, buildErr) } items = append(items, types.TransactWriteItem{ @@ -484,11 +484,11 @@ func (dynamo *Dynamo) ClearServerData(ctx context.Context, clientID string) ([]S continue } - if _, err := dynamo.TransactWriteItems( + if _, writeErr := dynamo.TransactWriteItems( ctx, &dynamodb.TransactWriteItemsInput{TransactItems: items}, - ); err != nil { - return syncEntities, fmt.Errorf("error deleting sync entities for client %s: %w", clientID, err) + ); writeErr != nil { + return syncEntities, fmt.Errorf("error deleting sync entities for client %s: %w", clientID, writeErr) } } } @@ -735,9 +735,9 @@ func (dynamo *Dynamo) GetUpdatesForType( // Use paginator to automatically handle UnprocessedKeys paginator := dynamodb.NewBatchGetItemPaginator(dynamo.Client, batchInput) for paginator.HasMorePages() { - batchOut, err := paginator.NextPage(ctx) - if err != nil { - return false, syncEntities, fmt.Errorf("error getting update items in a batch: %w", err) + batchOut, batchErr := paginator.NextPage(ctx) + if batchErr != nil { + return false, syncEntities, fmt.Errorf("error getting update items in a batch: %w", batchErr) } outAv = append(outAv, batchOut.Responses[Table]...) } diff --git a/datastore/sync_entity_test.go b/datastore/sync_entity_test.go index 330b3fdd..5cbdc11f 100644 --- a/datastore/sync_entity_test.go +++ b/datastore/sync_entity_test.go @@ -683,8 +683,8 @@ func (suite *SyncEntityTestSuite) TestGetUpdatesForType() { entity.ID = "id" + strconv.Itoa(i) entity.Mtime = aws.Int64(mtime) entity.DataTypeMtime = aws.String("123#" + strconv.FormatInt(*entity.Mtime, 10)) - _, err := suite.dynamo.InsertSyncEntity(context.Background(), &entity) - suite.Require().NoError(err, "InsertSyncEntity should succeed") + _, insertErr := suite.dynamo.InsertSyncEntity(context.Background(), &entity) + suite.Require().NoError(insertErr, "InsertSyncEntity should succeed") expectedSyncItems = append(expectedSyncItems, entity) } diff --git a/middleware/disabled_chain.go b/middleware/disabled_chain.go index 7898613f..763fcdcc 100644 --- a/middleware/disabled_chain.go +++ b/middleware/disabled_chain.go @@ -40,9 +40,9 @@ func DisabledChain(next http.Handler) http.Handler { csRsp := sync_pb.ClientToServerResponse{ ErrorCode: &errCode, } - out, err := proto.Marshal(&csRsp) - if err != nil { - log.Error().Err(err).Msg("Marshall ClientToServerResponse failed") + out, marshalErr := proto.Marshal(&csRsp) + if marshalErr != nil { + log.Error().Err(marshalErr).Msg("Marshall ClientToServerResponse failed") http.Error(w, "Marshal Error", http.StatusInternalServerError) return } From e51290d32228c0f6613a6b13c9881893c13eac6b Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Wed, 9 Sep 2026 22:58:43 -0500 Subject: [PATCH 05/28] chore(lint): fixes (#442) * chore(lint): Fix gocritic captLocal findings * chore(lint): Fix gocritic findings * chore(lint): Fix golines findings * chore(lint): Fix musttag findings * chore(lint): Fix gochecknoinits findings * chore(lint): Fix fatcontext findings * chore(lint): Ignore unparam on expectedChangesRemaining * chore(lint): Fix nonamedreturns findings * chore(lint): Fix revive findings * chore(lint): Compare PBSyncAttrs with go-cmp * chore(lint): Compare PBSyncEntity with go-cmp * refactor(server): Use LoadHighDeviceLimitClientIDsFromEnv helper --- command/command_test.go | 23 +++++----- command/device_limit.go | 9 ++-- datastore/datastore.go | 2 +- datastore/datastoretest/mock_datastore.go | 6 +-- datastore/instrumented_datastore.go | 4 +- datastore/sync_entity.go | 21 +++++---- datastore/sync_entity_test.go | 12 ++--- go.mod | 2 +- go.sum | 53 +---------------------- server/server.go | 3 ++ server/server_test.go | 2 +- 11 files changed, 44 insertions(+), 93 deletions(-) diff --git a/command/command_test.go b/command/command_test.go index 28d38610..39442cef 100644 --- a/command/command_test.go +++ b/command/command_test.go @@ -3,7 +3,6 @@ package command_test import ( "context" "encoding/binary" - "encoding/json" "fmt" "sort" "strconv" @@ -11,7 +10,9 @@ import ( "testing" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/suite" + "google.golang.org/protobuf/testing/protocmp" "github.com/brave/go-sync/cache" "github.com/brave/go-sync/command" @@ -194,8 +195,8 @@ func assertCommonResponse(suite *CommandTestSuite, rsp *sync_pb.ClientToServerRe func assertGetUpdatesResponse(suite *CommandTestSuite, rsp *sync_pb.GetUpdatesResponse, newMarker *[]*sync_pb.DataTypeProgressMarker, expectedPBSyncAttrs []*PBSyncAttrs, - expectedChangesRemaining int64) { //nolint:unparam - PBSyncAttrs := []*PBSyncAttrs{} + expectedChangesRemaining int64) { //nolint:unparam // kept for tests that expect a non-zero remaining count + pbSyncAttrs := []*PBSyncAttrs{} for _, entity := range rsp.Entries { // Update tokens in the expected NewProgressMarker var tokenPtr *[]byte @@ -210,20 +211,15 @@ func assertGetUpdatesResponse(suite *CommandTestSuite, rsp *sync_pb.GetUpdatesRe binary.PutVarint(*tokenPtr, *entity.Mtime) } - PBSyncAttrs = append(PBSyncAttrs, + pbSyncAttrs = append(pbSyncAttrs, NewPBSyncAttrs(entity.Name, entity.Version, entity.Deleted, entity.Folder, entity.ServerDefinedUniqueTag, entity.Specifics)) } sort.Sort(PBSyncAttrsByName(expectedPBSyncAttrs)) - sort.Sort(PBSyncAttrsByName(PBSyncAttrs)) + sort.Sort(PBSyncAttrsByName(pbSyncAttrs)) - // Marshal to json to ignore protobuf internal fields when checking equality. - s1, err := json.Marshal(expectedPBSyncAttrs) - suite.Require().NoError(err, "json.Marshal should succeed") - s2, err := json.Marshal(PBSyncAttrs) - suite.Require().NoError(err, "json.Marshal should succeed") - suite.Equal(s1, s2) + suite.Empty(cmp.Diff(expectedPBSyncAttrs, pbSyncAttrs, protocmp.Transform())) suite.Equal(*newMarker, rsp.NewProgressMarker) suite.Equal(expectedChangesRemaining, *rsp.ChangesRemaining) @@ -664,7 +660,8 @@ func assertTypeMtimeCacheValue(suite *CommandTestSuite, key string, mtime int64, } func insertSyncEntitiesWithoutUpdateCache( - suite *CommandTestSuite, entries []*sync_pb.SyncEntity, clientID string) (ret []*datastore.SyncEntity) { + suite *CommandTestSuite, entries []*sync_pb.SyncEntity, clientID string) []*datastore.SyncEntity { + var ret []*datastore.SyncEntity for _, entry := range entries { dbEntry, err := datastore.CreateDBSyncEntity(entry, nil, clientID) suite.Require().NoError(err, "Create db entity from pb entity should succeed") @@ -677,7 +674,7 @@ func insertSyncEntitiesWithoutUpdateCache( "Cache should not be updated") ret = append(ret, dbEntry) } - return + return ret } func (suite *CommandTestSuite) TestHandleClientToServerMessage_TypeMtimeCache_Basic() { diff --git a/command/device_limit.go b/command/device_limit.go index 1d517fb1..6746ad02 100644 --- a/command/device_limit.go +++ b/command/device_limit.go @@ -8,15 +8,16 @@ import ( const ( maxActiveDevices int = 50 highMaxActiveDevices int = 100 + + highDeviceLimitClientIDsEnv = "HIGH_DEVICE_LIMIT_CLIENT_IDS" ) var ( - highDeviceLimitClientIDs map[string]bool + highDeviceLimitClientIDs = make(map[string]bool) ) -func init() { - clientIDsEnv := os.Getenv("HIGH_DEVICE_LIMIT_CLIENT_IDS") - LoadHighDeviceLimitClientIDs(clientIDsEnv) +func LoadHighDeviceLimitClientIDsFromEnv() { + LoadHighDeviceLimitClientIDs(os.Getenv(highDeviceLimitClientIDsEnv)) } func LoadHighDeviceLimitClientIDs(clientIDList string) { diff --git a/datastore/datastore.go b/datastore/datastore.go index 6ff64648..690cb408 100644 --- a/datastore/datastore.go +++ b/datastore/datastore.go @@ -40,5 +40,5 @@ type Datastore interface { // IsSyncChainDisabled checks whether a given sync chain is deleted IsSyncChainDisabled(ctx context.Context, clientID string) (bool, error) // Checks if sync item exists for a client - HasItem(ctx context.Context, clientID string, ID string) (bool, error) + HasItem(ctx context.Context, clientID string, id string) (bool, error) } diff --git a/datastore/datastoretest/mock_datastore.go b/datastore/datastoretest/mock_datastore.go index 78dadd1f..726acacc 100644 --- a/datastore/datastoretest/mock_datastore.go +++ b/datastore/datastoretest/mock_datastore.go @@ -30,7 +30,7 @@ func (m *MockDatastore) UpdateSyncEntity( ctx context.Context, entity *datastore.SyncEntity, oldVersion int64, -) (conflict bool, deleted bool, err error) { +) (bool, bool, error) { args := m.Called(ctx, entity, oldVersion) return args.Bool(0), args.Bool(1), args.Error(2) } @@ -54,8 +54,8 @@ func (m *MockDatastore) HasServerDefinedUniqueTag(ctx context.Context, clientID return args.Bool(0), args.Error(1) } -func (m *MockDatastore) HasItem(ctx context.Context, clientID string, ID string) (bool, error) { - args := m.Called(ctx, clientID, ID) +func (m *MockDatastore) HasItem(ctx context.Context, clientID string, id string) (bool, error) { + args := m.Called(ctx, clientID, id) return args.Bool(0), args.Error(1) } diff --git a/datastore/instrumented_datastore.go b/datastore/instrumented_datastore.go index c3833ed1..bad5aabe 100644 --- a/datastore/instrumented_datastore.go +++ b/datastore/instrumented_datastore.go @@ -95,7 +95,7 @@ func (_d DatastoreWithPrometheus) GetUpdatesForType(ctx context.Context, dataTyp } // HasItem implements Datastore -func (_d DatastoreWithPrometheus) HasItem(ctx context.Context, clientID string, ID string) (b1 bool, err error) { +func (_d DatastoreWithPrometheus) HasItem(ctx context.Context, clientID string, id string) (b1 bool, err error) { _since := time.Now() defer func() { result := "ok" @@ -105,7 +105,7 @@ func (_d DatastoreWithPrometheus) HasItem(ctx context.Context, clientID string, datastoreDurationSummaryVec.WithLabelValues(_d.instanceName, "HasItem", result).Observe(time.Since(_since).Seconds()) }() - return _d.base.HasItem(ctx, clientID, ID) + return _d.base.HasItem(ctx, clientID, id) } // HasServerDefinedUniqueTag implements Datastore diff --git a/datastore/sync_entity.go b/datastore/sync_entity.go index 5c211888..70ce5c89 100644 --- a/datastore/sync_entity.go +++ b/datastore/sync_entity.go @@ -32,8 +32,8 @@ const ( reasonDeleted = "deleted" HistoryTypeID int = 963985 HistoryDeleteDirectiveTypeID int = 150251 - // Expiration time for history and history delete directive - // entities in seconds + // HistoryExpirationIntervalSecs is the expiration time for history and + // history delete directive entities in seconds. HistoryExpirationIntervalSecs = 14 * 24 * 60 * 60 // 14 days ) @@ -276,8 +276,8 @@ func (dynamo *Dynamo) HasServerDefinedUniqueTag(ctx context.Context, clientID st return out.Item != nil, nil } -func (dynamo *Dynamo) HasItem(ctx context.Context, clientID string, ID string) (bool, error) { - primaryKey := PrimaryKey{ClientID: clientID, ID: ID} +func (dynamo *Dynamo) HasItem(ctx context.Context, clientID string, id string) (bool, error) { + primaryKey := PrimaryKey{ClientID: clientID, ID: id} key, err := attributevalue.MarshalMap(primaryKey) if err != nil { @@ -451,7 +451,11 @@ func (dynamo *Dynamo) ClearServerData(ctx context.Context, clientID string) ([]S cond := expression.Name("Mtime").Equal(expression.Value(*item.Mtime)) condExpr, buildErr := expression.NewBuilder().WithCondition(cond).Build() if buildErr != nil { - return syncEntities, fmt.Errorf("error deleting sync entities for client %s: %w", clientID, buildErr) + return syncEntities, fmt.Errorf( + "error deleting sync entities for client %s: %w", + clientID, + buildErr, + ) } items = append(items, types.TransactWriteItem{ @@ -602,11 +606,12 @@ func (dynamo *Dynamo) UpdateSyncEntity(ctx context.Context, entity *SyncEntity, return false, false, fmt.Errorf("error unmarshalling old sync entity: %w", err) } var deleted bool - if entity.Deleted == nil { // No updates on Deleted this time. + switch { + case entity.Deleted == nil: // No updates on Deleted this time. deleted = false - } else if oldEntity.Deleted == nil { // Consider it as Deleted = false. + case oldEntity.Deleted == nil: // Consider it as Deleted = false. deleted = *entity.Deleted - } else { + default: deleted = !*oldEntity.Deleted && *entity.Deleted } return false, deleted, nil diff --git a/datastore/sync_entity_test.go b/datastore/sync_entity_test.go index 5cbdc11f..2420d01b 100644 --- a/datastore/sync_entity_test.go +++ b/datastore/sync_entity_test.go @@ -3,7 +3,6 @@ package datastore_test import ( "bytes" "context" - "encoding/json" "fmt" "sort" "strconv" @@ -11,8 +10,10 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/suite" "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/testing/protocmp" "github.com/brave/go-sync/datastore" "github.com/brave/go-sync/datastore/datastoretest" @@ -678,7 +679,7 @@ func (suite *SyncEntityTestSuite) TestGetUpdatesForType() { mtime := time.Now().UnixMilli() for i := 1; i <= 250; i++ { - mtime = mtime + 1 + mtime++ entity := entity1 entity.ID = "id" + strconv.Itoa(i) entity.Mtime = aws.Int64(mtime) @@ -899,12 +900,7 @@ func (suite *SyncEntityTestSuite) TestCreatePBSyncEntity() { pbEntity, err := datastore.CreatePBSyncEntity(&dbEntity) suite.Require().NoError(err, "CreatePBSyncEntity should succeed") - // Marshal to json to ignore protobuf internal fields when checking equality. - s1, err := json.Marshal(pbEntity) - suite.Require().NoError(err, "json.Marshal should succeed") - s2, err := json.Marshal(&expectedPBEntity) - suite.Require().NoError(err, "json.Marshal should succeed") - suite.Equal(s1, s2) + suite.Empty(cmp.Diff(&expectedPBEntity, pbEntity, protocmp.Transform())) // Nil UniquePosition should be unmarshalled as nil without error. dbEntity.UniquePosition = nil diff --git a/go.mod b/go.mod index 56c8fffc..3279d165 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/brave-intl/bat-go/libs v0.0.0-20250620104757-9e2f8ff87fd8 github.com/getsentry/sentry-go v0.39.0 github.com/go-chi/chi/v5 v5.2.5 + github.com/google/go-cmp v0.7.0 github.com/google/uuid v1.6.0 github.com/prometheus/client_golang v1.23.2 github.com/redis/go-redis/v9 v9.17.0 @@ -42,7 +43,6 @@ require ( github.com/go-chi/chi v4.1.2+incompatible // indirect github.com/gomodule/redigo v2.0.0+incompatible // indirect github.com/hashicorp/golang-lru v1.0.2 // indirect - github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/kr/text v0.2.0 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect diff --git a/go.sum b/go.sum index 5aa05bcf..e6106b2f 100644 --- a/go.sum +++ b/go.sum @@ -4,78 +4,42 @@ github.com/alicebob/miniredis/v2 v2.23.0 h1:+lwAJYjvvdIVg6doFHuotFjueJ/7KY10xo/v github.com/alicebob/miniredis/v2 v2.23.0/go.mod h1:XNqvJdQJv5mSuVMc0ynneafpnL/zv52acZ6kqeS0t88= github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so= github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= -github.com/aws/aws-sdk-go-v2 v1.32.7 h1:ky5o35oENWi0JYWUZkB7WYvVPP+bcRF5/Iq7JWSb5Rw= -github.com/aws/aws-sdk-go-v2 v1.32.7/go.mod h1:P5WJBrYqqbWVaOxgH0X/FYYD47/nooaPOZPlQdmiN2U= github.com/aws/aws-sdk-go-v2 v1.41.5 h1:dj5kopbwUsVUVFgO4Fi5BIT3t4WyqIDjGKCangnV/yY= github.com/aws/aws-sdk-go-v2 v1.41.5/go.mod h1:mwsPRE8ceUUpiTgF7QmQIJ7lgsKUPQOUl3o72QBrE1o= -github.com/aws/aws-sdk-go-v2/config v1.28.6 h1:D89IKtGrs/I3QXOLNTH93NJYtDhm8SYa9Q5CsPShmyo= -github.com/aws/aws-sdk-go-v2/config v1.28.6/go.mod h1:GDzxJ5wyyFSCoLkS+UhGB0dArhb9mI+Co4dHtoTxbko= github.com/aws/aws-sdk-go-v2/config v1.32.14 h1:opVIRo/ZbbI8OIqSOKmpFaY7IwfFUOCCXBsUpJOwDdI= github.com/aws/aws-sdk-go-v2/config v1.32.14/go.mod h1:U4/V0uKxh0Tl5sxmCBZ3AecYny4UNlVmObYjKuuaiOo= -github.com/aws/aws-sdk-go-v2/credentials v1.17.47 h1:48bA+3/fCdi2yAwVt+3COvmatZ6jUDNkDTIsqDiMUdw= -github.com/aws/aws-sdk-go-v2/credentials v1.17.47/go.mod h1:+KdckOejLW3Ks3b0E3b5rHsr2f9yuORBum0WPnE5o5w= github.com/aws/aws-sdk-go-v2/credentials v1.19.14 h1:n+UcGWAIZHkXzYt87uMFBv/l8THYELoX6gVcUvgl6fI= github.com/aws/aws-sdk-go-v2/credentials v1.19.14/go.mod h1:cJKuyWB59Mqi0jM3nFYQRmnHVQIcgoxjEMAbLkpr62w= -github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.15.24 h1:oB+JFeqQrLSkMqVVWf3zQq5uUPpO84sQbwqoQ2AXYX0= -github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.15.24/go.mod h1:b2gkt7DFR5t8nhDoG7XfLM8RER+kKTxRxkeeXVhps30= github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.20.37 h1:5jh3kI8vDKuAcNa87z3eytYvBCE4Tyk2S8vjdcLoMek= github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.20.37/go.mod h1:Q1MNQdT5LEs31od7h6zHZF2a6jjl+oI6/kBH3QYipoY= -github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression v1.7.59 h1:9tiJl90a05ktuXPrtFFQzUpbCdz5cX4StHPjlfhMH7M= -github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression v1.7.59/go.mod h1:SO7V5LvuKWqc5ylPyrAla40HzxGrHHwiCZD2tO3kUbw= github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression v1.8.37 h1:8clVLUTp0bBO7SZx5Nw0Q1XhF4ItE8W1hboDK9eHIN0= github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression v1.8.37/go.mod h1:U0KNwNOuLUPi/vdIWh6qYVBK4v8zKjN6BPpbsHSmPPA= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.21 h1:AmoU1pziydclFT/xRV+xXE/Vb8fttJCLRPv8oAkprc0= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.21/go.mod h1:AjUdLYe4Tgs6kpH4Bv7uMZo7pottoyHMn4eTcIcneaY= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.21 h1:NUS3K4BTDArQqNu2ih7yeDLaS3bmHD0YndtA6UP884g= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.21/go.mod h1:YWNWJQNjKigKY1RHVJCuupeWDrrHjRqHm0N9rdrWzYI= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.26 h1:I/5wmGMffY4happ8NOCuIUEWGUvvFp5NSeQcXl9RHcI= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.26/go.mod h1:FR8f4turZtNy6baO0KJ5FJUmXH/cSkI9fOngs0yl6mA= github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.21 h1:Rgg6wvjjtX8bNHcvi9OnXWwcE0a2vGpbwmtICOsvcf4= github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.21/go.mod h1:A/kJFst/nm//cyqonihbdpQZwiUhhzpqTsdbhDdRF9c= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.26 h1:zXFLuEuMMUOvEARXFUVJdfqZ4bvvSgdGRq/ATcrQxzM= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.26/go.mod h1:3o2Wpy0bogG1kyOPrgkXA8pgIfEEv0+m19O9D5+W8y8= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.21 h1:PEgGVtPoB6NTpPrBgqSE5hE/o47Ij9qk/SEZFbUOe9A= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.21/go.mod h1:p+hz+PRAYlY3zcpJhPwXlLC4C+kqn70WIHwnzAfs6ps= -github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 h1:VaRN3TlFdd6KxX1x3ILT5ynH6HvKgqdiXoTxAF4HQcQ= -github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1/go.mod h1:FbtygfRFze9usAadmnGJNc8KsP346kEe+y2/oyhGAGc= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.6 h1:qYQ4pzQ2Oz6WpQ8T3HvGHnZydA72MnLuFK9tJwmrbHw= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.6/go.mod h1:O3h0IK87yXci+kg6flUKzJnWeziQUKciKrLjcatSNcY= -github.com/aws/aws-sdk-go-v2/service/dynamodb v1.39.1 h1:SOJ3xkgrw8W0VQgyBUeep74yuf8kWALToFxNNwlHFvg= -github.com/aws/aws-sdk-go-v2/service/dynamodb v1.39.1/go.mod h1:J8xqRbx7HIc8ids2P8JbrKx9irONPEYq7Z1FpLDpi3I= github.com/aws/aws-sdk-go-v2/service/dynamodb v1.57.1 h1:Vk+a1j2pXZHkkYqHmEdpwe8eX6NDtFSBGfzuauMEWYQ= github.com/aws/aws-sdk-go-v2/service/dynamodb v1.57.1/go.mod h1:wHrWCwhXZrl2PuCP5t36UTacy9fCHDJ+vw1r3qxTL5M= -github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.24.11 h1:lBa70oU+Vmfjpl6cqjF1ZIJ0hiWkB7uQe5pGozE4yYg= -github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.24.11/go.mod h1:HywkMgYwY0uaybPvvctx6fkm3L1ssRKeGv7TPZ6OQ/M= github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.32.14 h1:Cnlebj/RmCf/4O3q4suVLLB/SBhbQf4zCQre6Dav+4E= github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.32.14/go.mod h1:lB9U9zBLviMTUHcHaaJ/vDBkRpHxV5775VJcdnm1DFk= -github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1 h1:iXtILhvDxB6kPvEXgsDhGaZCSC6LQET5ZHSdJozeI0Y= -github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1/go.mod h1:9nu0fVANtYiAePIBh2/pFUSwtJ402hLnp854CNoDOeE= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.7 h1:5EniKhLZe4xzL7a+fU3C2tfUN4nWIqlLesfrjkuPFTY= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.7/go.mod h1:x0nZssQ3qZSnIcePWLvcoFisRXJzcTVvYpAAdYX8+GI= -github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.10.7 h1:EqGlayejoCRXmnVC6lXl6phCm9R2+k35e0gWsO9G5DI= -github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.10.7/go.mod h1:BTw+t+/E5F3ZnDai/wSOYM54WUVjSdewE7Jvwtb7o+w= github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.11.21 h1:FTg+rVAPx1W21jsO57pxDS1ESy9a/JLFoaHeFubflJA= github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.11.21/go.mod h1:92xP4VIS1yO3eF2NPBaHGF4cmyZow8TmFzSaz1nNgzo= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.6 h1:50+XsN70RS7dwJ2CkVNXzj7U2L1HKP8nqTd3XWEXBN4= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.6/go.mod h1:WqgLmwY7so32kG01zD8CPTJWVWM+TzJoOVHwTg4aPug= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.21 h1:c31//R3xgIJMSC8S6hEVq+38DcvUlgFY0FM6mSI5oto= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.21/go.mod h1:r6+pf23ouCB718FUxaqzZdbpYFyDtehyZcmP5KL9FkA= github.com/aws/aws-sdk-go-v2/service/signin v1.0.9 h1:QKZH0S178gCmFEgst8hN0mCX1KxLgHBKKY/CLqwP8lg= github.com/aws/aws-sdk-go-v2/service/signin v1.0.9/go.mod h1:7yuQJoT+OoH8aqIxw9vwF+8KpvLZ8AWmvmUWHsGQZvI= -github.com/aws/aws-sdk-go-v2/service/sso v1.24.7 h1:rLnYAfXQ3YAccocshIH5mzNNwZBkBo+bP6EhIxak6Hw= -github.com/aws/aws-sdk-go-v2/service/sso v1.24.7/go.mod h1:ZHtuQJ6t9A/+YDuxOLnbryAmITtr8UysSny3qcyvJTc= github.com/aws/aws-sdk-go-v2/service/sso v1.30.15 h1:lFd1+ZSEYJZYvv9d6kXzhkZu07si3f+GQ1AaYwa2LUM= github.com/aws/aws-sdk-go-v2/service/sso v1.30.15/go.mod h1:WSvS1NLr7JaPunCXqpJnWk1Bjo7IxzZXrZi1QQCkuqM= -github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.6 h1:JnhTZR3PiYDNKlXy50/pNeix9aGMo6lLpXwJ1mw8MD4= -github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.6/go.mod h1:URronUEGfXZN1VpdktPSD1EkAL9mfrV+2F4sjH38qOY= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.19 h1:dzztQ1YmfPrxdrOiuZRMF6fuOwWlWpD2StNLTceKpys= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.19/go.mod h1:YO8TrYtFdl5w/4vmjL8zaBSsiNp3w0L1FfKVKenZT7w= -github.com/aws/aws-sdk-go-v2/service/sts v1.33.2 h1:s4074ZO1Hk8qv65GqNXqDjmkf4HSQqJukaLuuW0TpDA= -github.com/aws/aws-sdk-go-v2/service/sts v1.33.2/go.mod h1:mVggCnIWoM09jP71Wh+ea7+5gAp53q+49wDFs1SW5z8= github.com/aws/aws-sdk-go-v2/service/sts v1.41.10 h1:p8ogvvLugcR/zLBXTXrTkj0RYBUdErbMnAFFp12Lm/U= github.com/aws/aws-sdk-go-v2/service/sts v1.41.10/go.mod h1:60dv0eZJfeVXfbT1tFJinbHrDfSJ2GZl4Q//OSSNAVw= -github.com/aws/smithy-go v1.22.1 h1:/HPHZQ0g7f4eUeK6HKglFz8uwVfZKgoI25rb/J+dnro= -github.com/aws/smithy-go v1.22.1/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= github.com/aws/smithy-go v1.24.2 h1:FzA3bu/nt/vDvmnkg+R8Xl46gmzEDam6mZ1hzmwXFng= github.com/aws/smithy-go v1.24.2/go.mod h1:YE2RhdIuDbA5E5bTdciG9KrW3+TiEONeUWCqxX9i1Fc= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -105,8 +69,6 @@ github.com/getsentry/sentry-go v0.39.0 h1:uhnexj8PNCyCve37GSqxXOeXHh4cJNLNNB4w70 github.com/getsentry/sentry-go v0.39.0/go.mod h1:eRXCoh3uvmjQLY6qu63BjUZnaBu5L5WhMV1RwYO8W5s= github.com/go-chi/chi v4.1.2+incompatible h1:fGFk2Gmi/YKXk0OmGfBh0WgmN3XB8lVnEyNz34tQRec= github.com/go-chi/chi v4.1.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= -github.com/go-chi/chi/v5 v5.2.3 h1:WQIt9uxdsAbgIYgid+BpYc+liqQZGMHRaUwp0JUcvdE= -github.com/go-chi/chi/v5 v5.2.3/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops= github.com/go-chi/chi/v5 v5.2.5 h1:Eg4myHZBjyvJmAFjFvWgrqDTXFyOzjj7YIm3L3mu6Ug= github.com/go-chi/chi/v5 v5.2.5/go.mod h1:X7Gx4mteadT3eDOMTsXzmI4/rwUpOwBHLpAfupzFJP0= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= @@ -138,10 +100,6 @@ github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uG github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c= github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= -github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= -github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= -github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -218,8 +176,6 @@ go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q= -golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4= golang.org/x/crypto v0.54.0 h1:YLIA59K4fiNzHzjnZt2tUJQjQtUWfWbeHBqKtk3eScw= golang.org/x/crypto v0.54.0/go.mod h1:KWL8ny2AZdGR2cWmzeHrp2azQPGogOv+HeQaVEXC2dk= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= @@ -230,9 +186,8 @@ golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/ golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY= -golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU= golang.org/x/net v0.56.0 h1:Rw8j/hFzGvJUZwNBXnAtf5sVDVt+65SK2C7IxCxZt5o= +golang.org/x/net v0.56.0/go.mod h1:D3Ku6r+V6JROoZK144D2XfMHFcMq/0zSfLelVTCFKec= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -252,8 +207,6 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc= -golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs= golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -263,8 +216,6 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= -golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM= -golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM= golang.org/x/text v0.40.0 h1:Ub2Z6/xjgF1WrYQz2nuITOEegKFtiIy+rieRJ5lHZKs= golang.org/x/text v0.40.0/go.mod h1:hpnzDAfGV753zIKo+wk3u1bVKCGPbrnF7+7LBF/UHVY= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -287,8 +238,6 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/server/server.go b/server/server.go index 8db5a2ae..06a40353 100644 --- a/server/server.go +++ b/server/server.go @@ -24,6 +24,7 @@ import ( "github.com/rs/zerolog/log" "github.com/brave/go-sync/cache" + "github.com/brave/go-sync/command" "github.com/brave/go-sync/controller" "github.com/brave/go-sync/datastore" "github.com/brave/go-sync/middleware" @@ -46,6 +47,8 @@ func setupLogger(ctx context.Context) (context.Context, *zerolog.Logger) { } func setupRouter(ctx context.Context, logger *zerolog.Logger) (context.Context, *chi.Mux) { + command.LoadHighDeviceLimitClientIDsFromEnv() + r := chi.NewRouter() r.Use(chiware.RequestID) diff --git a/server/server_test.go b/server/server_test.go index e9af1204..f6fd7ca4 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -21,7 +21,7 @@ var ( func TestMain(m *testing.M) { testCtx, logger := server.SetupLogger(context.Background()) - serverCtx, mux = server.SetupRouter(testCtx, logger) + serverCtx, mux = server.SetupRouter(testCtx, logger) //nolint:fatcontext // TestMain assigns shared context once m.Run() } From 71f27af460f4524a1d4dac4c35d8e7ef2a072c50 Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Thu, 15 Oct 2026 22:56:33 -0500 Subject: [PATCH 06/28] chore(lint): Fix nestif findings (#443) * chore(lint): Fix command.go nestif findings * chore(lint): Fix datastore/item_count.go nestif findings * refactor: Rename bumpInterimCount * refactor: Rename insertErr/updateErr --- cache/cache.go | 4 +- command/command.go | 208 ++++++++++++++++++++++++++-------------- datastore/item_count.go | 154 ++++++++++++++++------------- 3 files changed, 222 insertions(+), 144 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index 9d16fc45..105c57cc 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -52,9 +52,9 @@ func (c *Cache) GetInterimCount(ctx context.Context, clientID string, countType return count, nil } -// IncrementInterimCount increments or decrements the amount of entities inserted in +// AdjustInterimCount increments or decrements the amount of entities inserted in // the DB that were not yet added to the item count -func (c *Cache) IncrementInterimCount( +func (c *Cache) AdjustInterimCount( ctx context.Context, clientID string, countType string, diff --git a/command/command.go b/command/command.go index 2a02ed55..77faf344 100644 --- a/command/command.go +++ b/command/command.go @@ -257,6 +257,117 @@ func getInterimItemCounts(ctx context.Context, cache *cache.Cache, clientID stri return newNormalCount, newHistoryCount, nil } +type commitCountState struct { + currentNormal int + currentHistory int + newNormal int + newHistory int + boostedQuota int +} + +func adjustInterimCount( + ctx context.Context, + cache *cache.Cache, + clientID string, + isHistoryRelatedItem bool, + subtract bool, + counts *commitCountState, +) error { + countType := normalCountTypeStr + if isHistoryRelatedItem { + countType = historyCountTypeStr + } + newCount, err := cache.AdjustInterimCount(ctx, clientID, countType, subtract) + if isHistoryRelatedItem { + counts.newHistory = newCount + } else { + counts.newNormal = newCount + } + return err +} + +func insertCommitEntity( + ctx context.Context, + db datastore.Datastore, + cache *cache.Cache, + clientID string, + entity *datastore.SyncEntity, + entryRsp *sync_pb.CommitResponse_EntryResponse, + idMap map[string]string, + counts *commitCountState, + isHistoryRelatedItem bool, +) (bool, error) { + total := counts.currentNormal + counts.currentHistory + counts.newNormal + counts.newHistory + if total >= maxClientObjectQuota+counts.boostedQuota { + rspType := sync_pb.CommitResponse_OVER_QUOTA + entryRsp.ResponseType = &rspType + entryRsp.ErrorMessage = aws.String( + fmt.Sprintf( + "There are already %v non-deleted objects in store", + counts.currentNormal+counts.currentHistory, + ), + ) + return true, nil + } + + // Insert all non-history items. For history items, ignore any items above history quota + // and lie to the client about the objects being synced instead of returning OVER_QUOTA + // so the client can continue to sync other entities. + if isHistoryRelatedItem && counts.currentHistory+counts.newHistory >= maxClientHistoryObjectQuota { + return false, nil + } + + conflict, err := db.InsertSyncEntity(ctx, entity) + if err != nil { + log.Error().Err(err).Msg("Insert sync entity failed") + rspType := sync_pb.CommitResponse_TRANSIENT_ERROR + if conflict { + rspType = sync_pb.CommitResponse_CONFLICT + } + entryRsp.ResponseType = &rspType + entryRsp.ErrorMessage = aws.String(fmt.Sprintf("Insert sync entity failed: %v", err.Error())) + return true, nil + } + + // Save client-generated to server-generated ID mapping when committing + // a new entry with OriginatorClientItemID (client-generated ID). + if entity.OriginatorClientItemID != nil { + idMap[*entity.OriginatorClientItemID] = entity.ID + } + + return false, adjustInterimCount(ctx, cache, clientID, isHistoryRelatedItem, false, counts) +} + +func updateCommitEntity( + ctx context.Context, + db datastore.Datastore, + cache *cache.Cache, + clientID string, + entity *datastore.SyncEntity, + oldVersion int64, + entryRsp *sync_pb.CommitResponse_EntryResponse, + counts *commitCountState, + isHistoryRelatedItem bool, +) (bool, error) { + conflict, deleted, err := db.UpdateSyncEntity(ctx, entity, oldVersion) + if err != nil { + log.Error().Err(err).Msg("Update sync entity failed") + rspType := sync_pb.CommitResponse_TRANSIENT_ERROR + entryRsp.ResponseType = &rspType + entryRsp.ErrorMessage = aws.String(fmt.Sprintf("Update sync entity failed: %v", err.Error())) + return true, nil + } + if conflict { + rspType := sync_pb.CommitResponse_CONFLICT + entryRsp.ResponseType = &rspType + return true, nil + } + if deleted { + return false, adjustInterimCount(ctx, cache, clientID, isHistoryRelatedItem, true, counts) + } + return false, nil +} + // handleCommitRequest handles the commit message and fills the commit response. // For each commit entry: // - new sync entity is created and inserted into the database if version is 0. @@ -284,19 +395,21 @@ func handleCommitRequest( errCode = sync_pb.SyncEnums_TRANSIENT_ERROR return &errCode, fmt.Errorf("error getting client's item count: %w", err) } - currentNormalItemCount := itemCounts.ItemCount - currentHistoryItemCount := itemCounts.SumHistoryCounts() - - boostedQuotaAddition := 0 - if currentHistoryItemCount > maxClientHistoryObjectQuota { + counts := commitCountState{ + currentNormal: itemCounts.ItemCount, + currentHistory: itemCounts.SumHistoryCounts(), + newNormal: newNormalCount, + newHistory: newHistoryCount, + } + if counts.currentHistory > maxClientHistoryObjectQuota { // Sync chains with history entities stored before the history count fix // may have history counts greater than the new history item quota. // "Boost" the quota with the difference between the history quota and count, // so users can start syncing other entities immediately, instead of waiting for the // history TTL to get rid of the excess items. - boostedQuotaAddition = min( + counts.boostedQuota = min( maxClientObjectQuota-maxClientHistoryObjectQuota, - currentHistoryItemCount-maxClientHistoryObjectQuota, + counts.currentHistory-maxClientHistoryObjectQuota, ) } @@ -348,74 +461,23 @@ func handleCommitRequest( } } - var interimErr error - if !isUpdateOp { // Create - if currentNormalItemCount+currentHistoryItemCount+newNormalCount+newHistoryCount >= maxClientObjectQuota+boostedQuotaAddition { - rspType := sync_pb.CommitResponse_OVER_QUOTA - entryRsp.ResponseType = &rspType - entryRsp.ErrorMessage = aws.String( - fmt.Sprintf( - "There are already %v non-deleted objects in store", - currentNormalItemCount+currentHistoryItemCount, - ), - ) - continue - } - - if !isHistoryRelatedItem || currentHistoryItemCount+newHistoryCount < maxClientHistoryObjectQuota { - // Insert all non-history items. For history items, ignore any items above history quoto - // and lie to the client about the objects being synced instead of returning OVER_QUOTA - // so the client can continue to sync other entities. - conflict, insertErr := db.InsertSyncEntity(ctx, entityToCommit) - if insertErr != nil { - log.Error().Err(insertErr).Msg("Insert sync entity failed") - rspType := sync_pb.CommitResponse_TRANSIENT_ERROR - if conflict { - rspType = sync_pb.CommitResponse_CONFLICT - } - entryRsp.ResponseType = &rspType - entryRsp.ErrorMessage = aws.String(fmt.Sprintf("Insert sync entity failed: %v", insertErr.Error())) - continue - } - - // Save client-generated to server-generated ID mapping when committing - // a new entry with OriginatorClientItemID (client-generated ID). - if entityToCommit.OriginatorClientItemID != nil { - idMap[*entityToCommit.OriginatorClientItemID] = entityToCommit.ID - } - - if isHistoryRelatedItem { - newHistoryCount, interimErr = cache.IncrementInterimCount(ctx, clientID, historyCountTypeStr, false) - } else { - newNormalCount, interimErr = cache.IncrementInterimCount(ctx, clientID, normalCountTypeStr, false) - } - } - } else { // Update - conflict, deleted, updateErr := db.UpdateSyncEntity(ctx, entityToCommit, oldVersion) - if updateErr != nil { - log.Error().Err(updateErr).Msg("Update sync entity failed") - rspType := sync_pb.CommitResponse_TRANSIENT_ERROR - entryRsp.ResponseType = &rspType - entryRsp.ErrorMessage = aws.String(fmt.Sprintf("Update sync entity failed: %v", updateErr.Error())) - continue - } - if conflict { - rspType := sync_pb.CommitResponse_CONFLICT - entryRsp.ResponseType = &rspType - continue - } - if deleted { - if isHistoryRelatedItem { - newHistoryCount, interimErr = cache.IncrementInterimCount(ctx, clientID, historyCountTypeStr, true) - } else { - newNormalCount, interimErr = cache.IncrementInterimCount(ctx, clientID, normalCountTypeStr, true) - } - } + var skipEntry bool + if isUpdateOp { + skipEntry, err = updateCommitEntity( + ctx, db, cache, clientID, entityToCommit, oldVersion, entryRsp, &counts, isHistoryRelatedItem, + ) + } else { + skipEntry, err = insertCommitEntity( + ctx, db, cache, clientID, entityToCommit, entryRsp, idMap, &counts, isHistoryRelatedItem, + ) } - if interimErr != nil { - log.Error().Err(interimErr).Msg("Interim count update failed") + if err != nil { + log.Error().Err(err).Msg("Interim count update failed") errCode = sync_pb.SyncEnums_TRANSIENT_ERROR - return &errCode, fmt.Errorf("interim count update failed: %w", interimErr) + return &errCode, fmt.Errorf("interim count update failed: %w", err) + } + if skipEntry { + continue } typeMtimeMap[*entityToCommit.DataType] = *entityToCommit.Mtime diff --git a/datastore/item_count.go b/datastore/item_count.go index 40c18f72..3000faf5 100644 --- a/datastore/item_count.go +++ b/datastore/item_count.go @@ -54,80 +54,96 @@ func (counts *ClientItemCounts) SumHistoryCounts() int { func (dynamo *Dynamo) initRealCountsAndUpdateHistoryCounts(ctx context.Context, counts *ClientItemCounts) error { now := time.Now().Unix() if counts.Version < CurrentCountVersion { - if counts.ItemCount > 0 { - // If last period change tiem is 0, assume that the old count - // exists in ItemCount, which may include history items that have expired - // Query the DB to get updated counts - pkCond := expression.Key(clientIDDataTypeMtimeIdxPk).Equal(expression.Value(counts.ClientID)) - filterCond := expression.And( - expression.Name(dataTypeAttrName). - In(expression.Value(HistoryTypeID), expression.Value(HistoryDeleteDirectiveTypeID)), - expression.Name(deletedAttrName).Equal(expression.Value(false)), - ) - expr, err := expression.NewBuilder().WithKeyCondition(pkCond).WithFilter(filterCond).Build() - if err != nil { - return fmt.Errorf("error building history item count query: %w", err) - } - historyCountInput := &dynamodb.QueryInput{ - ExpressionAttributeNames: expr.Names(), - ExpressionAttributeValues: expr.Values(), - KeyConditionExpression: expr.KeyCondition(), - FilterExpression: expr.Filter(), - TableName: aws.String(Table), - Select: types.SelectCount, - } - out, err := dynamo.Query(ctx, historyCountInput) - if err != nil { - return fmt.Errorf("error querying history item count: %w", err) - } - counts.HistoryItemCountPeriod1 = 0 - counts.HistoryItemCountPeriod2 = 0 - counts.HistoryItemCountPeriod3 = 0 - counts.HistoryItemCountPeriod4 = int(out.Count) - filterCond = expression.And( - expression.AttributeExists(expression.Name(dataTypeAttrName)), - expression.Name(dataTypeAttrName).NotEqual(expression.Value(HistoryTypeID)), - expression.Name(dataTypeAttrName).NotEqual(expression.Value(HistoryDeleteDirectiveTypeID)), - expression.Name(deletedAttrName).Equal(expression.Value(false)), - ) - expr, err = expression.NewBuilder().WithKeyCondition(pkCond).WithFilter(filterCond).Build() - if err != nil { - return fmt.Errorf("error building normal item count query: %w", err) - } - normalCountInput := &dynamodb.QueryInput{ - ExpressionAttributeNames: expr.Names(), - ExpressionAttributeValues: expr.Values(), - KeyConditionExpression: expr.KeyCondition(), - FilterExpression: expr.Filter(), - TableName: aws.String(Table), - Select: types.SelectCount, - } - out, err = dynamo.Query(ctx, normalCountInput) - if err != nil { - return fmt.Errorf("error querying history item count: %w", err) - } - counts.ItemCount = int(out.Count) - } - counts.LastPeriodChangeTime = now - counts.Version = CurrentCountVersion - } else { - timeSinceLastChange := now - counts.LastPeriodChangeTime - if timeSinceLastChange >= periodDurationSecs { - changeCount := int(timeSinceLastChange / periodDurationSecs) - for range changeCount { - // The records from "period 1"/the earliest period - // will be purged from the count, since they will be deleted via DDB TTL - counts.HistoryItemCountPeriod1 = counts.HistoryItemCountPeriod2 - counts.HistoryItemCountPeriod2 = counts.HistoryItemCountPeriod3 - counts.HistoryItemCountPeriod3 = counts.HistoryItemCountPeriod4 - counts.HistoryItemCountPeriod4 = 0 - } - counts.LastPeriodChangeTime += periodDurationSecs * int64(changeCount) + return dynamo.migrateLegacyItemCounts(ctx, counts, now) + } + rotateHistoryCountPeriods(counts, now) + return nil +} + +func (dynamo *Dynamo) migrateLegacyItemCounts(ctx context.Context, counts *ClientItemCounts, now int64) error { + if counts.ItemCount > 0 { + if err := dynamo.refreshItemCountsFromTable(ctx, counts); err != nil { + return err } } + counts.LastPeriodChangeTime = now + counts.Version = CurrentCountVersion return nil } +func (dynamo *Dynamo) countMatchingItems( + ctx context.Context, + pkCond expression.KeyConditionBuilder, + filterCond expression.ConditionBuilder, + kind string, +) (int, error) { + expr, err := expression.NewBuilder().WithKeyCondition(pkCond).WithFilter(filterCond).Build() + if err != nil { + return 0, fmt.Errorf("error building %s item count query: %w", kind, err) + } + out, err := dynamo.Query(ctx, &dynamodb.QueryInput{ + ExpressionAttributeNames: expr.Names(), + ExpressionAttributeValues: expr.Values(), + KeyConditionExpression: expr.KeyCondition(), + FilterExpression: expr.Filter(), + TableName: aws.String(Table), + Select: types.SelectCount, + }) + if err != nil { + return 0, fmt.Errorf("error querying %s item count: %w", kind, err) + } + return int(out.Count), nil +} + +func (dynamo *Dynamo) refreshItemCountsFromTable(ctx context.Context, counts *ClientItemCounts) error { + // If last period change time is 0, assume that the old count exists in + // ItemCount, which may include history items that have expired. + pkCond := expression.Key(clientIDDataTypeMtimeIdxPk).Equal(expression.Value(counts.ClientID)) + historyFilter := expression.And( + expression.Name(dataTypeAttrName). + In(expression.Value(HistoryTypeID), expression.Value(HistoryDeleteDirectiveTypeID)), + expression.Name(deletedAttrName).Equal(expression.Value(false)), + ) + historyCount, err := dynamo.countMatchingItems(ctx, pkCond, historyFilter, "history") + if err != nil { + return err + } + counts.HistoryItemCountPeriod1 = 0 + counts.HistoryItemCountPeriod2 = 0 + counts.HistoryItemCountPeriod3 = 0 + counts.HistoryItemCountPeriod4 = historyCount + + normalFilter := expression.And( + expression.AttributeExists(expression.Name(dataTypeAttrName)), + expression.Name(dataTypeAttrName).NotEqual(expression.Value(HistoryTypeID)), + expression.Name(dataTypeAttrName).NotEqual(expression.Value(HistoryDeleteDirectiveTypeID)), + expression.Name(deletedAttrName).Equal(expression.Value(false)), + ) + normalCount, err := dynamo.countMatchingItems(ctx, pkCond, normalFilter, "normal") + if err != nil { + return err + } + counts.ItemCount = normalCount + return nil +} + +func rotateHistoryCountPeriods(counts *ClientItemCounts, now int64) { + timeSinceLastChange := now - counts.LastPeriodChangeTime + if timeSinceLastChange < periodDurationSecs { + return + } + changeCount := int(timeSinceLastChange / periodDurationSecs) + for range changeCount { + // The records from "period 1"/the earliest period + // will be purged from the count, since they will be deleted via DDB TTL + counts.HistoryItemCountPeriod1 = counts.HistoryItemCountPeriod2 + counts.HistoryItemCountPeriod2 = counts.HistoryItemCountPeriod3 + counts.HistoryItemCountPeriod3 = counts.HistoryItemCountPeriod4 + counts.HistoryItemCountPeriod4 = 0 + } + counts.LastPeriodChangeTime += periodDurationSecs * int64(changeCount) +} + // GetClientItemCount returns the count of non-deleted sync items stored for // a given client. func (dynamo *Dynamo) GetClientItemCount(ctx context.Context, clientID string) (*ClientItemCounts, error) { From ca8d4e1e60faec3cbfac295b0c4d81eb463bccdf Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Tue, 20 Oct 2026 06:59:11 -0500 Subject: [PATCH 07/28] chore(lint): Fix gocognit findings (#445) * chore(lint): Fix ClearServerData gocognit findings * test(command): Add GetUpdates coverage * chore(lint): Fix handleGetUpdatesRequest gocognit findings --- command/command.go | 509 ++++++++++++++++++---------- command/get_updates_helpers_test.go | 120 +++++++ command/get_updates_test.go | 210 ++++++++++++ datastore/sync_entity.go | 147 ++++---- datastore/sync_entity_test.go | 34 ++ 5 files changed, 771 insertions(+), 249 deletions(-) create mode 100644 command/get_updates_helpers_test.go create mode 100644 command/get_updates_test.go diff --git a/command/command.go b/command/command.go index 77faf344..58bed7c7 100644 --- a/command/command.go +++ b/command/command.go @@ -83,6 +83,197 @@ func setupNewClient( return &success, nil } +func isNewClientOrigin(guMsg *sync_pb.GetUpdatesMessage) bool { + return guMsg.GetUpdatesOrigin != nil && *guMsg.GetUpdatesOrigin == sync_pb.SyncEnums_NEW_CLIENT +} + +func isPollOrigin(guMsg *sync_pb.GetUpdatesMessage) bool { + return guMsg.GetUpdatesOrigin != nil && *guMsg.GetUpdatesOrigin == sync_pb.SyncEnums_PERIODIC +} + +func maybeSetupNewClient( + ctx context.Context, + db datastore.Datastore, + clientID string, + isNewClient bool, +) (*sync_pb.SyncEnums_ErrorType, error) { + if !isNewClient { + return nil, nil //nolint:nilnil // no proto error code when setup is skipped + } + return setupNewClient(ctx, db, clientID) +} + +func shouldFetchFolders(guMsg *sync_pb.GetUpdatesMessage) bool { + if guMsg.FetchFolders != nil { + return *guMsg.FetchFolders + } + return true +} + +func progressMarkerToken(fromProgressMarker *sync_pb.DataTypeProgressMarker) []byte { + // Default token value is client's token, otherwise 0. + // This token will be updated when we return the updated entities. + if len(fromProgressMarker.Token) > 0 { + return fromProgressMarker.Token + } + token := make([]byte, binary.MaxVarintLen64) + binary.PutVarint(token, int64(0)) + return token +} + +func maybeSetNigoriEncryptionKeys(guRsp *sync_pb.GetUpdatesResponse, dataTypeID int32, isNewClient bool) { + if dataTypeID != nigoriTypeID || !isNewClient { + return + } + // Bypassing chromium's restriction here, our server won't provide the + // initial encryption keys like chromium does, this will be overwritten + // by our client. + guRsp.EncryptionKeys = make([][]byte, 1) + guRsp.EncryptionKeys[0] = []byte("1234") +} + +func nigoriRootNotReady(isNewClient bool, dataTypeID int32, token int64, entities []datastore.SyncEntity) bool { + // Due to eventually read consistency, it is possible that we cannot get + // the nigori root folder entity for this NEW_CLIENT GetUpdates request, + // which is essential for clients when initializing sync engine with nigori + // type. Return a transient error for clients to re-request in this case. + return isNewClient && dataTypeID == nigoriTypeID && token == 0 && len(entities) == 0 +} + +func appendGetUpdatesEntities( + guRsp *sync_pb.GetUpdatesResponse, + markerIndex int, + entities []datastore.SyncEntity, +) (int, *sync_pb.SyncEnums_ErrorType, error) { + // Fill the PB entry from above DB entries until maxSize is reached. + j := 0 + for ; j < len(entities) && len(guRsp.Entries) < cap(guRsp.Entries); j++ { + entity, createErr := datastore.CreatePBSyncEntity(&entities[j]) + if createErr != nil { + errCode := sync_pb.SyncEnums_TRANSIENT_ERROR + return 0, &errCode, fmt.Errorf("error creating protobuf sync entity from DB entity: %w", createErr) + } + guRsp.Entries = append(guRsp.Entries, entity) + } + // If entities are appended, use the lastest mtime as returned token. + if j != 0 { + guRsp.NewProgressMarker[markerIndex].Token = make([]byte, binary.MaxVarintLen64) + binary.PutVarint(guRsp.NewProgressMarker[markerIndex].Token, *entities[j-1].Mtime) + } + return j, nil, nil +} + +func maybeSetTypeMtime( + ctx context.Context, + cache *cache.Cache, + clientID string, + dataTypeID int, + changesRemaining int64, + appendedCount int, + token int64, + entities []datastore.SyncEntity, +) { + // Save (clientID#dataType, mtime) into cache after querying from DB. + // If changes_remaining = 1 in the response, client will send another poll + // request immediately, we do not save mtime into cache in this iteration + // because the client token in the subsequent poll request will be equal to + // this mtime and we will wrongly think there are no updates when we + // process that subsequent poll request. The cache will be updated in a + // subsequent poll request where changes_remaining = 0. + if changesRemaining == 1 { + return + } + mtime := token + if appendedCount != 0 { + mtime = *entities[appendedCount-1].Mtime + } + cache.SetTypeMtime(ctx, clientID, dataTypeID, mtime) +} + +func processGetUpdatesForType( + ctx context.Context, + cache *cache.Cache, + db datastore.Datastore, + clientID string, + fromProgressMarker *sync_pb.DataTypeProgressMarker, + guRsp *sync_pb.GetUpdatesResponse, + markerIndex int, + maxSize int, + fetchFolders bool, + isNewClient bool, + isPoll bool, + changesRemaining *int64, +) (*sync_pb.SyncEnums_ErrorType, error) { + guRsp.NewProgressMarker[markerIndex] = &sync_pb.DataTypeProgressMarker{ + DataTypeId: fromProgressMarker.DataTypeId, + Token: progressMarkerToken(fromProgressMarker), + } + + maybeSetNigoriEncryptionKeys(guRsp, *fromProgressMarker.DataTypeId, isNewClient) + + // No need to get updates for this type because we already reach the + // maximum GetUpdates size for this request. Continue to next type instead + // of break because we need to prepare NewProgressMarker for all entries in + // FromProgressMarker, where the returned token stays the same as the one + // passed in FromProgressMarker. + if len(guRsp.Entries) >= maxSize { + return nil, nil //nolint:nilnil // continue to next type; no proto error + } + + token, n := binary.Varint(guRsp.NewProgressMarker[markerIndex].Token) + if n <= 0 { + return nil, fmt.Errorf("failed at decoding token value %v", token) + } + + // Check cache to short circuit with 0 updates for polling requests. + if isPoll && + !cache.IsTypeMtimeUpdated(ctx, clientID, int(*fromProgressMarker.DataTypeId), token) { + return nil, nil //nolint:nilnil // cache hit; no proto error + } + + curMaxSize := maxSize - len(guRsp.Entries) + hasChangesRemaining, entities, err := db.GetUpdatesForType( + ctx, + int(*fromProgressMarker.DataTypeId), + token, + fetchFolders, + clientID, + curMaxSize, + ) + if err != nil { + log.Error().Err(err).Msgf("db.GetUpdatesForType failed for type %v", *fromProgressMarker.DataTypeId) + errCode := sync_pb.SyncEnums_TRANSIENT_ERROR + return &errCode, + fmt.Errorf("error getting updates for type %v: %w", *fromProgressMarker.DataTypeId, err) + } + + if nigoriRootNotReady(isNewClient, *fromProgressMarker.DataTypeId, token, entities) { + errCode := sync_pb.SyncEnums_TRANSIENT_ERROR + return &errCode, errors.New("nigori root folder entity is not ready yet") + } + + if hasChangesRemaining { + *changesRemaining = 1 // Chromium uses 1 instead of actual count of update entries remaining. + } + + j, errCode, err := appendGetUpdatesEntities(guRsp, markerIndex, entities) + if err != nil { + return errCode, err + } + + maybeSetTypeMtime( + ctx, + cache, + clientID, + int(*fromProgressMarker.DataTypeId), + *changesRemaining, + j, + token, + entities, + ) + return nil, nil //nolint:nilnil // type processed; no proto error +} + // handleGetUpdatesRequest handles GetUpdatesMessage and fills // GetUpdatesResponse. Target sync entities in the database will be updated or // deleted based on the client's requests. @@ -95,12 +286,10 @@ func handleGetUpdatesRequest( clientID string, ) (*sync_pb.SyncEnums_ErrorType, error) { errCode := sync_pb.SyncEnums_SUCCESS // default value, might be changed later - isNewClient := guMsg.GetUpdatesOrigin != nil && *guMsg.GetUpdatesOrigin == sync_pb.SyncEnums_NEW_CLIENT - isPoll := guMsg.GetUpdatesOrigin != nil && *guMsg.GetUpdatesOrigin == sync_pb.SyncEnums_PERIODIC - if isNewClient { - if setupErrCode, err := setupNewClient(ctx, db, clientID); err != nil { - return setupErrCode, err - } + isNewClient := isNewClientOrigin(guMsg) + isPoll := isPollOrigin(guMsg) + if setupErrCode, err := maybeSetupNewClient(ctx, db, clientID, isNewClient); err != nil { + return setupErrCode, err } changesRemaining := int64(0) @@ -110,118 +299,29 @@ func handleGetUpdatesRequest( return &errCode, nil } - fetchFolders := true - if guMsg.FetchFolders != nil { - fetchFolders = *guMsg.FetchFolders - } - + fetchFolders := shouldFetchFolders(guMsg) maxSize := maxGUBatchSize // Process from_progress_marker guRsp.NewProgressMarker = make([]*sync_pb.DataTypeProgressMarker, len(guMsg.FromProgressMarker)) guRsp.Entries = make([]*sync_pb.SyncEntity, 0, maxSize) for i, fromProgressMarker := range guMsg.FromProgressMarker { - guRsp.NewProgressMarker[i] = &sync_pb.DataTypeProgressMarker{} - guRsp.NewProgressMarker[i].DataTypeId = fromProgressMarker.DataTypeId - - // Default token value is client's token, otherwise 0. - // This token will be updated when we return the updated entities. - if len(fromProgressMarker.Token) > 0 { - guRsp.NewProgressMarker[i].Token = fromProgressMarker.Token - } else { - guRsp.NewProgressMarker[i].Token = make([]byte, binary.MaxVarintLen64) - binary.PutVarint(guRsp.NewProgressMarker[i].Token, int64(0)) - } - - if *fromProgressMarker.DataTypeId == nigoriTypeID && isNewClient { - // Bypassing chromium's restriction here, our server won't provide the - // initial encryption keys like chromium does, this will be overwritten - // by our client. - guRsp.EncryptionKeys = make([][]byte, 1) - guRsp.EncryptionKeys[0] = []byte("1234") - } - - // No need to get updates for this type because we already reach the - // maximum GetUpdates size for this request. Continue to next type instead - // of break because we need to prepare NewProgressMarker for all entries in - // FromProgressMarker, where the returned token stays the same as the one - // passed in FromProgressMarker. - if len(guRsp.Entries) >= maxSize { - continue - } - - token, n := binary.Varint(guRsp.NewProgressMarker[i].Token) - if n <= 0 { - return nil, fmt.Errorf("failed at decoding token value %v", token) - } - - // Check cache to short circuit with 0 updates for polling requests. - if isPoll && - !cache.IsTypeMtimeUpdated(ctx, clientID, int(*fromProgressMarker.DataTypeId), token) { - continue - } - - curMaxSize := maxSize - len(guRsp.Entries) - hasChangesRemaining, entities, err := db.GetUpdatesForType( + typeErrCode, err := processGetUpdatesForType( ctx, - int(*fromProgressMarker.DataTypeId), - token, - fetchFolders, + cache, + db, clientID, - curMaxSize, + fromProgressMarker, + guRsp, + i, + maxSize, + fetchFolders, + isNewClient, + isPoll, + &changesRemaining, ) if err != nil { - log.Error().Err(err).Msgf("db.GetUpdatesForType failed for type %v", *fromProgressMarker.DataTypeId) - errCode = sync_pb.SyncEnums_TRANSIENT_ERROR - return &errCode, - fmt.Errorf("error getting updates for type %v: %w", *fromProgressMarker.DataTypeId, err) - } - - // Due to eventually read consistency, it is possible that we cannot get - // the nigori root folder entity for this NEW_CLIENT GetUpdates request, - // which is essential for clients when initializing sync engine with nigori - // type. Return a transient error for clients to re-request in this case. - if isNewClient && *fromProgressMarker.DataTypeId == nigoriTypeID && - token == 0 && len(entities) == 0 { - errCode = sync_pb.SyncEnums_TRANSIENT_ERROR - return &errCode, errors.New("nigori root folder entity is not ready yet") - } - - if hasChangesRemaining { - changesRemaining = 1 // Chromium uses 1 instead of actual count of update entries remaining. - } - - // Fill the PB entry from above DB entries until maxSize is reached. - j := 0 - for ; j < len(entities) && len(guRsp.Entries) < cap(guRsp.Entries); j++ { - entity, createErr := datastore.CreatePBSyncEntity(&entities[j]) - if createErr != nil { - errCode = sync_pb.SyncEnums_TRANSIENT_ERROR - return &errCode, fmt.Errorf("error creating protobuf sync entity from DB entity: %w", createErr) - } - guRsp.Entries = append(guRsp.Entries, entity) - } - // If entities are appended, use the lastest mtime as returned token. - if j != 0 { - guRsp.NewProgressMarker[i].Token = make([]byte, binary.MaxVarintLen64) - binary.PutVarint(guRsp.NewProgressMarker[i].Token, *entities[j-1].Mtime) - } - - // Save (clientID#dataType, mtime) into cache after querying from DB. - // If changes_remaining = 1 in the response, client will send another poll - // request immediately, we do not save mtime into cache in this iteration - // because the client token in the subsequent poll request will be equal to - // this mtime and we will wrongly think there are no updates when we - // process that subsequent poll request. The cache will be updated in a - // subsequent poll request where changes_remaining = 0. - if changesRemaining != 1 { - var mtime int64 - if j == 0 { - mtime = token - } else { - mtime = *entities[j-1].Mtime - } - cache.SetTypeMtime(ctx, clientID, int(*fromProgressMarker.DataTypeId), mtime) + return typeErrCode, err } } @@ -368,6 +468,119 @@ func updateCommitEntity( return false, nil } +func applyBoostedHistoryQuota(counts *commitCountState) { + if counts.currentHistory <= maxClientHistoryObjectQuota { + return + } + // Sync chains with history entities stored before the history count fix + // may have history counts greater than the new history item quota. + // "Boost" the quota with the difference between the history quota and count, + // so users can start syncing other entities immediately, instead of waiting for the + // history TTL to get rid of the excess items. + counts.boostedQuota = min( + maxClientObjectQuota-maxClientHistoryObjectQuota, + counts.currentHistory-maxClientHistoryObjectQuota, + ) +} + +func replaceClientGeneratedParentID(entity *datastore.SyncEntity, idMap map[string]string) { + // Check if ParentID is a client-generated ID which appears in previous + // commit entries, if so, replace with corresponding server-generated ID. + if entity.ParentID == nil { + return + } + serverParentID, ok := idMap[*entity.ParentID] + if !ok { + return + } + entity.ParentID = &serverParentID +} + +func resolveHistoryUpdateOp( + ctx context.Context, + db datastore.Datastore, + clientID string, + entity *datastore.SyncEntity, + entryRsp *sync_pb.CommitResponse_EntryResponse, +) (bool, bool) { + // Check if item exists using client_unique_tag + isUpdateOp, err := db.HasItem(ctx, clientID, *entity.ClientDefinedUniqueTag) + if err != nil { + log.Error().Err(err).Msg("Insert history sync entity failed") + rspType := sync_pb.CommitResponse_TRANSIENT_ERROR + entryRsp.ResponseType = &rspType + entryRsp.ErrorMessage = aws.String(fmt.Sprintf("Insert history sync entity failed: %v", err.Error())) + return false, true + } + return isUpdateOp, false +} + +func commitEntry( + ctx context.Context, + cache *cache.Cache, + db datastore.Datastore, + clientID string, + pbEntity *sync_pb.SyncEntity, + cacheGUID *string, + entryRsp *sync_pb.CommitResponse_EntryResponse, + idMap map[string]string, + typeMtimeMap map[int]int64, + counts *commitCountState, + sizeMonitor *ItemSizeMonitor, +) error { + entityToCommit, createErr := datastore.CreateDBSyncEntity(pbEntity, cacheGUID, clientID) + if createErr != nil { // Can't unmarshal & marshal the message from PB into DB format + rspType := sync_pb.CommitResponse_INVALID_MESSAGE + entryRsp.ResponseType = &rspType + entryRsp.ErrorMessage = aws.String( + fmt.Sprintf("Cannot convert protobuf sync entity to DB format: %v", createErr.Error()), + ) + return nil + } + + sizeMonitor.Observe(*entityToCommit.DataType, pbEntity) + replaceClientGeneratedParentID(entityToCommit, idMap) + + oldVersion := *entityToCommit.Version + isUpdateOp := oldVersion != 0 + isHistoryRelatedItem := *entityToCommit.DataType == datastore.HistoryTypeID || + *entityToCommit.DataType == datastore.HistoryDeleteDirectiveTypeID + *entityToCommit.Version = *entityToCommit.Mtime + if *entityToCommit.DataType == datastore.HistoryTypeID { + var skip bool + isUpdateOp, skip = resolveHistoryUpdateOp(ctx, db, clientID, entityToCommit, entryRsp) + if skip { + return nil + } + } + + var skipEntry bool + var err error + if isUpdateOp { + skipEntry, err = updateCommitEntity( + ctx, db, cache, clientID, entityToCommit, oldVersion, entryRsp, counts, isHistoryRelatedItem, + ) + } else { + skipEntry, err = insertCommitEntity( + ctx, db, cache, clientID, entityToCommit, entryRsp, idMap, counts, isHistoryRelatedItem, + ) + } + if err != nil { + return err + } + if skipEntry { + return nil + } + + typeMtimeMap[*entityToCommit.DataType] = *entityToCommit.Mtime + rspType := sync_pb.CommitResponse_SUCCESS + entryRsp.ResponseType = &rspType + entryRsp.IdString = aws.String(entityToCommit.ID) + entryRsp.Version = entityToCommit.Version + entryRsp.Mtime = entityToCommit.Mtime + return nil +} + // handleCommitRequest handles the commit message and fills the commit response. // For each commit entry: // - new sync entity is created and inserted into the database if version is 0. @@ -401,17 +614,7 @@ func handleCommitRequest( newNormal: newNormalCount, newHistory: newHistoryCount, } - if counts.currentHistory > maxClientHistoryObjectQuota { - // Sync chains with history entities stored before the history count fix - // may have history counts greater than the new history item quota. - // "Boost" the quota with the difference between the history quota and count, - // so users can start syncing other entities immediately, instead of waiting for the - // history TTL to get rid of the excess items. - counts.boostedQuota = min( - maxClientObjectQuota-maxClientHistoryObjectQuota, - counts.currentHistory-maxClientHistoryObjectQuota, - ) - } + applyBoostedHistoryQuota(&counts) commitRsp.Entryresponse = make([]*sync_pb.CommitResponse_EntryResponse, len(commitMsg.Entries)) @@ -423,70 +626,14 @@ func handleCommitRequest( for i, v := range commitMsg.Entries { entryRsp := &sync_pb.CommitResponse_EntryResponse{} commitRsp.Entryresponse[i] = entryRsp - - entityToCommit, createErr := datastore.CreateDBSyncEntity(v, commitMsg.CacheGuid, clientID) - if createErr != nil { // Can't unmarshal & marshal the message from PB into DB format - rspType := sync_pb.CommitResponse_INVALID_MESSAGE - entryRsp.ResponseType = &rspType - entryRsp.ErrorMessage = aws.String( - fmt.Sprintf("Cannot convert protobuf sync entity to DB format: %v", createErr.Error()), - ) - continue - } - - sizeMonitor.Observe(*entityToCommit.DataType, v) - - // Check if ParentID is a client-generated ID which appears in previous - // commit entries, if so, replace with corresponding server-generated ID. - if entityToCommit.ParentID != nil { - if serverParentID, ok := idMap[*entityToCommit.ParentID]; ok { - entityToCommit.ParentID = &serverParentID - } - } - - oldVersion := *entityToCommit.Version - isUpdateOp := oldVersion != 0 - isHistoryRelatedItem := *entityToCommit.DataType == datastore.HistoryTypeID || - *entityToCommit.DataType == datastore.HistoryDeleteDirectiveTypeID - *entityToCommit.Version = *entityToCommit.Mtime - if *entityToCommit.DataType == datastore.HistoryTypeID { - // Check if item exists using client_unique_tag - isUpdateOp, err = db.HasItem(ctx, clientID, *entityToCommit.ClientDefinedUniqueTag) - if err != nil { - log.Error().Err(err).Msg("Insert history sync entity failed") - rspType := sync_pb.CommitResponse_TRANSIENT_ERROR - entryRsp.ResponseType = &rspType - entryRsp.ErrorMessage = aws.String(fmt.Sprintf("Insert history sync entity failed: %v", err.Error())) - continue - } - } - - var skipEntry bool - if isUpdateOp { - skipEntry, err = updateCommitEntity( - ctx, db, cache, clientID, entityToCommit, oldVersion, entryRsp, &counts, isHistoryRelatedItem, - ) - } else { - skipEntry, err = insertCommitEntity( - ctx, db, cache, clientID, entityToCommit, entryRsp, idMap, &counts, isHistoryRelatedItem, - ) - } - if err != nil { - log.Error().Err(err).Msg("Interim count update failed") + commitErr := commitEntry( + ctx, cache, db, clientID, v, commitMsg.CacheGuid, entryRsp, idMap, typeMtimeMap, &counts, sizeMonitor, + ) + if commitErr != nil { + log.Error().Err(commitErr).Msg("Interim count update failed") errCode = sync_pb.SyncEnums_TRANSIENT_ERROR - return &errCode, fmt.Errorf("interim count update failed: %w", err) - } - if skipEntry { - continue + return &errCode, fmt.Errorf("interim count update failed: %w", commitErr) } - - typeMtimeMap[*entityToCommit.DataType] = *entityToCommit.Mtime - // Prepare success response - rspType := sync_pb.CommitResponse_SUCCESS - entryRsp.ResponseType = &rspType - entryRsp.IdString = aws.String(entityToCommit.ID) - entryRsp.Version = entityToCommit.Version - entryRsp.Mtime = entityToCommit.Mtime } sizeMonitor.LogWarnings() diff --git a/command/get_updates_helpers_test.go b/command/get_updates_helpers_test.go new file mode 100644 index 00000000..10aa97ed --- /dev/null +++ b/command/get_updates_helpers_test.go @@ -0,0 +1,120 @@ +package command //nolint:testpackage // tests unexported GetUpdates helpers + +import ( + "context" + "encoding/binary" + "strconv" + "testing" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/brave/go-sync/cache" + "github.com/brave/go-sync/datastore" + "github.com/brave/go-sync/datastore/datastoretest" + "github.com/brave/go-sync/schema/protobuf/sync_pb" +) + +func TestIsNewClientAndPollOrigin(t *testing.T) { + newClient := sync_pb.SyncEnums_NEW_CLIENT + poll := sync_pb.SyncEnums_PERIODIC + trigger := sync_pb.SyncEnums_GU_TRIGGER + + assert.False(t, isNewClientOrigin(&sync_pb.GetUpdatesMessage{})) + assert.False(t, isPollOrigin(&sync_pb.GetUpdatesMessage{})) + assert.True(t, isNewClientOrigin(&sync_pb.GetUpdatesMessage{GetUpdatesOrigin: &newClient})) + assert.True(t, isPollOrigin(&sync_pb.GetUpdatesMessage{GetUpdatesOrigin: &poll})) + assert.False(t, isNewClientOrigin(&sync_pb.GetUpdatesMessage{GetUpdatesOrigin: &trigger})) + assert.False(t, isPollOrigin(&sync_pb.GetUpdatesMessage{GetUpdatesOrigin: &trigger})) +} + +func TestShouldFetchFolders(t *testing.T) { + assert.True(t, shouldFetchFolders(&sync_pb.GetUpdatesMessage{})) + assert.True(t, shouldFetchFolders(&sync_pb.GetUpdatesMessage{FetchFolders: aws.Bool(true)})) + assert.False(t, shouldFetchFolders(&sync_pb.GetUpdatesMessage{FetchFolders: aws.Bool(false)})) +} + +func TestProgressMarkerToken(t *testing.T) { + existing := []byte{1, 2, 3} + assert.Equal(t, existing, progressMarkerToken(&sync_pb.DataTypeProgressMarker{Token: existing})) + + decoded, n := binary.Varint(progressMarkerToken(&sync_pb.DataTypeProgressMarker{})) + require.Positive(t, n) + assert.Equal(t, int64(0), decoded) +} + +func TestMaybeSetNigoriEncryptionKeys(t *testing.T) { + rsp := &sync_pb.GetUpdatesResponse{} + maybeSetNigoriEncryptionKeys(rsp, nigoriTypeID, false) + assert.Nil(t, rsp.EncryptionKeys) + + maybeSetNigoriEncryptionKeys(rsp, 32904, true) + assert.Nil(t, rsp.EncryptionKeys) + + maybeSetNigoriEncryptionKeys(rsp, nigoriTypeID, true) + require.Len(t, rsp.EncryptionKeys, 1) + assert.Equal(t, []byte("1234"), rsp.EncryptionKeys[0]) +} + +func TestAppendGetUpdatesEntities(t *testing.T) { + mtime := int64(42) + entities := []datastore.SyncEntity{{ + ID: "id1", + Version: aws.Int64(1), + Mtime: &mtime, + Ctime: aws.Int64(1), + Deleted: aws.Bool(false), + Folder: aws.Bool(false), + }} + rsp := &sync_pb.GetUpdatesResponse{ + Entries: make([]*sync_pb.SyncEntity, 0, 10), + NewProgressMarker: []*sync_pb.DataTypeProgressMarker{{}}, + } + + j, errCode, err := appendGetUpdatesEntities(rsp, 0, entities) + require.NoError(t, err) + assert.Nil(t, errCode) + assert.Equal(t, 1, j) + require.Len(t, rsp.Entries, 1) + decoded, n := binary.Varint(rsp.NewProgressMarker[0].Token) + require.Positive(t, n) + assert.Equal(t, mtime, decoded) + + j, errCode, err = appendGetUpdatesEntities(rsp, 0, nil) + require.NoError(t, err) + assert.Nil(t, errCode) + assert.Equal(t, 0, j) +} + +func TestMaybeSetupNewClient_Skip(t *testing.T) { + errCode, err := maybeSetupNewClient(context.Background(), new(datastoretest.MockDatastore), "client", false) + require.NoError(t, err) + assert.Nil(t, errCode) +} + +func TestMaybeSetTypeMtime(t *testing.T) { + c := cache.NewCache(cache.NewRedisClient()) + t.Cleanup(func() { + require.NoError(t, c.FlushAll(context.Background())) + }) + + mtime := int64(99) + entities := []datastore.SyncEntity{{Mtime: &mtime}} + key := c.GetTypeMtimeKey("client", 1) + + maybeSetTypeMtime(context.Background(), c, "client", 1, 1, 1, 5, entities) + val, err := c.Get(context.Background(), key, false) + require.NoError(t, err) + assert.Empty(t, val, "cache should not be updated when changes remaining = 1") + + maybeSetTypeMtime(context.Background(), c, "client", 1, 0, 0, 5, entities) + val, err = c.Get(context.Background(), key, false) + require.NoError(t, err) + assert.Equal(t, strconv.FormatInt(5, 10), val) + + maybeSetTypeMtime(context.Background(), c, "client", 1, 0, 1, 5, entities) + val, err = c.Get(context.Background(), key, false) + require.NoError(t, err) + assert.Equal(t, strconv.FormatInt(mtime, 10), val) +} diff --git a/command/get_updates_test.go b/command/get_updates_test.go new file mode 100644 index 00000000..0d1b01cf --- /dev/null +++ b/command/get_updates_test.go @@ -0,0 +1,210 @@ +package command_test + +import ( + "context" + "encoding/binary" + "errors" + "testing" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" + + "github.com/brave/go-sync/cache" + "github.com/brave/go-sync/command" + "github.com/brave/go-sync/datastore" + "github.com/brave/go-sync/datastore/datastoretest" + "github.com/brave/go-sync/schema/protobuf/sync_pb" +) + +const ( + getUpdatesNigoriType int32 = 47745 + getUpdatesBookmarkType int32 = 32904 + getUpdatesDeviceInfoType int = 154522 + getUpdatesNigoriTag string = "google_chrome_nigori" + getUpdatesDefaultMaxSize int = 500 +) + +type GetUpdatesTestSuite struct { + suite.Suite + + cache *cache.Cache +} + +func (suite *GetUpdatesTestSuite) SetupSuite() { + suite.cache = cache.NewCache(cache.NewRedisClient()) +} + +func (suite *GetUpdatesTestSuite) TearDownTest() { + suite.Require().NoError( + suite.cache.FlushAll(context.Background()), "Failed to clear cache") +} + +func tokenBytes(value int64) []byte { + token := make([]byte, binary.MaxVarintLen64) + binary.PutVarint(token, value) + return token +} + +func getUpdatesRequest( + marker []*sync_pb.DataTypeProgressMarker, + origin *sync_pb.SyncEnums_GetUpdatesOrigin, +) *sync_pb.ClientToServerMessage { + contents := sync_pb.ClientToServerMessage_GET_UPDATES + return &sync_pb.ClientToServerMessage{ + MessageContents: &contents, + GetUpdates: &sync_pb.GetUpdatesMessage{ + FromProgressMarker: marker, + GetUpdatesOrigin: origin, + }, + } +} + +func (suite *GetUpdatesTestSuite) handleGetUpdates( + msg *sync_pb.ClientToServerMessage, + db datastore.Datastore, +) *sync_pb.ClientToServerResponse { + rsp := &sync_pb.ClientToServerResponse{} + err := command.HandleClientToServerMessage( + context.Background(), + suite.cache, + msg, + rsp, + db, + "client", + ) + suite.Require().NoError(err) + return rsp +} + +func (suite *GetUpdatesTestSuite) TestHandleGetUpdatesRequest_NilProgressMarkers() { + rsp := suite.handleGetUpdates( + getUpdatesRequest(nil, nil), + new(datastoretest.MockDatastore), + ) + suite.Require().NotNil(rsp.ErrorCode) + suite.Equal(sync_pb.SyncEnums_SUCCESS, *rsp.ErrorCode) + suite.Require().NotNil(rsp.GetUpdates) + suite.Equal(int64(0), *rsp.GetUpdates.ChangesRemaining) +} + +func (suite *GetUpdatesTestSuite) TestHandleGetUpdatesRequest_InvalidToken() { + rsp := &sync_pb.ClientToServerResponse{} + err := command.HandleClientToServerMessage( + context.Background(), + suite.cache, + getUpdatesRequest([]*sync_pb.DataTypeProgressMarker{{ + DataTypeId: aws.Int32(getUpdatesNigoriType), + Token: []byte{0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80}, + }}, nil), + rsp, + new(datastoretest.MockDatastore), + "client", + ) + suite.Require().Error(err) + suite.Contains(err.Error(), "failed at decoding token value") +} + +func (suite *GetUpdatesTestSuite) TestHandleGetUpdatesRequest_CreatePBSyncEntityError() { + mtime := int64(1) + db := new(datastoretest.MockDatastore) + db.On("GetUpdatesForType", mock.Anything, int(getUpdatesNigoriType), int64(0), true, "client", getUpdatesDefaultMaxSize). + Return(false, []datastore.SyncEntity{{ + ID: "nigori", + Version: aws.Int64(1), + Mtime: &mtime, + Specifics: []byte("not-valid-protobuf"), + }}, nil) + + rsp := suite.handleGetUpdates( + getUpdatesRequest([]*sync_pb.DataTypeProgressMarker{{ + DataTypeId: aws.Int32(getUpdatesNigoriType), + Token: tokenBytes(0), + }}, nil), + db, + ) + suite.Require().NotNil(rsp.ErrorCode) + suite.Equal(sync_pb.SyncEnums_TRANSIENT_ERROR, *rsp.ErrorCode) + suite.Require().NotNil(rsp.ErrorMessage) + suite.Contains(*rsp.ErrorMessage, "error creating protobuf sync entity") + db.AssertExpectations(suite.T()) +} + +func (suite *GetUpdatesTestSuite) TestHandleGetUpdatesRequest_GetUpdatesForTypeError() { + db := new(datastoretest.MockDatastore) + db.On("GetUpdatesForType", mock.Anything, int(getUpdatesNigoriType), int64(0), true, "client", getUpdatesDefaultMaxSize). + Return(false, []datastore.SyncEntity{}, errors.New("db down")) + + rsp := suite.handleGetUpdates( + getUpdatesRequest([]*sync_pb.DataTypeProgressMarker{{ + DataTypeId: aws.Int32(getUpdatesNigoriType), + Token: tokenBytes(0), + }}, nil), + db, + ) + suite.Require().NotNil(rsp.ErrorCode) + suite.Equal(sync_pb.SyncEnums_TRANSIENT_ERROR, *rsp.ErrorCode) + db.AssertExpectations(suite.T()) +} + +func (suite *GetUpdatesTestSuite) TestHandleGetUpdatesRequest_NigoriRootNotReady() { + db := new(datastoretest.MockDatastore) + db.On("GetUpdatesForType", mock.Anything, getUpdatesDeviceInfoType, int64(0), false, "client", getUpdatesDefaultMaxSize). + Return(false, []datastore.SyncEntity{}, nil) + db.On("HasServerDefinedUniqueTag", mock.Anything, "client", getUpdatesNigoriTag). + Return(true, nil) + db.On("GetUpdatesForType", mock.Anything, int(getUpdatesNigoriType), int64(0), true, "client", getUpdatesDefaultMaxSize). + Return(false, []datastore.SyncEntity{}, nil) + + origin := sync_pb.SyncEnums_NEW_CLIENT + rsp := suite.handleGetUpdates( + getUpdatesRequest([]*sync_pb.DataTypeProgressMarker{{ + DataTypeId: aws.Int32(getUpdatesNigoriType), + Token: tokenBytes(0), + }}, &origin), + db, + ) + suite.Require().NotNil(rsp.ErrorCode) + suite.Equal(sync_pb.SyncEnums_TRANSIENT_ERROR, *rsp.ErrorCode) + suite.Require().NotNil(rsp.ErrorMessage) + suite.Contains(*rsp.ErrorMessage, "nigori root folder entity is not ready") +} + +func (suite *GetUpdatesTestSuite) TestHandleGetUpdatesRequest_SkipTypeWhenBatchFull() { + mtime := int64(7) + entities := make([]datastore.SyncEntity, getUpdatesDefaultMaxSize) + for i := range entities { + itemMtime := mtime + int64(i) + entities[i] = datastore.SyncEntity{ + ID: "nigori", + Version: aws.Int64(1), + Mtime: &itemMtime, + Ctime: aws.Int64(1), + Deleted: aws.Bool(false), + Folder: aws.Bool(true), + } + } + db := new(datastoretest.MockDatastore) + db.On("GetUpdatesForType", mock.Anything, int(getUpdatesNigoriType), int64(0), true, "client", getUpdatesDefaultMaxSize). + Return(false, entities, nil) + + bookmarkToken := tokenBytes(3) + rsp := suite.handleGetUpdates( + getUpdatesRequest([]*sync_pb.DataTypeProgressMarker{ + {DataTypeId: aws.Int32(getUpdatesNigoriType), Token: tokenBytes(0)}, + {DataTypeId: aws.Int32(getUpdatesBookmarkType), Token: bookmarkToken}, + }, nil), + db, + ) + suite.Require().NotNil(rsp.ErrorCode) + suite.Equal(sync_pb.SyncEnums_SUCCESS, *rsp.ErrorCode) + suite.Require().NotNil(rsp.GetUpdates) + suite.Require().Len(rsp.GetUpdates.Entries, getUpdatesDefaultMaxSize) + suite.Require().Len(rsp.GetUpdates.NewProgressMarker, 2) + suite.Equal(bookmarkToken, rsp.GetUpdates.NewProgressMarker[1].Token) + db.AssertExpectations(suite.T()) +} + +func TestGetUpdatesTestSuite(t *testing.T) { + suite.Run(t, new(GetUpdatesTestSuite)) +} diff --git a/datastore/sync_entity.go b/datastore/sync_entity.go index 70ce5c89..4e1f1844 100644 --- a/datastore/sync_entity.go +++ b/datastore/sync_entity.go @@ -384,15 +384,7 @@ func (dynamo *Dynamo) DisableSyncChain(ctx context.Context, clientID string) err return nil } -// ClearServerData deletes all items for a given clientID. It uses a paginated -// Query (capped at 1MB per page by DynamoDB) and processes each page in -// transactional delete batches before fetching the next page, keeping each -// transaction comfortably under the 4MB TransactWriteItems limit. The Query -// uses a projection so the heavy Specifics blob is never fetched; only the -// attributes required to build the delete (primary key, Mtime, Version) and -// to invalidate downstream caches (DataType) are returned. -func (dynamo *Dynamo) ClearServerData(ctx context.Context, clientID string) ([]SyncEntity, error) { - syncEntities := []SyncEntity{} +func clearServerDataQueryInput(clientID string) (*dynamodb.QueryInput, error) { keyCond := expression.KeyEqual(expression.Key(pk), expression.Value(clientID)) proj := expression.NamesList( expression.Name(pk), @@ -403,15 +395,89 @@ func (dynamo *Dynamo) ClearServerData(ctx context.Context, clientID string) ([]S ) expr, err := expression.NewBuilder().WithKeyCondition(keyCond).WithProjection(proj).Build() if err != nil { - return syncEntities, fmt.Errorf("error building expression to clear server data: %w", err) + return nil, fmt.Errorf("error building expression to clear server data: %w", err) } - input := &dynamodb.QueryInput{ + return &dynamodb.QueryInput{ ExpressionAttributeNames: expr.Names(), ExpressionAttributeValues: expr.Values(), KeyConditionExpression: expr.KeyCondition(), ProjectionExpression: expr.Projection(), TableName: aws.String(Table), + }, nil +} + +func transactDeleteForSyncEntity(item SyncEntity) (*types.TransactWriteItem, error) { + if item.ID == disabledChainID { + return nil, nil //nolint:nilnil // skip the disabled-chain marker; no delete item + } + + del := &types.Delete{ + TableName: aws.String(Table), + Key: map[string]types.AttributeValue{ + pk: &types.AttributeValueMemberS{Value: item.ClientID}, + sk: &types.AttributeValueMemberS{Value: item.ID}, + }, + } + + // Fail delete if race condition detected (modified time has changed). + if item.Version != nil && item.Mtime != nil { + cond := expression.Name("Mtime").Equal(expression.Value(*item.Mtime)) + condExpr, err := expression.NewBuilder().WithCondition(cond).Build() + if err != nil { + return nil, err + } + del.ConditionExpression = condExpr.Condition() + del.ExpressionAttributeNames = condExpr.Names() + del.ExpressionAttributeValues = condExpr.Values() + } + + return &types.TransactWriteItem{Delete: del}, nil +} + +func (dynamo *Dynamo) transactDeleteSyncEntities( + ctx context.Context, + clientID string, + pageEntities []SyncEntity, +) error { + for i := 0; i < len(pageEntities); i += maxTransactDeleteItemSize { + j := min(i+maxTransactDeleteItemSize, len(pageEntities)) + items := make([]types.TransactWriteItem, 0, j-i) + for _, item := range pageEntities[i:j] { + writeItem, err := transactDeleteForSyncEntity(item) + if err != nil { + return fmt.Errorf("error deleting sync entities for client %s: %w", clientID, err) + } + if writeItem == nil { + continue + } + items = append(items, *writeItem) + } + if len(items) == 0 { + continue + } + if _, err := dynamo.TransactWriteItems( + ctx, + &dynamodb.TransactWriteItemsInput{TransactItems: items}, + ); err != nil { + return fmt.Errorf("error deleting sync entities for client %s: %w", clientID, err) + } + } + return nil +} + +// ClearServerData deletes all items for a given clientID. It uses a paginated +// Query (capped at 1MB per page by DynamoDB) and processes each page in +// transactional delete batches before fetching the next page, keeping each +// transaction comfortably under the 4MB TransactWriteItems limit. The Query +// uses a projection so the heavy Specifics blob is never fetched; only the +// attributes required to build the delete (primary key, Mtime, Version) and +// to invalidate downstream caches (DataType) are returned. +func (dynamo *Dynamo) ClearServerData(ctx context.Context, clientID string) ([]SyncEntity, error) { + syncEntities := []SyncEntity{} + input, err := clearServerDataQueryInput(clientID) + if err != nil { + return syncEntities, err } paginator := dynamodb.NewQueryPaginator(dynamo.Client, input) @@ -437,63 +503,8 @@ func (dynamo *Dynamo) ClearServerData(ctx context.Context, clientID string) ([]S Msg("Queried sync entities for deletion") pageIndex++ - for i := int32(0); i < page.Count; i += maxTransactDeleteItemSize { - j := min(i+maxTransactDeleteItemSize, page.Count) - - items := make([]types.TransactWriteItem, 0, j-i) - for _, item := range pageEntities[i:j] { - if item.ID == disabledChainID { - continue - } - - // Fail delete if race condition detected (modified time has changed). - if item.Version != nil && item.Mtime != nil { - cond := expression.Name("Mtime").Equal(expression.Value(*item.Mtime)) - condExpr, buildErr := expression.NewBuilder().WithCondition(cond).Build() - if buildErr != nil { - return syncEntities, fmt.Errorf( - "error deleting sync entities for client %s: %w", - clientID, - buildErr, - ) - } - - items = append(items, types.TransactWriteItem{ - Delete: &types.Delete{ - ConditionExpression: condExpr.Condition(), - ExpressionAttributeNames: condExpr.Names(), - ExpressionAttributeValues: condExpr.Values(), - TableName: aws.String(Table), - Key: map[string]types.AttributeValue{ - pk: &types.AttributeValueMemberS{Value: item.ClientID}, - sk: &types.AttributeValueMemberS{Value: item.ID}, - }, - }, - }) - } else { - // If row doesn't hold Mtime, delete as usual. - items = append(items, types.TransactWriteItem{ - Delete: &types.Delete{ - TableName: aws.String(Table), - Key: map[string]types.AttributeValue{ - pk: &types.AttributeValueMemberS{Value: item.ClientID}, - sk: &types.AttributeValueMemberS{Value: item.ID}, - }, - }, - }) - } - } - - if len(items) == 0 { - continue - } - - if _, writeErr := dynamo.TransactWriteItems( - ctx, - &dynamodb.TransactWriteItemsInput{TransactItems: items}, - ); writeErr != nil { - return syncEntities, fmt.Errorf("error deleting sync entities for client %s: %w", clientID, writeErr) - } + if deleteErr := dynamo.transactDeleteSyncEntities(ctx, clientID, pageEntities); deleteErr != nil { + return syncEntities, deleteErr } } diff --git a/datastore/sync_entity_test.go b/datastore/sync_entity_test.go index 2420d01b..60b0b332 100644 --- a/datastore/sync_entity_test.go +++ b/datastore/sync_entity_test.go @@ -1075,6 +1075,40 @@ func (suite *SyncEntityTestSuite) TestClearServerDataPagination() { } } +// Production clear-data always DisableSyncChain first, leaving a disabled_chain +// marker that ClearServerData must skip so IsSyncChainDisabled stays true. +func (suite *SyncEntityTestSuite) TestClearServerDataSkipsDisabledChainMarker() { + entity := datastore.SyncEntity{ + ClientID: "client1", + ID: "id1", + Version: aws.Int64(1), + Ctime: aws.Int64(12345678), + Mtime: aws.Int64(12345678), + DataType: aws.Int(123), + Folder: aws.Bool(false), + Deleted: aws.Bool(false), + DataTypeMtime: aws.String("123#12345678"), + } + _, err := suite.dynamo.InsertSyncEntity(context.Background(), &entity) + suite.Require().NoError(err, "InsertSyncEntity should succeed") + + suite.Require().NoError( + suite.dynamo.DisableSyncChain(context.Background(), entity.ClientID), + "DisableSyncChain should succeed") + + cleared, err := suite.dynamo.ClearServerData(context.Background(), entity.ClientID) + suite.Require().NoError(err, "ClearServerData should succeed") + suite.GreaterOrEqual(len(cleared), 1) + + remaining, err := datastoretest.ScanSyncEntities(suite.dynamo) + suite.Require().NoError(err, "ScanSyncEntities should succeed") + suite.Empty(remaining, "sync entities should be deleted") + + disabled, err := suite.dynamo.IsSyncChainDisabled(context.Background(), entity.ClientID) + suite.Require().NoError(err, "IsSyncChainDisabled should succeed") + suite.True(disabled, "disabled_chain marker must not be deleted") +} + // Some entries have a nil Mtime; ClearServerData must handle them without panicking. func (suite *SyncEntityTestSuite) TestClearServerDataLegacyMissingMtime() { entity := datastore.SyncEntity{ From 4dbfd3d7b8d3c64c3ba0de06b0af5ac69e21bb97 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 27 Oct 2026 19:14:16 +0000 Subject: [PATCH 08/28] chore(deps): update dependency go to 1.27 (#448) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 93bbf7b3..37d9a969 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: - uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0 with: - go-version: 1.26 + go-version: 1.27 - name: lint uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0 From 8fc46897df3520432621feadb9cae0217f2bc315 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 27 Oct 2026 14:49:12 -0500 Subject: [PATCH 09/28] fix(deps): update module github.com/stretchr/testify to v1.12.1 (#452) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- go.mod | 8 +++----- go.sum | 15 ++++++--------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 3279d165..da60f164 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/prometheus/client_golang v1.23.2 github.com/redis/go-redis/v9 v9.17.0 github.com/rs/zerolog v1.34.0 - github.com/stretchr/testify v1.11.1 + github.com/stretchr/testify v1.12.1 google.golang.org/protobuf v1.36.8 ) @@ -38,7 +38,6 @@ require ( github.com/aws/smithy-go v1.24.2 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/go-chi/chi v4.1.2+incompatible // indirect github.com/gomodule/redigo v2.0.0+incompatible // indirect @@ -47,7 +46,6 @@ require ( github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_model v0.6.2 // indirect github.com/prometheus/common v0.66.1 // indirect github.com/prometheus/procfs v0.16.1 // indirect @@ -55,11 +53,11 @@ require ( github.com/rs/xid v1.6.0 // indirect github.com/satori/go.uuid v1.2.0 // indirect github.com/shengdoushi/base58 v1.0.0 // indirect - github.com/stretchr/objx v0.5.2 // indirect + github.com/stretchr/objx v0.5.3 // indirect github.com/throttled/throttled/v2 v2.13.0 // indirect go.yaml.in/yaml/v2 v2.4.2 // indirect + go.yaml.in/yaml/v3 v3.0.5 // indirect golang.org/x/crypto v0.54.0 // indirect golang.org/x/sys v0.47.0 // indirect golang.org/x/text v0.40.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index e6106b2f..31d50c1e 100644 --- a/go.sum +++ b/go.sum @@ -59,8 +59,6 @@ github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= @@ -131,7 +129,6 @@ github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4 github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h0RJWRi/o0o= github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg= @@ -157,12 +154,12 @@ github.com/shengdoushi/base58 v1.0.0/go.mod h1:m5uIILfzcKMw6238iWAhP4l3s5+uXyF3+ github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/objx v0.5.3 h1:jmXUvGomnU1o3W/V5h2VEradbpJDwGrzugQQvL0POH4= +github.com/stretchr/objx v0.5.3/go.mod h1:rDQraq+vQZU7Fde9LOZLr8Tax6zZvy4kuNKF+QYS+U0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= -github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE= +github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg= github.com/throttled/throttled/v2 v2.13.0 h1:pUbMDnDvUEwtSc9N8HrNjctwlGIVer0hdHNCbb2gl3Y= github.com/throttled/throttled/v2 v2.13.0/go.mod h1:+EAvrG2hZAQTx8oMpBu8fq6Xmm+d1P2luKK7fIY1Esc= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= @@ -173,6 +170,8 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI= go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU= +go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw= +go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= @@ -240,5 +239,3 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From c63464af1d3cd06d13791bb7e752f5d7e1b4c6ea Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 27 Oct 2026 20:01:01 +0000 Subject: [PATCH 10/28] chore(deps): update actions/checkout action to v7.0.1 (#446) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 37d9a969..e0fdb13f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: name: lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0 with: @@ -27,7 +27,7 @@ jobs: name: test runs-on: ubuntu-latest steps: - - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: test run: make docker && make docker-test From 7fd177a25d92a69893b7673f313b154a859cfd2b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 27 Oct 2026 17:00:23 -0500 Subject: [PATCH 11/28] chore(deps): update public.ecr.aws/docker/library/golang docker tag to v1.27 (#450) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c23c953b..c47327e1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM public.ecr.aws/docker/library/golang:1.26 as builder +FROM public.ecr.aws/docker/library/golang:1.27 as builder ARG VERSION ARG BUILD_TIME From 92bcacf98975b19ceb36f18262f5a6e4206093e3 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 27 Oct 2026 22:28:36 +0000 Subject: [PATCH 12/28] chore(deps): update actions/setup-go action to v7 (#453) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e0fdb13f..b26c7987 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0 + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 with: go-version: 1.27 From 2a1b383725c37673d6274bd2801f7056a30d8205 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 27 Oct 2026 17:41:18 -0500 Subject: [PATCH 13/28] chore(deps): update alpine docker tag to v3.24 (#447) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: mschfh <37435502+mschfh@users.noreply.github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c47327e1..9ce5f451 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ RUN CGO_ENABLED=0 GOOS=linux go build \ -ldflags "-X github.com/brave/go-sync/server.version=${VERSION} -X github.com/brave/go-sync/server.buildTime=${BUILD_TIME} -X github.com/brave/go-sync/server.commit=${COMMIT}" \ -o main . -FROM alpine:3.23 as artifact +FROM alpine:3.24 as artifact RUN apk add --update ca-certificates # Certificates for SSL COPY --from=builder /src/main main From 4e445367e637851178f4bc3aa756dd4bb75e87f3 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 27 Oct 2026 20:46:39 -0500 Subject: [PATCH 14/28] chore(deps): update golangci/golangci-lint-action action to v9.3.0 (#449) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b26c7987..4a662463 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: go-version: 1.27 - name: lint - uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0 + uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0 test: name: test From 3aeee9488fe311b883df808a67a80d1f8d0aff4c Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 28 Oct 2026 01:49:42 +0000 Subject: [PATCH 15/28] fix(deps): update module github.com/go-chi/chi/v5 to v5.5.0 (#451) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index da60f164..5ca96437 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/dynamodb v1.57.1 github.com/brave-intl/bat-go/libs v0.0.0-20250620104757-9e2f8ff87fd8 github.com/getsentry/sentry-go v0.39.0 - github.com/go-chi/chi/v5 v5.2.5 + github.com/go-chi/chi/v5 v5.5.0 github.com/google/go-cmp v0.7.0 github.com/google/uuid v1.6.0 github.com/prometheus/client_golang v1.23.2 diff --git a/go.sum b/go.sum index 31d50c1e..bd4b08e7 100644 --- a/go.sum +++ b/go.sum @@ -67,8 +67,8 @@ github.com/getsentry/sentry-go v0.39.0 h1:uhnexj8PNCyCve37GSqxXOeXHh4cJNLNNB4w70 github.com/getsentry/sentry-go v0.39.0/go.mod h1:eRXCoh3uvmjQLY6qu63BjUZnaBu5L5WhMV1RwYO8W5s= github.com/go-chi/chi v4.1.2+incompatible h1:fGFk2Gmi/YKXk0OmGfBh0WgmN3XB8lVnEyNz34tQRec= github.com/go-chi/chi v4.1.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= -github.com/go-chi/chi/v5 v5.2.5 h1:Eg4myHZBjyvJmAFjFvWgrqDTXFyOzjj7YIm3L3mu6Ug= -github.com/go-chi/chi/v5 v5.2.5/go.mod h1:X7Gx4mteadT3eDOMTsXzmI4/rwUpOwBHLpAfupzFJP0= +github.com/go-chi/chi/v5 v5.5.0 h1:xdKQ1dJmVJsmgahrXSKhUx8NyVPzpwdlyrrQFpMPJgg= +github.com/go-chi/chi/v5 v5.5.0/go.mod h1:d1IG7GtKPSjPyBP365PH8sAGVHk3qfB/IhjFNRH1wWM= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= github.com/go-redis/redis v6.15.8+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= From 31ad41afd4d33e3fd7434b4cc54c17c2f2f6f9c0 Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Thu, 29 Oct 2026 12:22:21 -0500 Subject: [PATCH 16/28] fix(server): remove spoofable chiware.RealIP middleware (#454) RealIP is deprecated (vulnerable to IP spoofing), drop the unused middleware. --- server/server.go | 1 - 1 file changed, 1 deletion(-) diff --git a/server/server.go b/server/server.go index 06a40353..79ae0705 100644 --- a/server/server.go +++ b/server/server.go @@ -52,7 +52,6 @@ func setupRouter(ctx context.Context, logger *zerolog.Logger) (context.Context, r := chi.NewRouter() r.Use(chiware.RequestID) - r.Use(chiware.RealIP) r.Use(chiware.Heartbeat("/")) if logger != nil { From 4033575d41bc98d6e217117b561ca7dd707b4d63 Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Wed, 29 Oct 2025 03:56:20 -0500 Subject: [PATCH 17/28] chore(lint): update golangci-lint config --- .golangci.yaml | 472 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 443 insertions(+), 29 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 11193fa4..9c68ce0a 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,32 +1,314 @@ +# This file is licensed under the terms of the MIT license https://opensource.org/license/mit +# Copyright (c) 2021-2025 Marat Reymers + +## Golden config for golangci-lint v2.5.0 +# +# This is the best config for golangci-lint based on my experience and opinion. +# It is very strict, but not extremely strict. +# Feel free to adapt it to suit your needs. +# If this config helps you, please consider keeping a link to this file (see the next comment). + +# Based on https://gist.github.com/maratori/47a4d00457a92aa426dbd48a18776322 + version: "2" run: go: "1.25" timeout: 3m +issues: + # Maximum count of issues with the same text. + # Set to 0 to disable. + # Default: 3 + max-same-issues: 50 + +formatters: + enable: + - goimports # checks if the code and import statements are formatted according to the 'goimports' command + - golines # checks if code is formatted, and fixes long lines + + ## you may want to enable + #- gci # checks if code and import statements are formatted, with additional rules + #- gofmt # checks if the code is formatted according to 'gofmt' command + #- gofumpt # enforces a stricter format than 'gofmt', while being backwards compatible + #- swaggo # formats swaggo comments + + # All settings can be found here https://github.com/golangci/golangci-lint/blob/HEAD/.golangci.reference.yml + settings: + goimports: + # A list of prefixes, which, if set, checks import paths + # with the given prefixes are grouped after 3rd-party packages. + # Default: [] + local-prefixes: + - github.com/brave/go-sync + + golines: + # Target maximum line length. + # Default: 100 + max-len: 120 + linters: - default: none enable: - - govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string - - ineffassign # Detects when assignments to existing variables are not used - - revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. - - unused # Finds unused code + - asasalint # checks for pass []any as any in variadic func(...any) + - asciicheck # checks that your code does not contain non-ASCII identifiers + - bidichk # checks for dangerous unicode character sequences + - bodyclose # checks whether HTTP response body is closed successfully + - canonicalheader # checks whether net/http.Header uses canonical header + - copyloopvar # detects places where loop variables are copied (Go 1.22+) + - cyclop # checks function and package cyclomatic complexity + - depguard # checks if package imports are in a list of acceptable packages + - dupl # tool for code clone detection + - durationcheck # checks for two durations multiplied together + - embeddedstructfieldcheck # checks embedded types in structs + - errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases + - errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error + - errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13 + - exhaustive # checks exhaustiveness of enum switch statements + - exptostd # detects functions from golang.org/x/exp/ that can be replaced by std functions + - fatcontext # detects nested contexts in loops + - forbidigo # forbids identifiers + - funcorder # checks the order of functions, methods, and constructors + - funlen # tool for detection of long functions + - gocheckcompilerdirectives # validates go compiler directive comments (//go:) + - gochecknoglobals # checks that no global variables exist + - gochecknoinits # checks that no init functions are present in Go code + - gochecksumtype # checks exhaustiveness on Go "sum types" + - gocognit # computes and checks the cognitive complexity of functions + - goconst # finds repeated strings that could be replaced by a constant + - gocritic # provides diagnostics that check for bugs, performance and style issues + - gocyclo # computes and checks the cyclomatic complexity of functions + - godoclint # checks Golang's documentation practice + - godot # checks if comments end in a period + - gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod + - goprintffuncname # checks that printf-like functions are named with f at the end + - gosec # inspects source code for security problems + - govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string + - iface # checks the incorrect use of interfaces, helping developers avoid interface pollution + - ineffassign # detects when assignments to existing variables are not used + - intrange # finds places where for loops could make use of an integer range + - iotamixing # checks if iotas are being used in const blocks with other non-iota declarations + - loggercheck # checks key value pairs for common logger libraries (kitlog,klog,logr,zap) + - makezero # finds slice declarations with non-zero initial length + - mirror # reports wrong mirror patterns of bytes/strings usage + - mnd # detects magic numbers + - musttag # enforces field tags in (un)marshaled structs + - nakedret # finds naked returns in functions greater than a specified function length + - nestif # reports deeply nested if statements + - nilerr # finds the code that returns nil even if it checks that the error is not nil + - nilnesserr # reports that it checks for err != nil, but it returns a different nil value error (powered by nilness and nilerr) + - nilnil # checks that there is no simultaneous return of nil error and an invalid value + - noctx # finds sending http request without context.Context + - nolintlint # reports ill-formed or insufficient nolint directives + - nonamedreturns # reports all named returns + - nosprintfhostport # checks for misuse of Sprintf to construct a host with port in a URL + - perfsprint # checks that fmt.Sprintf can be replaced with a faster alternative + - predeclared # finds code that shadows one of Go's predeclared identifiers + - promlinter # checks Prometheus metrics naming via promlint + - protogetter # reports direct reads from proto message fields when getters should be used + - reassign # checks that package variables are not reassigned + - recvcheck # checks for receiver type consistency + - revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint + - rowserrcheck # checks whether Err of rows is checked successfully + - sloglint # ensure consistent code style when using log/slog + - spancheck # checks for mistakes with OpenTelemetry/Census spans + - sqlclosecheck # checks that sql.Rows and sql.Stmt are closed + - staticcheck # is a go vet on steroids, applying a ton of static analysis checks + - testableexamples # checks if examples are testable (have an expected output) + - testifylint # checks usage of github.com/stretchr/testify + - testpackage # makes you use a separate _test package + - tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes + - unconvert # removes unnecessary type conversions + - unparam # reports unused function parameters + - unqueryvet # detects SELECT * in SQL queries and SQL builders, encouraging explicit column selection + - unused # checks for unused constants, variables, functions and types + - usestdlibvars # detects the possibility to use variables/constants from the Go standard library + - usetesting # reports uses of functions with replacement inside the testing package + - wastedassign # finds wasted assignment statements + - whitespace # detects leading and trailing whitespace + + # enable after initial code cleanup + #- exhaustruct # [highly recommend to enable] checks if all structure fields are initialized + + ## you may want to enable + #- arangolint # opinionated best practices for arangodb client + #- decorder # checks declaration order and count of types, constants, variables and functions + #- ginkgolinter # [if you use ginkgo/gomega] enforces standards of using ginkgo and gomega + #- godox # detects usage of FIXME, TODO and other keywords inside comments + #- goheader # checks is file header matches to pattern + #- inamedparam # [great idea, but too strict, need to ignore a lot of cases by default] reports interfaces with unnamed method parameters + #- interfacebloat # checks the number of methods inside an interface + #- ireturn # accept interfaces, return concrete types + #- noinlineerr # disallows inline error handling `if err := ...; err != nil {` + #- prealloc # [premature optimization, but can be used in some cases] finds slice declarations that could potentially be preallocated + #- tagalign # checks that struct tags are well aligned + #- varnamelen # [great idea, but too many false positives] checks that the length of a variable's name matches its scope + #- wrapcheck # checks that errors returned from external packages are wrapped + #- zerologlint # detects the wrong usage of zerolog that a user forgets to dispatch zerolog.Event + + ## disabled + #- containedctx # detects struct contained context.Context field + #- contextcheck # [too many false positives] checks the function whether use a non-inherited context + #- dogsled # checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) + #- dupword # [useless without config] checks for duplicate words in the source code + #- err113 # [too strict] checks the errors handling expressions + #- errchkjson # [don't see profit + I'm against of omitting errors like in the first example https://github.com/breml/errchkjson] checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted + #- forcetypeassert # [replaced by errcheck] finds forced type assertions + #- gomodguard # [use more powerful depguard] allow and block lists linter for direct Go module dependencies + #- gosmopolitan # reports certain i18n/l10n anti-patterns in your Go codebase + #- grouper # analyzes expression groups + #- importas # enforces consistent import aliases + #- lll # [replaced by golines] reports long lines + #- maintidx # measures the maintainability index of each function + #- misspell # [useless] finds commonly misspelled English words in comments + #- nlreturn # [too strict and mostly code is not more readable] checks for a new line before return and branch statements to increase code clarity + #- paralleltest # [too many false positives] detects missing usage of t.Parallel() method in your Go test + #- tagliatelle # checks the struct tags + #- thelper # detects golang test helpers without t.Helper() call and checks the consistency of test helpers + #- wsl # [too strict and mostly code is not more readable] whitespace linter forces you to use empty lines + #- wsl_v5 # [too strict and mostly code is not more readable] add or remove empty lines + + # All settings can be found here https://github.com/golangci/golangci-lint/blob/HEAD/.golangci.reference.yml settings: cyclop: # The maximal code complexity to report. # Default: 10 - max-complexity: 10 + max-complexity: 30 # The maximal average package complexity. - # If it's higher than 0.0 (float) the check is enabled + # If it's higher than 0.0 (float) the check is enabled. # Default: 0.0 - package-average: 10 + package-average: 10.0 + + depguard: + # Rules to apply. + # + # Variables: + # - File Variables + # Use an exclamation mark `!` to negate a variable. + # Example: `!$test` matches any file that is not a go test file. + # + # `$all` - matches all go files + # `$test` - matches all go test files + # + # - Package Variables + # + # `$gostd` - matches all of go's standard library (Pulled from `GOROOT`) + # + # Default (applies if no custom rules are defined): Only allow $gostd in all files. + rules: + "deprecated": + # List of file globs that will match this list of settings to compare against. + # By default, if a path is relative, it is relative to the directory where the golangci-lint command is executed. + # The placeholder '${base-path}' is substituted with a path relative to the mode defined with `run.relative-path-mode`. + # The placeholder '${config-path}' is substituted with a path relative to the configuration file. + # Default: $all + files: + - "$all" + # List of packages that are not allowed. + # Entries can be a variable (starting with $), a string prefix, or an exact match (if ending with $). + # Default: [] + deny: + - pkg: github.com/golang/protobuf + desc: Use google.golang.org/protobuf instead, see https://developers.google.com/protocol-buffers/docs/reference/go/faq#modules + - pkg: github.com/satori/go.uuid + desc: Use github.com/google/uuid instead, satori's package is not maintained + - pkg: github.com/gofrs/uuid$ + desc: Use github.com/gofrs/uuid/v5 or later, it was not a go module before v5 + "non-test files": + files: + - "!$test" + deny: + - pkg: math/rand$ + desc: Use math/rand/v2 instead, see https://go.dev/blog/randv2 + "non-main files": + files: + - "!**/main.go" + deny: + - pkg: log$ + desc: Use log/slog instead, see https://go.dev/blog/slog + + embeddedstructfieldcheck: + # Checks that sync.Mutex and sync.RWMutex are not used as embedded fields. + # Default: false + forbid-mutex: true + errcheck: # Report about not checking of errors in type assertions: `a := b.(MyStruct)`. # Such cases aren't reported by default. # Default: false check-type-assertions: true + + exhaustive: + # Program elements to check for exhaustiveness. + # Default: [ switch ] + check: + - switch + - map + + exhaustruct: + # List of regular expressions to match type names that should be excluded from processing. + # Anonymous structs can be matched by '' alias. + # Has precedence over `include`. + # Each regular expression must match the full type name, including package path. + # For example, to match type `net/http.Cookie` regular expression should be `.*/http\.Cookie`, + # but not `http\.Cookie`. + # Default: [] + exclude: + # std libs + - ^net/http.Client$ + - ^net/http.Cookie$ + - ^net/http.Request$ + - ^net/http.Response$ + - ^net/http.Server$ + - ^net/http.Transport$ + - ^net/url.URL$ + - ^os/exec.Cmd$ + - ^reflect.StructField$ + # public libs + - ^github.com/Shopify/sarama.Config$ + - ^github.com/Shopify/sarama.ProducerMessage$ + - ^github.com/mitchellh/mapstructure.DecoderConfig$ + - ^github.com/prometheus/client_golang/.+Opts$ + - ^github.com/spf13/cobra.Command$ + - ^github.com/spf13/cobra.CompletionOptions$ + - ^github.com/stretchr/testify/mock.Mock$ + - ^github.com/testcontainers/testcontainers-go.+Request$ + - ^github.com/testcontainers/testcontainers-go.FromDockerfile$ + - ^golang.org/x/tools/go/analysis.Analyzer$ + - ^google.golang.org/protobuf/.+Options$ + - ^gopkg.in/yaml.v3.Node$ + # Allows empty structures in return statements. + # Default: false + allow-empty-returns: true + + funcorder: + # Checks if the exported methods of a structure are placed before the non-exported ones. + # Default: true + struct-method: false + + funlen: + # Checks the number of lines in a function. + # If lower than 0, disable the check. + # Default: 60 + lines: 100 + # Checks the number of statements in a function. + # If lower than 0, disable the check. + # Default: 40 + statements: 50 + + gochecksumtype: + # Presence of `default` case in switch statements satisfies exhaustiveness, if all members are not listed. + # Default: true + default-signifies-exhaustive: false + + gocognit: + # Minimal code complexity to report. + # Default: 30 (but we recommend 10-20) + min-complexity: 20 + gocritic: + # Settings passed to gocritic. + # The settings key is the name of a supported gocritic checker. + # The list of supported checkers can be found at https://go-critic.com/overview. settings: - # Must be valid enabled check name. captLocal: # Whether to restrict checker to params only. # Default: true @@ -35,27 +317,159 @@ linters: # Whether to skip (*x).method() calls where x is a pointer receiver. # Default: true skipRecvDeref: false - unused: - exported-fields-are-used: false + + godoclint: + # List of rules to enable in addition to the default set. + # Default: empty + enable: + # Assert no unused link in godocs. + # https://github.com/godoc-lint/godoc-lint?tab=readme-ov-file#no-unused-link + - no-unused-link + + govet: + # Enable all analyzers. + # Default: false + enable-all: true + # Disable analyzers by name. + # Run `GL_DEBUG=govet golangci-lint run --enable=govet` to see default, all available analyzers, and enabled analyzers. + # Default: [] + disable: + - fieldalignment # too strict + # Settings per analyzer. + settings: + shadow: + # Whether to be strict about shadowing; can be noisy. + # Default: false + strict: true + + inamedparam: + # Skips check for interface methods with only a single parameter. + # Default: false + skip-single-param: true + + mnd: + # List of function patterns to exclude from analysis. + # Values always ignored: `time.Date`, + # `strconv.FormatInt`, `strconv.FormatUint`, `strconv.FormatFloat`, + # `strconv.ParseInt`, `strconv.ParseUint`, `strconv.ParseFloat`. + # Default: [] + ignored-functions: + - args.Error + - flag.Arg + - flag.Duration.* + - flag.Float.* + - flag.Int.* + - flag.Uint.* + - os.Chmod + - os.Mkdir.* + - os.OpenFile + - os.WriteFile + - prometheus.ExponentialBuckets.* + - prometheus.LinearBuckets + + nakedret: + # Make an issue if func has more lines of code than this setting, and it has naked returns. + # Default: 30 + max-func-lines: 0 + + nolintlint: + # Exclude following linters from requiring an explanation. + # Default: [] + allow-no-explanation: [ funlen, gocognit, golines ] + # Enable to require an explanation of nonzero length after each nolint directive. + # Default: false + require-explanation: true + # Enable to require nolint directives to mention the specific linter being suppressed. + # Default: false + require-specific: true + + perfsprint: + # Optimizes into strings concatenation. + # Default: true + strconcat: false + + reassign: + # Patterns for global variable names that are checked for reassignment. + # See https://github.com/curioswitch/go-reassign#usage + # Default: ["EOF", "Err.*"] + patterns: + - ".*" + + rowserrcheck: + # database/sql is always checked. + # Default: [] + packages: + - github.com/jmoiron/sqlx + + sloglint: + # Enforce not using global loggers. + # Values: + # - "": disabled + # - "all": report all global loggers + # - "default": report only the default slog logger + # https://github.com/go-simpler/sloglint?tab=readme-ov-file#no-global + # Default: "" + no-global: all + # Enforce using methods that accept a context. + # Values: + # - "": disabled + # - "all": report all contextless calls + # - "scope": report only if a context exists in the scope of the outermost function + # https://github.com/go-simpler/sloglint?tab=readme-ov-file#context-only + # Default: "" + context: scope + + staticcheck: + # SAxxxx checks in https://staticcheck.dev/docs/configuration/options/#checks + # Example (to disable some checks): [ "all", "-SA1000", "-SA1001"] + # Default: ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022"] + checks: + - all + # Incorrect or missing package comment. + # https://staticcheck.dev/docs/checks/#ST1000 + - -ST1000 + # Use consistent method receiver names. + # https://staticcheck.dev/docs/checks/#ST1016 + - -ST1016 + # Omit embedded fields from selector expression. + # https://staticcheck.dev/docs/checks/#QF1008 + - -QF1008 + + usetesting: + # Enable/disable `os.TempDir()` detections. + # Default: false + os-temp-dir: true exclusions: - generated: lax + # Log a warning if an exclusion rule is unused. + # Default: false + warn-unused: true + # Predefined exclusion rules. + # Default: [] presets: - - comments - - common-false-positives - - legacy - std-error-handling - paths: - - third_party$ - - builtin$ - - examples$ - -formatters: - enable: - - gofmt - exclusions: - generated: lax - paths: - - third_party$ - - builtin$ - - examples$ + - common-false-positives + # Excluding configuration per-path, per-linter, per-text and per-source. + rules: + - source: 'TODO' + linters: [ godot ] + - text: 'should have a package comment' + linters: [ revive ] + - text: 'exported \S+ \S+ should have comment( \(or a comment on this block\))? or be unexported' + linters: [ revive ] + - text: 'package comment should be of the form ".+"' + source: '// ?(nolint|TODO)' + linters: [ revive ] + - text: 'comment on exported \S+ \S+ should be of the form ".+"' + source: '// ?(nolint|TODO)' + linters: [ revive, staticcheck ] + - path: '_test\.go' + linters: + - bodyclose + - dupl + - errcheck + - funlen + - goconst + - gosec + - noctx + - wrapcheck From 8b2fa80b3d175b8168efaa5eb01cffaadcd34134 Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Wed, 29 Oct 2025 04:11:04 -0500 Subject: [PATCH 18/28] chore(lint): add ARGS support to golangci-lint command in Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3f40a34c..94a030b7 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ test: go test -v ./... lint: - docker run -t --rm -v "$$(pwd):/app" -w /app golangci/golangci-lint golangci-lint run -v + docker run -t --rm -v "$$(pwd):/app" -w /app golangci/golangci-lint golangci-lint run -v $(ARGS) clean: rm -f sync-server From e90b8b5a4268ea985f74b56288c90a26a824479d Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Wed, 29 Oct 2025 04:38:37 -0500 Subject: [PATCH 19/28] chore(lint): add caching for golangci-lint in Makefile --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 94a030b7..e9553381 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,11 @@ test: go test -v ./... lint: - docker run -t --rm -v "$$(pwd):/app" -w /app golangci/golangci-lint golangci-lint run -v $(ARGS) + docker run -t --rm \ + -v "$$(pwd):/app" \ + -v go-sync-golangci-cache:/root/.cache/golangci-lint \ + -w /app \ + golangci/golangci-lint golangci-lint run -v $(ARGS) clean: rm -f sync-server From 5bf9a6d1a3ae951f294ab141a3fe8385331a73a7 Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Wed, 29 Oct 2025 05:54:17 -0500 Subject: [PATCH 20/28] chore(lint): disable godot, gochecknoglobals --- .golangci.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 9c68ce0a..e1762a8b 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -69,7 +69,6 @@ linters: - funcorder # checks the order of functions, methods, and constructors - funlen # tool for detection of long functions - gocheckcompilerdirectives # validates go compiler directive comments (//go:) - - gochecknoglobals # checks that no global variables exist - gochecknoinits # checks that no init functions are present in Go code - gochecksumtype # checks exhaustiveness on Go "sum types" - gocognit # computes and checks the cognitive complexity of functions @@ -77,7 +76,6 @@ linters: - gocritic # provides diagnostics that check for bugs, performance and style issues - gocyclo # computes and checks the cyclomatic complexity of functions - godoclint # checks Golang's documentation practice - - godot # checks if comments end in a period - gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod - goprintffuncname # checks that printf-like functions are named with f at the end - gosec # inspects source code for security problems @@ -127,6 +125,9 @@ linters: # enable after initial code cleanup #- exhaustruct # [highly recommend to enable] checks if all structure fields are initialized + #- godot # checks if comments end in a period + #- gochecknoglobals # checks that no global variables exist + ## you may want to enable #- arangolint # opinionated best practices for arangodb client From 18601f1c375d6c9014550595ad51dee14103f636 Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Wed, 5 Nov 2025 04:00:00 -0500 Subject: [PATCH 21/28] chore(lint): disnable protogetter linter and configure usestdlibvars --- .golangci.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.golangci.yaml b/.golangci.yaml index e1762a8b..e0c4c564 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -101,7 +101,6 @@ linters: - perfsprint # checks that fmt.Sprintf can be replaced with a faster alternative - predeclared # finds code that shadows one of Go's predeclared identifiers - promlinter # checks Prometheus metrics naming via promlint - - protogetter # reports direct reads from proto message fields when getters should be used - reassign # checks that package variables are not reassigned - recvcheck # checks for receiver type consistency - revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint @@ -127,6 +126,7 @@ linters: #- exhaustruct # [highly recommend to enable] checks if all structure fields are initialized #- godot # checks if comments end in a period #- gochecknoglobals # checks that no global variables exist + #- protogetter # reports direct reads from proto message fields when getters should be used ## you may want to enable @@ -436,6 +436,9 @@ linters: # https://staticcheck.dev/docs/checks/#QF1008 - -QF1008 + usestdlibvars: + http-method: false # do not suggest using http.MethodGet, http.MethodPost, etc. + usetesting: # Enable/disable `os.TempDir()` detections. # Default: false From 50bbabdb90c4533fe1da888c6dbad945b60cbabd Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Wed, 5 Nov 2025 06:26:11 -0500 Subject: [PATCH 22/28] chore(lint): enable gofmt and modernize linters, add errcheck args.Get exclusion --- .golangci.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.golangci.yaml b/.golangci.yaml index e0c4c564..77f6138b 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -25,10 +25,10 @@ formatters: enable: - goimports # checks if the code and import statements are formatted according to the 'goimports' command - golines # checks if code is formatted, and fixes long lines + - gofmt # checks if the code is formatted according to 'gofmt' command ## you may want to enable #- gci # checks if code and import statements are formatted, with additional rules - #- gofmt # checks if the code is formatted according to 'gofmt' command #- gofumpt # enforces a stricter format than 'gofmt', while being backwards compatible #- swaggo # formats swaggo comments @@ -86,6 +86,7 @@ linters: - iotamixing # checks if iotas are being used in const blocks with other non-iota declarations - loggercheck # checks key value pairs for common logger libraries (kitlog,klog,logr,zap) - makezero # finds slice declarations with non-zero initial length + - modernize # suggests using modern Go features - mirror # reports wrong mirror patterns of bytes/strings usage - mnd # detects magic numbers - musttag # enforces field tags in (un)marshaled structs @@ -477,3 +478,8 @@ linters: - gosec - noctx - wrapcheck + # Disable errcheck for testify mock args.Get() type assertions + - text: 'Error return value is not checked' + source: 'args\.Get\(' + linters: + - errcheck From 70ad6c220eb95691fb812dbaaae45504e892a5bd Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Wed, 5 Nov 2025 18:10:34 -0500 Subject: [PATCH 23/28] chore(lint): allow redis.Nil check --- .golangci.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.golangci.yaml b/.golangci.yaml index 77f6138b..06f8b53e 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -483,3 +483,8 @@ linters: source: 'args\.Get\(' linters: - errcheck + # Allow == comparison for known sentinel errors from external libraries + - text: 'comparing with == will fail on wrapped errors' + source: 'err == redis\.Nil' + linters: + - errorlint From ca2b84d5dbf49588eec0d82edae0d691b8231b1c Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Tue, 2 Dec 2025 05:50:16 -0500 Subject: [PATCH 24/28] chore(lint): disable mnd linter --- .golangci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yaml b/.golangci.yaml index 06f8b53e..5a48d208 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -88,7 +88,6 @@ linters: - makezero # finds slice declarations with non-zero initial length - modernize # suggests using modern Go features - mirror # reports wrong mirror patterns of bytes/strings usage - - mnd # detects magic numbers - musttag # enforces field tags in (un)marshaled structs - nakedret # finds naked returns in functions greater than a specified function length - nestif # reports deeply nested if statements @@ -139,6 +138,7 @@ linters: #- inamedparam # [great idea, but too strict, need to ignore a lot of cases by default] reports interfaces with unnamed method parameters #- interfacebloat # checks the number of methods inside an interface #- ireturn # accept interfaces, return concrete types + #- mnd # detects magic numbers #- noinlineerr # disallows inline error handling `if err := ...; err != nil {` #- prealloc # [premature optimization, but can be used in some cases] finds slice declarations that could potentially be preallocated #- tagalign # checks that struct tags are well aligned From c4f9bb49b5a6e00b0b0e554b259024e0a077250a Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Fri, 28 Aug 2026 19:06:34 -0500 Subject: [PATCH 25/28] chore(lint): ignore deprecated sync.proto fields --- .golangci.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.golangci.yaml b/.golangci.yaml index 5a48d208..5dd02624 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -488,3 +488,9 @@ linters: source: 'err == redis\.Nil' linters: - errorlint + # Chromium still ships CommitResponse.mtime as deprecated in sync.proto; + # we keep populating it for clients that read the field. + - path: 'command/command(_test)?\.go' + text: 'Marked as deprecated in sync\.proto' + linters: [ staticcheck ] + From 25b70bde03ee888171e1133809786640bab14834 Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Thu, 29 Oct 2026 16:46:49 +0100 Subject: [PATCH 26/28] chore(lint): replace deprecated exhaustive map check with mapliteral --- .golangci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yaml b/.golangci.yaml index 5dd02624..cfc8660b 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -243,7 +243,7 @@ linters: # Default: [ switch ] check: - switch - - map + - mapliteral exhaustruct: # List of regular expressions to match type names that should be excluded from processing. From 2cc68446b6c14dbca46dbb056cc799237c497c2d Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 6 Nov 2026 17:25:13 -0500 Subject: [PATCH 27/28] Merge pull request #412 from brave/renovate/amazon-dynamodb-local-3-x chore(deps): update amazon/dynamodb-local docker tag to v3.3.2 --- dynamo.Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dynamo.Dockerfile b/dynamo.Dockerfile index 07040a5d..274a3599 100644 --- a/dynamo.Dockerfile +++ b/dynamo.Dockerfile @@ -1,5 +1,5 @@ ARG DB_LOCATION=/home/dynamodblocal/db -FROM amazon/dynamodb-local:3.1.0 AS install +FROM amazon/dynamodb-local:3.3.2 AS install USER root RUN yum -y install awscli @@ -24,7 +24,7 @@ RUN mkdir -p ${DB_LOCATION} && \ --endpoint-url http://localhost:8000 && \ kill $DYNAMO_PID -FROM amazon/dynamodb-local:3.1.0 +FROM amazon/dynamodb-local:3.3.2 ARG DB_LOCATION COPY --chown=dynamodblocal:dynamodblocal --from=install ${DB_LOCATION} /db From 76745a639255f81c5a4a3d5093d6a3f0fa53f50e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 6 Nov 2026 17:35:04 -0500 Subject: [PATCH 28/28] fix(deps): update aws-sdk-go-v2 monorepo (#428) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- go.mod | 38 ++++++++++++++--------------- go.sum | 76 +++++++++++++++++++++++++++++----------------------------- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/go.mod b/go.mod index 5ca96437..375c8543 100644 --- a/go.mod +++ b/go.mod @@ -3,11 +3,11 @@ module github.com/brave/go-sync go 1.25.0 require ( - github.com/aws/aws-sdk-go-v2 v1.41.5 - github.com/aws/aws-sdk-go-v2/config v1.32.14 - github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.20.37 - github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression v1.8.37 - github.com/aws/aws-sdk-go-v2/service/dynamodb v1.57.1 + github.com/aws/aws-sdk-go-v2 v1.47.5 + github.com/aws/aws-sdk-go-v2/config v1.33.13 + github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.21.17 + github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression v1.10.5 + github.com/aws/aws-sdk-go-v2/service/dynamodb v1.72.3 github.com/brave-intl/bat-go/libs v0.0.0-20250620104757-9e2f8ff87fd8 github.com/getsentry/sentry-go v0.39.0 github.com/go-chi/chi/v5 v5.5.0 @@ -22,20 +22,20 @@ require ( require ( github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect - github.com/aws/aws-sdk-go-v2/credentials v1.19.14 // indirect - github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.21 // indirect - github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.21 // indirect - github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.21 // indirect - github.com/aws/aws-sdk-go-v2/internal/ini v1.8.6 // indirect - github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.32.14 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.7 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.11.21 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.21 // indirect - github.com/aws/aws-sdk-go-v2/service/signin v1.0.9 // indirect - github.com/aws/aws-sdk-go-v2/service/sso v1.30.15 // indirect - github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.19 // indirect - github.com/aws/aws-sdk-go-v2/service/sts v1.41.10 // indirect - github.com/aws/smithy-go v1.24.2 // indirect + github.com/aws/aws-sdk-go-v2/credentials v1.20.13 // indirect + github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.20.5 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.5.8 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.8.8 // indirect + github.com/aws/aws-sdk-go-v2/internal/v4a v1.5.8 // indirect + github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.46.4 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.23 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.13.8 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.14.8 // indirect + github.com/aws/aws-sdk-go-v2/service/signin v1.12.1 // indirect + github.com/aws/aws-sdk-go-v2/service/sso v1.39.1 // indirect + github.com/aws/aws-sdk-go-v2/service/ssooidc v1.44.1 // indirect + github.com/aws/aws-sdk-go-v2/service/sts v1.51.6 // indirect + github.com/aws/smithy-go v1.28.7 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect diff --git a/go.sum b/go.sum index bd4b08e7..4083264b 100644 --- a/go.sum +++ b/go.sum @@ -4,44 +4,44 @@ github.com/alicebob/miniredis/v2 v2.23.0 h1:+lwAJYjvvdIVg6doFHuotFjueJ/7KY10xo/v github.com/alicebob/miniredis/v2 v2.23.0/go.mod h1:XNqvJdQJv5mSuVMc0ynneafpnL/zv52acZ6kqeS0t88= github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so= github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= -github.com/aws/aws-sdk-go-v2 v1.41.5 h1:dj5kopbwUsVUVFgO4Fi5BIT3t4WyqIDjGKCangnV/yY= -github.com/aws/aws-sdk-go-v2 v1.41.5/go.mod h1:mwsPRE8ceUUpiTgF7QmQIJ7lgsKUPQOUl3o72QBrE1o= -github.com/aws/aws-sdk-go-v2/config v1.32.14 h1:opVIRo/ZbbI8OIqSOKmpFaY7IwfFUOCCXBsUpJOwDdI= -github.com/aws/aws-sdk-go-v2/config v1.32.14/go.mod h1:U4/V0uKxh0Tl5sxmCBZ3AecYny4UNlVmObYjKuuaiOo= -github.com/aws/aws-sdk-go-v2/credentials v1.19.14 h1:n+UcGWAIZHkXzYt87uMFBv/l8THYELoX6gVcUvgl6fI= -github.com/aws/aws-sdk-go-v2/credentials v1.19.14/go.mod h1:cJKuyWB59Mqi0jM3nFYQRmnHVQIcgoxjEMAbLkpr62w= -github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.20.37 h1:5jh3kI8vDKuAcNa87z3eytYvBCE4Tyk2S8vjdcLoMek= -github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.20.37/go.mod h1:Q1MNQdT5LEs31od7h6zHZF2a6jjl+oI6/kBH3QYipoY= -github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression v1.8.37 h1:8clVLUTp0bBO7SZx5Nw0Q1XhF4ItE8W1hboDK9eHIN0= -github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression v1.8.37/go.mod h1:U0KNwNOuLUPi/vdIWh6qYVBK4v8zKjN6BPpbsHSmPPA= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.21 h1:NUS3K4BTDArQqNu2ih7yeDLaS3bmHD0YndtA6UP884g= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.21/go.mod h1:YWNWJQNjKigKY1RHVJCuupeWDrrHjRqHm0N9rdrWzYI= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.21 h1:Rgg6wvjjtX8bNHcvi9OnXWwcE0a2vGpbwmtICOsvcf4= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.21/go.mod h1:A/kJFst/nm//cyqonihbdpQZwiUhhzpqTsdbhDdRF9c= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.21 h1:PEgGVtPoB6NTpPrBgqSE5hE/o47Ij9qk/SEZFbUOe9A= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.21/go.mod h1:p+hz+PRAYlY3zcpJhPwXlLC4C+kqn70WIHwnzAfs6ps= -github.com/aws/aws-sdk-go-v2/internal/ini v1.8.6 h1:qYQ4pzQ2Oz6WpQ8T3HvGHnZydA72MnLuFK9tJwmrbHw= -github.com/aws/aws-sdk-go-v2/internal/ini v1.8.6/go.mod h1:O3h0IK87yXci+kg6flUKzJnWeziQUKciKrLjcatSNcY= -github.com/aws/aws-sdk-go-v2/service/dynamodb v1.57.1 h1:Vk+a1j2pXZHkkYqHmEdpwe8eX6NDtFSBGfzuauMEWYQ= -github.com/aws/aws-sdk-go-v2/service/dynamodb v1.57.1/go.mod h1:wHrWCwhXZrl2PuCP5t36UTacy9fCHDJ+vw1r3qxTL5M= -github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.32.14 h1:Cnlebj/RmCf/4O3q4suVLLB/SBhbQf4zCQre6Dav+4E= -github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.32.14/go.mod h1:lB9U9zBLviMTUHcHaaJ/vDBkRpHxV5775VJcdnm1DFk= -github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.7 h1:5EniKhLZe4xzL7a+fU3C2tfUN4nWIqlLesfrjkuPFTY= -github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.7/go.mod h1:x0nZssQ3qZSnIcePWLvcoFisRXJzcTVvYpAAdYX8+GI= -github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.11.21 h1:FTg+rVAPx1W21jsO57pxDS1ESy9a/JLFoaHeFubflJA= -github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.11.21/go.mod h1:92xP4VIS1yO3eF2NPBaHGF4cmyZow8TmFzSaz1nNgzo= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.21 h1:c31//R3xgIJMSC8S6hEVq+38DcvUlgFY0FM6mSI5oto= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.21/go.mod h1:r6+pf23ouCB718FUxaqzZdbpYFyDtehyZcmP5KL9FkA= -github.com/aws/aws-sdk-go-v2/service/signin v1.0.9 h1:QKZH0S178gCmFEgst8hN0mCX1KxLgHBKKY/CLqwP8lg= -github.com/aws/aws-sdk-go-v2/service/signin v1.0.9/go.mod h1:7yuQJoT+OoH8aqIxw9vwF+8KpvLZ8AWmvmUWHsGQZvI= -github.com/aws/aws-sdk-go-v2/service/sso v1.30.15 h1:lFd1+ZSEYJZYvv9d6kXzhkZu07si3f+GQ1AaYwa2LUM= -github.com/aws/aws-sdk-go-v2/service/sso v1.30.15/go.mod h1:WSvS1NLr7JaPunCXqpJnWk1Bjo7IxzZXrZi1QQCkuqM= -github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.19 h1:dzztQ1YmfPrxdrOiuZRMF6fuOwWlWpD2StNLTceKpys= -github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.19/go.mod h1:YO8TrYtFdl5w/4vmjL8zaBSsiNp3w0L1FfKVKenZT7w= -github.com/aws/aws-sdk-go-v2/service/sts v1.41.10 h1:p8ogvvLugcR/zLBXTXrTkj0RYBUdErbMnAFFp12Lm/U= -github.com/aws/aws-sdk-go-v2/service/sts v1.41.10/go.mod h1:60dv0eZJfeVXfbT1tFJinbHrDfSJ2GZl4Q//OSSNAVw= -github.com/aws/smithy-go v1.24.2 h1:FzA3bu/nt/vDvmnkg+R8Xl46gmzEDam6mZ1hzmwXFng= -github.com/aws/smithy-go v1.24.2/go.mod h1:YE2RhdIuDbA5E5bTdciG9KrW3+TiEONeUWCqxX9i1Fc= +github.com/aws/aws-sdk-go-v2 v1.47.5 h1:5yA+A+BiXbDq1ZLbYwPViwhEGDMdR0MEhL8Jh2LnLS4= +github.com/aws/aws-sdk-go-v2 v1.47.5/go.mod h1:iNIkogrRvFwm+1OQIUOP2lPBtlXZboOIUWiCa+pHEMw= +github.com/aws/aws-sdk-go-v2/config v1.33.13 h1:u52x6ISQOx172tpwM0VRxhJzEsTJYpMcEYUGM2A1wrw= +github.com/aws/aws-sdk-go-v2/config v1.33.13/go.mod h1:/ixtz6XPHb42zekjQ0LqD9XjTpTysNWhIGwufY1OzI4= +github.com/aws/aws-sdk-go-v2/credentials v1.20.13 h1:j4z41OtspmQ3ftQycaDunJ26b69a9SHfaSVUPqgRv8k= +github.com/aws/aws-sdk-go-v2/credentials v1.20.13/go.mod h1:SgPA1oS3b+dlMxZb618jDmGNscpXSCaxz15igS52OlE= +github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.21.17 h1:ML2l+ADkvyL8ztff61JLR46pPb9/ukdeKC7r8CwlaSg= +github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.21.17/go.mod h1:Xboz5uzoEY8kIcetu/0THEGLBzaYoL8+aNwDJUNwbJ4= +github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression v1.10.5 h1:hmVzfIAhudRPwRyO43B5QNvuGiuGGdKcHu1b1V5ef5s= +github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression v1.10.5/go.mod h1:Tym9WvcWFfhGpPRmf9fM8IkLoh6OYG/eKGwHUB8oQ70= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.20.5 h1:iXjy2SFhGYNB1jWZBhQqq8HbhsbPF23w+/zbMvPXsTg= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.20.5/go.mod h1:k0RUiBnyXU0AXRJ9tJmY2jQke6XUIX2PNVnWtvgaPtc= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.5.8 h1:gzIWc3DTPfPbWKrQnmL6BV6WD7NPD1htxzgdk/bQ/Z4= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.5.8/go.mod h1:vvUA5cDAZWGo4R14FZPZfXfJCmgsafOWEq78Kg0D+ug= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.8.8 h1:PWv+vG8aCLS8qd+HPdYhK7Vees90aKHWFFQ1AGYD/8E= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.8.8/go.mod h1:xxPZEpflYHJA12366ZGyq66z9dHPCoeCIu99Jck+MPw= +github.com/aws/aws-sdk-go-v2/internal/v4a v1.5.8 h1:WOp5De9iWdEHDPh2Kb0tBP3vGBm/dVAuRGh4a4tqduo= +github.com/aws/aws-sdk-go-v2/internal/v4a v1.5.8/go.mod h1:z8W8YgfhbWl62XqcTtK+CxPrE+iHGRVUOtrrbIOp7ZY= +github.com/aws/aws-sdk-go-v2/service/dynamodb v1.72.3 h1:W2GBZXhuN8NshnX0y6emc1AHp++za3XmPAFEVJ5ZdD0= +github.com/aws/aws-sdk-go-v2/service/dynamodb v1.72.3/go.mod h1:8AVcr/vb8bgJu2xczpXR3NMmQGG2w32FnaDs/dy1Aq0= +github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.46.4 h1:2dyCVnVjyUBJ72p+48spXZRco60pFynUEjZnnnCpLgo= +github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.46.4/go.mod h1:V25GXiTMhCdLxKNWsQcOVQS6gWPIzdQzthspbcwY3pc= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.23 h1:MCIR6iZaCKO4UE0hUvoWWLI6JVjppopV64JfAJaMjng= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.23/go.mod h1:pphWFS+z0MmIPivj8c/6bATd1Z+Av7Ust75DPdEFsPA= +github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.13.8 h1:xCaLoExpQNJicsc4k3fmmdvG/UqEhUX4YTxOGWt/eow= +github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.13.8/go.mod h1:RtTo73Ln8hbPjHFE22MEp/JcHOnAOQZIOSXjS4rLYzM= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.14.8 h1:+PMpWlJYOn2tm7sm6OZ/ZLd4jStl17T7wjNapd1Rczs= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.14.8/go.mod h1:cnG3xZLGQL4c/bt8pjdzlFtZsW7epBBuNS04a5xMjdo= +github.com/aws/aws-sdk-go-v2/service/signin v1.12.1 h1:WZLC+k/CZx11kZGQDqu9mpA8yhiXGX2I//jhuJE1FDo= +github.com/aws/aws-sdk-go-v2/service/signin v1.12.1/go.mod h1:wxAk0D2oVBSjuXEIzvcKxTZfM90zticdAbh/VD42L0Y= +github.com/aws/aws-sdk-go-v2/service/sso v1.39.1 h1:4VB/dnDo7pmXSLQMszSoBzWndENuc7mzwTpD6lQn77A= +github.com/aws/aws-sdk-go-v2/service/sso v1.39.1/go.mod h1:UGsEYgWz4Gi+46vDQ5zkFLqUgJziyOE2SXjZjgmfmHc= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.44.1 h1:w8yui2ZqdHmGwVBDGvazoIvKw/DnLENBLkYnN8q8iqo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.44.1/go.mod h1:gJSdIY6YUzDvqQLcMtPVZgBRHrFwzHryvpE8Igzbxps= +github.com/aws/aws-sdk-go-v2/service/sts v1.51.6 h1:BVjKrtRUtSYKztBCCfE1oAB+d3ViKcW2cKZfserOqMQ= +github.com/aws/aws-sdk-go-v2/service/sts v1.51.6/go.mod h1:eSukFLeLkPMm+1OxDR+F0joauZdyBkF47Ow7MqjZiJw= +github.com/aws/smithy-go v1.28.7 h1:h/n1SHrwVtaDYLz8mR1/Kq4Xh4RaFbFW7bOYckg9mfE= +github.com/aws/smithy-go v1.28.7/go.mod h1:YE2RhdIuDbA5E5bTdciG9KrW3+TiEONeUWCqxX9i1Fc= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/brave-intl/bat-go/libs v0.0.0-20250620104757-9e2f8ff87fd8 h1:DUBBDWBwozxpET6HCTDSRKAfyiqKRNvOyeqI463epaI=