Skip to content

Commit

Permalink
feature: Add routes for ancillary_files_restored, complete_restoratio…
Browse files Browse the repository at this point in the history
…n and partial_restoration
  • Loading branch information
sfauvel committed Jan 30, 2025
1 parent 90316d7 commit bbc3d0d
Show file tree
Hide file tree
Showing 8 changed files with 613 additions and 76 deletions.
424 changes: 362 additions & 62 deletions mithril-aggregator/src/http_server/routes/statistics_routes.rs

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions mithril-aggregator/src/metrics/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ build_metrics_service!(
"Number of Cardano immutable files full restorations since startup on a Mithril aggregator node"
),
cardano_database_immutable_files_restored:MetricCounter(
"mithril_aggregator_cardano_db_immutable_files_restored_since_startup",
"Number of Cardano immutable files restored since startup on a Mithril aggregator node"
"mithril_aggregator_cardano_db_immutable_files_restored",
"Number of Cardano immutable files restored on a Mithril aggregator node"
),
cardano_database_ancillary_files_restored:MetricCounter(
"mithril_aggregator_cardano_db_ancillary_files_restored_since_startup",
"Number of Cardano ancillary files restored since startup on a Mithril aggregator node"
"mithril_aggregator_cardano_db_ancillary_files_restored",
"Number of Cardano ancillary files restored on a Mithril aggregator node"
),
cardano_database_full_restoration_since_startup:MetricCounter(
"mithril_aggregator_cardano_db_full_restoration_since_startup",
"Number of full Cardano database restoration since startup on a Mithril aggregator node"
cardano_database_complete_restoration:MetricCounter(
"mithril_aggregator_cardano_db_complete_restoration",
"Number of complete Cardano database restoration on a Mithril aggregator node"
),
cardano_database_partial_restoration_since_startup:MetricCounter(
"mithril_aggregator_cardano_db_partial_restoration_since_startup",
"Number of partial Cardano database restoration since startup on a Mithril aggregator node"
cardano_database_partial_restoration:MetricCounter(
"mithril_aggregator_cardano_db_partial_restoration",
"Number of partial Cardano database restoration on a Mithril aggregator node"
),
artifact_detail_cardano_database_total_served_since_startup:MetricCounter(
"mithril_aggregator_artifact_detail_cardano_database_total_served_since_startup",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use serde::{Deserialize, Serialize};

/// Message structure of an ancillary files restoration
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct CardanoDatabaseAncillaryFilesRestoredMessage {
/// Number of ancillary files restored.
pub nb_ancillary_files: u32,
}

impl CardanoDatabaseAncillaryFilesRestoredMessage {
/// Return a dummy test entity (test-only).
pub fn dummy() -> Self {
Self {
nb_ancillary_files: 34,
}
}
}

#[cfg(test)]
mod tests {
use super::*;

const CURRENT_JSON: &str = r#"{
"nb_ancillary_files": 62
}"#;

fn golden_message_current() -> CardanoDatabaseAncillaryFilesRestoredMessage {
CardanoDatabaseAncillaryFilesRestoredMessage {
nb_ancillary_files: 62,
}
}

#[test]
fn test_current_json_deserialized_into_current_message() {
let json = CURRENT_JSON;
let message: CardanoDatabaseAncillaryFilesRestoredMessage =
serde_json::from_str(json).unwrap();

assert_eq!(golden_message_current(), message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use serde::{Deserialize, Serialize};

/// Message structure of a complete Cardano database restoration
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct CardanoDatabaseCompleteRestorationMessage {
/// Number of complete restoration.
pub nb_complete_restoration: u32,
}

impl CardanoDatabaseCompleteRestorationMessage {
/// Return a dummy test entity (test-only).
pub fn dummy() -> Self {
Self {
nb_complete_restoration: 34,
}
}
}

#[cfg(test)]
mod tests {
use super::*;

const CURRENT_JSON: &str = r#"{
"nb_complete_restoration": 62
}"#;

fn golden_message_current() -> CardanoDatabaseCompleteRestorationMessage {
CardanoDatabaseCompleteRestorationMessage {
nb_complete_restoration: 62,
}
}

#[test]
fn test_current_json_deserialized_into_current_message() {
let json = CURRENT_JSON;
let message: CardanoDatabaseCompleteRestorationMessage =
serde_json::from_str(json).unwrap();

assert_eq!(golden_message_current(), message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct CardanoDatabaseImmutableFilesRestoredMessage {
/// Number of immutable files restored.
pub nb_immutable_files: u64,
pub nb_immutable_files: u32,
}

impl CardanoDatabaseImmutableFilesRestoredMessage {
Expand All @@ -22,11 +22,10 @@ mod tests {

const CURRENT_JSON: &str = r#"{
"nb_immutable_files": 62
},
}"#;

fn golden_message_current() -> SnapshotMessage {
SnapshotMessage {
fn golden_message_current() -> CardanoDatabaseImmutableFilesRestoredMessage {
CardanoDatabaseImmutableFilesRestoredMessage {
nb_immutable_files: 62,
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use serde::{Deserialize, Serialize};

/// Message structure of a partial Cardano database restoration
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct CardanoDatabasePartialRestorationMessage {
/// Number of partial restoration.
pub nb_partial_restoration: u32,
}

impl CardanoDatabasePartialRestorationMessage {
/// Return a dummy test entity (test-only).
pub fn dummy() -> Self {
Self {
nb_partial_restoration: 34,
}
}
}

#[cfg(test)]
mod tests {
use super::*;

const CURRENT_JSON: &str = r#"{
"nb_partial_restoration": 62
}"#;

fn golden_message_current() -> CardanoDatabasePartialRestorationMessage {
CardanoDatabasePartialRestorationMessage {
nb_partial_restoration: 62,
}
}

#[test]
fn test_current_json_deserialized_into_current_message() {
let json = CURRENT_JSON;
let message: CardanoDatabasePartialRestorationMessage = serde_json::from_str(json).unwrap();

assert_eq!(golden_message_current(), message);
}
}
6 changes: 6 additions & 0 deletions mithril-common/src/messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
mod aggregator_features;
mod aggregator_status;
mod cardano_database;
mod cardano_database_ancillary_files_restored;
mod cardano_database_complete_restoration;
mod cardano_database_digest_list;
mod cardano_database_immutable_files_restored;
mod cardano_database_list;
mod cardano_database_partial_restoration;
mod cardano_stake_distribution;
mod cardano_stake_distribution_list;
mod cardano_transaction_snapshot;
Expand All @@ -30,13 +33,16 @@ pub use aggregator_features::{
};
pub use aggregator_status::AggregatorStatusMessage;
pub use cardano_database::{ArtifactsLocationsMessagePart, CardanoDatabaseSnapshotMessage};
pub use cardano_database_ancillary_files_restored::CardanoDatabaseAncillaryFilesRestoredMessage;
pub use cardano_database_complete_restoration::CardanoDatabaseCompleteRestorationMessage;
pub use cardano_database_digest_list::{
CardanoDatabaseDigestListItemMessage, CardanoDatabaseDigestListMessage,
};
pub use cardano_database_immutable_files_restored::CardanoDatabaseImmutableFilesRestoredMessage;
pub use cardano_database_list::{
CardanoDatabaseSnapshotListItemMessage, CardanoDatabaseSnapshotListMessage,
};
pub use cardano_database_partial_restoration::CardanoDatabasePartialRestorationMessage;
pub use cardano_stake_distribution::CardanoStakeDistributionMessage;
pub use cardano_stake_distribution_list::{
CardanoStakeDistributionListItemMessage, CardanoStakeDistributionListMessage,
Expand Down
110 changes: 110 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,70 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/Error"

/statistics/cardano-database/ancillary-files-restored:
post:
summary: Records ancillary files restored event
description: Records ancillary files restored event
requestBody:
description: Ancillary files restored message
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/CardanoDatabaseAncillaryFilesRestoredMessage"
responses:
"201":
description: Event successfully recorded
default:
description: Record event bad request
content:
application/json:
schema:
$ref: "#/components/schemas/Error"

/statistics/cardano-database/complete-restoration:
post:
summary: Records complete restoration event
description: Records complete restoration event
requestBody:
description: Complete restoration message
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/CardanoDatabaseCompleteRestorationMessage"
responses:
"201":
description: Event successfully recorded
default:
description: Record event bad request
content:
application/json:
schema:
$ref: "#/components/schemas/Error"

/statistics/cardano-database/partial-restoration:
post:
summary: Records partial restoration event
description: Records partial restoration event
requestBody:
description: Partial restoration message
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/CardanoDatabasePartialRestorationMessage"
responses:
"201":
description: Event successfully recorded
default:
description: Record event bad request
content:
application/json:
schema:
$ref: "#/components/schemas/Error"

components:
schemas:
AggregatorStatusMessage:
Expand Down Expand Up @@ -1915,6 +1979,52 @@ components:
"nb_immutable_files": 15
}

CardanoDatabaseAncillaryFilesRestoredMessage:
description: CardanoDatabaseAncillaryFilesRestoredMessage represents a Cardano database Ancillary files restored event
type: object
additionalProperties: false
required:
- nb_ancillary_files
properties:
nb_ancillary_files:
description: Number of ancillary files restored
type: integer
examples:
- {
"nb_ancillary_files": 15
}

CardanoDatabaseCompleteRestorationMessage:
description: CardanoDatabaseCompleteRestorationMessage represents a Cardano database complete restoration event
type: object
additionalProperties: false
required:
- nb_complete_restoration
properties:
nb_complete_restoration:
description: Number of complete restoration
type: integer
examples:
- {
"nb_complete_restoration": 15
}

CardanoDatabasePartialRestorationMessage:
description: CardanoDatabasePartialRestorationMessage represents a Cardano database partial restoration event
type: object
additionalProperties: false
required:
- nb_partial_restoration
properties:
nb_partial_restoration:
description: Number of partial restoration
type: integer
examples:
- {
"nb_partial_restoration": 15
}


CardanoDatabaseArtifactsLocationsMessagePart:
description: CardanoDatabaseArtifactsLocationsMessagePart represents the locations of the Cardano database artifacts
type: object
Expand Down

0 comments on commit bbc3d0d

Please sign in to comment.