Skip to content
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

Feature: expose librdkafka statistics as swift metrics #92

Conversation

blindspotbounty
Copy link
Collaborator

@blindspotbounty blindspotbounty commented Jul 18, 2023

This is approximate solution for exposing librdkafka statistics callback (#79)

Main ideas:

  1. Specify interval for metrics updates
  2. Allow to specify metrics per librdkafka key

@blindspotbounty blindspotbounty marked this pull request as ready for review July 19, 2023 07:08
Copy link
Contributor

@felixschlegel felixschlegel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally a good start! However, I think we should not have a statistics closure and all these new initializers, but rather an AsyncSequence as we do with KafkaConsumer.messages or the producer acknowledgements. The implementation of statistics should therefore follow a similar pattern. Feel free to reach out to me if you need any more pointers for that!

Sources/SwiftKafka/KafkaClient.swift Outdated Show resolved Hide resolved
Tests/SwiftKafkaTests/KafkaProducerTests.swift Outdated Show resolved Hide resolved
@blindspotbounty
Copy link
Collaborator Author

Generally a good start! However, I think we should not have a statistics closure and all these new initializers, but rather an AsyncSequence as we do with KafkaConsumer.messages or the producer acknowledgements. The implementation of statistics should therefore follow a similar pattern. Feel free to reach out to me if you need any more pointers for that!

Thank you for the feedback. I think I got you. Basically, we add type to KafkaEvent, e.g. statistics and use it across the code.
Let me try it out, it sounds promising regarding how it should look like.

@felixschlegel
Copy link
Contributor

Generally a good start! However, I think we should not have a statistics closure and all these new initializers, but rather an AsyncSequence as we do with KafkaConsumer.messages or the producer acknowledgements. The implementation of statistics should therefore follow a similar pattern. Feel free to reach out to me if you need any more pointers for that!

Thank you for the feedback. I think I got you. Basically, we add type to KafkaEvent, e.g. statistics and use it across the code. Let me try it out, it sounds promising regarding how it should look like.

Yes, so you would probably want to add that to KafkaEvent, receive the statistics event through KafkaClient.eventPoll and then yield the statistics to some new AsyncSequence that is exposed by KafkaConsumer + KafkaProducer.

@blindspotbounty blindspotbounty marked this pull request as draft July 20, 2023 14:58
@blindspotbounty
Copy link
Collaborator Author

Generally a good start! However, I think we should not have a statistics closure and all these new initializers, but rather an AsyncSequence as we do with KafkaConsumer.messages or the producer acknowledgements. The implementation of statistics should therefore follow a similar pattern. Feel free to reach out to me if you need any more pointers for that!

Thank you for the feedback. I think I got you. Basically, we add type to KafkaEvent, e.g. statistics and use it across the code. Let me try it out, it sounds promising regarding how it should look like.

Yes, so you would probably want to add that to KafkaEvent, receive the statistics event through KafkaClient.eventPoll and then yield the statistics to some new AsyncSequence that is exposed by KafkaConsumer + KafkaProducer.

I pushed a draft for Consumer (not touching producer so far), just to be sure that I got the idea correctly. If it is okay, I will perform other cleanup in code and put the same code for producer as well.

@felixschlegel
Copy link
Contributor

Yes it is going into the right direction!

@blindspotbounty blindspotbounty force-pushed the feature/sc-1976/gsoc-expose-librdkafka-statistics branch from 2f2d828 to c870864 Compare July 26, 2023 15:37
Sources/SwiftKafka/Configuration/KafkaConfiguration.swift Outdated Show resolved Hide resolved
Sources/SwiftKafka/KafkaConsumer.swift Outdated Show resolved Hide resolved
Sources/SwiftKafka/KafkaProducer.swift Outdated Show resolved Hide resolved
Tests/SwiftKafkaTests/KafkaConsumerTests.swift Outdated Show resolved Hide resolved
Tests/SwiftKafkaTests/KafkaProducerTests.swift Outdated Show resolved Hide resolved
Sources/SwiftKafka/KafkaConsumerEvent.swift Outdated Show resolved Hide resolved
Sources/SwiftKafka/Utilities/KafkaStatistics.swift Outdated Show resolved Hide resolved
Copy link
Contributor

@felixschlegel felixschlegel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Please see my comments 😄

Sources/Kafka/Configuration/KafkaConfiguration.swift Outdated Show resolved Hide resolved
Sources/Kafka/KafkaProducer.swift Outdated Show resolved Hide resolved
Sources/Kafka/KafkaConsumer.swift Outdated Show resolved Hide resolved
Sources/Kafka/KafkaProducer.swift Show resolved Hide resolved
Tests/KafkaTests/Utilities.swift Outdated Show resolved Hide resolved
@blindspotbounty blindspotbounty changed the title Feature: expose librdkafka statistics Feature: expose librdkafka statistics as swift metrics Aug 29, 2023
Copy link
Contributor

@felixschlegel felixschlegel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @blindspotbounty,

Again, excellent work!
I have left some minor comments inline and also a comment regarding how we are "filling in" the statistics.

-Felix

Tests/KafkaTests/KafkaConsumerTests.swift Outdated Show resolved Hide resolved
Tests/KafkaTests/KafkaConsumerTests.swift Outdated Show resolved Hide resolved
Tests/KafkaTests/KafkaProducerTests.swift Outdated Show resolved Hide resolved
Sources/Kafka/KafkaConsumer.swift Outdated Show resolved Hide resolved
Sources/Kafka/Utilities/KafkaStatistics.swift Outdated Show resolved Hide resolved
Sources/Kafka/Utilities/KafkaStatistics.swift Outdated Show resolved Hide resolved
Sources/Kafka/Utilities/KafkaStatisticsJsonModel.swift Outdated Show resolved Hide resolved
Sources/Kafka/Utilities/KafkaStatistics.swift Outdated Show resolved Hide resolved
Copy link
Contributor

@FranzBusch FranzBusch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good and thanks for the work. I left some comments inline

Package.swift Outdated Show resolved Hide resolved
Sources/Kafka/RDKafka/RDKafkaStatistics.swift Outdated Show resolved Hide resolved
Sources/Kafka/RDKafka/RDKafkaStatistics.swift Outdated Show resolved Hide resolved
Tests/KafkaTests/KafkaConsumerTests.swift Outdated Show resolved Hide resolved
@FranzBusch
Copy link
Contributor

@blindspotbounty If you are ready and can push up the changes addressing the review, I am happy to get this over the line

@blindspotbounty
Copy link
Collaborator Author

@FranzBusch I've pushed commit with addressing conversations. But remained two conversations open in case it should be different.

Copy link
Contributor

@FranzBusch FranzBusch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are really close! Thanks for all the work on this one last comment

Sources/Kafka/RDKafka/RDKafkaStatistics.swift Outdated Show resolved Hide resolved
Copy link
Contributor

@FranzBusch FranzBusch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good! Thanks for doing the work.

@FranzBusch
Copy link
Contributor

@swift-server-bot add to allowlist

@FranzBusch
Copy link
Contributor

@swift-ci please test

@FranzBusch FranzBusch enabled auto-merge (squash) October 31, 2023 17:36
@FranzBusch
Copy link
Contributor

@blindspotbounty can you take a look at the CI failures?

auto-merge was automatically disabled November 3, 2023 08:51

Head branch was pushed to by a user without write access

@blindspotbounty
Copy link
Collaborator Author

@FranzBusch sure. But I think it is better to restart ci after resolving conflicts.

@FranzBusch
Copy link
Contributor

@swift-ci please test

@blindspotbounty
Copy link
Collaborator Author

Seems, it is the same as for PR for backpressure:

11:12:15 /code/Sources/Kafka/RDKafka/RDKafkaClient.swift:33:17: error: stored property 'kafkaHandle' of 'Sendable'-conforming class 'RDKafkaClient' has non-sendable type 'OpaquePointer'

#139 (comment)

@FranzBusch FranzBusch merged commit c3bbb75 into swift-server:main Nov 6, 2023
4 of 6 checks passed
blindspotbounty added a commit to ordo-one/swift-kafka-client that referenced this pull request Aug 6, 2024
* Feature: expose librdkafka statistics as swift metrics (swift-server#92)

* introduce statistics for producer

* add statistics to new consumer with events

* fix some artefacts

* adjust to KeyRefreshAttempts

* draft: statistics with metrics

* make structures internal

* Update Sources/Kafka/Configuration/KafkaConfiguration+Metrics.swift

Co-authored-by: Felix Schlegel <[email protected]>

* Update Sources/Kafka/Configuration/KafkaConsumerConfiguration.swift

Co-authored-by: Felix Schlegel <[email protected]>

* Update Sources/Kafka/Configuration/KafkaConfiguration+Metrics.swift

Co-authored-by: Felix Schlegel <[email protected]>

* Update Sources/Kafka/Configuration/KafkaConfiguration+Metrics.swift

Co-authored-by: Felix Schlegel <[email protected]>

* address review comments

* formatting

* map gauges in one place

* move json mode as rd kafka statistics, misc renaming + docc

* address review comments

* remove import Metrics

* divide producer/consumer configuration

* apply swiftformat

* fix code after conflicts

* fix formatting

---------

Co-authored-by: Felix Schlegel <[email protected]>

* Add benchmark infratructure without actual tests (swift-server#146)

* add benchmark infratructure without actual test

* apply swiftformat

* fix header in sh file

* use new async seq methods

* Update to latest librdkafka & add a define for RAND_priv_bytes (swift-server#148)

Co-authored-by: Franz Busch <[email protected]>

* exit from consumer batch loop when no more messages left (swift-server#153)

* Lower requirements for consumer state machine (swift-server#154)

* lower requirements for kafka consumer

* add twin test for kafka producer

* defer source.finish (swift-server#157)

* Add two consumer benchmark (swift-server#149)

* benchmark for consumer

* attempty to speedup benchmarks

* check CI works for one test

* enable one more test

* try to lower poll interval

* adjust max duration of test

* remain only manual commit test

* check if commit is the reason for test delays

* try all with schedule commit

* revert max test time to 5 seconds

* dockerfiles

* test set threasholds

* create dummy thresholds from ci results

* disable benchmark in CI

* add header

* add stable metrics

* update thresholds to stable metrics only

* try use '1' instead of 'true'

* adjust thresholds to CI results (as temporary measure)

* set 20% threshold..

* move arc to unstable metrics

* try use 'true' in quotes for CI

* try reduce number of messages for more reliable results

* try upgrade bench

* disable benchmark in CI

* Update librdkafka for BoringSSL (swift-server#162)

* chore(patch): [sc-8379] use returned error (swift-server#163)

* [producer message] Allow optional key for initializer (swift-server#164)

Co-authored-by: Harish Yerra <[email protected]>

* Allow groupID to be specified when assigning partition (swift-server#161)

* Allow groupID to be specified when assigning partition

Motivation:

A Consumer Group can provide a lot of benefits even if the
dynamic loadbalancing features are not used.

Modifications:

Allow for an optional GroupID when creating a partition
consumer.

Result:

Consumer Groups can now be used when manual assignment is
used.

* fix format

---------

Co-authored-by: Ómar Kjartan Yasin <[email protected]>
Co-authored-by: blindspotbounty <[email protected]>
Co-authored-by: Franz Busch <[email protected]>

* Wrap rd_kafka_consumer_poll into iterator (use librdkafka embedded backpressure) (swift-server#158)

* remove message sequence

* test consumer with implicit rebalance

* misc + format

* remove artefact

* don't check a lot of messages

* fix typo

* slow down first consumer to lower message to fit CI timeout

* remove helpers

* use exact benchmark version to avoid missing thresholds error (as no thresholds so far)

* add deprecated marks for backpressure, change comment for future dev

* address comments

---------

Co-authored-by: Felix Schlegel <[email protected]>
Co-authored-by: Axel Andersson <[email protected]>
Co-authored-by: Franz Busch <[email protected]>
Co-authored-by: Samuel M <[email protected]>
Co-authored-by: Harish Yerra <[email protected]>
Co-authored-by: Harish Yerra <[email protected]>
Co-authored-by: Omar Yasin <[email protected]>
Co-authored-by: Ómar Kjartan Yasin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants