Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion app/src/gen/ProviderIncident.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 5 additions & 10 deletions crates/culprit-checks/src/checks/signals/sequence_capacity.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;
use crate::evidence::{Observation, Requirement as Evidence};
use culprit_core::operations::SequenceCapacity;
use culprit_core::operations::{LowSequenceHeadroom, SequenceCapacity};

pub fn sequence_capacity_info() -> CheckInfo {
CheckInfo {
Expand Down Expand Up @@ -34,15 +34,10 @@ fn near_limits(s: &Snapshot) -> Vec<NearLimit<'_>> {
let mut out: Vec<NearLimit<'_>> = s
.sequences()
.filter_map(|seq| {
let (remaining, total) = seq.remaining()?;
if total == 0 {
return None;
}
let fraction = remaining as f64 / total as f64;
if fraction > 0.01 && (remaining > 10_000 || fraction > 0.1) {
return None;
}
let severity = if remaining <= 10_000 { Severity::Medium } else { Severity::Low };
let (remaining, severity) = match seq.low_headroom()? {
LowSequenceHeadroom::FewSteps(steps) => (u128::from(steps), Severity::Medium),
LowSequenceHeadroom::SmallFraction(steps) => (steps, Severity::Low),
};
Some(NearLimit::Sequence { sequence: seq, remaining, severity })
})
.collect();
Expand Down
25 changes: 25 additions & 0 deletions crates/culprit-core/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,32 @@ pub struct SequenceCapacity {
pub allocated: bool,
}

/// Step counts from a native allocation point to its effective bound. They do not predict a failure time.
pub enum LowSequenceHeadroom {
FewSteps(u16),
SmallFraction(u128),
}

impl LowSequenceHeadroom {
pub(crate) const FEW_STEPS_LIMIT: u16 = 10_000;
}

impl SequenceCapacity {
pub fn low_headroom(&self) -> Option<LowSequenceHeadroom> {
let (remaining, span) = self.remaining()?;
if span == 0 {
return None;
}
// A small absolute count is actionable only in the final tenth of the range.
if remaining <= u128::from(LowSequenceHeadroom::FEW_STEPS_LIMIT) && remaining <= span / 10 {
Some(LowSequenceHeadroom::FewSteps(remaining as u16))
} else if remaining <= span / 100 {
Some(LowSequenceHeadroom::SmallFraction(remaining))
} else {
None
}
}

pub fn remaining(&self) -> Option<(u128, u128)> {
let (now, step, min, max) = (
self.current.parse::<i128>().ok()?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,16 @@ pub enum ProviderIncident {
},
SequenceBoundary {
sequence: String,
/// Older boundary records carry zero remaining steps in their discriminator alone.
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
remaining_steps: Option<std::num::NonZeroU16>,
},
AutoIncrementBoundary {
column: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
remaining_steps: Option<std::num::NonZeroU16>,
},
ChecksumFailure {
at: String,
Expand Down Expand Up @@ -161,8 +168,12 @@ impl ProviderIncident {
pub(super) fn valid(&self) -> bool {
match self {
Self::MysqlDigestRegression { regression } => regression.is_valid(),
Self::SequenceBoundary { sequence } => valid_key(sequence),
Self::AutoIncrementBoundary { column } => valid_key(column),
Self::SequenceBoundary { sequence: name, remaining_steps }
| Self::AutoIncrementBoundary { column: name, remaining_steps } => {
valid_key(name)
&& remaining_steps
.is_none_or(|steps| steps.get() <= crate::operations::LowSequenceHeadroom::FEW_STEPS_LIMIT)
}
Self::ChecksumFailure { at } => canonical_time(at).is_ok(),
Self::PostgresCleanupHorizon { pin } => pin.is_valid(),
Self::InnodbWaits { interval } => interval.increase().is_some(),
Expand Down Expand Up @@ -250,10 +261,6 @@ impl ProviderIncident {
}
Self::ThreadPoolGroupStalled { group: point.group }
}
(
ProviderIncidentSource::PostgresSequences | ProviderIncidentSource::MysqlAllocators,
crate::ObservationBody::CatalogCounters(point),
) => sequences::boundary(family, header, row, point)?,
_ => postgres::from_operational_record(family, header, row)
.or_else(|| mssql::from_operational_record(family, header, row))
.or_else(|| yugabyte::from_operational_record(family, header, row))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ pub(super) fn from_operational_record(
row: &crate::Observation,
) -> Option<ProviderIncident> {
match (family, &row.body) {
(ProviderIncidentSource::MysqlAllocators, crate::ObservationBody::CatalogCounters(point))
if row.source == "information_schema.tables" && point.catalog.object_type == "auto-increment" =>
{
allocation_capacity(header, row, point)
}
(
ProviderIncidentSource::GaleraComponent,
crate::ObservationBody::Engine(crate::facts::EngineFact::Mysql(crate::facts::MysqlFact::MariadbGalera(
Expand Down Expand Up @@ -41,6 +46,53 @@ pub(super) fn from_operational_record(
}
}

fn allocation_capacity(
header: &CollectionDescription,
row: &crate::Observation,
point: &NativeCatalogCounters,
) -> Option<ProviderIncident> {
let identity = &point.catalog.identity;
let properties = &point.catalog.properties;
let name = properties.get("name")?;
if identity.qualifiers.get("schema")? != &header.target.database()?.database
|| identity.id != serde_json::to_string(&[name]).ok()?
{
return None;
}
let counter = point.counters.counters.iter().find(|value| {
value.key == "next_value"
&& value.native_name == "next_value"
&& value.native_object == row.source
&& value.scope == point.counters.scope
&& value.nature == CounterNature::Gauge
&& value.unit == CounterUnit::Count
})?;
let sequence = crate::catalog_projection::mysql_sequence_capacity(
name.clone(),
properties.get("table_name").cloned(),
properties.get("column_type")?,
counter.value.integer()?.to_string(),
positive(properties.get("step")?)?.to_string(),
)?;
let steps = super::sequences::capacity_steps(row, point, &sequence)?;
Some(ProviderIncident::AutoIncrementBoundary {
column: sequence.name,
remaining_steps: std::num::NonZeroU16::new(steps),
})
}

pub(super) fn auto_increment_capacity_title(name: &str, remaining_steps: Option<std::num::NonZeroU16>) -> String {
match remaining_steps {
None => crate::t!("incident.native.auto.boundary", name = name),
Some(steps) => crate::t!(
"incident.native.auto.near_boundary",
name = name,
n = steps.get(),
count = crate::format::digits(steps.to_string())
),
}
}

pub(super) fn observes_healthy_operational(
family: ProviderIncidentSource,
header: &CollectionDescription,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ pub(super) fn from_operational_record(
row: &crate::Observation,
) -> Option<ProviderIncident> {
match (family, &row.body) {
(ProviderIncidentSource::PostgresSequences, crate::ObservationBody::CatalogCounters(point))
if row.source == "pg_sequences" && point.catalog.object_type == "sequence" =>
{
allocation_capacity(row, point)
}
(
ProviderIncidentSource::PostgresDatabase | ProviderIncidentSource::PostgresArchiver,
crate::ObservationBody::CounterSet(point),
Expand Down Expand Up @@ -67,6 +72,33 @@ pub(super) fn from_operational_record(
}
}

fn allocation_capacity(row: &crate::Observation, point: &NativeCatalogCounters) -> Option<ProviderIncident> {
let identity = &point.catalog.identity;
positive(&identity.id)?;
positive(identity.qualifiers.get("database_oid")?)?;
if !matches!(point.catalog.properties.get("cycle")?.as_str(), "f" | "false") {
return None;
}
let sequence = crate::catalog_projection::pg_sequence_capacity(point)?;
let steps = super::sequences::capacity_steps(row, point, &sequence)?;
Some(ProviderIncident::SequenceBoundary {
sequence: sequence.name,
remaining_steps: std::num::NonZeroU16::new(steps),
})
}

pub(super) fn sequence_capacity_title(name: &str, remaining_steps: Option<std::num::NonZeroU16>) -> String {
match remaining_steps {
None => crate::t!("incident.native.sequence.boundary", name = name),
Some(steps) => crate::t!(
"incident.native.sequence.near_boundary",
name = name,
n = steps.get(),
count = crate::format::digits(steps.to_string())
),
}
}

pub(super) fn observes_healthy_operational(
family: ProviderIncidentSource,
header: &CollectionDescription,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ impl ProviderIncident {
Self::ThreadPoolGroupStalled { group } => {
crate::t!("incident.mariadb.thread_pool.stalled", group = group.to_string())
}
Self::SequenceBoundary { sequence } => crate::t!("incident.native.sequence.boundary", name = sequence),
Self::AutoIncrementBoundary { column } => crate::t!("incident.native.auto.boundary", name = column),
Self::SequenceBoundary { sequence, remaining_steps } => {
postgres::sequence_capacity_title(sequence, *remaining_steps)
}
Self::AutoIncrementBoundary { column, remaining_steps } => {
mysql::auto_increment_capacity_title(column, *remaining_steps)
}
Self::ChecksumFailure { at } => crate::t!("incident.native.checksum", at = at),
Self::ArchiveFailure { at, wal } => crate::t!("incident.native.archive", at = at, wal = wal),
Self::Replication { problem } => problem.title(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,58 +1,19 @@
//! An allocation boundary can be established from one native point without predicting an exhaustion date.
//! Exact capacity incidents share the scan policy and require a database-scoped, identity-bound native row.
use super::*;
use crate::catalog_projection::{mysql_sequence_capacity, pg_sequence_capacity};
use crate::operations::{LowSequenceHeadroom, SequenceCapacity};

pub(super) fn boundary(
family: ProviderIncidentSource,
header: &CollectionDescription,
pub(super) fn capacity_steps(
row: &crate::Observation,
point: &NativeCatalogCounters,
) -> Option<ProviderIncident> {
sequence: &SequenceCapacity,
) -> Option<u16> {
if !point.is_valid() || row.key != point.catalog.key().ok()? || point.counters.scope != MeasurementScope::Database {
return None;
}
let identity = &point.catalog.identity;
let properties = &point.catalog.properties;
let (sequence, incident) = match (family, row.source.as_str(), point.catalog.object_type.as_str()) {
(ProviderIncidentSource::PostgresSequences, "pg_sequences", "sequence") => {
positive(&identity.id)?;
positive(identity.qualifiers.get("database_oid")?)?;
if !matches!(properties.get("cycle")?.as_str(), "f" | "false") {
return None;
}
let sequence = pg_sequence_capacity(point)?;
let incident = ProviderIncident::SequenceBoundary { sequence: sequence.name.clone() };
(sequence, incident)
}
(ProviderIncidentSource::MysqlAllocators, "information_schema.tables", "auto-increment") => {
let name = properties.get("name")?;
if identity.qualifiers.get("schema")? != &header.target.database()?.database
|| identity.id != serde_json::to_string(&[name]).ok()?
{
return None;
}
let counter = point.counters.counters.iter().find(|value| {
value.key == "next_value"
&& value.native_name == "next_value"
&& value.native_object == row.source
&& value.scope == point.counters.scope
&& value.nature == CounterNature::Gauge
&& value.unit == CounterUnit::Count
})?;
let step = positive(properties.get("step")?)?;
let sequence = mysql_sequence_capacity(
name.clone(),
properties.get("table_name").cloned(),
properties.get("column_type")?,
counter.value.integer()?.to_string(),
step.to_string(),
)?;
(sequence, ProviderIncident::AutoIncrementBoundary { column: name.clone() })
}
_ => return None,
};
let (remaining, span) = sequence.remaining()?;
(remaining == 0 && span > 0).then_some(incident)
match sequence.low_headroom()? {
LowSequenceHeadroom::FewSteps(steps) => Some(steps),
LowSequenceHeadroom::SmallFraction(_) => None,
}
}

#[cfg(test)]
Expand Down
Loading
Loading