Skip to content

Commit c3da1c0

Browse files
committed
Pass up more cluster metadata
1 parent 4966e07 commit c3da1c0

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

src/clients/base/base.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ export class Base<OptionsType extends BaseOptions = BaseOptions> extends EventEm
409409

410410
// This should never change, but we act defensively here
411411
for (const broker of metadata.brokers) {
412-
const { host, port } = broker
413-
brokers.set(broker.nodeId, { host, port })
412+
const { host, port, rack } = broker
413+
brokers.set(broker.nodeId, { host, port, rack })
414414
}
415415

416416
this.#metadata.brokers = brokers
@@ -428,7 +428,9 @@ export class Base<OptionsType extends BaseOptions = BaseOptions> extends EventEm
428428
partitions[rawPartition.partitionIndex] = {
429429
leader: rawPartition.leaderId,
430430
leaderEpoch: rawPartition.leaderEpoch,
431-
replicas: rawPartition.replicaNodes
431+
replicas: rawPartition.replicaNodes,
432+
isr: rawPartition.isrNodes,
433+
offlineReplicas: rawPartition.offlineReplicas
432434
}
433435
}
434436

src/clients/base/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { type Broker, type ConnectionOptions } from '../../network/connection.ts'
2+
import { type NullableString } from '../../protocol/definitions.ts'
23
import { type Metrics } from '../metrics.ts'
34

45
export interface TopicWithPartitionAndOffset {
@@ -11,6 +12,8 @@ export interface ClusterPartitionMetadata {
1112
leader: number
1213
leaderEpoch: number
1314
replicas: number[]
15+
isr: number[]
16+
offlineReplicas: number[]
1417
}
1518

1619
export interface ClusterTopicMetadata {
@@ -22,7 +25,7 @@ export interface ClusterTopicMetadata {
2225

2326
export interface ClusterMetadata {
2427
id: string
25-
brokers: Map<number, Broker>
28+
brokers: Map<number, Broker & { rack: NullableString }>
2629
topics: Map<string, ClusterTopicMetadata>
2730
lastUpdate: number
2831
}

test/clients/base/sasl-oauthbearer.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ test('should connect to SASL protected broker using SASL/OAUTHBEARER', async t =
5050

5151
const metadata = await base.metadata({ topics: [] })
5252

53-
deepStrictEqual(metadata.brokers.get(1), saslBroker)
53+
deepStrictEqual(metadata.brokers.get(1), { ...saslBroker, rack: null })
5454
})
5555

5656
test('should handle authentication errors', async t => {
@@ -103,7 +103,7 @@ test('should accept a function as credential provider', async t => {
103103

104104
const metadata = await base.metadata({ topics: [] })
105105

106-
deepStrictEqual(metadata.brokers.get(1), saslBroker)
106+
deepStrictEqual(metadata.brokers.get(1), { ...saslBroker, rack: null })
107107
})
108108

109109
test('should accept an async function as credential provider', async t => {
@@ -134,7 +134,7 @@ test('should accept an async function as credential provider', async t => {
134134

135135
const metadata = await base.metadata({ topics: [] })
136136

137-
deepStrictEqual(metadata.brokers.get(1), saslBroker)
137+
deepStrictEqual(metadata.brokers.get(1), { ...saslBroker, rack: null })
138138
})
139139

140140
test('should handle sync credential provider errors', async t => {

test/clients/base/sasl.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ for (const mechanism of allowedSASLMechanisms) {
4949

5050
const metadata = await base.metadata({ topics: [] })
5151

52-
deepStrictEqual(metadata.brokers.get(1), saslBroker)
52+
deepStrictEqual(metadata.brokers.get(1), { ...saslBroker, rack: null })
5353
})
5454

5555
test(`${mechanism} - should handle authentication errors`, async t => {
@@ -90,7 +90,7 @@ for (const mechanism of allowedSASLMechanisms) {
9090

9191
const metadata = await base.metadata({ topics: [] })
9292

93-
deepStrictEqual(metadata.brokers.get(1), saslBroker)
93+
deepStrictEqual(metadata.brokers.get(1), { ...saslBroker, rack: null })
9494
})
9595

9696
test(`${mechanism} - should accept an async function as credential provider`, async t => {
@@ -113,7 +113,7 @@ for (const mechanism of allowedSASLMechanisms) {
113113

114114
const metadata = await base.metadata({ topics: [] })
115115

116-
deepStrictEqual(metadata.brokers.get(1), saslBroker)
116+
deepStrictEqual(metadata.brokers.get(1), { ...saslBroker, rack: null })
117117
})
118118

119119
test(`${mechanism} - should handle sync credential provider errors`, async t => {

0 commit comments

Comments
 (0)