Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(msd): adding timestamp of last successful sync #496

Merged
merged 3 commits into from
Jun 17, 2024
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
83 changes: 2 additions & 81 deletions Cargo.Bazel.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "4bbd989bbf5c42e742aa858a262040efe99e2a94f7211a585016f04055bd73bb",
"checksum": "87e2c8f3dba5c353695777f770c5dd8e59ed40002ef4a441217e73677175c77b",
"crates": {
"actix-codec 0.5.2": {
"name": "actix-codec",
Expand Down Expand Up @@ -30087,7 +30087,7 @@
"target": "ic_types"
},
{
"id": "opentelemetry 0.21.0",
"id": "opentelemetry 0.22.0",
"target": "opentelemetry"
},
{
Expand Down Expand Up @@ -32306,85 +32306,6 @@
},
"license": "MIT"
},
"opentelemetry 0.21.0": {
"name": "opentelemetry",
"version": "0.21.0",
"repository": {
"Http": {
"url": "https://static.crates.io/crates/opentelemetry/0.21.0/download",
"sha256": "1e32339a5dc40459130b3bd269e9892439f55b33e772d2a9d402a789baaf4e8a"
}
},
"targets": [
{
"Library": {
"crate_name": "opentelemetry",
"crate_root": "src/lib.rs",
"srcs": [
"**/*.rs"
]
}
}
],
"library_target_name": "opentelemetry",
"common_attrs": {
"compile_data_glob": [
"**"
],
"crate_features": {
"common": [
"default",
"metrics",
"pin-project-lite",
"trace"
],
"selects": {}
},
"deps": {
"common": [
{
"id": "futures-core 0.3.30",
"target": "futures_core"
},
{
"id": "futures-sink 0.3.30",
"target": "futures_sink"
},
{
"id": "indexmap 2.2.6",
"target": "indexmap"
},
{
"id": "once_cell 1.19.0",
"target": "once_cell"
},
{
"id": "pin-project-lite 0.2.14",
"target": "pin_project_lite"
},
{
"id": "thiserror 1.0.61",
"target": "thiserror"
},
{
"id": "urlencoding 2.1.3",
"target": "urlencoding"
}
],
"selects": {
"cfg(all(target_arch = \"wasm32\", not(target_os = \"wasi\")))": [
{
"id": "js-sys 0.3.69",
"target": "js_sys"
}
]
}
},
"edition": "2021",
"version": "0.21.0"
},
"license": "Apache-2.0"
},
"opentelemetry 0.22.0": {
"name": "opentelemetry",
"version": "0.22.0",
Expand Down
24 changes: 4 additions & 20 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions rs/ic-observability/multiservice-discovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ tokio = { workspace = true }
url = { workspace = true }
futures.workspace = true
axum = "0.7.4"
axum-otel-metrics = "0.8.0"
opentelemetry = { version = "0.21.0", features = ["metrics"] }
axum-otel-metrics = "0.8.1"
opentelemetry = { version = "0.22.0", features = ["metrics"] }
retry = { workspace = true }

[dev-dependencies]
Expand Down
17 changes: 16 additions & 1 deletion rs/ic-observability/multiservice-discovery/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
collections::HashMap,
sync::{Arc, RwLock},
time::{SystemTime, UNIX_EPOCH},
};

use opentelemetry::{global, metrics::Observer, KeyValue};
Expand Down Expand Up @@ -32,6 +33,7 @@ struct LatestValues {
sync_registry_error: u64,
definitions_load_successful: u64,
definitions_sync_successful: u64,
successful_sync_ts: u64,
}

impl LatestValues {
Expand All @@ -41,6 +43,7 @@ impl LatestValues {
sync_registry_error: 0,
definitions_load_successful: 0,
definitions_sync_successful: 0,
successful_sync_ts: 0,
}
}
}
Expand Down Expand Up @@ -76,11 +79,17 @@ impl RunningDefinitionsMetrics {
.u64_observable_gauge("msd.definitions.sync.successful")
.with_description("Status of last sync of the registry with NNS of definition")
.init();
let successful_sync_ts = meter
.clone()
.u64_observable_gauge("msd.definitions.sync.ts")
.with_description("Timestamp of last successful sync")
.init();
let instruments = [
load_new_targets_error.as_any(),
sync_registry_error.as_any(),
definitions_load_successful.as_any(),
definitions_sync_successful.as_any(),
successful_sync_ts.as_any(),
];
let s = latest_values_by_network.clone();
let update_instruments = move |observer: &dyn Observer| {
Expand All @@ -95,6 +104,7 @@ impl RunningDefinitionsMetrics {
(&sync_registry_error, latest_values.sync_registry_error),
(&definitions_load_successful, latest_values.definitions_load_successful),
(&definitions_sync_successful, latest_values.definitions_sync_successful),
(&successful_sync_ts, latest_values.successful_sync_ts),
]
.into_iter()
{
Expand All @@ -111,7 +121,12 @@ impl RunningDefinitionsMetrics {
let mut s = self.latest_values_by_network.write().unwrap();
let latest_values = s.entry(network).or_insert(LatestValues::new());
latest_values.definitions_sync_successful = match success {
true => 1,
true => {
let now = SystemTime::now();
let since_epoch = now.duration_since(UNIX_EPOCH).unwrap();
latest_values.successful_sync_ts = since_epoch.as_secs();
1
}
false => {
latest_values.sync_registry_error += 1;
0
Expand Down
Loading