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

Add NATS event callback metrics #5554

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/naxum/src/middleware/ack/on_failure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl OnFailure for DefaultOnFailure {
trace!("nacking message");
if let Err(err) = acker.ack_with(jetstream::AckKind::Nak(None)).await {
warn!(
error = ?err,
si.error.message = ?err,
subject = head.subject.as_str(),
"failed to nack the message",
);
Expand Down
2 changes: 1 addition & 1 deletion lib/naxum/src/middleware/ack/on_success.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl OnSuccess for DefaultOnSuccess {
trace!("double acking message");
if let Err(err) = acker.double_ack().await {
warn!(
error = ?err,
si.error.message = ?err,
subject = head.subject.as_str(),
"failed to double ack the message",
);
Expand Down
2 changes: 1 addition & 1 deletion lib/naxum/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ where
Err(err) => {
if failed_count > MAX_FAILED_MESSAGES {
warn!(
error = ?err,
si.error.message = ?err,
"failed to read message in after {} consecutive failures; closing stream",
failed_count,
);
Expand Down
1 change: 1 addition & 0 deletions lib/si-data-nats/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ rust_library(
name = "si-data-nats",
deps = [
"//lib/telemetry-rs:telemetry",
"//lib/telemetry-utils-rs:telemetry-utils",
"//third-party/rust:async-nats",
"//third-party/rust:bytes",
"//third-party/rust:futures",
Expand Down
1 change: 1 addition & 0 deletions lib/si-data-nats/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ publish.workspace = true

[dependencies]
telemetry = { path = "../../lib/telemetry-rs" }
telemetry-utils = { path = "../../lib/telemetry-utils-rs" }

async-nats = { workspace = true }
bytes = { workspace = true }
Expand Down
24 changes: 24 additions & 0 deletions lib/si-data-nats/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use async_nats::{subject::ToSubject, ToServerAddrs};
use bytes::Bytes;
use serde::{Deserialize, Serialize};
use telemetry::prelude::*;
use telemetry_utils::metric;
use thiserror::Error;
use tokio::sync::Mutex;

Expand Down Expand Up @@ -121,6 +122,29 @@ impl Client {
if let Some(connection_name) = &config.connection_name {
options = options.name(connection_name);
}

options = options.event_callback(|event| async move {
match event {
Event::Connected => metric!(counter.nats.event_callback.connected = 1),
Event::Disconnected => metric!(counter.nats.event_callback.disconnected = 1),
Event::Closed => metric!(counter.nats.event_callback.closed = 1),
Event::LameDuckMode => metric!(counter.nats.event_callback.lame_duck_mode = 1),
Event::Draining => metric!(counter.nats.event_callback.draining = 1),
Event::SlowConsumer(sid) => {
metric!(counter.nats.event_callback.slow_consumer = 1);
warn!(%sid, "nats event callback: slow consumers for subscription");
}
Event::ServerError(server_error) => {
metric!(counter.nats.event_callback.server_error = 1);
error!(si.error.message = ?server_error, "nats event callback: server error")
}
Event::ClientError(client_error) => {
metric!(counter.nats.event_callback.client_error = 1);
error!(si.error.message = ?client_error, "nats event callback: client error")
}
}
});

Self::connect_with_options(&config.url, config.subject_prefix.clone(), options).await
}

Expand Down
2 changes: 1 addition & 1 deletion lib/veritech-server/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ where
};
request.dec_run_metric();
if let Err(err) = publisher.publish_result(&func_result_error).await {
error!(error = ?err, "failed to publish errored result");
error!(si.error.message = ?err, "failed to publish errored result");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/veritech-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl Server {
#[inline]
pub async fn run(self) {
if let Err(err) = self.try_run().await {
error!(error = ?err, "error while running veritech main loop");
error!(si.error.message = ?err, "error while running veritech main loop");
}
}

Expand Down