Skip to content

Commit bf47352

Browse files
bump ancla, fix datacenter watch (#589)
* bump ancla, fix datacenter watch * fixed datacenter watch tests * fixed basculechecks tests * updated changelog, prep for release
1 parent 17466b7 commit bf47352

File tree

9 files changed

+211
-82
lines changed

9 files changed

+211
-82
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
## [v2.0.3]
10+
- Bumped argus to v0.6.0 and fixed related datacenter watch code. [#589](https://github.com/xmidt-org/webpa-common/pull/589)
11+
912
## [v2.0.2]
1013
- Added logic to xhttp for retrying on http errors.[#588](https://github.com/xmidt-org/webpa-common/pull/588)
1114

@@ -220,7 +223,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
220223
- The first official release. We will be better about documenting changes
221224
moving forward.
222225

223-
[Unreleased]: https://github.com/xmidt-org/webpa-common/compare/v2.0.2...HEAD
226+
[Unreleased]: https://github.com/xmidt-org/webpa-common/compare/v2.0.3...HEAD
227+
[v2.0.3]: https://github.com/xmidt-org/webpa-common/compare/v2.0.2...v2.0.3
224228
[v2.0.2]: https://github.com/xmidt-org/webpa-common/compare/v2.0.1...v2.0.2
225229
[v2.0.1]: https://github.com/xmidt-org/webpa-common/compare/v2.0.0...v2.0.1
226230
[v2.0.0]: https://github.com/xmidt-org/webpa-common/compare/v1.11.9...v2.0.0

basculechecks/capabilitiesvalidator_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ func TestCheckCapabilities(t *testing.T) {
230230
}
231231

232232
func TestGetCapabilities(t *testing.T) {
233+
type testType int
233234
goodKeyVal := []string{"cap1", "cap2"}
234235
emptyVal := []string{}
235236
getCapabilitiesErr := errors.New("couldn't get capabilities using key")
@@ -280,7 +281,7 @@ func TestGetCapabilities(t *testing.T) {
280281
},
281282
{
282283
description: "Non String List Capabilities Error",
283-
keyValue: []int{0, 1, 2},
284+
keyValue: []testType{0, 1, 2},
284285
expectedVals: emptyVal,
285286
expectedReason: UndeterminedCapabilities,
286287
expectedErr: badCapabilitiesErr,

basculechecks/metricvalidator.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@ import (
2222
"fmt"
2323
"regexp"
2424

25-
"github.com/go-kit/kit/log"
2625
"github.com/spf13/cast"
2726
"github.com/xmidt-org/bascule"
2827
)
2928

30-
var defaultLogger = log.NewNopLogger()
31-
3229
// CapabilitiesChecker is an object that can determine if a request is
3330
// authorized given a bascule.Authentication object. If it's not authorized, a
3431
// reason and error are given for logging and metrics.

basculechecks/metricvalidator_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ func TestMetricValidatorFunc(t *testing.T) {
147147
}
148148

149149
func TestPrepMetrics(t *testing.T) {
150+
type testType int
150151
var (
151152
goodURL = "/asnkfn/aefkijeoij/aiogj"
152153
matchingURL = "/fnvvdsjkfji/mac:12345544322345334/geigosj"
@@ -221,7 +222,7 @@ func TestPrepMetrics(t *testing.T) {
221222
},
222223
{
223224
description: "Non String Slice Partner ID Error",
224-
partnerIDs: []int{0, 1, 2},
225+
partnerIDs: []testType{0, 1, 2},
225226
url: goodURL,
226227
includeToken: true,
227228
includeAttributes: true,

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ require (
1313
github.com/gorilla/mux v1.8.0
1414
github.com/gorilla/schema v1.0.3-0.20180614150749-e0e4b92809ac
1515
github.com/gorilla/websocket v1.4.2
16-
github.com/hashicorp/consul/api v1.7.0
16+
github.com/hashicorp/consul/api v1.10.1
1717
github.com/jtacoma/uritemplates v1.0.0
1818
github.com/justinas/alice v1.2.0
1919
github.com/miekg/dns v1.1.26
20-
github.com/mitchellh/mapstructure v1.4.1
20+
github.com/mitchellh/mapstructure v1.4.2
2121
github.com/prometheus/client_golang v1.10.0
2222
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da
2323
github.com/segmentio/ksuid v1.0.2
24-
github.com/spf13/cast v1.3.1
24+
github.com/spf13/cast v1.4.1
2525
github.com/spf13/pflag v1.0.5
26-
github.com/spf13/viper v1.7.1
26+
github.com/spf13/viper v1.9.0
2727
github.com/stretchr/testify v1.7.0
2828
github.com/ugorji/go/codec v1.1.7
29-
github.com/xmidt-org/argus v0.5.1
29+
github.com/xmidt-org/argus v0.6.0
3030
github.com/xmidt-org/bascule v0.10.2
3131
github.com/xmidt-org/candlelight v0.0.5
3232
github.com/xmidt-org/themis v0.4.7

go.sum

Lines changed: 140 additions & 30 deletions
Large diffs are not rendered by default.

service/consul/datacenterWatch.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package consul
33
import (
44
"context"
55
"errors"
6+
"fmt"
67
"sync"
78
"time"
89

@@ -21,7 +22,7 @@ type datacenterWatcher struct {
2122
environment Environment
2223
options Options
2324
inactiveDatacenters map[string]bool
24-
chrysomClient *chrysom.Client
25+
stopListener func(context.Context) error
2526
consulWatchInterval time.Duration
2627
lock sync.RWMutex
2728
}
@@ -75,15 +76,18 @@ func newDatacenterWatcher(logger log.Logger, environment Environment, options Op
7576
m := &chrysom.Measures{
7677
Polls: environment.Provider().NewCounterVec(chrysom.PollCounter),
7778
}
78-
chrysomClient, err := chrysom.NewClient(options.Chrysom, m, getLogger, logging.WithLogger)
79-
79+
basic, err := chrysom.NewBasicClient(options.Chrysom.BasicClientConfig, getLogger, logging.WithLogger)
80+
if err != nil {
81+
return nil, fmt.Errorf("failed to create chrysom basic client: %v", err)
82+
}
83+
listener, err := chrysom.NewListenerClient(options.Chrysom.Listen, logging.WithLogger, m, basic)
8084
if err != nil {
81-
return nil, err
85+
return nil, fmt.Errorf("failed to create chrysom listener client: %v", err)
8286
}
8387

8488
//create chrysom client and start it
85-
datacenterWatcher.chrysomClient = chrysomClient
86-
datacenterWatcher.chrysomClient.Start(context.Background())
89+
datacenterWatcher.stopListener = listener.Stop
90+
listener.Start(context.Background())
8791
logger.Log(level.Key(), level.DebugValue(), logging.MessageKey(), "started chrysom, argus client")
8892
}
8993

@@ -97,8 +101,8 @@ func newDatacenterWatcher(logger log.Logger, environment Environment, options Op
97101
}
98102

99103
func (d *datacenterWatcher) stop() {
100-
if d.chrysomClient != nil {
101-
d.chrysomClient.Stop(context.Background())
104+
if d.stopListener != nil {
105+
d.stopListener(context.Background())
102106
}
103107
}
104108

service/consul/datacenterWatch_test.go

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,22 @@ func TestNewDatacenterWatcher(t *testing.T) {
2929
noProviderEnv := new(service.MockEnvironment)
3030
noProviderEnv.On("Provider").Return(nil, false)
3131

32-
validChrysomConfig := chrysom.ClientConfig{
33-
Bucket: "random-bucket",
34-
Listen: chrysom.ListenerConfig{
35-
PullInterval: 10 * time.Second,
32+
validChrysomConfig := ChrysomConfig{
33+
BasicClientConfig: chrysom.BasicClientConfig{
34+
Bucket: "random-bucket",
35+
Address: "http://argus:6600",
36+
Auth: chrysom.Auth{
37+
Basic: "Basic auth",
38+
},
39+
Logger: logger,
3640
},
37-
Address: "http://argus:6600",
38-
Auth: chrysom.Auth{
39-
Basic: "Basic auth",
41+
Listen: chrysom.ListenerClientConfig{
42+
PullInterval: 10 * time.Second,
4043
},
41-
Logger: logger,
4244
}
4345

46+
nopStop := func(_ context.Context) error { return nil }
47+
4448
tests := []struct {
4549
description string
4650
logger log.Logger
@@ -79,8 +83,10 @@ func TestNewDatacenterWatcher(t *testing.T) {
7983
mockServiceEnvironment, new(mockClient),
8084
},
8185
options: Options{
82-
Chrysom: chrysom.ClientConfig{
83-
Bucket: "",
86+
Chrysom: ChrysomConfig{
87+
BasicClientConfig: chrysom.BasicClientConfig{
88+
Bucket: "",
89+
},
8490
},
8591
},
8692
expectedWatcher: &datacenterWatcher{
@@ -115,7 +121,7 @@ func TestNewDatacenterWatcher(t *testing.T) {
115121
},
116122
consulWatchInterval: defaultWatchInterval,
117123
inactiveDatacenters: make(map[string]bool),
118-
chrysomClient: &chrysom.Client{},
124+
stopListener: nopStop,
119125
},
120126
},
121127
{
@@ -139,7 +145,7 @@ func TestNewDatacenterWatcher(t *testing.T) {
139145
},
140146
inactiveDatacenters: make(map[string]bool),
141147
consulWatchInterval: 10 * time.Second,
142-
chrysomClient: &chrysom.Client{},
148+
stopListener: nopStop,
143149
},
144150
},
145151
{
@@ -201,39 +207,40 @@ func TestNewDatacenterWatcher(t *testing.T) {
201207
mockServiceEnvironment, new(mockClient),
202208
},
203209
options: Options{
204-
Chrysom: chrysom.ClientConfig{
205-
Bucket: "random-bucket",
206-
Listen: chrysom.ListenerConfig{
207-
PullInterval: 0,
210+
Chrysom: ChrysomConfig{
211+
BasicClientConfig: chrysom.BasicClientConfig{
212+
Bucket: "random-bucket",
213+
Address: "http://argus:6600",
214+
Auth: chrysom.Auth{
215+
Basic: "Basic auth",
216+
},
217+
Logger: logger,
208218
},
209-
Address: "http://argus:6600",
210-
Auth: chrysom.Auth{
211-
Basic: "Basic auth",
219+
Listen: chrysom.ListenerClientConfig{
220+
PullInterval: 0,
212221
},
213-
Logger: logger,
214222
},
215223
},
216224
expectedErr: errors.New("chrysom pull interval cannot be 0"),
217225
},
218226
}
219227

220-
for _, testCase := range tests {
221-
t.Run(testCase.description, func(t *testing.T) {
228+
for _, tc := range tests {
229+
t.Run(tc.description, func(t *testing.T) {
222230
assert := assert.New(t)
223-
w, err := newDatacenterWatcher(testCase.logger, testCase.environment, testCase.options)
231+
w, err := newDatacenterWatcher(tc.logger, tc.environment, tc.options)
224232

225-
if testCase.expectedErr == nil {
233+
if tc.expectedErr == nil {
226234
assert.NotNil(w.inactiveDatacenters)
227-
assert.Equal(testCase.expectedWatcher.consulWatchInterval, w.consulWatchInterval)
228-
229-
if testCase.expectedWatcher.chrysomClient != nil {
230-
assert.NotNil(w.chrysomClient)
231-
testCase.expectedWatcher.chrysomClient = w.chrysomClient
235+
assert.Equal(tc.expectedWatcher.consulWatchInterval, w.consulWatchInterval)
236+
assert.Equal(tc.expectedWatcher.logger, w.logger)
237+
assert.Equal(tc.expectedWatcher.environment, w.environment)
238+
assert.Equal(tc.expectedWatcher.options, w.options)
239+
if tc.expectedWatcher.stopListener != nil {
240+
assert.NotNil(w.stopListener)
232241
}
233-
234-
assert.Equal(testCase.expectedWatcher, w)
235242
} else {
236-
assert.Equal(testCase.expectedErr, err)
243+
assert.Equal(tc.expectedErr, err)
237244
}
238245

239246
})

service/consul/options.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@ type Watch struct {
1919

2020
type Options struct {
2121
Client *api.Config `json:"client"`
22-
Chrysom chrysom.ClientConfig `json:"chrysom"`
22+
Chrysom ChrysomConfig `json:"chrysom"`
2323
DisableGenerateID bool `json:"disableGenerateID"`
2424
DatacenterRetries int `json:"datacenterRetries"`
2525
DatacenterWatchInterval time.Duration `json:"datacenterWatchInterval"`
2626
Registrations []api.AgentServiceRegistration `json:"registrations,omitempty"`
2727
Watches []Watch `json:"watches,omitempty"`
2828
}
2929

30+
type ChrysomConfig struct {
31+
chrysom.BasicClientConfig `mapstructure:",squash"`
32+
Listen chrysom.ListenerClientConfig
33+
}
34+
3035
func (o *Options) config() *api.Config {
3136
if o != nil && o.Client != nil {
3237
return o.Client

0 commit comments

Comments
 (0)