Skip to content

Commit

Permalink
fix: check brokers and broker discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
achoimet committed Jan 30, 2025
1 parent 5d4c17b commit cf9d609
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
10 changes: 6 additions & 4 deletions extkafka/broker_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,13 @@ func toBrokerTarget(broker kadm.BrokerDetail, controller int32) discovery_kit_ap
if broker.Rack != nil {
attributes["kafka.broker.rack"] = []string{*broker.Rack}
}
podName := strings.Split(broker.Host, ".")[0]
namespace := strings.Split(broker.Host, ".")[2]
if len(strings.Split(broker.Host, ".")) == 4 && strings.HasSuffix(broker.Host, ".svc") {
podName := strings.Split(broker.Host, ".")[0]
namespace := strings.Split(broker.Host, ".")[2]

attributes["kafka.pod.name"] = []string{podName}
attributes["kafka.pod.namespace"] = []string{namespace}
attributes["kafka.pod.name"] = []string{podName}
attributes["kafka.pod.namespace"] = []string{namespace}
}

return discovery_kit_api.Target{
Id: id,
Expand Down
21 changes: 21 additions & 0 deletions extkafka/check_brokers.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ func BrokerCheckStatus(ctx context.Context, state *CheckBrokersState) (*action_k
for _, c := range keys {
if slices.Contains(state.ExpectedChanges, c) {
state.StateCheckSuccess = true
} else {
state.StateCheckSuccess = false
}
}

Expand Down Expand Up @@ -316,6 +318,25 @@ func areSlicesEqualUnordered(slice1, slice2 []int32) bool {
return slices.Equal(sorted1, sorted2)
}

// CompareStringSlices sorts and checks if two slices have the same elements
func CompareStringSlices(a, b []string) bool {
if len(a) != len(b) {
return false
}

// Sort both slices
sort.Strings(a)
sort.Strings(b)

// Compare element by element
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}

func findMissingElements(slice1, slice2 []int32) []int32 {
// Create a map to store elements in slice2
elementMap := make(map[int32]bool)
Expand Down

0 comments on commit cf9d609

Please sign in to comment.