Skip to content

Add a metric recording the overall time spent building each crate #2186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/build_queue.rs
Original file line number Diff line number Diff line change
@@ -164,10 +164,7 @@ impl BuildQueue {
.is_some())
}

pub(crate) fn process_next_crate(
&self,
f: impl FnOnce(&QueuedCrate) -> Result<()>,
) -> Result<()> {
fn process_next_crate(&self, f: impl FnOnce(&QueuedCrate) -> Result<()>) -> Result<()> {
let mut conn = self.db.get()?;
let mut transaction = conn.transaction()?;

@@ -198,11 +195,13 @@ impl BuildQueue {
None => return Ok(()),
};

let res = f(&to_process).with_context(|| {
format!(
"Failed to build package {}-{} from queue",
to_process.name, to_process.version
)
let res = self.metrics.build_time.observe_closure_duration(|| {
f(&to_process).with_context(|| {
format!(
"Failed to build package {}-{} from queue",
to_process.name, to_process.version
)
})
});
self.metrics.total_builds.inc();
if let Err(err) =
@@ -631,6 +630,7 @@ mod tests {
let metrics = env.instance_metrics();
assert_eq!(metrics.total_builds.get(), 9);
assert_eq!(metrics.failed_builds.get(), 1);
assert_eq!(metrics.build_time.get_sample_count(), 9);

// no invalidations were run since we don't have a distribution id configured
assert!(cdn::queued_or_active_crate_invalidations(&mut *env.db().conn())?.is_empty());
12 changes: 12 additions & 0 deletions src/metrics/macros.rs
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ macro_rules! metrics {
pub(crate) recently_accessed_releases: RecentlyAccessedReleases,
pub(crate) cdn_invalidation_time: prometheus::HistogramVec,
pub(crate) cdn_queue_time: prometheus::HistogramVec,
pub(crate) build_time: prometheus::Histogram,
}
impl $name {
$vis fn new() -> Result<Self, prometheus::Error> {
@@ -61,11 +62,22 @@ macro_rules! metrics {
)?;
registry.register(Box::new(cdn_queue_time.clone()))?;

let build_time = prometheus::Histogram::with_opts(
prometheus::HistogramOpts::new(
"build_time",
"time spent building crates",
)
.namespace($namespace)
.buckets($crate::metrics::build_time_histogram_buckets()),
)?;
registry.register(Box::new(build_time.clone()))?;

Ok(Self {
registry,
recently_accessed_releases: RecentlyAccessedReleases::new(),
cdn_invalidation_time,
cdn_queue_time,
build_time,
$(
$(#[$meta])*
$metric,
33 changes: 30 additions & 3 deletions src/metrics/mod.rs
Original file line number Diff line number Diff line change
@@ -30,11 +30,38 @@ pub const CDN_INVALIDATION_HISTOGRAM_BUCKETS: &[f64; 11] = &[
1200.0, // 20
1800.0, // 30
2700.0, // 45
6000.0, // 60
12000.0, // 120
24000.0, // 240
6000.0, // 100
12000.0, // 200
24000.0, // 400
];

/// the measured times of building crates will be put into these buckets
pub fn build_time_histogram_buckets() -> Vec<f64> {
vec![
30.0, // 0.5
60.0, // 1
120.0, // 2
180.0, // 3
240.0, // 4
300.0, // 5
360.0, // 6
420.0, // 7
480.0, // 8
540.0, // 9
600.0, // 10
660.0, // 11
720.0, // 12
780.0, // 13
840.0, // 14
900.0, // 15
1200.0, // 20
1800.0, // 30
2400.0, // 40
3000.0, // 50
3600.0, // 60
]
}

metrics! {
pub struct InstanceMetrics {
/// The number of idle database connections