Skip to content

Commit

Permalink
add some timing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverb123 committed Oct 28, 2024
1 parent eae92ad commit 7dbf4bb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
21 changes: 16 additions & 5 deletions rust/cymbal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use cymbal::{
app_context::AppContext,
config::Config,
error::Error,
metric_consts::{ERRORS, EVENT_RECEIVED, STACK_PROCESSED},
metric_consts::{
ERRORS, EVENT_RECEIVED, MAIN_LOOP_TIME, PER_FRAME_TIME, PER_STACK_TIME, STACK_PROCESSED,
},
types::{frames::RawFrame, ErrProps},
};
use envconfig::Envconfig;
Expand Down Expand Up @@ -60,6 +62,7 @@ async fn main() -> Result<(), Error> {
start_health_liveness_server(&config, context.clone());

loop {
let whole_loop = common_metrics::timing_guard(MAIN_LOOP_TIME, &[]);
context.worker_liveness.report_healthy().await;
// Just grab the event as a serde_json::Value and immediately drop it,
// we can work out a real type for it later (once we're deployed etc)
Expand Down Expand Up @@ -109,25 +112,33 @@ async fn main() -> Result<(), Error> {
continue;
}

// TODO - we should resolve all traces
let Some(trace) = exception_list[0].stacktrace.as_ref() else {
metrics::counter!(ERRORS, "cause" => "no_stack_trace").increment(1);
continue;
};

let stack_trace: &Vec<RawFrame> = &trace.frames;

let mut resolved_frames = Vec::new();
let per_stack = common_metrics::timing_guard(PER_STACK_TIME, &[]);
let mut frames = Vec::with_capacity(stack_trace.len());
for frame in stack_trace {
let resolved = match frame.resolve(event.team_id, &context.catalog).await {
Ok(r) => r,
match frame.resolve(event.team_id, &context.catalog).await {
Ok(r) => frames.push(r),
Err(err) => {
metrics::counter!(ERRORS, "cause" => "frame_not_parsable").increment(1);
error!("Error parsing stack frame: {:?}", err);
continue;
}
};
resolved_frames.push(resolved);
}
per_stack
.label(
"resolved_any",
if frames.len() > 0 { "true" } else { "false" },
)
.fin();
whole_loop.label("had_frame", "true").fin();

metrics::counter!(STACK_PROCESSED).increment(1);
}
Expand Down
3 changes: 3 additions & 0 deletions rust/cymbal/src/metric_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ pub const STORE_CACHE_MISSES: &str = "cymbal_store_cache_misses";
pub const STORE_CACHED_BYTES: &str = "cymbal_store_cached_bytes";
pub const STORE_CACHE_SIZE: &str = "cymbal_store_cache_size";
pub const STORE_CACHE_EVICTIONS: &str = "cymbal_store_cache_evictions";
pub const MAIN_LOOP_TIME: &str = "cymbal_main_loop_time";
pub const PER_FRAME_TIME: &str = "cymbal_per_frame_time";
pub const PER_STACK_TIME: &str = "cymbal_per_stack_time";
2 changes: 0 additions & 2 deletions rust/cymbal/src/symbol_store/caching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ impl CacheInner {
}
}

// TODO - someone smarter than me should replace all this with a proper caching lib,
// but I'm too lazy, I uhh mean task focused, to go evaluate one right now.
impl CacheInner {
fn insert<T>(&mut self, key: String, value: Arc<T>, bytes: usize)
where
Expand Down
15 changes: 13 additions & 2 deletions rust/cymbal/src/types/frames.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use serde::{Deserialize, Serialize};

use crate::{error::Error, langs::js::RawJSFrame, symbol_store::Catalog};
use crate::{
error::Error, langs::js::RawJSFrame, metric_consts::PER_FRAME_TIME, symbol_store::Catalog,
};

// We consume a huge variety of differently shaped stack frames, which we have special-case
// transformation for, to produce a single, unified representation of a frame.
Expand All @@ -14,7 +16,16 @@ impl RawFrame {
pub async fn resolve(&self, team_id: i32, catalog: &Catalog) -> Result<Frame, Error> {
let RawFrame::JavaScript(raw) = self;

raw.resolve(team_id, catalog).await
let frame_resolve_time = common_metrics::timing_guard(PER_FRAME_TIME, &[]);
let res = raw.resolve(team_id, catalog).await;
if res.is_err() {
frame_resolve_time.label("outcome", "failed")
} else {
frame_resolve_time.label("outcome", "success")
}
.fin();

res
}
}

Expand Down

0 comments on commit 7dbf4bb

Please sign in to comment.