Skip to content

Commit

Permalink
Merge pull request #22 from maier/master
Browse files Browse the repository at this point in the history
v0.0.11
  • Loading branch information
maier authored May 16, 2023
2 parents f52099e + e48a4fa commit fe5ce24
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 22 deletions.
10 changes: 3 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ linters-settings:

linters:
enable:
- deadcode
- errcheck
- gocritic
- gofmt
Expand All @@ -49,15 +48,11 @@ linters:
- misspell
- prealloc
- staticcheck
- structcheck
- typecheck
- unparam
- unused
- varcheck
# - gci
- godot
- godox
# - goerr113
- predeclared
- unconvert
- wrapcheck
Expand All @@ -67,13 +62,14 @@ linters:
- errorlint
- wrapcheck
- goconst
# - stylecheck
- forcetypeassert
# - goimports
disable:
- scopelint # deprecated
- golint # deprecated
- maligned # deprecated
- varcheck # deprecated
- structcheck # deprecated
- deadcode # deprecated
disable-all: false
presets:
- bugs
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v0.0.11

* fix: init broker list correctly in edge cases
* fix: lint, struct alignment
* fix: lint, unused param

# v0.0.10

* feat: add gzip size of sent data stat
Expand Down
14 changes: 14 additions & 0 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,17 @@ func (tc *TrapCheck) fetchBroker(cid, checkType string) error {
if cid == "" {
return fmt.Errorf("invalid broker cid (empty)")
}

if checkType == "" {
return fmt.Errorf("invalid check type (empty)")
}

if tc.brokerList == nil {
if err := tc.initBrokerList(); err != nil {
return err
}
}

broker, err := tc.brokerList.GetBroker(cid)
// broker, err := tc.client.FetchBroker(apiclient.CIDType(&cid))
if err != nil {
Expand All @@ -55,6 +63,12 @@ func (tc *TrapCheck) getBroker(checkType string) error {
return tc.fetchBroker(tc.checkConfig.Brokers[0], checkType)
}

if tc.brokerList == nil {
if err := tc.initBrokerList(); err != nil {
return err
}
}

//
// otherwise, select an applicable broker
//
Expand Down
2 changes: 1 addition & 1 deletion check_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/circonus-labs/go-apiclient"
)

func (tc *TrapCheck) UpdateCheckTags(ctx context.Context, tags []string) (*apiclient.CheckBundle, error) {
func (tc *TrapCheck) UpdateCheckTags(_ context.Context, tags []string) (*apiclient.CheckBundle, error) {
if tc.checkBundle == nil {
return nil, fmt.Errorf("invalid state, check bundle is nil")
}
Expand Down
8 changes: 4 additions & 4 deletions internal/broker_list/broker_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ type BrokerList interface {
SearchBrokerList(searchTags apiclient.TagType) (*[]apiclient.Broker, error)
}

type brokerList struct {
type brokerList struct { //nolint:govet
lastRefresh time.Time
logger Logger
client API
brokers *[]apiclient.Broker
sync.Mutex
logger Logger
client API
brokers *[]apiclient.Broker
}

var brokerListInstance *brokerList
Expand Down
6 changes: 6 additions & 0 deletions tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ func (tc *TrapCheck) clearTLSConfig() {
// setBrokerTLSConfig sets the broker tls configuration if was
// not supplied by the caller in the configuration.
func (tc *TrapCheck) setBrokerTLSConfig() error {
if tc.brokerList == nil {
if err := tc.initBrokerList(); err != nil {
return err
}
}

if tc.resetTLSConfig {
tc.broker = nil // force refresh
tc.tlsConfig = nil // don't use, refresh and reset
Expand Down
34 changes: 24 additions & 10 deletions trapcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,6 @@ func New(cfg *Config) (*TrapCheck, error) {
}
}

if err := brokerList.Init(cfg.Client, tc.Log); err != nil {
return nil, fmt.Errorf("initializing broker list: %w", err)
}

if bl, err := brokerList.GetInstance(); err != nil {
return nil, fmt.Errorf("getting broker list instance: %w", err)
} else {
tc.brokerList = bl
}

dur := cfg.BrokerMaxResponseTime
if dur == "" {
dur = defaultBrokerMaxResponseTime
Expand Down Expand Up @@ -165,6 +155,10 @@ func New(cfg *Config) (*TrapCheck, error) {
tc.checkBundle = tc.checkConfig
}

if err := tc.initBrokerList(); err != nil {
return nil, err
}

if err := tc.setBrokerTLSConfig(); err != nil {
return nil, err
}
Expand Down Expand Up @@ -249,13 +243,33 @@ func NewFromCheckBundle(cfg *Config, bundle *apiclient.CheckBundle) (*TrapCheck,

tc.submissionURL = surl

if err := tc.initBrokerList(); err != nil {
return nil, err
}

if err := tc.setBrokerTLSConfig(); err != nil {
return nil, err
}

return tc, nil
}

func (tc *TrapCheck) initBrokerList() error {
if tc.brokerList != nil {
return nil
}
if err := brokerList.Init(tc.client, tc.Log); err != nil {
return fmt.Errorf("initializing broker list: %w", err)
}

bl, err := brokerList.GetInstance()
if err != nil {
return fmt.Errorf("getting broker list instance: %w", err)
}
tc.brokerList = bl
return nil
}

// SendMetrics submits the metrics to the broker
// metrics must be valid JSON encoded data for the broker httptrap check
// returns trap results in a structure or an error.
Expand Down

0 comments on commit fe5ce24

Please sign in to comment.