Skip to content

Commit

Permalink
fix: count both success and failures of reconile loop
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielc committed Feb 2, 2024
1 parent 06bbea0 commit 2fee683
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 7 deletions.
2 changes: 1 addition & 1 deletion common/src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub async fn init_metrics_prom(
Ok((meter, shutdown, join))
}

// /metrics scrape endpoin
// /metrics scrape endpoint.
async fn handle(_req: Request<Body>) -> Result<Response<Body>, Infallible> {
let mut data = Vec::new();
let encoder = TextEncoder::new();
Expand Down
31 changes: 28 additions & 3 deletions operator/src/network/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use kube::{
},
Resource,
};
use opentelemetry::global;
use opentelemetry::{global, KeyValue};
use rand::RngCore;
use tracing::{debug, error, info, trace, warn};

Expand Down Expand Up @@ -208,8 +208,33 @@ async fn reconcile(
.u64_counter("network_reconcile_count")
.with_description("Number of network reconciles")
.init();
runs.add(1, &[]);

match reconcile_(network, cx).await {
Ok(action) => {
runs.add(
1,
&[KeyValue {
key: "result".into(),
value: "ok".into(),
}],
);
Ok(action)
}
Err(err) => {
runs.add(
1,
&[KeyValue {
key: "result".into(),
value: "err".into(),
}],
);
Err(err)
}
}
}
async fn reconcile_(
network: Arc<Network>,
cx: Arc<Context<impl IpfsRpcClient, impl RngCore, impl Clock>>,
) -> Result<Action, Error> {
let spec = network.spec();
debug!(?spec, "reconcile");

Expand Down
32 changes: 29 additions & 3 deletions operator/src/simulation/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use kube::{
},
Resource, ResourceExt,
};
use opentelemetry::global;
use opentelemetry::{global, KeyValue};
use rand::{distributions::Alphanumeric, thread_rng, Rng, RngCore};

use tracing::{debug, error, info};
Expand Down Expand Up @@ -123,7 +123,6 @@ pub async fn run() {
})
.await;
}

/// Perform a reconile pass for the Simulation CRD
async fn reconcile(
simulation: Arc<Simulation>,
Expand All @@ -134,8 +133,35 @@ async fn reconcile(
.u64_counter("simulation_reconcile_count")
.with_description("Number of simulation reconciles")
.init();
runs.add(1, &[]);

match reconcile_(simulation, cx).await {
Ok(action) => {
runs.add(
1,
&[KeyValue {
key: "result".into(),
value: "ok".into(),
}],
);
Ok(action)
}
Err(err) => {
runs.add(
1,
&[KeyValue {
key: "result".into(),
value: "err".into(),
}],
);
Err(err)
}
}
}
/// Perform a reconile pass for the Simulation CRD
async fn reconcile_(
simulation: Arc<Simulation>,
cx: Arc<Context<impl IpfsRpcClient, impl RngCore, impl Clock>>,
) -> Result<Action, Error> {
let spec = simulation.spec();

let status = if let Some(status) = &simulation.status {
Expand Down

0 comments on commit 2fee683

Please sign in to comment.