rs-zero 0.2.6

Rust-first microservice framework inspired by go-zero engineering practices
Documentation
#![cfg(feature = "profiling")]

use std::{collections::BTreeMap, time::Duration};

use rs_zero::profiling::{
    ProfilingConfig, ProfilingHandle, PyroscopeConfig, build_pyroscope_agent_config,
};

#[test]
fn profiling_default_is_disabled_and_noop_shutdown_is_safe() {
    let config = ProfilingConfig::default();
    let handle = ProfilingHandle::disabled();

    assert!(!config.enabled);
    assert!(!handle.is_running());
    handle.shutdown().expect("shutdown");
}

#[test]
fn pyroscope_config_normalizes_tags_and_sample_rate() {
    let mut tags = BTreeMap::new();
    tags.insert("env".to_string(), "staging".to_string());
    let config = PyroscopeConfig {
        endpoint: "http://127.0.0.1:4040".to_string(),
        service_name: "orders".to_string(),
        sample_rate: 0,
        tags,
        shutdown_timeout: Duration::from_secs(2),
    };

    let normalized = build_pyroscope_agent_config(config).expect("config");

    assert_eq!(normalized.service_name, "orders");
    assert_eq!(normalized.sample_rate, 100);
    assert_eq!(normalized.tags["env"], "staging");
}