Skip to content

Commit

Permalink
use aws http client builder and add back aws cfg settings
Browse files Browse the repository at this point in the history
  • Loading branch information
rt-joe committed May 25, 2024
1 parent cd834f6 commit 3c185e4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ require (
)

require (
github.com/aws/aws-sdk-go-v2 v1.26.1
github.com/aws/aws-sdk-go-v2 v1.26.2
github.com/aws/aws-sdk-go-v2/config v1.27.13
github.com/aws/aws-sdk-go-v2/service/timestreamquery v1.23.1
github.com/aws/aws-sdk-go-v2/service/timestreamwrite v1.25.6
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/aws/aws-sdk-go-v2 v1.26.1 h1:5554eUqIYVWpU0YmeeYZ0wU64H2VLBs8TlhRB2L+EkA=
github.com/aws/aws-sdk-go-v2 v1.26.1/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM=
github.com/aws/aws-sdk-go-v2 v1.26.2 h1:OTRAL8EPdNoOdiq5SUhCaHhVPBU2wxAUe5uwasoJGRM=
github.com/aws/aws-sdk-go-v2 v1.26.2/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM=
github.com/aws/aws-sdk-go-v2/config v1.27.13 h1:WbKW8hOzrWoOA/+35S5okqO/2Ap8hkkFUzoW8Hzq24A=
github.com/aws/aws-sdk-go-v2/config v1.27.13/go.mod h1:XLiyiTMnguytjRER7u5RIkhIqS8Nyz41SwAWb4xEjxs=
github.com/aws/aws-sdk-go-v2/credentials v1.17.13 h1:XDCJDzk/u5cN7Aple7D/MiAhx1Rjo/0nueJ0La8mRuE=
Expand Down
29 changes: 11 additions & 18 deletions timestream.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import (
"context"
"fmt"
"math"
"net"
"net/http"
"strconv"
"strings"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/timestreamquery"
"github.com/aws/aws-sdk-go-v2/service/timestreamwrite"
Expand Down Expand Up @@ -82,25 +82,18 @@ func newTimestreamQueryPaginator(client TimestreamQueryApi, params *timestreamqu
}

func newTimeStreamAdapter(ctx context.Context, logger *zap.SugaredLogger, cfg *adapterCfg, newQueryPaginator NewQueryPaginator, writeSvc *timestreamwrite.Client, querySvc *timestreamquery.Client) TimeStreamAdapter {
tr := &http.Transport{
ResponseHeaderTimeout: 20 * time.Second,
// Using DefaultTransport values for other parameters: https://golang.org/pkg/net/http/#RoundTripper
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
KeepAlive: 30 * time.Second,
Timeout: 30 * time.Second,
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
if writeSvc == nil || querySvc == nil {
client := awshttp.NewBuildableClient().WithTransportOptions(func(tr *http.Transport) {
tr.ResponseHeaderTimeout = 20 * time.Second

// So client makes HTTP/2 requests
_ = http2.ConfigureTransport(tr)
// Enable HTTP/2
err := http2.ConfigureTransport(tr)
if err != nil {
logger.Fatalw("Unable to configure HTTP/2 transport", "error", err)
}
})

if writeSvc == nil || querySvc == nil {
awsCfg, err := config.LoadDefaultConfig(ctx, config.WithRegion(cfg.awsRegion))
awsCfg, err := config.LoadDefaultConfig(ctx, config.WithRegion(cfg.awsRegion), config.WithHTTPClient(client), config.WithRetryMaxAttempts(10))
if err != nil {
logger.Fatalw("Unable to load AWS SDK config", "error", err)
}
Expand Down

0 comments on commit 3c185e4

Please sign in to comment.