forked from DataDog/kafka-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtopics_legacy.go
More file actions
98 lines (81 loc) · 2.64 KB
/
Copy pathtopics_legacy.go
File metadata and controls
98 lines (81 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"strconv"
"github.com/DataDog/kafka-kit/v4/mapper"
)
// TopicStates is a map of topic names to kafakzk.TopicState.
type TopicStates map[string]mapper.TopicState
// legacyGetTopicsWithThrottledBrokers returns a topicThrottledReplicas that
// includes any topics that have partitions assigned to brokers with a static
// throttle rate set.
func (tm *ThrottleManager) legacyGetTopicsWithThrottledBrokers() (topicThrottledReplicas, error) {
// Fetch all topic states.
states, err := tm.legacyGetAllTopicStates()
if err != nil {
return nil, err
}
// Lookup brokers with overrides set that are not a reassignment participant.
throttledBrokers := tm.brokerOverrides.Filter(notReassignmentParticipant)
// Construct a topicThrottledReplicas that includes any topics with replicas
// assigned to brokers with overrides. The throttled list only includes brokers
// with throttles set rather than all configured replicas.
var throttleLists = make(topicThrottledReplicas)
// For each topic...
for topicName, state := range states {
// TODO(jamie): make this configurable.
if topicName == "__consumer_offsets" {
continue
}
// For each partition...
for partn, replicas := range state.Partitions {
// For each replica assignment...
for _, assignedID := range replicas {
// If the replica is a throttled broker, append that broker to the
// throttled list for this {topic, partition}.
if _, exists := throttledBrokers[assignedID]; exists {
throttleLists.addReplica(
topic(topicName),
partn,
replicaType("followers"),
strconv.Itoa(assignedID))
}
}
}
}
return throttleLists, nil
}
// legacyGetAllTopicStates returns a TopicStates for all topics in Kafka.
func (tm *ThrottleManager) legacyGetAllTopicStates() (TopicStates, error) {
var states = make(TopicStates)
// Get all topics.
topics, err := tm.zk.GetTopics(topicsRegex)
if err != nil {
return nil, err
}
// Fetch state for each topic.
for _, topic := range topics {
state, err := tm.zk.GetTopicState(topic)
if err != nil {
return nil, err
}
states[topic] = *state
}
return states, nil
}
/*
This code isn't currently accessed, but holding it as a comment until we
remove all the deprecated bits.
// TopicStatesFilterFn specifies a filter function.
type TopicStatesFilterFn func(mapper.TopicState) bool
// Filter takes a TopicStatesFilterFn and returns a TopicStates where
// all elements return true as an input to the filter func.
func (t TopicStates) Filter(fn TopicStatesFilterFn) TopicStates {
var ts = make(TopicStates)
for name, state := range t {
if fn(state) {
ts[name] = state
}
}
return ts
}
*/