Skip to content

Commit 6d92277

Browse files
authored
Sets ConfigEntry.Default flag in addition to the ConfigEntry.Source for Kafka versions > V1_1_0_0 (#1594)
* Set describeConfigsRequest.Version in ListTopics for consistency with DescribeConfig This breaks the output of ListTopics for newer request versions, it now includes default configuration settings. * Set ConfigEntry.Default for KafkaVersions > 0 Clients can now rely on the `Default` flag again and don't have to check the `Source` for higher Kafka versions. * Set ConfigEntry.Source to default for KafkaVersions <= 0 when applicable * Add tests for default flag/source
1 parent 4ee86d9 commit 6d92277

File tree

5 files changed

+123
-2
lines changed

5 files changed

+123
-2
lines changed

admin.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,15 @@ func (ca *clusterAdmin) ListTopics() (map[string]TopicDetail, error) {
338338
describeConfigsReq := &DescribeConfigsRequest{
339339
Resources: describeConfigsResources,
340340
}
341+
342+
if ca.conf.Version.IsAtLeast(V1_1_0_0) {
343+
describeConfigsReq.Version = 1
344+
}
345+
346+
if ca.conf.Version.IsAtLeast(V2_0_0_0) {
347+
describeConfigsReq.Version = 2
348+
}
349+
341350
describeConfigsResp, err := b.DescribeConfigs(describeConfigsReq)
342351
if err != nil {
343352
return nil, err

admin_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func TestClusterAdminListTopics(t *testing.T) {
149149
})
150150

151151
config := NewConfig()
152-
config.Version = V1_0_0_0
152+
config.Version = V1_1_0_0
153153
admin, err := NewClusterAdmin([]string{seedBroker.Addr()}, config)
154154
if err != nil {
155155
t.Fatal(err)

describe_configs_response.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,16 @@ func (r *ConfigEntry) decode(pd packetDecoder, version int16) (err error) {
249249
return err
250250
}
251251
r.Default = defaultB
252+
if defaultB {
253+
r.Source = SourceDefault
254+
}
252255
} else {
253256
source, err := pd.getInt8()
254257
if err != nil {
255258
return err
256259
}
257260
r.Source = ConfigSource(source)
261+
r.Default = r.Source == SourceDefault
258262
}
259263

260264
sensitive, err := pd.getBool()

describe_configs_response_test.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ var (
2525
0, // Sensitive
2626
}
2727

28+
describeConfigsResponseWithDefaultv0 = []byte{
29+
0, 0, 0, 0, //throttle
30+
0, 0, 0, 1, // response
31+
0, 0, //errorcode
32+
0, 0, //string
33+
2, // topic
34+
0, 3, 'f', 'o', 'o',
35+
0, 0, 0, 1, //configs
36+
0, 10, 's', 'e', 'g', 'm', 'e', 'n', 't', '.', 'm', 's',
37+
0, 4, '1', '0', '0', '0',
38+
0, // ReadOnly
39+
1, // Default
40+
0, // Sensitive
41+
}
42+
2843
describeConfigsResponsePopulatedv1 = []byte{
2944
0, 0, 0, 0, //throttle
3045
0, 0, 0, 1, // response
@@ -59,6 +74,22 @@ var (
5974
0, 4, '1', '0', '0', '0',
6075
4, // Source
6176
}
77+
78+
describeConfigsResponseWithDefaultv1 = []byte{
79+
0, 0, 0, 0, //throttle
80+
0, 0, 0, 1, // response
81+
0, 0, //errorcode
82+
0, 0, //string
83+
2, // topic
84+
0, 3, 'f', 'o', 'o',
85+
0, 0, 0, 1, //configs
86+
0, 10, 's', 'e', 'g', 'm', 'e', 'n', 't', '.', 'm', 's',
87+
0, 4, '1', '0', '0', '0',
88+
0, // ReadOnly
89+
5, // Source
90+
0, // Sensitive
91+
0, 0, 0, 0, // No Synonym
92+
}
6293
)
6394

6495
func TestDescribeConfigsResponsev0(t *testing.T) {
@@ -86,6 +117,7 @@ func TestDescribeConfigsResponsev0(t *testing.T) {
86117
ReadOnly: false,
87118
Default: false,
88119
Sensitive: false,
120+
Source: SourceUnknown,
89121
},
90122
},
91123
},
@@ -94,6 +126,40 @@ func TestDescribeConfigsResponsev0(t *testing.T) {
94126
testResponse(t, "response with error", response, describeConfigsResponsePopulatedv0)
95127
}
96128

129+
func TestDescribeConfigsResponseWithDefaultv0(t *testing.T) {
130+
var response *DescribeConfigsResponse
131+
132+
response = &DescribeConfigsResponse{
133+
Resources: []*ResourceResponse{},
134+
}
135+
testVersionDecodable(t, "empty", response, describeConfigsResponseEmpty, 0)
136+
if len(response.Resources) != 0 {
137+
t.Error("Expected no groups")
138+
}
139+
140+
response = &DescribeConfigsResponse{
141+
Version: 0, Resources: []*ResourceResponse{
142+
{
143+
ErrorCode: 0,
144+
ErrorMsg: "",
145+
Type: TopicResource,
146+
Name: "foo",
147+
Configs: []*ConfigEntry{
148+
{
149+
Name: "segment.ms",
150+
Value: "1000",
151+
ReadOnly: false,
152+
Default: true,
153+
Sensitive: false,
154+
Source: SourceDefault,
155+
},
156+
},
157+
},
158+
},
159+
}
160+
testResponse(t, "response with default", response, describeConfigsResponseWithDefaultv0)
161+
}
162+
97163
func TestDescribeConfigsResponsev1(t *testing.T) {
98164
var response *DescribeConfigsResponse
99165

@@ -119,6 +185,7 @@ func TestDescribeConfigsResponsev1(t *testing.T) {
119185
Value: "1000",
120186
ReadOnly: false,
121187
Source: SourceStaticBroker,
188+
Default: false,
122189
Sensitive: false,
123190
Synonyms: []*ConfigSynonym{},
124191
},
@@ -154,6 +221,7 @@ func TestDescribeConfigsResponseWithSynonym(t *testing.T) {
154221
Value: "1000",
155222
ReadOnly: false,
156223
Source: SourceStaticBroker,
224+
Default: false,
157225
Sensitive: false,
158226
Synonyms: []*ConfigSynonym{
159227
{
@@ -169,3 +237,39 @@ func TestDescribeConfigsResponseWithSynonym(t *testing.T) {
169237
}
170238
testResponse(t, "response with error", response, describeConfigsResponseWithSynonymv1)
171239
}
240+
241+
func TestDescribeConfigsResponseWithDefaultv1(t *testing.T) {
242+
var response *DescribeConfigsResponse
243+
244+
response = &DescribeConfigsResponse{
245+
Resources: []*ResourceResponse{},
246+
}
247+
testVersionDecodable(t, "empty", response, describeConfigsResponseEmpty, 0)
248+
if len(response.Resources) != 0 {
249+
t.Error("Expected no groups")
250+
}
251+
252+
response = &DescribeConfigsResponse{
253+
Version: 1,
254+
Resources: []*ResourceResponse{
255+
{
256+
ErrorCode: 0,
257+
ErrorMsg: "",
258+
Type: TopicResource,
259+
Name: "foo",
260+
Configs: []*ConfigEntry{
261+
{
262+
Name: "segment.ms",
263+
Value: "1000",
264+
ReadOnly: false,
265+
Source: SourceDefault,
266+
Default: true,
267+
Sensitive: false,
268+
Synonyms: []*ConfigSynonym{},
269+
},
270+
},
271+
},
272+
},
273+
}
274+
testResponse(t, "response with error", response, describeConfigsResponseWithDefaultv1)
275+
}

mockresponses.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ func (mr *MockDescribeConfigsResponse) For(reqBody versionedDecoder) encoder {
736736
}
737737

738738
includeSynonyms := (req.Version > 0)
739+
includeSource := (req.Version > 0)
739740

740741
for _, r := range req.Resources {
741742
var configEntries []*ConfigEntry
@@ -770,9 +771,12 @@ func (mr *MockDescribeConfigsResponse) For(reqBody versionedDecoder) encoder {
770771
maxMessageBytes := &ConfigEntry{Name: "max.message.bytes",
771772
Value: "1000000",
772773
ReadOnly: false,
773-
Default: true,
774+
Default: !includeSource,
774775
Sensitive: false,
775776
}
777+
if includeSource {
778+
maxMessageBytes.Source = SourceDefault
779+
}
776780
if includeSynonyms {
777781
maxMessageBytes.Synonyms = []*ConfigSynonym{
778782
{

0 commit comments

Comments
 (0)