-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add metric implementation and address some suspected logic bugs. #20
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
aidanhall34
wants to merge
7
commits into
kindredgroup:master
Choose a base branch
from
aidanhall34:feat/metrics
base: master
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
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4cbe1e8
chore: commit wip
59ae096
chore: typo
b6b83ed
chore: push up some refactoring and add some experimental histogram b…
000fc91
chore: prepare demo push
c203754
fix: fix utc v local time spec bug + add consumer metrics
653e5cc
chore: add log line if we see time go backwards when recording kafka …
ac33cc4
chore: clean pr for merge
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
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,79 @@ | ||
| use super::super::register_telemetry::DEFAULT_OTEL_SERVICE_NAME; | ||
| use opentelemetry::{ | ||
| global, | ||
| metrics::{Counter, Histogram}, | ||
| KeyValue, | ||
| }; | ||
| use std::sync::LazyLock; | ||
|
|
||
| struct Metrics { | ||
| msg_consume_seconds: Histogram<f64>, | ||
| msg_consume_latency_seconds: Histogram<f64>, | ||
| msg_publish_seconds: Histogram<f64>, | ||
| msg_jitter_seconds: Histogram<f64>, | ||
| msg_resets: Counter<u64>, | ||
| } | ||
|
|
||
| impl Metrics { | ||
| fn new() -> Self { | ||
| let meter = global::meter(DEFAULT_OTEL_SERVICE_NAME); | ||
| Self { | ||
| // input consumption metrics | ||
| msg_consume_seconds: meter | ||
| .f64_histogram("msg.consume.service.time") | ||
| .with_description("Service time after receiving a message from the input queue") | ||
| .with_unit("s") | ||
| .build(), | ||
| msg_consume_latency_seconds: meter // Aka "lag time" | ||
| .f64_histogram("msg.consume.latency") | ||
| .with_description("Message latency on the input queue") | ||
| .with_unit("s") | ||
| .build(), | ||
| msg_publish_seconds: meter | ||
| .f64_histogram("msg.process.service.time") | ||
| .with_description("The service time of \"message ready\" processing loop. Only increments when messages are found") | ||
| .with_unit("s") | ||
| .build(), | ||
| msg_jitter_seconds: meter | ||
| .f64_histogram("msg.jitter") | ||
| .with_unit("s") | ||
| .with_description("The delta between the desired published time and confirmed published time of messages to the output topic") | ||
| .build(), | ||
| msg_resets: meter.u64_counter("msg.reset").with_description("The count of messages reset").build(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static METRICS: LazyLock<Metrics> = LazyLock::new(Metrics::new); | ||
|
|
||
| pub enum ConsumedMessageDestinations { | ||
| KAFKA, | ||
| DATABASE, | ||
| DROPPED, | ||
| } | ||
|
|
||
| pub enum Status { | ||
| SUCCESS, | ||
| ERROR, | ||
| } | ||
|
|
||
| pub fn record_msg_consume(process_time: f64, destination: ConsumedMessageDestinations, status: Status) { | ||
| let d = match destination { | ||
| ConsumedMessageDestinations::DATABASE => "database", | ||
| ConsumedMessageDestinations::KAFKA => "kafka", | ||
| ConsumedMessageDestinations::DROPPED => "dropped", | ||
| }; | ||
| let s = match status { | ||
| Status::ERROR => "error", | ||
| Status::SUCCESS => "success", | ||
| }; | ||
| METRICS | ||
| .msg_consume_seconds | ||
| .record(process_time, &[KeyValue::new("destination", d), KeyValue::new("status", s)]); | ||
| } | ||
|
|
||
| pub fn record_msg_consume_latency(latency: f64, partition: i32) { | ||
| METRICS | ||
| .msg_consume_latency_seconds | ||
| .record(latency, &[KeyValue::new("partition", partition.to_string())]); | ||
| } |
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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| pub mod metrics; | ||
| pub mod prometheus_exporter; |
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 |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| mod metrics; | ||
| pub mod metrics; | ||
| pub mod register_telemetry; | ||
| mod traces; |
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,20 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Produces a message every 5 seconds | ||
| # tested in image: | ||
| # apache/kafka:4.1.1 | ||
| while true | ||
| do | ||
| for i in "-5" "+10"; | ||
| do | ||
| echo "chronosMessageId:$(cat /proc/sys/kernel/random/uuid),chronosDeadline:$(date --date="$i seconds" --iso-8601=seconds) $(cat /proc/sys/kernel/random/uuid)::{\"msg\": \"I'm a msg!\"}" > /tmp/msg.$i ; | ||
| /opt/kafka/bin/kafka-console-producer.sh \ | ||
| --topic "chronos.in" \ | ||
| --property "parse.key=true" \ | ||
| --property "parse.headers=true" \ | ||
| --property "key.separator=::" \ | ||
| --property "headers.delimiter= " \ | ||
| --bootstrap-server "kafka:9092" < /tmp/msg.$i ; | ||
| done; | ||
| sleep 10; | ||
| done; |
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.