Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/clients/base/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,8 @@ export class Base<OptionsType extends BaseOptions = BaseOptions> extends EventEm

// This should never change, but we act defensively here
for (const broker of metadata.brokers) {
const { host, port } = broker
brokers.set(broker.nodeId, { host, port })
const { host, port, rack } = broker
brokers.set(broker.nodeId, { host, port, rack })
}

this.#metadata.brokers = brokers
Expand All @@ -619,7 +619,9 @@ export class Base<OptionsType extends BaseOptions = BaseOptions> extends EventEm
partitions[rawPartition.partitionIndex] = {
leader: rawPartition.leaderId,
leaderEpoch: rawPartition.leaderEpoch,
replicas: rawPartition.replicaNodes
replicas: rawPartition.replicaNodes,
isr: rawPartition.isrNodes,
offlineReplicas: rawPartition.offlineReplicas
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/clients/base/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type Broker, type ConnectionOptions } from '../../network/connection.ts'
import { type NullableString } from '../../protocol/definitions.ts'
import { type Metrics } from '../metrics.ts'

export interface TopicWithPartitionAndOffset {
Expand All @@ -11,6 +12,8 @@ export interface ClusterPartitionMetadata {
leader: number
leaderEpoch: number
replicas: number[]
isr: number[]
offlineReplicas: number[]
}

export interface ClusterTopicMetadata {
Expand All @@ -20,9 +23,13 @@ export interface ClusterTopicMetadata {
lastUpdate: number
}

export interface BrokerWithRack extends Broker {
rack: NullableString
}

export interface ClusterMetadata {
id: string
brokers: Map<number, Broker>
brokers: Map<number, BrokerWithRack>
topics: Map<string, ClusterTopicMetadata>
lastUpdate: number
}
Expand Down
6 changes: 3 additions & 3 deletions test/clients/base/sasl-oauthbearer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test('should connect to SASL protected broker using SASL/OAUTHBEARER', async t =

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

deepStrictEqual(metadata.brokers.get(1), saslBroker)
deepStrictEqual(metadata.brokers.get(1), { ...saslBroker, rack: null })
})

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

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

deepStrictEqual(metadata.brokers.get(1), saslBroker)
deepStrictEqual(metadata.brokers.get(1), { ...saslBroker, rack: null })
})

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

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

deepStrictEqual(metadata.brokers.get(1), saslBroker)
deepStrictEqual(metadata.brokers.get(1), { ...saslBroker, rack: null })
})

test('should handle sync credential provider errors', async t => {
Expand Down
6 changes: 3 additions & 3 deletions test/clients/base/sasl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ for (const mechanism of allowedSASLMechanisms) {

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

deepStrictEqual(metadata.brokers.get(1), saslBroker)
deepStrictEqual(metadata.brokers.get(1), { ...saslBroker, rack: null })
})

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

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

deepStrictEqual(metadata.brokers.get(1), saslBroker)
deepStrictEqual(metadata.brokers.get(1), { ...saslBroker, rack: null })
})

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

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

deepStrictEqual(metadata.brokers.get(1), saslBroker)
deepStrictEqual(metadata.brokers.get(1), { ...saslBroker, rack: null })
})

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