Skip to content

Commit 3db32e4

Browse files
committed
add builder metrics
Counters for some basic build metrics.
1 parent c1df5e3 commit 3db32e4

File tree

5 files changed

+77
-11
lines changed

5 files changed

+77
-11
lines changed

ofborg/src/bin/builder.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use async_std::task;
66
use tracing::{info, warn};
77

88
use ofborg::easyamqp::{self, ChannelExt, ConsumerExt};
9-
use ofborg::easylapin;
10-
use ofborg::{checkout, config, tasks};
9+
use ofborg::{checkout, config, easylapin, metrics, tasks};
1110

1211
// FIXME: remove with rust/cargo update
1312
#[allow(clippy::cognitive_complexity)]
@@ -93,6 +92,8 @@ fn main() -> Result<(), Box<dyn Error>> {
9392
},
9493
)?;
9594

95+
metrics::spawn_server();
96+
9697
info!("Fetching jobs from {}", &queue_name);
9798
task::block_on(handle);
9899

ofborg/src/easylapin.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
use std::pin::Pin;
22

3-
use crate::config::RabbitMQConfig;
4-
use crate::easyamqp::{
5-
BindQueueConfig, ChannelExt, ConsumeConfig, ConsumerExt, ExchangeConfig, ExchangeType,
6-
QueueConfig,
7-
};
8-
use crate::notifyworker::{NotificationReceiver, SimpleNotifyWorker};
9-
use crate::ofborg;
10-
use crate::worker::{Action, SimpleWorker};
11-
123
use async_std::future::Future;
134
use async_std::stream::StreamExt;
145
use async_std::task;
@@ -21,6 +12,16 @@ use lapin::types::{AMQPValue, FieldTable};
2112
use lapin::{BasicProperties, Channel, Connection, ConnectionProperties, ExchangeKind};
2213
use tracing::{debug, trace};
2314

15+
use crate::config::RabbitMQConfig;
16+
use crate::easyamqp::{
17+
BindQueueConfig, ChannelExt, ConsumeConfig, ConsumerExt, ExchangeConfig, ExchangeType,
18+
QueueConfig,
19+
};
20+
use crate::metrics;
21+
use crate::notifyworker::{NotificationReceiver, SimpleNotifyWorker};
22+
use crate::ofborg;
23+
use crate::worker::{Action, SimpleWorker};
24+
2425
pub fn from_config(cfg: &RabbitMQConfig) -> Result<Connection, lapin::Error> {
2526
let mut props = FieldTable::default();
2627
props.insert(
@@ -166,6 +167,8 @@ impl<'a, W: SimpleNotifyWorker + 'a> ConsumerExt<'a, W> for NotifyChannel {
166167
Ok(Box::pin(async move {
167168
while let Some(Ok(deliver)) = consumer.next().await {
168169
debug!(?deliver.delivery_tag, "consumed delivery");
170+
metrics::JOBS_RECEIVED.inc();
171+
169172
let mut receiver = ChannelNotificationReceiver {
170173
channel: &mut chan,
171174
deliver: &deliver,

ofborg/src/message/buildresult.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ pub enum BuildStatus {
1111
UnexpectedError { err: String },
1212
}
1313

14+
impl BuildStatus {
15+
pub fn as_label(&self) -> &'static str {
16+
match self {
17+
BuildStatus::Skipped => "skipped",
18+
BuildStatus::Success => "success",
19+
BuildStatus::Failure => "failure",
20+
BuildStatus::TimedOut => "timeout",
21+
BuildStatus::UnexpectedError { err } => "unexpected",
22+
}
23+
}
24+
}
25+
1426
impl From<BuildStatus> for String {
1527
fn from(status: BuildStatus) -> String {
1628
match status {

ofborg/src/metrics.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,38 @@ use tracing::info;
1212

1313
use crate::ofborg;
1414

15+
lazy_static! {
16+
pub static ref JOBS_RECEIVED: IntCounter = register_int_counter!(
17+
"ofborg_jobs_received_total",
18+
"Total number of jobs received."
19+
)
20+
.unwrap();
21+
pub static ref BUILDS_RECEIVED: CounterVec = register_counter_vec!(
22+
"ofborg_builds_received_total",
23+
"Total number of builds received.",
24+
&["system"]
25+
)
26+
.unwrap();
27+
pub static ref BUILDS_FINISHED: CounterVec = register_counter_vec!(
28+
"ofborg_builds_finished_total",
29+
"Total number of builds finished.",
30+
&["system", "status"]
31+
)
32+
.unwrap();
33+
pub static ref BUILDS_ATTRIBUTES_ATTEMPTED: CounterVec = register_counter_vec!(
34+
"ofborg_builds_attributes_attempted_total",
35+
"Total number of attributes attempted to build.",
36+
&["system"]
37+
)
38+
.unwrap();
39+
pub static ref BUILDS_ATTRIBUTES_NOT_ATTEMPTED: CounterVec = register_counter_vec!(
40+
"ofborg_builds_attributes_not_attempted_total",
41+
"Total number of attributes not attempted to build.",
42+
&["system"]
43+
)
44+
.unwrap();
45+
}
46+
1547
lazy_static! {
1648
static ref VERSION: GaugeVec = register_gauge_vec!(
1749
"ofborg_version",

ofborg/src/tasks/build.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::checkout;
22
use crate::commentparser;
33
use crate::message::buildresult::{BuildResult, BuildStatus, V1Tag};
44
use crate::message::{buildjob, buildlogmsg};
5+
use crate::metrics;
56
use crate::nix;
67
use crate::notifyworker;
78
use crate::worker;
@@ -280,6 +281,9 @@ impl notifyworker::SimpleNotifyWorker for BuildWorker {
280281
) {
281282
let span = debug_span!("job", pr = ?job.pr.number);
282283
let _enter = span.enter();
284+
metrics::BUILDS_RECEIVED
285+
.with_label_values(&[&self.system])
286+
.inc();
283287

284288
let mut actions = self.actions(&job, notifier);
285289

@@ -347,6 +351,14 @@ impl notifyworker::SimpleNotifyWorker for BuildWorker {
347351
cannot_build_attrs.join(", ")
348352
);
349353

354+
metrics::BUILDS_ATTRIBUTES_ATTEMPTED
355+
.with_label_values(&[&self.system])
356+
.inc_by(can_build.len() as f64);
357+
358+
metrics::BUILDS_ATTRIBUTES_NOT_ATTEMPTED
359+
.with_label_values(&[&self.system])
360+
.inc_by(cannot_build_attrs.len() as f64);
361+
350362
actions.log_started(can_build.clone(), cannot_build_attrs.clone());
351363
actions.log_instantiation_errors(cannot_build);
352364

@@ -375,7 +387,13 @@ impl notifyworker::SimpleNotifyWorker for BuildWorker {
375387
.last();
376388
info!("----->8-----");
377389

390+
let status_label = status.as_label();
378391
actions.build_finished(status, can_build, cannot_build_attrs);
392+
393+
metrics::BUILDS_FINISHED
394+
.with_label_values(&[&self.system, status_label])
395+
.inc();
396+
379397
info!("Build done!");
380398
}
381399
}

0 commit comments

Comments
 (0)