Skip to content

Commit

Permalink
Merge pull request #21 from circonus-labs/CIRC-9594
Browse files Browse the repository at this point in the history
v0.0.10
  • Loading branch information
maier authored Mar 28, 2023
2 parents 9ace143 + 5296f45 commit 954efb2
Show file tree
Hide file tree
Showing 12 changed files with 662 additions and 398 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# v0.0.10

* feat: add gzip size of sent data stat
* feat: singleton broker list [CIRC-9594]

# v0.0.9

* chore: add RefreshCheckBundle tests
Expand Down
29 changes: 15 additions & 14 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ func (tc *TrapCheck) fetchBroker(cid, checkType string) error {
if checkType == "" {
return fmt.Errorf("invalid check type (empty)")
}
broker, err := tc.client.FetchBroker(apiclient.CIDType(&cid))
broker, err := tc.brokerList.GetBroker(cid)
// broker, err := tc.client.FetchBroker(apiclient.CIDType(&cid))
if err != nil {
return fmt.Errorf("retrieving broker (%s): %w", cid, err)
}
if valid, err := tc.isValidBroker(broker, checkType); !valid {
if valid, err := tc.isValidBroker(&broker, checkType); !valid {
return fmt.Errorf("%s (%s) is an invalid broker for check type %s: %w", tc.broker.Name, tc.checkConfig.Brokers[0], checkType, err)
}
tc.broker = broker
tc.broker = &broker
return nil
}

Expand All @@ -57,33 +58,33 @@ func (tc *TrapCheck) getBroker(checkType string) error {
//
// otherwise, select an applicable broker
//
var brokerList *[]apiclient.Broker
var list *[]apiclient.Broker

if len(tc.brokerSelectTags) > 0 {
filter := apiclient.SearchFilterType{
"f__tags_has": tc.brokerSelectTags,
}
bl, err := tc.client.SearchBrokers(nil, &filter)
// filter := apiclient.SearchFilterType{
// "f__tags_has": tc.brokerSelectTags,
// }
bl, err := tc.brokerList.SearchBrokerList(tc.brokerSelectTags) // tc.client.SearchBrokers(nil, &filter)
if err != nil {
return fmt.Errorf("search brokers: %w", err)
}
brokerList = bl
list = bl
} else {
bl, err := tc.client.FetchBrokers()
bl, err := tc.brokerList.GetBrokerList() // tc.client.FetchBrokers()
if err != nil {
return fmt.Errorf("fetch brokers: %w", err)
}
brokerList = bl
list = bl
}

if len(*brokerList) == 0 {
if len(*list) == 0 {
return fmt.Errorf("zero brokers found")
}

validBrokers := make(map[string]apiclient.Broker)
haveEnterprise := false

for _, broker := range *brokerList {
for _, broker := range *list {
broker := broker
valid, err := tc.isValidBroker(&broker, checkType)
if err != nil {
Expand All @@ -109,7 +110,7 @@ func (tc *TrapCheck) getBroker(checkType string) error {
}

if len(validBrokers) == 0 {
return fmt.Errorf("found %d broker(s), zero are valid", len(*brokerList))
return fmt.Errorf("found %d broker(s), zero are valid", len(*list))
}

validBrokerKeys := reflect.ValueOf(validBrokers).MapKeys()
Expand Down
Loading

0 comments on commit 954efb2

Please sign in to comment.