Skip to content

Commit 84ceebb

Browse files
Dont crash sidecar on failure and Prometheus metrics (#19)
* Changing behavior of sidecar mode. - Sidecar mode failures no longer terminate vct. - VCT running in sidecar mode now runs prometheus metrics endpoint. - Various cleanup and refactoring. * Improve changelog file * Fix debug logging for logging timeout duration in seconds. * Initial sidecar sync failure should emit sync error metrics. * - group imports - prometheus port defaults to 9191 now * - cleanup
1 parent c4cbf81 commit 84ceebb

File tree

16 files changed

+338
-102
lines changed

16 files changed

+338
-102
lines changed

CHANGELOG

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
v1.3.0: 22-Nov-2021
2+
* Errors during sync loop while running sidecar mode will no longer terminate vault-ctrl-tool.
3+
* Sidecar mode now can run a Prometheus metrics endpoint which emits metrics about sidecar syncs.
4+
Prometheus can be toggled with "--enable-prometheus-metrics" and have its port overridden by "--prometheus-port".
5+
* Added better documentation and some refactoring and cleanup of internal libraries.
6+
* Vault client HTTP timeout and maxRetries are now configurable using "--vault-client-timeout" and "--vault-client-retries" flags.
7+
Note: These now default to 30s and 2, respectively. Compared to previous version of vault-ctrl-tool which where 60s, 2.
8+
19
v1.2.0: 26-May-2021
210
* Added --force-refresh-ttl which temporary credentials will optionally be renewed before their actual expiry.
311
* Added --sts-ttl flag which lets you specify token ttl for aws tokens

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CURRENTOS := $(shell go env GOOS)
22
CURRENTARCH := $(shell go env GOARCH)
33
COMMIT := $(shell git rev-parse --short HEAD)
4-
VERSION := v1.2.0
4+
VERSION := v1.3.0
55
LDFLAGS="-X main.buildVersion=$(VERSION) -X main.commitVersion=$(COMMIT)"
66

77
.DEFAULT_GOAL := build
@@ -19,6 +19,7 @@ test: mocks ## Run unit tests
1919

2020
darwin-binary: mocks ## Build a macOS binary
2121
GOOS=darwin GOARCH=amd64 go build -trimpath -ldflags $(LDFLAGS) -o bin/vault-ctrl-tool.darwin.amd64 .
22+
GOOS=darwin GOARCH=arm64 go build -trimpath -ldflags $(LDFLAGS) -o bin/vault-ctrl-tool.darwin.arm64 .
2223

2324
linux-binary: mocks ## Build a Linux (amd64) binary
2425
GOOS=linux GOARCH=amd64 go build -trimpath -ldflags $(LDFLAGS) -o bin/vault-ctrl-tool.linux.amd64 .

briefcase/briefcase.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"errors"
7+
"fmt"
78
"io/ioutil"
89
"time"
910

@@ -111,13 +112,13 @@ func LoadBriefcase(filename string, mtrics *metrics.Metrics) (*Briefcase, error)
111112
zlog.Info().Str("filename", filename).Msg("reading briefcase")
112113
bytes, err := ioutil.ReadFile(filename)
113114
if err != nil {
114-
return nil, err
115+
return nil, fmt.Errorf("could not read briefcase data: %w", err)
115116
}
116117

117118
bc := NewBriefcase(mtrics)
118119
err = json.Unmarshal(bytes, bc)
119120
if err != nil {
120-
return nil, err
121+
return nil, fmt.Errorf("could not parse briefcase data: %w", err)
121122
}
122123

123124
return bc, nil

e2e/e2e_test.go

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ package e2e
33
import (
44
"context"
55
"encoding/json"
6+
"io/ioutil"
7+
"os"
8+
"path"
9+
"testing"
10+
"time"
11+
612
"github.com/golang/mock/gomock"
713
"github.com/hashicorp/vault/api"
814
mtrics "github.com/hootsuite/vault-ctrl-tool/v2/metrics"
915
"github.com/hootsuite/vault-ctrl-tool/v2/util/clock"
1016
"github.com/stretchr/testify/assert"
11-
"io/ioutil"
1217
testing2 "k8s.io/utils/clock/testing"
13-
"os"
14-
"path"
15-
"testing"
16-
"time"
1718
)
1819

1920
// TestSyncWithPinnedVersion ensures that when requesting a specific version of a secret in a config file cascades
@@ -53,8 +54,10 @@ secrets:
5354

5455
fakeClock := testing2.NewFakeClock(time.Now())
5556
ctx := clock.Set(context.Background(), fakeClock)
56-
err := fixture.syncer.PerformSync(ctx, fakeClock.Now().AddDate(1, 0, 0), *fixture.cliFlags)
5757

58+
vtoken, err := fixture.syncer.GetVaultToken(ctx, *fixture.cliFlags)
59+
assert.NoError(t, err)
60+
err = fixture.syncer.PerformSync(ctx, vtoken, fakeClock.Now().AddDate(1, 0, 0), *fixture.cliFlags)
5861
assert.NoError(t, err)
5962
assert.FileExists(t, path.Join(fixture.workDir, "example-output"))
6063
assert.Equal(t, 1, fixture.metrics.Counter(mtrics.SecretUpdates))
@@ -97,7 +100,10 @@ secrets:
97100

98101
fakeClock := testing2.NewFakeClock(time.Now())
99102
ctx := clock.Set(context.Background(), fakeClock)
100-
err := fixture1.syncer.PerformSync(ctx, fakeClock.Now().AddDate(1, 0, 0), *fixture1.cliFlags)
103+
104+
vtoken, err := fixture1.syncer.GetVaultToken(ctx, *fixture1.cliFlags)
105+
assert.NoError(t, err)
106+
err = fixture1.syncer.PerformSync(ctx, vtoken, fakeClock.Now().AddDate(1, 0, 0), *fixture1.cliFlags)
101107

102108
assert.NoError(t, err)
103109
assert.FileExists(t, path.Join(fixture1.workDir, "foo"))
@@ -124,7 +130,9 @@ secrets:
124130
return response, nil
125131
}).Times(1)
126132

127-
err = fixture2.syncer.PerformSync(ctx, fakeClock.Now().AddDate(1, 0, 0), *fixture1.cliFlags)
133+
vtoken, err = fixture2.syncer.GetVaultToken(ctx, *fixture2.cliFlags)
134+
assert.NoError(t, err)
135+
err = fixture2.syncer.PerformSync(ctx, vtoken, fakeClock.Now().AddDate(1, 0, 0), *fixture1.cliFlags)
128136

129137
assert.NoError(t, err)
130138
assert.FileExists(t, path.Join(fixture2.workDir, "foo"))
@@ -178,7 +186,9 @@ secrets:
178186
fakeClock := testing2.NewFakeClock(time.Date(2019, 10, 2, 22, 52, 20, 0, time.UTC))
179187

180188
ctx := clock.Set(context.Background(), fakeClock)
181-
err := fixture1.syncer.PerformSync(ctx, fakeClock.Now().AddDate(1, 0, 0), *fixture1.cliFlags)
189+
vtoken, err := fixture1.syncer.GetVaultToken(ctx, *fixture1.cliFlags)
190+
assert.NoError(t, err)
191+
err = fixture1.syncer.PerformSync(ctx, vtoken, fakeClock.Now().AddDate(1, 0, 0), *fixture1.cliFlags)
182192

183193
assert.NoError(t, err)
184194
assert.FileExists(t, path.Join(fixture1.workDir, "foo"))
@@ -209,7 +219,9 @@ secrets:
209219
return response, nil
210220
}).Times(1)
211221

212-
err = fixture2.syncer.PerformSync(ctx, fakeClock.Now().AddDate(1, 0, 0), *fixture1.cliFlags)
222+
vtoken, err = fixture2.syncer.GetVaultToken(ctx, *fixture2.cliFlags)
223+
assert.NoError(t, err)
224+
err = fixture2.syncer.PerformSync(ctx, vtoken, fakeClock.Now().AddDate(1, 0, 0), *fixture1.cliFlags)
213225

214226
assert.NoError(t, err)
215227

@@ -247,7 +259,9 @@ version: 3
247259

248260
fakeClock := testing2.NewFakeClock(time.Now())
249261
ctx := clock.Set(context.Background(), fakeClock)
250-
err := fixture.syncer.PerformSync(ctx, fakeClock.Now().AddDate(1, 0, 0), *fixture.cliFlags)
262+
vtoken, err := fixture.syncer.GetVaultToken(ctx, *fixture.cliFlags)
263+
assert.NoError(t, err)
264+
err = fixture.syncer.PerformSync(ctx, vtoken, fakeClock.Now().AddDate(1, 0, 0), *fixture.cliFlags)
251265

252266
assert.NoError(t, err)
253267
assert.Equal(t, 1, fixture.metrics.Counter(mtrics.BriefcaseReset))
@@ -295,7 +309,9 @@ secrets:
295309

296310
fakeClock := testing2.NewFakeClock(time.Now())
297311
ctx := clock.Set(context.Background(), fakeClock)
298-
err := fixture.syncer.PerformSync(ctx, fakeClock.Now().AddDate(1, 0, 0), *fixture.cliFlags)
312+
vtoken, err := fixture.syncer.GetVaultToken(ctx, *fixture.cliFlags)
313+
assert.NoError(t, err)
314+
err = fixture.syncer.PerformSync(ctx, vtoken, fakeClock.Now().AddDate(1, 0, 0), *fixture.cliFlags)
299315

300316
assert.NoError(t, err)
301317

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ module github.com/hootsuite/vault-ctrl-tool/v2
33
go 1.15
44

55
require (
6-
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
7-
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
86
github.com/aws/aws-sdk-go v1.35.25
97
github.com/golang/mock v1.5.0
108
github.com/hashicorp/vault/api v1.0.4
9+
github.com/prometheus/client_golang v1.11.0
1110
github.com/rs/zerolog v1.20.0
1211
github.com/stretchr/testify v1.6.1
1312
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0

0 commit comments

Comments
 (0)