Generate graph requests from the dashboard configuration
This commit is contained in:
parent
db5f2260bd
commit
9b24993736
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue