Skip to content

Commit 180a113

Browse files
authored
Add GH workflow and goreleaser, run gofmt (#18)
1 parent 09ce9e4 commit 180a113

File tree

13 files changed

+163
-71
lines changed

13 files changed

+163
-71
lines changed

.github/workflows/test.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Test
2+
3+
on: [push]
4+
5+
jobs:
6+
go-test:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: set up go
10+
uses: actions/setup-go@v2
11+
with:
12+
go-version: 1.22
13+
- name: checkout the code
14+
uses: actions/checkout@v2
15+
- name: check format
16+
run: if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then exit 1; fi
17+
# - name: test
18+
# run: make test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
.idea
12
dynamodb-sync
3+
4+
dist/

.goreleaser.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
version: 2
3+
4+
before:
5+
hooks:
6+
- rm -rf ./dist
7+
- go mod tidy
8+
- go generate ./...
9+
10+
builds:
11+
- env: [CGO_ENABLED=0]
12+
goos:
13+
- linux
14+
goarch:
15+
- amd64
16+
- arm64
17+
18+
changelog:
19+
sort: asc
20+
filters:
21+
exclude:
22+
- "^docs:"
23+
- "^test:"

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.PHONY: clean
2+
clean:
3+
rm -f dynamodb-sync
4+
5+
.PHONY: fmt
6+
fmt:
7+
gofmt -s -w .
8+
9+
.PHONY: test
10+
test:
11+
go test -v ./...
12+
13+
.PHONY: build
14+
build: clean
15+
GOOS=linux GOARCH=amd64 go build

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
# dynamodb-sync
1+
[![Test build status](https://github.com/thumbtack/dynamodb-sync/workflows/Test/badge.svg)](https://github.com/thumbtack/dynamodb-sync/actions?query=workflow%3ATest)
2+
3+
## dynamodb-sync

checkpoint.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ func (sync *syncState) isCheckpointFound(key primaryKey) bool {
128128

129129
// Update the checkpoint for `key's` local state
130130
// sync : timestamp,
131-
// checkpoint[`shardId`]: `sequenceNumber`
131+
//
132+
// checkpoint[`shardId`]: `sequenceNumber`
132133
func (sync *syncState) updateCheckpointLocal(
133134
key primaryKey,
134135
sequenceNumber string,

go.mod

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module github.com/thumbtack/dynamodb-sync
2+
3+
go 1.22
4+
5+
require (
6+
github.com/aws/aws-sdk-go v1.54.1
7+
github.com/sirupsen/logrus v1.9.3
8+
golang.org/x/time v0.5.0
9+
)
10+
11+
require (
12+
github.com/jmespath/go-jmespath v0.4.0 // indirect
13+
github.com/stretchr/testify v1.9.0 // indirect
14+
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
15+
)

go.sum

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
github.com/aws/aws-sdk-go v1.54.1 h1:+ULL7oLC+v3T00fOMIohUarPI3SR3oyDd6FBEvgdhvs=
2+
github.com/aws/aws-sdk-go v1.54.1/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
3+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
5+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6+
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
7+
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
8+
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
9+
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
10+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
11+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
12+
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
13+
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
14+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
15+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
16+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
17+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
18+
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
19+
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
20+
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
21+
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
22+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
23+
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
24+
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
25+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
26+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
27+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

main.go

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,8 @@ package main
2525
import (
2626
"encoding/json"
2727
"errors"
28-
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
2928
"strings"
3029

31-
//"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
32-
"github.com/thumbtack/go/lib/metrics"
33-
//"github.com/thumbtack/go/lib/monitoring"
3430
"io/ioutil"
3531
"net/http"
3632
_ "net/http/pprof"
@@ -40,6 +36,7 @@ import (
4036
"time"
4137

4238
"github.com/aws/aws-sdk-go/aws"
39+
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
4340
"github.com/aws/aws-sdk-go/aws/session"
4441
"github.com/aws/aws-sdk-go/service/dynamodb"
4542
"github.com/aws/aws-sdk-go/service/dynamodbstreams"
@@ -61,7 +58,6 @@ var ddbTable = os.Getenv(paramCheckpointTable)
6158
var ddbRegion = os.Getenv(paramCheckpointRegion)
6259
var ddbEndpoint = os.Getenv(paramCheckpointEndpoint)
6360
var ddbClient = ddbConfigConnect(ddbRegion, ddbEndpoint, maxRetries, *logger)
64-
var metricsClient = newMetricsClient()
6561

6662
type config struct {
6763
SrcTable string `json:"src_table"`
@@ -77,7 +73,7 @@ type config struct {
7773
ReadQps int64 `json:"read_qps"`
7874
WriteQps int64 `json:"write_qps"`
7975
UpdateCheckpointThreshold int `json:"update_checkpoint_threshold"`
80-
EnableStreaming *bool `json:"enable_streaming"`
76+
EnableStreaming *bool `json:"enable_streaming"`
8177
}
8278

8379
// Config file is read and dumped into this struct
@@ -108,12 +104,12 @@ func NewSyncState(tableConfig config) *syncState {
108104
var stream *dynamodbstreams.DynamoDBStreams
109105

110106
tr := &http.Transport{
111-
MaxIdleConns: 2048,
112-
MaxConnsPerHost: 1024,
107+
MaxIdleConns: 2048,
108+
MaxConnsPerHost: 1024,
113109
}
114110
httpClient := &http.Client{
115-
Timeout:8*time.Second,
116-
Transport:tr}
111+
Timeout: 8 * time.Second,
112+
Transport: tr}
117113

118114
srcSess := session.Must(
119115
session.NewSession(
@@ -169,8 +165,8 @@ func NewSyncState(tableConfig config) *syncState {
169165
}
170166

171167
type appConfig struct {
172-
sync []config
173-
verbose bool
168+
sync []config
169+
verbose bool
174170
}
175171

176172
// The primary key of the Checkpoint ddb table, of the stream etc
@@ -199,15 +195,6 @@ func ddbConfigConnect(region string, endpoint string, maxRetries int, logger log
199195
)))
200196
}
201197

202-
func newMetricsClient() (client metrics.Client) {
203-
client, err := metrics.NewAlfredAppClient()
204-
if err != nil {
205-
logger.WithFields(logging.Fields{"Error":err}).Error("Error in initializing metrics")
206-
os.Exit(1)
207-
}
208-
return client
209-
}
210-
211198
// app constructor
212199
func NewApp() *appConfig {
213200
logger.SetLevel(logging.InfoLevel)
@@ -239,8 +226,8 @@ func NewApp() *appConfig {
239226
}
240227

241228
return &appConfig{
242-
sync: tableConfig,
243-
verbose: true,
229+
sync: tableConfig,
230+
verbose: true,
244231
}
245232
}
246233

@@ -277,7 +264,6 @@ func setDefaults(tableConfig []config) ([]config, error) {
277264
continue
278265
}
279266

280-
281267
if tableConfig[i].ReadQps == 0 {
282268
tableConfig[i].ReadQps = 500
283269
}

replicate.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package main
22

33
import (
4-
"golang.org/x/time/rate"
54
"sync"
65
"time"
76

7+
"golang.org/x/time/rate"
8+
89
"github.com/aws/aws-sdk-go/aws"
910
"github.com/aws/aws-sdk-go/service/dynamodb"
1011
"github.com/aws/aws-sdk-go/service/dynamodbstreams"
@@ -196,8 +197,8 @@ func (sync *syncState) streamSync(key primaryKey, streamArn string) error {
196197
numShards := 0
197198

198199
type shardStats struct {
199-
numShards int
200-
tableName string
200+
numShards int
201+
tableName string
201202
}
202203

203204
type activeShardStats struct {
@@ -227,7 +228,7 @@ func (sync *syncState) streamSync(key primaryKey, streamArn string) error {
227228
}
228229

229230
numShards += len(result.StreamDescription.Shards)
230-
231+
231232
for _, shard := range result.StreamDescription.Shards {
232233
sync.checkpointLock.RLock()
233234
_, ok := sync.expiredShards[*shard.ShardId]

0 commit comments

Comments
 (0)