Skip to content

Commit

Permalink
Move transaction retry timeseries to TOML
Browse files Browse the repository at this point in the history
  • Loading branch information
bnaecker committed Jul 5, 2024
1 parent f40cebe commit 5535dc4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
22 changes: 5 additions & 17 deletions nexus/db-queries/src/transaction_retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,15 @@
use async_bb8_diesel::AsyncConnection;
use chrono::Utc;
use diesel::result::Error as DieselError;
use oximeter::{types::Sample, Metric, MetricsError, Target};
use oximeter::{types::Sample, MetricsError};
use rand::{thread_rng, Rng};
use slog::{info, warn, Logger};
use std::sync::{Arc, Mutex};
use std::time::Duration;

// Identifies "which" transaction is retrying
#[derive(Debug, Clone, Target)]
struct DatabaseTransaction {
name: String,
}

// Identifies that a retry has occurred, and track how long
// the transaction took (either since starting, or since the last
// retry failure was recorded).
#[derive(Debug, Clone, Metric)]
struct RetryData {
#[datum]
latency: f64,
attempt: u32,
}
oximeter::use_timeseries!("database-transaction.toml");
use database_transaction::DatabaseTransaction;
use database_transaction::RetryData;

// Collects all transaction retry samples
#[derive(Debug, Default, Clone)]
Expand Down Expand Up @@ -156,7 +144,7 @@ impl RetryHelper {

let _ = self.producer.append(
&DatabaseTransaction { name: self.name.into() },
&RetryData { latency, attempt },
&RetryData { datum: latency, attempt },
);

// This backoff is not exponential, but I'm not sure we actually want
Expand Down
26 changes: 26 additions & 0 deletions oximeter/oximeter/schema/database-transaction.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
format_version = 1

[target]
name = "database_transaction"
description = "A named transaction run in the control plane database"
authz_scope = "fleet"
versions = [
{ version = 1, fields = [ "name" ] }
]

[[metrics]]
name = "retry_data"
description = "Information about a retried transaction"
units = "bytes"
datum_type = "f64"
versions = [
{ added_in = 1, fields = [ "attempt" ] }
]

[fields.name]
type = "string"
description = "The name of the transaction"

[fields.attempt]
type = "u32"
description = "The attempt at running the transaction"

0 comments on commit 5535dc4

Please sign in to comment.