diff --git a/Cargo.lock b/Cargo.lock index 12eb1e96a..8af291413 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -298,7 +298,7 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "agent" -version = "0.12.11" +version = "0.12.12" dependencies = [ "akri-debug-echo", "akri-discovery-utils", @@ -358,7 +358,7 @@ dependencies = [ [[package]] name = "akri-debug-echo" -version = "0.12.11" +version = "0.12.12" dependencies = [ "akri-discovery-utils", "akri-shared", @@ -376,7 +376,7 @@ dependencies = [ [[package]] name = "akri-discovery-utils" -version = "0.12.11" +version = "0.12.12" dependencies = [ "akri-shared", "anyhow", @@ -398,7 +398,7 @@ dependencies = [ [[package]] name = "akri-onvif" -version = "0.12.11" +version = "0.12.12" dependencies = [ "akri-discovery-utils", "anyhow", @@ -427,7 +427,7 @@ dependencies = [ [[package]] name = "akri-opcua" -version = "0.12.11" +version = "0.12.12" dependencies = [ "akri-discovery-utils", "anyhow", @@ -446,7 +446,7 @@ dependencies = [ [[package]] name = "akri-shared" -version = "0.12.11" +version = "0.12.12" dependencies = [ "anyhow", "async-trait", @@ -471,7 +471,7 @@ dependencies = [ [[package]] name = "akri-udev" -version = "0.12.11" +version = "0.12.12" dependencies = [ "akri-discovery-utils", "anyhow", @@ -986,7 +986,7 @@ checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935" [[package]] name = "controller" -version = "0.12.11" +version = "0.12.12" dependencies = [ "akri-shared", "anyhow", @@ -1178,7 +1178,7 @@ checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" [[package]] name = "debug-echo-discovery-handler" -version = "0.12.11" +version = "0.12.12" dependencies = [ "akri-debug-echo", "akri-discovery-utils", @@ -2479,7 +2479,7 @@ checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" [[package]] name = "onvif-discovery-handler" -version = "0.12.11" +version = "0.12.12" dependencies = [ "akri-discovery-utils", "akri-onvif", @@ -2529,7 +2529,7 @@ dependencies = [ [[package]] name = "opcua-discovery-handler" -version = "0.12.11" +version = "0.12.12" dependencies = [ "akri-discovery-utils", "akri-opcua", @@ -4134,7 +4134,7 @@ dependencies = [ [[package]] name = "udev-discovery-handler" -version = "0.12.11" +version = "0.12.12" dependencies = [ "akri-discovery-utils", "akri-udev", @@ -4145,7 +4145,7 @@ dependencies = [ [[package]] name = "udev-video-broker" -version = "0.12.11" +version = "0.12.12" dependencies = [ "akri-shared", "env_logger", @@ -4422,7 +4422,7 @@ dependencies = [ [[package]] name = "webhook-configuration" -version = "0.12.11" +version = "0.12.12" dependencies = [ "actix-rt 2.7.0", "actix-web", diff --git a/agent/Cargo.toml b/agent/Cargo.toml index d7b3ffd83..7074c5f6c 100644 --- a/agent/Cargo.toml +++ b/agent/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "agent" -version = "0.12.11" +version = "0.12.12" license = "Apache-2.0" authors = ["Kate Goldenring ", ""] edition = "2018" diff --git a/agent/src/main.rs b/agent/src/main.rs index c5dc99210..36522ba52 100644 --- a/agent/src/main.rs +++ b/agent/src/main.rs @@ -1,7 +1,5 @@ extern crate hyper; #[macro_use] -extern crate lazy_static; -#[macro_use] extern crate log; #[macro_use] extern crate serde_derive; @@ -9,7 +7,6 @@ mod util; use akri_shared::akri::{metrics::run_metrics_server, API_NAMESPACE}; use log::{info, trace}; -use prometheus::{HistogramVec, IntGaugeVec}; use std::{ collections::HashMap, env, @@ -28,13 +25,6 @@ use util::{ slot_reconciliation::periodic_slot_reconciliation, }; -lazy_static! { - // Reports the number of Instances visible to this node, grouped by Configuration and whether it is shared - pub static ref INSTANCE_COUNT_METRIC: IntGaugeVec = prometheus::register_int_gauge_vec!("akri_instance_count", "Akri Instance Count", &["configuration", "is_shared"]).unwrap(); - // Reports the time to get discovery results, grouped by Configuration - pub static ref DISCOVERY_RESPONSE_TIME_METRIC: HistogramVec = prometheus::register_histogram_vec!("akri_discovery_response_time", "Akri Discovery Response Time", &["configuration"]).unwrap(); -} - /// This is the entry point for the Akri Agent. /// It must be built on unix systems, since the underlying libraries for the `DevicePluginService` unix socket connection are unix only. #[cfg(unix)] diff --git a/agent/src/util/discovery_operator.rs b/agent/src/util/discovery_operator.rs index ebdd0e4ff..eecb9ad97 100644 --- a/agent/src/util/discovery_operator.rs +++ b/agent/src/util/discovery_operator.rs @@ -1,6 +1,6 @@ -use super::super::INSTANCE_COUNT_METRIC; #[cfg(any(test, feature = "agent-full"))] use super::embedded_discovery_handlers::get_discovery_handler; +use super::metrics::INSTANCE_COUNT_METRIC; use super::{ config_action::ConfigId, constants::SHARED_INSTANCE_OFFLINE_GRACE_PERIOD_SECS, @@ -68,6 +68,8 @@ pub struct DiscoveryOperator { config: Configuration, /// Akri Instances discovered by this `DiscoveryOperator` device_plugin_context: Arc>, + /// Timestamp of DiscoveryOperator is created when config is created or updated + config_timestamp: Instant, } #[cfg_attr(test, automock)] @@ -81,6 +83,7 @@ impl DiscoveryOperator { discovery_handler_map, config, device_plugin_context, + config_timestamp: Instant::now(), } } fn get_config_id(&self) -> ConfigId { @@ -105,6 +108,11 @@ impl DiscoveryOperator { pub fn get_device_plugin_context(&self) -> Arc> { self.device_plugin_context.clone() } + /// Returns config_timestamp field. Allows the struct to be mocked. + #[allow(dead_code)] + pub fn get_config_timestamp(&self) -> Instant { + self.config_timestamp + } #[allow(dead_code)] pub async fn stop_all_discovery(&self) { let mut discovery_handler_map = self.discovery_handler_map.lock().unwrap().clone(); @@ -794,6 +802,7 @@ async fn get_discovery_property_value_from_config_map( } pub mod start_discovery { + use super::super::metrics::{DISCOVERY_RESPONSE_RESULT_METRIC, DISCOVERY_RESPONSE_TIME_METRIC}; use super::super::registration::{DiscoveryDetails, DiscoveryHandlerEndpoint}; // Use this `mockall` macro to automate importing a mock type in test mode, or a real type otherwise. use super::super::device_plugin_builder::{DevicePluginBuilder, DevicePluginBuilderInterface}; @@ -1038,11 +1047,26 @@ pub mod start_discovery { dh_details: &'a DiscoveryDetails, node_name: String, ) -> anyhow::Result<()> { + // get discovery handler name for metric use + let dh_name = discovery_operator.get_config().spec.discovery_handler.name; + let (_config_namespace, config_name) = discovery_operator.get_config_id(); + let mut first_call = true; loop { - if let Some(stream_type) = discovery_operator + let stream_type = discovery_operator .get_stream(kube_interface.clone(), endpoint) - .await - { + .await; + let request_result = stream_type.as_ref().map(|_| "Success").unwrap_or("Fail"); + DISCOVERY_RESPONSE_RESULT_METRIC + .with_label_values(&[&dh_name, request_result]) + .inc(); + if first_call { + first_call = false; + let start_time = discovery_operator.get_config_timestamp(); + DISCOVERY_RESPONSE_TIME_METRIC + .with_label_values(&[&config_name]) + .observe(start_time.elapsed().as_secs_f64()); + } + if let Some(stream_type) = stream_type { match stream_type { StreamType::External(mut stream) => { match discovery_operator @@ -1574,6 +1598,11 @@ pub mod tests { .unwrap(); }); } + // Config timestamp should be called + mock_discovery_operator + .expect_get_config_timestamp() + .times(1) + .returning(Instant::now); let (mut finished_discovery_sender, finished_discovery_receiver) = tokio::sync::mpsc::channel(2); let (new_dh_sender, _) = broadcast::channel(2); @@ -1636,6 +1665,11 @@ pub mod tests { .expect_internal_do_discover() .times(1) .returning(|_, _, _, _| Ok(())); + // Config timestamp should be called + mock_discovery_operator + .expect_get_config_timestamp() + .times(1) + .returning(Instant::now); let mock_kube_interface: Arc = Arc::new(MockKubeInterface::new()); start_discovery::do_discover( Arc::new(mock_discovery_operator), diff --git a/agent/src/util/metrics.rs b/agent/src/util/metrics.rs new file mode 100644 index 000000000..4f43a22d9 --- /dev/null +++ b/agent/src/util/metrics.rs @@ -0,0 +1,28 @@ +use lazy_static::lazy_static; +use prometheus::{opts, register_int_counter_vec, HistogramVec, IntCounterVec, IntGaugeVec}; + +// Discovery request response time bucket (in seconds) +const DISCOVERY_RESPONSE_TIME_BUCKETS: &[f64; 9] = + &[0.25, 0.5, 1.0, 1.5, 2.0, 3.0, 5.0, 10.0, 60.0]; + +lazy_static! { + // Reports the number of Instances visible to this node, grouped by Configuration and whether it is shared + pub static ref INSTANCE_COUNT_METRIC: IntGaugeVec = prometheus::register_int_gauge_vec!( + "akri_instance_count", + "Akri Instance Count", + &["configuration", "is_shared"]) + .expect("akri_instance_count metric can be created"); + // Reports the time to get discovery results, grouped by Configuration + pub static ref DISCOVERY_RESPONSE_TIME_METRIC: HistogramVec = prometheus::register_histogram_vec!( + "akri_discovery_response_time", + "Akri Discovery Response Time", + &["configuration"], + DISCOVERY_RESPONSE_TIME_BUCKETS.to_vec() + ) + .expect("akri_discovery_response_time metric can be created"); + // Reports the result of discover requests, grouped by Discovery Handler name and whether it is succeeded + pub static ref DISCOVERY_RESPONSE_RESULT_METRIC: IntCounterVec = register_int_counter_vec!( + opts!("akri_discovery_response_result", "Akri Discovery Response Result"), + &["discovery_handler_name", "result"]) + .expect("akri_discovery_response_result metric can be created"); +} diff --git a/agent/src/util/mod.rs b/agent/src/util/mod.rs index 7d219cccd..cd796f956 100644 --- a/agent/src/util/mod.rs +++ b/agent/src/util/mod.rs @@ -6,6 +6,7 @@ mod device_plugin_service; pub mod discovery_operator; #[cfg(any(test, feature = "agent-full"))] pub mod embedded_discovery_handlers; +mod metrics; pub mod registration; pub mod slot_reconciliation; pub mod streaming_extension; diff --git a/controller/Cargo.toml b/controller/Cargo.toml index 670fcdb2d..6bbbb6681 100644 --- a/controller/Cargo.toml +++ b/controller/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "controller" -version = "0.12.11" +version = "0.12.12" license = "Apache-2.0" authors = ["", ""] edition = "2018" diff --git a/deployment/helm/Chart.yaml b/deployment/helm/Chart.yaml index 586c3acae..5555923f9 100644 --- a/deployment/helm/Chart.yaml +++ b/deployment/helm/Chart.yaml @@ -16,9 +16,9 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.12.11 +version: 0.12.12 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. -appVersion: 0.12.11 +appVersion: 0.12.12 diff --git a/discovery-handler-modules/debug-echo-discovery-handler/Cargo.toml b/discovery-handler-modules/debug-echo-discovery-handler/Cargo.toml index c85dd9a00..51d30c192 100644 --- a/discovery-handler-modules/debug-echo-discovery-handler/Cargo.toml +++ b/discovery-handler-modules/debug-echo-discovery-handler/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "debug-echo-discovery-handler" -version = "0.12.11" +version = "0.12.12" license = "Apache-2.0" authors = ["Kate Goldenring "] edition = "2018" diff --git a/discovery-handler-modules/onvif-discovery-handler/Cargo.toml b/discovery-handler-modules/onvif-discovery-handler/Cargo.toml index d550623c1..9b3640d4b 100644 --- a/discovery-handler-modules/onvif-discovery-handler/Cargo.toml +++ b/discovery-handler-modules/onvif-discovery-handler/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "onvif-discovery-handler" -version = "0.12.11" +version = "0.12.12" license = "Apache-2.0" authors = ["Kate Goldenring "] edition = "2018" diff --git a/discovery-handler-modules/opcua-discovery-handler/Cargo.toml b/discovery-handler-modules/opcua-discovery-handler/Cargo.toml index 26056b432..3d97ce42f 100644 --- a/discovery-handler-modules/opcua-discovery-handler/Cargo.toml +++ b/discovery-handler-modules/opcua-discovery-handler/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "opcua-discovery-handler" -version = "0.12.11" +version = "0.12.12" license = "Apache-2.0" authors = ["Kate Goldenring "] edition = "2018" diff --git a/discovery-handler-modules/udev-discovery-handler/Cargo.toml b/discovery-handler-modules/udev-discovery-handler/Cargo.toml index b9429adc4..be05d566f 100644 --- a/discovery-handler-modules/udev-discovery-handler/Cargo.toml +++ b/discovery-handler-modules/udev-discovery-handler/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "udev-discovery-handler" -version = "0.12.11" +version = "0.12.12" license = "Apache-2.0" authors = ["Kate Goldenring "] edition = "2018" diff --git a/discovery-handlers/debug-echo/Cargo.toml b/discovery-handlers/debug-echo/Cargo.toml index 3b872acee..eb756c544 100644 --- a/discovery-handlers/debug-echo/Cargo.toml +++ b/discovery-handlers/debug-echo/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "akri-debug-echo" -version = "0.12.11" +version = "0.12.12" license = "Apache-2.0" authors = ["Kate Goldenring "] edition = "2018" diff --git a/discovery-handlers/onvif/Cargo.toml b/discovery-handlers/onvif/Cargo.toml index 8ad541e4b..b2c625fe6 100644 --- a/discovery-handlers/onvif/Cargo.toml +++ b/discovery-handlers/onvif/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "akri-onvif" -version = "0.12.11" +version = "0.12.12" license = "Apache-2.0" authors = ["Kate Goldenring "] edition = "2018" diff --git a/discovery-handlers/opcua/Cargo.toml b/discovery-handlers/opcua/Cargo.toml index 6633f717e..ce315ebb6 100644 --- a/discovery-handlers/opcua/Cargo.toml +++ b/discovery-handlers/opcua/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "akri-opcua" -version = "0.12.11" +version = "0.12.12" license = "Apache-2.0" authors = ["Kate Goldenring "] edition = "2018" diff --git a/discovery-handlers/udev/Cargo.toml b/discovery-handlers/udev/Cargo.toml index 170adc206..33ded88db 100644 --- a/discovery-handlers/udev/Cargo.toml +++ b/discovery-handlers/udev/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "akri-udev" -version = "0.12.11" +version = "0.12.12" license = "Apache-2.0" authors = ["Kate Goldenring "] edition = "2018" diff --git a/discovery-utils/Cargo.toml b/discovery-utils/Cargo.toml index f98f0aa68..21d86f77d 100644 --- a/discovery-utils/Cargo.toml +++ b/discovery-utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "akri-discovery-utils" -version = "0.12.11" +version = "0.12.12" license = "Apache-2.0" authors = ["Kate Goldenring "] edition = "2018" diff --git a/samples/brokers/udev-video-broker/Cargo.toml b/samples/brokers/udev-video-broker/Cargo.toml index 035f9c82c..9152fa0be 100644 --- a/samples/brokers/udev-video-broker/Cargo.toml +++ b/samples/brokers/udev-video-broker/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "udev-video-broker" -version = "0.12.11" +version = "0.12.12" license = "Apache-2.0" authors = ["Kate Goldenring ", ""] edition = "2018" diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 5f6b73313..177667ae7 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "akri-shared" -version = "0.12.11" +version = "0.12.12" license = "Apache-2.0" authors = [""] edition = "2018" diff --git a/version.txt b/version.txt index 0801881ee..a31499ef5 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.12.11 +0.12.12 diff --git a/webhooks/validating/configuration/Cargo.toml b/webhooks/validating/configuration/Cargo.toml index 1e4a8fa9c..8d4c803dd 100644 --- a/webhooks/validating/configuration/Cargo.toml +++ b/webhooks/validating/configuration/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "webhook-configuration" -version = "0.12.11" +version = "0.12.12" license = "Apache-2.0" authors = ["DazWilkin "] edition = "2018"