-
Notifications
You must be signed in to change notification settings - Fork 0
Add count
#65
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
Open
danielmaclaren
wants to merge
5
commits into
main
Choose a base branch
from
bluesky_52
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add count
#65
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
082db27
counts feature
danielmaclaren 64592f3
cargo fmt correction
danielmaclaren 53fc42a
Tom's reviews (minus extra command line, which will be resolved in an…
danielmaclaren f89ad19
comments resolved minus the extra commands (to be another ticket)
danielmaclaren c205d0a
cargo fmt check and README.md
danielmaclaren 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| use crate::cli_utils::BrokerAndTopic; | ||
| use futures::stream::StreamExt; | ||
| use log::error; | ||
| use rdkafka::consumer::{Consumer, DefaultConsumerContext, StreamConsumer}; | ||
| use rdkafka::{ClientConfig, Message}; | ||
| use tokio::time::{self, Duration}; | ||
| use uuid::Uuid; | ||
|
|
||
| pub async fn count(topic: BrokerAndTopic, message_interval: u64) { | ||
| let consumer: StreamConsumer<DefaultConsumerContext> = ClientConfig::new() | ||
| .set("group.id", Uuid::new_v4().to_string()) | ||
| .set("bootstrap.servers", topic.broker()) | ||
| .create() | ||
| .expect("Consumer creation failed"); | ||
|
|
||
| consumer | ||
| .subscribe(&[&topic.topic]) | ||
| .unwrap_or_else(|e| panic!("Failed to subscribe to topic {}: {}", topic.topic, e)); | ||
|
|
||
| let start = std::time::Instant::now(); | ||
| let mut bytes_this_second: usize = 0; | ||
| let mut total_bytes: usize = 0; | ||
| let mut stream = consumer.stream(); | ||
| let mut interval = time::interval(Duration::from_secs(message_interval)); | ||
|
|
||
| loop { | ||
| tokio::select! { | ||
| _msg = stream.next() => { | ||
| match _msg { | ||
| Some(Ok(msg)) => { | ||
| if msg.payload().is_some() { | ||
| bytes_this_second += msg.payload_len(); | ||
| total_bytes += msg.payload_len(); | ||
| } | ||
|
|
||
| }, | ||
| Some(Err(e)) => error!("Error reading from stream {:?}", e), | ||
| None => {} | ||
| } | ||
| } | ||
| _ = interval.tick() => { | ||
| println!("{:.5} Mbit/s (since program start: average {:.5} Mbit/s, {:.5} MB total)", | ||
| bytes_this_second as f64/125000.0, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only true if Streaming at
|
||
| total_bytes as f64 / 125000.0 / start.elapsed().as_secs_f64(), | ||
| total_bytes as f64 / 1_000_000.0 | ||
| ); | ||
| bytes_this_second = 0; | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should provide some way to pass extra parameters here - either as command line args, in a config file, in env variables, whatever.
Probably extra command line args is easiest.
I'd rather not have to recompile if it turns out we need to specify a queue size or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'll do this separately for all commands as part of #14