← Back to Pull requests

Add KafkaConsumer.metadata(topic:timeout:) for cluster metadata #262

Merged
ssikka100 merged 12 files (801 lines) on Oct 05, 2026 16:06 UTC
View on GitHub
ssikka100 ssikka100 commented on Sep 30, 2026 02:24 UTC
Author

Resolves #156. Resolves #31.

Adds KafkaConsumer.metadata(topic:timeout:), which fetches cluster metadata from a broker (rd_kafka_metadata): brokers, and per topic its partitions with leader, replicas, and in-sync replicas.

let metadata = try await consumer.metadata(topic: "orders")  // nil = all topics

metadata.brokers                  // [Broker] — id, host, port
for partition in metadata.topics.first?.partitions ?? [] {
    partition.leader              // Int? — nil if no leader
    partition.replicas            // [Int]
    partition.inSyncReplicas      // [Int]
}

  • New KafkaClusterMetadata value type (Broker, Topic, Partition, OriginatingBroker). Same model as the Rust/Go/Python librdkafka clients. originatingBroker.id is nil when a bootstrap connection answered before its broker ID was known.

  • A missing topic is reported via Topic.error (new KafkaError.RDKafkaCode.unknownTopicOrPartition), not thrown, and is never auto-created unless allow.auto.create.topics is on.

  • Runs on the blocking queue; works before and after run().

  • Metadata types use var properties and public initializers; KafkaConsumer.Rebalance also moves to var for consistency (non-breaking).

  • Additive only (semver minor).
  • Diff: 801 lines (+799 / -2) across 12 files Reviewer: FranzBusch Review duration: 8022m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.59) × (1 − Review Confidence (0.68)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.59 · 801 lines diff across 12 files
    0.59
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.43 · 1 substantive comment(s)
    0.43
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    68%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.400
    Real PR Conversation Timeline
    3 items
    FranzBusch FranzBusch commented on code on Oct 02, 2026 13:35 UTC
    Code Review
    Sources/Kafka/KafkaClusterMetadata.swift:1
    @@ -0,0 +1,154 @@
    +//===----------------------------------------------------------------------===//
    +//
    +// This source file is part of the swift-kafka-client open source project
    +//
    +// Copyright (c) 2026 Apple Inc. and the swift-kafka-client project authors
    +// Licensed under Apache License v2.0
    +//
    +// See LICENSE.txt for license information
    +// See CONTRIBUTORS.txt for the list of swift-kafka-client project authors
    +//
    +// SPDX-License-Identifier: Apache-2.0
    +//
    +//===----------------------------------------------------------------------===//
    +
    +import Crdkafka
    +
    +/// A snapshot of Kafka cluster metadata, as reported by a broker.
    +///
    +/// Retrieve it with ``KafkaConsumer/metadata(topic:timeout:)``. The metadata reflects the
    +/// responding broker's view of the cluster at the time of the request, so leadership and
    +/// in-sync replica information can change immediately afterwards (for example, during a
    +/// leader election).
    +public struct KafkaClusterMetadata: Sendable, Hashable {

    Can we make all properties vars inside here. These are value types and there are no-invariants we want to uphold. Also all types should gain public inits

    FranzBusch FranzBusch approved these changes on Oct 05, 2026 14:26 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    ssikka100 ssikka100
    Labels
    risk: low confidence: 68.2% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 59.1% (MEDIUM) · Higher = larger blast radius
    59.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 68.2% · Lower = rushed or shallow review
    68.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.8% · Safe to merge
    18.8%