Skip to content

Commit

Permalink
fix: add partitions attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
achoimet committed Nov 21, 2024
1 parent ea76846 commit 352e311
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion extkafka/partition_attack_elect_new_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (f kafkaBrokerElectNewLeaderAttack) Start(ctx context.Context, state *Kafka

topicSet.Add(state.Topic, partitions...)

results, err := client.ElectLeaders(ctx, kadm.ElectLiveReplica, topicSet)
results, err := client.ElectLeaders(ctx, kadm.ElectPreferredReplica, topicSet)
if err != nil {
return nil, fmt.Errorf("failed to elect new leader for topic %s and partitions %s: %s", state.Topic, state.Partitions, err)
}
Expand Down
28 changes: 28 additions & 0 deletions extkafka/topic_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ func (r *kafkaTopicDiscovery) DescribeTarget() discovery_kit_api.TargetDescripti
{Attribute: "steadybit.label"},
{Attribute: "kafka.topic.name"},
{Attribute: "kafka.topic.partitions-leaders"},
{Attribute: "kafka.topic.partitions-replicas"},
{Attribute: "kafka.topic.partitions-isr"},
{Attribute: "kafka.topic.replication-factor"},
},
OrderBy: []discovery_kit_api.OrderBy{
Expand Down Expand Up @@ -89,6 +91,20 @@ func (r *kafkaTopicDiscovery) DescribeAttributes() []discovery_kit_api.Attribute
Other: "Kafka topic partitions leaders",
},
},
{
Attribute: "kafka.topic.partitions-replicas",
Label: discovery_kit_api.PluralLabel{
One: "Kafka topic partitions replicas",
Other: "Kafka topic partitions replicas",
},
},
{
Attribute: "kafka.topic.partitions-isr",
Label: discovery_kit_api.PluralLabel{
One: "Kafka topic partitions in-sync-replicas",
Other: "Kafka topic partitions in-sync-replicas",
},
},
{
Attribute: "kafka.topic.replication-factor",
Label: discovery_kit_api.PluralLabel{
Expand Down Expand Up @@ -132,6 +148,8 @@ func toTopicTarget(topic kadm.TopicDetail) discovery_kit_api.Target {

partitions := make([]string, len(topic.Partitions))
partitionsLeaders := make([]string, len(topic.Partitions))
partitionsReplicas := make([]string, len(topic.Partitions))
partitionsInSyncReplicas := make([]string, len(topic.Partitions))

for i, partDetail := range topic.Partitions.Sorted() {
partitions[i] = strconv.FormatInt(int64(partDetail.Partition), 10)
Expand All @@ -141,10 +159,20 @@ func toTopicTarget(topic kadm.TopicDetail) discovery_kit_api.Target {
partitionsLeaders[i] = strconv.FormatInt(int64(partDetail.Partition), 10) + "->leader=" + strconv.FormatInt(int64(partDetail.Leader), 10)
}

for i, partDetail := range topic.Partitions.Sorted() {
partitionsReplicas[i] = strconv.FormatInt(int64(partDetail.Partition), 10) + "->replicas=" + fmt.Sprintf("%v", partDetail.Replicas)
}

for i, partDetail := range topic.Partitions.Sorted() {
partitionsInSyncReplicas[i] = strconv.FormatInt(int64(partDetail.Partition), 10) + "->in-sync-replicas=" + fmt.Sprintf("%v", partDetail.ISR)
}

attributes := make(map[string][]string)
attributes["kafka.topic.name"] = []string{topic.Topic}
attributes["kafka.topic.partitions"] = partitions
attributes["kafka.topic.partitions-leaders"] = partitionsLeaders
attributes["kafka.topic.partitions-replicas"] = partitionsReplicas
attributes["kafka.topic.partitions-isr"] = partitionsReplicas
attributes["kafka.topic.replication-factor"] = []string{fmt.Sprintf("%v", topic.Partitions.NumReplicas())}

return discovery_kit_api.Target{
Expand Down

0 comments on commit 352e311

Please sign in to comment.