-
Notifications
You must be signed in to change notification settings - Fork 27
Feature: expose librdkafka statistics as swift metrics #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
FranzBusch
merged 26 commits into
swift-server:main
from
ordo-one:feature/sc-1976/gsoc-expose-librdkafka-statistics
Nov 6, 2023
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
c870864
introduce statistics for producer
blindspotbounty 633773f
Merge remote-tracking branch 'origin/main' into feature/sc-1976/gsoc-…
blindspotbounty d9887b9
add statistics to new consumer with events
blindspotbounty e5f0483
Merge remote-tracking branch 'origin/main' into feature/sc-1976/gsoc-…
blindspotbounty d55a7fd
fix some artefacts
blindspotbounty 8b4525b
adjust to KeyRefreshAttempts
blindspotbounty 23e08fc
draft: statistics with metrics
blindspotbounty 612a3c4
make structures internal
blindspotbounty 5c10435
Update Sources/Kafka/Configuration/KafkaConfiguration+Metrics.swift
blindspotbounty 2be2bd9
Update Sources/Kafka/Configuration/KafkaConsumerConfiguration.swift
blindspotbounty 2cd0f8b
Update Sources/Kafka/Configuration/KafkaConfiguration+Metrics.swift
blindspotbounty abd97de
Update Sources/Kafka/Configuration/KafkaConfiguration+Metrics.swift
blindspotbounty 15284e1
address review comments
blindspotbounty a4ee678
formatting
blindspotbounty 0a0f1b8
map gauges in one place
blindspotbounty dcdbe21
Merge remote-tracking branch 'origin/main' into feature/sc-1976/gsoc-…
blindspotbounty 5448eb4
move json mode as rd kafka statistics, misc renaming + docc
blindspotbounty 900cb38
Merge branch 'main' into feature/sc-1976/gsoc-expose-librdkafka-stati…
blindspotbounty a83c970
address review comments
blindspotbounty 4ebdf9d
remove import Metrics
blindspotbounty 05cf1b9
divide producer/consumer configuration
blindspotbounty 3febfcd
apply swiftformat
blindspotbounty 455be80
Merge branch 'main' into feature/sc-1976/gsoc-expose-librdkafka-stati…
blindspotbounty a96edf7
Merge branch 'main' into feature/sc-1976/gsoc-expose-librdkafka-stati…
blindspotbounty af05f5b
fix code after conflicts
blindspotbounty 8a3caf3
fix formatting
blindspotbounty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
Sources/Kafka/Configuration/KafkaConfiguration+Metrics.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the swift-kafka-client open source project | ||
// | ||
// Copyright (c) 2023 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 Metrics | ||
|
||
extension KafkaConfiguration { | ||
// MARK: - Metrics | ||
|
||
/// Configuration for the consumer metrics emitted by `SwiftKafka`. | ||
public struct ConsumerMetrics: Sendable { | ||
internal var enabled: Bool { | ||
self.updateInterval != nil && | ||
(self.queuedOperation != nil || | ||
self.totalKafkaBrokerRequests != nil || | ||
self.totalKafkaBrokerBytesSent != nil || | ||
self.totalKafkaBrokerResponses != nil || | ||
self.totalKafkaBrokerResponsesSize != nil || | ||
self.totalKafkaBrokerMessagesBytesRecieved != nil || | ||
self.topicsInMetadataCache != nil) | ||
} | ||
|
||
/// Update interval for statistics. | ||
public var updateInterval: Duration? | ||
|
||
/// Number of operations (callbacks, events, etc) waiting in the queue. | ||
public var queuedOperation: Gauge? | ||
|
||
/// Total number of requests sent to Kafka brokers. | ||
public var totalKafkaBrokerRequests: Gauge? | ||
/// Total number of bytes transmitted to Kafka brokers. | ||
public var totalKafkaBrokerBytesSent: Gauge? | ||
/// Total number of responses received from Kafka brokers. | ||
public var totalKafkaBrokerResponses: Gauge? | ||
/// Total number of bytes received from Kafka brokers. | ||
public var totalKafkaBrokerResponsesSize: Gauge? | ||
|
||
/// Total number of messages consumed, not including ignored messages (due to offset, etc), from Kafka brokers. | ||
public var totalKafkaBrokerMessagesRecieved: Gauge? | ||
/// Total number of message bytes (including framing) received from Kafka brokers. | ||
public var totalKafkaBrokerMessagesBytesRecieved: Gauge? | ||
|
||
/// Number of topics in the metadata cache. | ||
public var topicsInMetadataCache: Gauge? | ||
|
||
private static func record<T: BinaryInteger>(_ value: T?, to: Gauge?) { | ||
guard let value, | ||
let to else { | ||
return | ||
} | ||
to.record(value) | ||
} | ||
|
||
internal func update(with rdKafkaStatistics: RDKafkaStatistics) { | ||
Self.record(rdKafkaStatistics.queuedOperation, to: self.queuedOperation) | ||
|
||
Self.record(rdKafkaStatistics.totalKafkaBrokerRequests, to: self.totalKafkaBrokerRequests) | ||
Self.record(rdKafkaStatistics.totalKafkaBrokerBytesSent, to: self.totalKafkaBrokerBytesSent) | ||
Self.record(rdKafkaStatistics.totalKafkaBrokerResponses, to: self.totalKafkaBrokerResponses) | ||
Self.record(rdKafkaStatistics.totalKafkaBrokerResponsesSize, to: self.totalKafkaBrokerResponsesSize) | ||
|
||
Self.record(rdKafkaStatistics.totalKafkaBrokerMessagesRecieved, to: self.totalKafkaBrokerMessagesRecieved) | ||
Self.record(rdKafkaStatistics.totalKafkaBrokerMessagesBytesRecieved, to: self.totalKafkaBrokerMessagesBytesRecieved) | ||
|
||
Self.record(rdKafkaStatistics.topicsInMetadataCache, to: self.topicsInMetadataCache) | ||
} | ||
} | ||
|
||
/// Configuration for the producer metrics emitted by `SwiftKafka`. | ||
public struct ProducerMetrics: Sendable { | ||
internal var enabled: Bool { | ||
self.updateInterval != nil && | ||
(self.queuedOperation != nil || | ||
self.queuedProducerMessages != nil || | ||
self.queuedProducerMessagesSize != nil || | ||
self.totalKafkaBrokerRequests != nil || | ||
self.totalKafkaBrokerBytesSent != nil || | ||
self.totalKafkaBrokerResponses != nil || | ||
self.totalKafkaBrokerResponsesSize != nil || | ||
self.totalKafkaBrokerMessagesSent != nil || | ||
self.totalKafkaBrokerMessagesBytesSent != nil || | ||
self.topicsInMetadataCache != nil) | ||
} | ||
|
||
/// Update interval for statistics. | ||
public var updateInterval: Duration? | ||
|
||
/// Number of operations (callbacks, events, etc) waiting in the queue. | ||
public var queuedOperation: Gauge? | ||
/// Current number of queued producer messages. | ||
public var queuedProducerMessages: Gauge? | ||
/// Current total size in bytes of queued producer messages. | ||
public var queuedProducerMessagesSize: Gauge? | ||
|
||
/// Total number of requests sent to Kafka brokers. | ||
public var totalKafkaBrokerRequests: Gauge? | ||
/// Total number of bytes transmitted to Kafka brokers. | ||
public var totalKafkaBrokerBytesSent: Gauge? | ||
/// Total number of responses received from Kafka brokers. | ||
public var totalKafkaBrokerResponses: Gauge? | ||
/// Total number of bytes received from Kafka brokers. | ||
public var totalKafkaBrokerResponsesSize: Gauge? | ||
|
||
/// Total number of messages transmitted (produced) to Kafka brokers. | ||
public var totalKafkaBrokerMessagesSent: Gauge? | ||
/// Total number of message bytes (including framing, such as per-Message framing and MessageSet/batch framing) transmitted to Kafka brokers. | ||
public var totalKafkaBrokerMessagesBytesSent: Gauge? | ||
|
||
/// Number of topics in the metadata cache. | ||
public var topicsInMetadataCache: Gauge? | ||
|
||
private static func record<T: BinaryInteger>(_ value: T?, to: Gauge?) { | ||
guard let value, | ||
let to else { | ||
return | ||
} | ||
to.record(value) | ||
} | ||
|
||
internal func update(with rdKafkaStatistics: RDKafkaStatistics) { | ||
Self.record(rdKafkaStatistics.queuedOperation, to: self.queuedOperation) | ||
Self.record(rdKafkaStatistics.queuedProducerMessages, to: self.queuedProducerMessages) | ||
Self.record(rdKafkaStatistics.queuedProducerMessagesSize, to: self.queuedProducerMessagesSize) | ||
|
||
Self.record(rdKafkaStatistics.totalKafkaBrokerRequests, to: self.totalKafkaBrokerRequests) | ||
Self.record(rdKafkaStatistics.totalKafkaBrokerBytesSent, to: self.totalKafkaBrokerBytesSent) | ||
Self.record(rdKafkaStatistics.totalKafkaBrokerResponses, to: self.totalKafkaBrokerResponses) | ||
Self.record(rdKafkaStatistics.totalKafkaBrokerResponsesSize, to: self.totalKafkaBrokerResponsesSize) | ||
|
||
Self.record(rdKafkaStatistics.totalKafkaBrokerMessagesSent, to: self.totalKafkaBrokerMessagesSent) | ||
Self.record(rdKafkaStatistics.totalKafkaBrokerMessagesBytesSent, to: self.totalKafkaBrokerMessagesBytesSent) | ||
|
||
Self.record(rdKafkaStatistics.topicsInMetadataCache, to: self.topicsInMetadataCache) | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.