Skip to content

Commit

Permalink
fix: metrics console back up (#1836)
Browse files Browse the repository at this point in the history
  • Loading branch information
callicles authored Oct 16, 2024
1 parent d6c453e commit 2c8549d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions apps/framework-cli/src/cli/local_webserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,12 @@ async fn log_route(req: Request<Incoming>) -> Response<Full<Bytes>> {
}

async fn metrics_log_route(req: Request<Incoming>, metrics: Arc<Metrics>) -> Response<Full<Bytes>> {
debug!("Received metrics log route");

let body = to_reader(req).await;
let parsed: Result<MetricEvent, serde_json::Error> = serde_json::from_reader(body);
debug!("Parsed metrics log route: {:?}", parsed);

if let Ok(MetricEvent::StreamingFunctionEvent {
count_in,
count_out,
Expand Down
23 changes: 22 additions & 1 deletion apps/framework-cli/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::metrics_inserter::MetricsInserter;
use crate::utilities::constants::{CLI_VERSION, CONTEXT, CTX_SESSION_ID};
use crate::utilities::decode_object;
use chrono::{DateTime, Utc};
use log::warn;
use log::{debug, warn};

const DEFAULT_ANONYMOUS_METRICS_URL: &str =
"https://moosefood.514.dev/ingest/MooseSessionTelemetry/0.6";
Expand Down Expand Up @@ -49,6 +49,7 @@ pub enum MetricsErrors {
}

#[derive(Debug, Clone, Deserialize)]
#[serde(untagged)]
pub enum MetricEvent {
// GetMetricsRegistryAsString(tokio::sync::oneshot::Sender<String>),
IngestedEvent {
Expand Down Expand Up @@ -104,6 +105,7 @@ pub struct Metrics {
registry: Arc<Mutex<Registry>>,
}

#[derive(Clone, Debug)]
pub struct Statistics {
pub http_latency_histogram_aggregate: Histogram,
pub http_latency_histogram: Family<HTTPLabel, Histogram>,
Expand Down Expand Up @@ -262,6 +264,7 @@ impl Metrics {
registry.register(
TOTAL_LATENCY,
"Total latency of HTTP requests",
// Those clones are ok because this is cloning an Arc reference behind the scenes
data.http_latency_histogram_aggregate.clone(),
);
registry.register(
Expand Down Expand Up @@ -322,6 +325,9 @@ impl Metrics {
if export_metrics {
let _ = metrics_inserter.insert(message.clone()).await;
}

debug!("Received Metrics Event: {:?}", message);

match message {
MetricEvent::IngestedEvent {
timestamp: _,
Expand All @@ -338,9 +344,20 @@ impl Metrics {
path: route.clone(),
})
.inc_by(bytes);

data.http_ingested_request_count.inc();
data.http_ingested_total_bytes.inc_by(bytes);

data.http_latency_histogram
.get_or_create(&HTTPLabel {
method: method.clone(),
path: route.clone(),
})
.observe(latency.as_secs_f64());

data.http_latency_histogram_aggregate
.observe(latency.as_secs_f64());

data.http_ingested_latency_sum_ms
.inc_by(latency.as_millis() as u64);

Expand All @@ -366,8 +383,10 @@ impl Metrics {
path: route.clone(),
})
.observe(latency.as_secs_f64());

data.http_latency_histogram_aggregate
.observe(latency.as_secs_f64());

data.http_consumed_latency_sum_ms
.inc_by(latency.as_millis() as u64);

Expand Down Expand Up @@ -433,6 +452,8 @@ impl Metrics {
.inc_by(bytes);
}
};

debug!("Updated metrics: {:?}", data);
}
});

Expand Down

0 comments on commit 2c8549d

Please sign in to comment.