From 9b249937366e60f3dc546a600d3093071b8ff463 Mon Sep 17 00:00:00 2001 From: Olivier Date: Sat, 8 Jan 2022 16:36:12 +0000 Subject: [PATCH] Generate graph requests from the dashboard configuration --- bare-metrics-gui/src/graph.rs | 2 +- bare-metrics-gui/src/main.rs | 45 +++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/bare-metrics-gui/src/graph.rs b/bare-metrics-gui/src/graph.rs index 8d54517..7ed8d15 100644 --- a/bare-metrics-gui/src/graph.rs +++ b/bare-metrics-gui/src/graph.rs @@ -1,6 +1,6 @@ use crate::background_loader::MetricsLogReadingRequester; use crate::config::GraphRequest; -use bare_metrics_core::structures::{UnixTimestampMilliseconds}; +use bare_metrics_core::structures::UnixTimestampMilliseconds; use eframe::egui::{ Color32, Frame as EguiFrame, PointerButton, Pos2, Rect, Sense, Stroke, TextStyle, Ui, Vec2, }; diff --git a/bare-metrics-gui/src/main.rs b/bare-metrics-gui/src/main.rs index 0c7644a..85aee8b 100644 --- a/bare-metrics-gui/src/main.rs +++ b/bare-metrics-gui/src/main.rs @@ -1,4 +1,6 @@ -use crate::background_loader::{MetricsLogReaderMessage, MetricsLogReadingRequester}; +use crate::background_loader::{ + MetricsLogReaderMessage, MetricsLogReaderNotification, MetricsLogReadingRequester, +}; use crate::config::{DashboardConfig, GraphRequest}; use crate::graph::Graph; @@ -7,7 +9,8 @@ use eframe::egui::{CentralPanel, CtxRef}; use eframe::epi::{App, Frame, Storage}; use eframe::NativeOptions; use env_logger::Env; -use log::info; +use log::{debug, info, warn}; +use std::collections::{BTreeMap}; use std::fs::File; use std::path::PathBuf; use std::str::FromStr; @@ -25,6 +28,8 @@ pub struct MetricsGui { impl App for MetricsGui { fn update(&mut self, ctx: &CtxRef, _frame: &mut Frame<'_>) { + self.handle_messages(); + let Self { requester, dashboard, @@ -75,6 +80,42 @@ impl App for MetricsGui { } } +impl MetricsGui { + fn handle_messages(&mut self) { + while let Ok(msg) = self.requester.rx.try_recv() { + match msg { + MetricsLogReaderNotification::MetricDescriptorsAvailable { .. } => { + info!("Metric descriptors are available"); + self.on_metric_descriptors_available(); + } + MetricsLogReaderNotification::WindowLoadStateChange { .. } => { + debug!("State change"); + } + } + } + } + + fn on_metric_descriptors_available(&mut self) { + if !self.graph_requests.is_empty() { + warn!("TODO: don't know how to handle multiple appearances of descriptors"); + return; + } + if let Some(dashboard) = self.dashboard.as_ref() { + for graph in dashboard.graphs.iter() { + // TODO frankly we should maybe be using metric IDs in the graph requests + self.graph_requests.push(GraphRequest { + metric_name: graph.name.clone(), + // TODO we need something better about the metric labels + metric_labels: BTreeMap::new(), + derivation: graph.transform.clone(), + }); + } + } else { + // TODO Build some stuff automatically based on alphabetical ordering + } + } +} + fn main() -> anyhow::Result<()> { env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();