Skip to content

Conversation

@marc-sift
Copy link
Contributor

No description provided.

@@ -0,0 +1,21 @@
/// Build descriptor's so that the Black Hole gRPC server can
/// stand up the reflection service.
fn main() -> Result<(), Box<dyn std::error::Error>> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

There shouldn't be a need for you to compile these protos since they're already compiled and available in the sift_rs crate which you can add as a dependency like here:

sift_rs = { workspace = true }

use crate::cmd::test_server::metrics_streaming_client::Metrics;

pub async fn run(ctx: Context, args: TestServerArgs) -> Result<ExitCode> {
let local_address = args.local_address.unwrap_or("127.0.0.1:50051".into());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer 0.0.0.0 since it's more user-friendly. Allows it to be reached inside of a docker network for example. Also as a note of good practice:

local_address = args.local_address.unwrap_or_else(|| "127.0.0.1:50051".to_string())

for lazy evaluation of the fallback rather than immediate


pub async fn run(ctx: Context, args: TestServerArgs) -> Result<ExitCode> {
let local_address = args.local_address.unwrap_or("127.0.0.1:50051".into());
let addr = local_address.parse()?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Generally helpful to include contextual information with errors for better traceability:

use anyhow::{Result, Context};

let addr = local_address.parse().context("foobar")?;

Copy link
Collaborator

Choose a reason for hiding this comment

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

Same for all other places.

// Initialize streaming client.
let mut streaming_client =
MetricsStreamingClient::build(ctx, &args.stream_metrics, &args.metrics_asset_name)?;
if streaming_client.is_some() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer:

if let Some(client) = streaming_client.as_mut() {
    client.initialize.await.context("failed to initialize client").await?;
}


// Start task to ingest metrics to Sift.
let ingest_metrics_task = tokio::spawn(async move {
if streaming_client.is_none() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer:

let Some(mut client) = streaming_client else {
    return;
};

return;
}

let mut client = streaming_client.unwrap();
Copy link
Collaborator

@solidiquis solidiquis Dec 30, 2025

Choose a reason for hiding this comment

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

see:

let Some(mut client) = streaming_client else {
    return;
};

Copy link
Collaborator

@solidiquis solidiquis left a comment

Choose a reason for hiding this comment

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

Definitely run: cargo fmt and cargo clippy. The latter will give you a lot of good feedback.

last_total_num_messages = current_total_num_messages;

// Clear terminal and print metrics.
stdout()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Calling stdout() repeatedly is bad for performance because it will repeatedly get a handle and lock stdout. See this method to acquire the handle/lock once: https://doc.rust-lang.org/std/io/struct.Stdout.html#method.lock

#[derive(Default)]
pub struct TestServer {
/// Total number of streams created.
total_num_streams: AtomicU32,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do these need to be atomics?

#[tonic::async_trait]
impl PingService for TestServer {
async fn ping(&self, _request: Request<PingRequest>) -> Result<Response<PingResponse>, Status> {
let resp = PingResponse {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You might be able to just do PingResponse::default().

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