diff --git a/.gitignore b/.gitignore index 951abe5..436debc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea dynamodb-sync -.idea +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..21b1251 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,25 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com + +version: 2 + +before: + hooks: + - rm -rf ./dist + - go mod tidy + - go generate ./... + +builds: + - env: [CGO_ENABLED=0] + goos: + - linux + goarch: + - amd64 + - arm64 + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" diff --git a/go.mod b/go.mod index 1f68824..3d4b585 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/thumbtack/dynamodb-sync go 1.22 require ( - github.com/aws/aws-sdk-go v1.50.32 + github.com/aws/aws-sdk-go v1.54.1 github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.9.0 golang.org/x/time v0.5.0 diff --git a/go.sum b/go.sum index 669d017..db74b0e 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/aws/aws-sdk-go v1.50.32 h1:POt81DvegnpQKM4DMDLlHz1CO6OBnEoQ1gRhYFd7QRY= -github.com/aws/aws-sdk-go v1.50.32/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= +github.com/aws/aws-sdk-go v1.54.1 h1:+ULL7oLC+v3T00fOMIohUarPI3SR3oyDd6FBEvgdhvs= +github.com/aws/aws-sdk-go v1.54.1/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= 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= diff --git a/main.go b/main.go index 35fcb3b..65c9d76 100644 --- a/main.go +++ b/main.go @@ -1,5 +1,5 @@ /* - Copyright 2024 Thumbtack, Inc. + Copyright 2018-2024 Thumbtack, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/replicate.go b/replicate.go index 59e4583..08d866c 100644 --- a/replicate.go +++ b/replicate.go @@ -28,7 +28,7 @@ func (ss *syncState) isFreshStart() bool { "dst table": ss.checkpointPK.dstTable, "State Timestamp": ss.timestamp, }).Info("Checking if fresh start") - return ss.timestamp.IsZero() || time.Now().Sub(ss.timestamp) > streamRetentionHours + return ss.timestamp.IsZero() || time.Since(ss.timestamp) > streamRetentionHours } func (ss *syncState) replicate(quit <-chan bool) { diff --git a/stream.go b/stream.go index f08c78e..93845df 100644 --- a/stream.go +++ b/stream.go @@ -1,7 +1,6 @@ package main import ( - "errors" "fmt" "time" @@ -17,10 +16,8 @@ func (ss *syncState) getStreamArn() (string, error) { TableName: aws.String(ss.tableConfig.SrcTable), }) if err != nil || describeTableResult.Table.StreamSpecification == nil { - return "", errors.New(fmt.Sprintf( - "Failed to get StreamARN for table %s. Check if stream is enabled", - ss.checkpointPK.sourceTable), - ) + return "", fmt.Errorf("failed to get StreamARN for table %s. Check if stream is enabled", + ss.checkpointPK.sourceTable) } streamArn := describeTableResult.Table.LatestStreamArn logger.WithFields(logging.Fields{ diff --git a/table.go b/table.go index 8d76d7d..fd9f3a9 100644 --- a/table.go +++ b/table.go @@ -213,8 +213,7 @@ func increaseCapacity( }).Error("failed to increase capacity") return err } - waitForTableUpdate(tableName, dynamo) - return nil + return waitForTableUpdate(tableName, dynamo) } func decreaseCapacity( @@ -243,8 +242,7 @@ func decreaseCapacity( }).Error("failed to decrease capacity") return err } - waitForTableUpdate(tableName, dynamo) - return nil + return waitForTableUpdate(tableName, dynamo) } func generateGsiUpdate( @@ -271,7 +269,7 @@ func generateGsiUpdate( return result } -func waitForTableUpdate(tableName string, dynamo *dynamodb.DynamoDB) { +func waitForTableUpdate(tableName string, dynamo *dynamodb.DynamoDB) error { status := "" statusInput := &dynamodb.DescribeTableInput{ TableName: aws.String(tableName), @@ -284,20 +282,19 @@ func waitForTableUpdate(tableName string, dynamo *dynamodb.DynamoDB) { "error": err, }).Error("failed to get the table status") // likely an internal error from DDB, nothing can be done here - break + return err } else { status = *output.Table.TableStatus logger.WithFields(logging.Fields{ "table": tableName, }).Debug("Updating table throughput") - time.Sleep(1 * time.Second) + time.Sleep(3 * time.Second) } } - if status == "ACTIVE" { - logger.WithFields(logging.Fields{ - "Table": tableName, - }).Info("Successfully updated table throughput") - } + logger.WithFields(logging.Fields{ + "Table": tableName, + }).Info("Successfully updated table throughput") + return nil } // getCapacity returns the read and write capacity of the given table and its gsi diff --git a/utils.go b/utils.go index 5622d30..9a0f427 100644 --- a/utils.go +++ b/utils.go @@ -2,7 +2,6 @@ package main import ( "encoding/json" - "io/ioutil" "net/http" "os" "strings" @@ -44,7 +43,7 @@ func getSession(region, endpoint string, httpClient *http.Client) *session.Sessi // parseConfigFile reads and parses the config file func parseConfigFile(filepath string) (configs []*syncConfig, err error) { var data []byte - data, err = ioutil.ReadFile(filepath) + data, err = os.ReadFile(filepath) if err == nil { err = json.Unmarshal(data, &configs) }