Skip to content

Commit

Permalink
consistency between impls
Browse files Browse the repository at this point in the history
Signed-off-by: clux <[email protected]>
  • Loading branch information
clux committed Jun 25, 2024
1 parent bb161e4 commit 37771cb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct Context {
async fn reconcile(doc: Arc<Document>, ctx: Arc<Context>) -> Result<Action> {
let trace_id = telemetry::get_trace_id();
Span::current().record("trace_id", &field::display(&trace_id));
let _timer = ctx.metrics.app.reconciler.count_and_measure();
let _timer = ctx.metrics.app.reconcile.count_and_measure();
ctx.diagnostics.write().await.last_event = Utc::now();
let ns = doc.namespace().unwrap(); // doc is namespace scoped
let docs: Api<Document> = Api::namespaced(ctx.client.clone(), &ns);
Expand All @@ -78,7 +78,7 @@ async fn reconcile(doc: Arc<Document>, ctx: Arc<Context>) -> Result<Action> {

fn error_policy(doc: Arc<Document>, error: &Error, ctx: Arc<Context>) -> Action {
warn!("reconcile failed: {:?}", error);
ctx.metrics.app.reconciler.set_failure(&doc, error);
ctx.metrics.app.reconcile.set_failure(&doc, error);
Action::requeue(Duration::from_secs(5 * 60))
}

Expand Down Expand Up @@ -270,7 +270,7 @@ mod test {
assert!(err.to_string().contains("IllegalDocument"));
// calling error policy with the reconciler error should cause the correct metric to be set
error_policy(doc.clone(), &err, testctx.clone());
let metrics = &testctx.metrics.app.reconciler;
let metrics = &testctx.metrics.app.reconcile;
let failures = metrics.get_failures("illegal", "finalizererror(applyfailed(illegaldocument))");
assert_eq!(failures, 1);
}
Expand Down
25 changes: 11 additions & 14 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,18 @@ pub struct Metrics {
/// All metrics
#[derive(MetricGroup, Default)]
pub struct AppMetrics {
#[metric(namespace = "doc_ctrl")]
pub reconciler: ReconcilerMetrics,
#[metric(namespace = "doc_ctrl_reconcile")]
pub reconcile: ReconcileMetrics,
}

/// Metrics related to the reconciler
#[derive(MetricGroup)]
#[metric(new())]
pub struct ReconcilerMetrics {
/// reconciliations
pub reconciliations: Counter,
/// reconciliation errors
pub struct ReconcileMetrics {
pub runs: Counter,
pub failures: CounterVec<ErrorLabelSet>,
/// duration of reconcile to complete in seconds
#[metric(metadata = Thresholds::with_buckets([0.01, 0.1, 0.25, 0.5, 1., 5., 15., 60.]))]
pub reconcile_duration: Histogram<8>,
#[metric(metadata = Thresholds::with_buckets([0.01, 0.1, 0.25, 0.5, 1., 5., 15., 60.]), rename = "duration_seconds")]
pub duration: Histogram<8>,
}

#[derive(LabelGroup)]
Expand All @@ -43,13 +40,13 @@ pub struct ErrorLabels<'a> {
error: &'a str,
}

impl Default for ReconcilerMetrics {
impl Default for ReconcileMetrics {
fn default() -> Self {
ReconcilerMetrics::new()
ReconcileMetrics::new()
}
}

impl ReconcilerMetrics {
impl ReconcileMetrics {
pub fn set_failure(&self, doc: &Document, e: &Error) {
self.failures.inc(ErrorLabels {
instance: doc.name_any().as_ref(),
Expand All @@ -58,8 +55,8 @@ impl ReconcilerMetrics {
}

pub fn count_and_measure(&self) -> HistogramTimer<'_, 8> {
self.reconciliations.inc();
self.reconcile_duration.start_timer()
self.runs.inc();
self.duration.start_timer()
}

#[cfg(test)]
Expand Down

0 comments on commit 37771cb

Please sign in to comment.