Skip to content

Commit

Permalink
Add a ThreadLocal metrics aggregator
Browse files Browse the repository at this point in the history
Thus far, this only works for `count` metrics, but we can extend it in the future as well.
  • Loading branch information
Swatinem committed Feb 19, 2024
1 parent da5fa76 commit 396f183
Show file tree
Hide file tree
Showing 4 changed files with 274 additions and 76 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

125 changes: 74 additions & 51 deletions crates/symbolicator-js/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
//! Should be `0`, as we should find/use files from within bundles or as individual artifacts.
use symbolic::debuginfo::sourcebundle::SourceFileType;
use symbolicator_service::metric;
use symbolicator_service::{metric, metrics};

use crate::interface::ResolvedWith;

Expand Down Expand Up @@ -117,6 +117,18 @@ impl JsMetrics {
}

pub fn submit_metrics(&self, artifact_bundles: u64) {
metrics::with_client(|client| {
client.with_local_aggregator(|aggregator| {
self.submit_metrics_inner(aggregator, artifact_bundles);
});
})
}

fn submit_metrics_inner(
&self,
aggregator: &mut metrics::LocalAggregator,
artifact_bundles: u64,
) {
metric!(time_raw("js.needed_files") = self.needed_files);
metric!(time_raw("js.api_requests") = self.api_requests);
metric!(time_raw("js.queried_bundles") = self.queried_bundles);
Expand All @@ -129,74 +141,85 @@ impl JsMetrics {
// have a per-event avg, etc.

// Sources:
metric!(
counter("js.found_via_bundle_debugid") += self.found_source_via_debugid,
"type" => "source",
aggregator.emit_count(
"js.found_via_bundle_debugid",
self.found_source_via_debugid,
&[("type", "source")],
);
metric!(
counter("js.found_via_bundle_url") += self.found_source_via_release,
"type" => "source",
"lookup" => "release",
aggregator.emit_count(
"js.found_via_bundle_url",
self.found_source_via_release,
&[("type", "source"), ("lookup", "release")],
);
metric!(
counter("js.found_via_bundle_url") += self.found_source_via_release_old,
"type" => "source",
"lookup" => "release-old",
aggregator.emit_count(
"js.found_via_bundle_url",
self.found_source_via_release_old,
&[("type", "source"), ("lookup", "release-old")],
);
metric!(
counter("js.found_via_scraping") += self.found_source_via_scraping,
"type" => "source",
aggregator.emit_count(
"js.found_via_scraping",
self.found_source_via_scraping,
&[("type", "source")],
);
metric!(
counter("js.file_not_found") += self.source_not_found,
"type" => "source",
aggregator.emit_count(
"js.file_not_found",
self.source_not_found,
&[("type", "source")],
);

// SourceMaps:
metric!(
counter("js.found_via_bundle_debugid") += self.found_sourcemap_via_debugid,
"type" => "sourcemap",
aggregator.emit_count(
"js.found_via_bundle_debugid",
self.found_sourcemap_via_debugid,
&[("type", "sourcemap")],
);
metric!(
counter("js.found_via_bundle_url") += self.found_sourcemap_via_release,
"type" => "sourcemap",
"lookup" => "release",
aggregator.emit_count(
"js.found_via_bundle_url",
self.found_sourcemap_via_release,
&[("type", "sourcemap"), ("lookup", "release")],
);
metric!(
counter("js.found_via_bundle_url") += self.found_sourcemap_via_release_old,
"type" => "sourcemap",
"lookup" => "release-old",
aggregator.emit_count(
"js.found_via_bundle_url",
self.found_sourcemap_via_release_old,
&[("type", "sourcemap"), ("lookup", "release-old")],
);
metric!(
counter("js.found_via_scraping") += self.found_sourcemap_via_scraping,
"type" => "sourcemap",
aggregator.emit_count(
"js.found_via_scraping",
self.found_sourcemap_via_scraping,
&[("type", "sourcemap")],
);
metric!(
counter("js.file_not_found") += self.sourcemap_not_found,
"type" => "sourcemap",
aggregator.emit_count(
"js.file_not_found",
self.sourcemap_not_found,
&[("type", "sourcemap")],
);
metric!(counter("js.sourcemap_not_needed") += self.sourcemap_not_needed);
aggregator.emit_count("js.sourcemap_not_needed", self.sourcemap_not_needed, &[]);

// Lookup Method:
metric!(
counter("js.bundle_lookup") += self.found_bundle_via_bundleindex,
"method" => "bundleindex"
aggregator.emit_count(
"js.bundle_lookup",
self.found_bundle_via_bundleindex,
&[("method", "bundleindex")],
);
metric!(
counter("js.bundle_lookup") += self.found_bundle_via_debugid,
"method" => "debugid"
aggregator.emit_count(
"js.bundle_lookup",
self.found_bundle_via_debugid,
&[("method", "debugid")],
);
metric!(
counter("js.bundle_lookup") += self.found_bundle_via_index,
"method" => "index"
aggregator.emit_count(
"js.bundle_lookup",
self.found_bundle_via_index,
&[("method", "index")],
);
metric!(
counter("js.bundle_lookup") += self.found_bundle_via_release,
"method" => "release"
aggregator.emit_count(
"js.bundle_lookup",
self.found_bundle_via_release,
&[("method", "release")],
);
metric!(
counter("js.bundle_lookup") += self.found_bundle_via_release_old,
"method" => "release-old"
aggregator.emit_count(
"js.bundle_lookup",
self.found_bundle_via_release_old,
&[("method", "release-old")],
);
}
}
3 changes: 3 additions & 0 deletions crates/symbolicator-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ aws-sdk-s3 = "1.4.0"
aws-types = "1.0.1"
cadence = "1.0.0"
chrono = { version = "0.4.19", features = ["serde"] }
crossbeam-utils = "0.8.19"
filetime = "0.2.16"
flate2 = "1.0.23"
futures = "0.3.12"
Expand All @@ -29,6 +30,7 @@ moka = { version = "0.12.1", features = ["future", "sync"] }
once_cell = "1.17.1"
rand = "0.8.5"
reqwest = { version = "0.11.0", features = ["gzip", "brotli", "deflate", "json", "stream", "trust-dns"] }
rustc-hash = "1.1.0"
sentry = { version = "0.32.1", features = ["tracing"] }
serde = { version = "1.0.137", features = ["derive", "rc"] }
serde_json = "1.0.81"
Expand All @@ -38,6 +40,7 @@ symbolic = { version = "12.7.1", features = ["cfi", "common-serde", "debuginfo",
symbolicator-sources = { path = "../symbolicator-sources" }
tempfile = "3.2.0"
thiserror = "1.0.31"
thread_local = "1.1.7"
tokio = { version = "1.24.2", features = ["rt", "macros", "fs"] }
tokio-util = { version = "0.7.1", features = ["io"] }
tracing = "0.1.34"
Expand Down
Loading

0 comments on commit 396f183

Please sign in to comment.