Skip to content

Commit 1b53ca4

Browse files
authored
Merge pull request #80 from practo/keep-alive
Keep alive support for redshift connection
2 parents 98338ac + 5df3e33 commit 1b53ca4

39 files changed

+442
-964
lines changed

redshiftsink/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ BASEIMAGE ?= gcr.io/distroless/static
2525

2626
TAG := $(VERSION)
2727

28-
BUILD_IMAGE ?= golang:1.15.1-alpine
28+
BUILD_IMAGE ?= golang:1.15.2-alpine
2929

3030
# If you want to build all binaries, see the 'all-build' rule.
3131
# If you want to build all containers, see the 'all-container' rule.

redshiftsink/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ require (
66
github.com/Shopify/sarama v1.26.5-0.20200810201100-25aedae6c37b
77
github.com/aws/aws-sdk-go v1.34.1
88
github.com/hashicorp/go-multierror v1.0.0
9-
github.com/lib/pq v1.8.0
109
github.com/linkedin/goavro/v2 v2.9.8
1110
github.com/practo/gobatch v0.0.0-20200822085922-4905d08d9f40
1211
github.com/practo/klog/v2 v2.2.1
12+
github.com/practo/pq v0.0.0-20200930024154-af3ceb106a20
1313
github.com/prometheus/client_golang v1.7.0
1414
github.com/riferrei/srclient v0.0.0-20200820123217-6a5d2a4bf9d1
1515
github.com/spf13/cobra v1.0.0

redshiftsink/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
169169
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
170170
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
171171
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
172-
github.com/lib/pq v1.8.0 h1:9xohqzkUwzR4Ga4ivdTcawVS89YSDVxXMa3xJX3cGzg=
173-
github.com/lib/pq v1.8.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
174172
github.com/linkedin/goavro/v2 v2.9.7/go.mod h1:UgQUb2N/pmueQYH9bfqFioWxzYCZXSfF8Jw03O5sjqA=
175173
github.com/linkedin/goavro/v2 v2.9.8 h1:jN50elxBsGBDGVDEKqUlDuU1cFwJ11K/yrJCBMe/7Wg=
176174
github.com/linkedin/goavro/v2 v2.9.8/go.mod h1:UgQUb2N/pmueQYH9bfqFioWxzYCZXSfF8Jw03O5sjqA=
@@ -214,6 +212,8 @@ github.com/practo/gobatch v0.0.0-20200822085922-4905d08d9f40 h1:ukO+fKWBM3U9LYZh
214212
github.com/practo/gobatch v0.0.0-20200822085922-4905d08d9f40/go.mod h1:OR//ozfD9hhQvQ1exBwHezn3VtEV1BjaLWj1LP+gAAk=
215213
github.com/practo/klog/v2 v2.2.1 h1:yV/SavG73KHSmCVwtDap1RGe+2jd86e1eugT+Mv2/FA=
216214
github.com/practo/klog/v2 v2.2.1/go.mod h1:WMkpfPwTxLgSLookpI4UUv2zL7tMltKACK/FHB1zLV0=
215+
github.com/practo/pq v0.0.0-20200930024154-af3ceb106a20 h1:05vUPBE8rE/C036Jb/Rzt4699sv+GzZSxAWVlw0wblk=
216+
github.com/practo/pq v0.0.0-20200930024154-af3ceb106a20/go.mod h1:C7JAQ0g3vCXYh7S7oWN8aTirSBqT8Xi4bUbGi1jP9Ak=
217217
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
218218
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
219219
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=

redshiftsink/pkg/redshift/redshift.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import (
1111
// Use our own version of the postgres library so we get keep-alive support.
1212
// See https://github.com/Clever/pq/pull/1
1313
// TODO: https://github.com/Clever/s3-to-redshift/issues/163
14-
_ "github.com/lib/pq"
14+
// TCP keep alive support pending: https://github.com/lib/pq/issues/360
15+
_ "github.com/practo/pq"
1516
"strings"
1617
)
1718

@@ -68,6 +69,9 @@ type dbExecCloser interface {
6869
QueryContext(
6970
c context.Context, q string, a ...interface{}) (*sql.Rows, error)
7071
QueryRowContext(c context.Context, q string, a ...interface{}) *sql.Row
72+
// tcp max conn time
73+
// https://github.com/lib/pq/issues/360#issuecomment-565121408
74+
// SetConnMaxLifetime(d time.Duration)
7175
}
7276

7377
// Redshift wraps a dbExecCloser and can be used to perform
@@ -128,7 +132,7 @@ type ColInfo struct {
128132

129133
func NewRedshift(ctx context.Context, conf RedshiftConfig) (*Redshift, error) {
130134
source := fmt.Sprintf(
131-
"host=%s port=%s dbname=%s connect_timeout=%d",
135+
"host=%s port=%s dbname=%s keepalive=1 connect_timeout=%d",
132136
conf.Host, conf.Port, conf.Database, conf.Timeout,
133137
)
134138
// TODO: make ssl configurable
@@ -141,7 +145,13 @@ func NewRedshift(ctx context.Context, conf RedshiftConfig) (*Redshift, error) {
141145
if err := sqldb.Ping(); err != nil {
142146
return nil, err
143147
}
144-
return &Redshift{sqldb, ctx, conf}, nil
148+
r := &Redshift{sqldb, ctx, conf}
149+
150+
// TODO: not using this
151+
// klog.Info("Setting Redshift ConnMaxLifetime=-1 (keep alive)")
152+
// r.SetConnMaxLifetime(1200 * time.Second)
153+
154+
return r, nil
145155
}
146156

147157
// Begin wraps a new transaction in the databases context

redshiftsink/vendor/github.com/lib/pq/README.md

Lines changed: 0 additions & 30 deletions
This file was deleted.

redshiftsink/vendor/github.com/lib/pq/connector.go

Lines changed: 0 additions & 115 deletions
This file was deleted.

redshiftsink/vendor/github.com/lib/pq/go.mod

Lines changed: 0 additions & 3 deletions
This file was deleted.

redshiftsink/vendor/github.com/lib/pq/krb.go

Lines changed: 0 additions & 27 deletions
This file was deleted.

redshiftsink/vendor/github.com/lib/pq/notice.go

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)