From 8fc2f55ac461f7389c9f09718ab0cc1d173724c8 Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Mon, 25 Oct 2021 00:38:59 +0300 Subject: [PATCH] mv grafana to datasources --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 4 ++-- src/datasources.rs | 1 + src/{grafana_service.rs => datasources/grafana.rs} | 11 ++++++----- .../grafana}/prometheus.rs | 6 +++--- src/lib.rs | 2 +- src/main.rs | 4 ++-- 8 files changed, 17 insertions(+), 15 deletions(-) create mode 100644 src/datasources.rs rename src/{grafana_service.rs => datasources/grafana.rs} (95%) rename src/{grafana_service => datasources/grafana}/prometheus.rs (93%) diff --git a/Cargo.lock b/Cargo.lock index e625c16..e75f604 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -690,7 +690,7 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "subbeat" -version = "0.0.2" +version = "0.0.3" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 857ce2f..48eb782 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "subbeat" -version = "0.0.2" +version = "0.0.3" edition = "2018" license = "MIT OR Apache-2.0" diff --git a/README.md b/README.md index ecd5c77..4261343 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,10 @@ subbeat ## Example ``` -subbeat grafana http://localhost:3000 eyJrIjoiWnRRMTNmcGpvTHNPb3UzNzdUNUphRm53Rk9tMTNzOTQiLCJuIjoic3ViYmVhdC10ZXN0IiwiaWQiOjF9 "/api/datasources/proxy/1/api/v1/query_range" "rate(go_memstats_alloc_bytes_total[5m])" 1634672070 1634672970 15 +subbeat grafana http://localhost:3000 eyJrIjoiWnRRMTNmcGpvTHNPb3UzNzdUNUphRm53Rk9tMTNzOTQiLCJuIjoic3ViYmVhdC10ZXN0IiwiaWQiOjF9 "/api/datasources/proxy/1/api/v1/query_range" "rate(go_memstats_alloc_bytes_total[5m])" 1634672070 1635110190 15 ``` ### Datasources #### Grafana -* Prometheus \ No newline at end of file +* Prometheus diff --git a/src/datasources.rs b/src/datasources.rs new file mode 100644 index 0000000..c5e6c31 --- /dev/null +++ b/src/datasources.rs @@ -0,0 +1 @@ +pub mod grafana; \ No newline at end of file diff --git a/src/grafana_service.rs b/src/datasources/grafana.rs similarity index 95% rename from src/grafana_service.rs rename to src/datasources/grafana.rs index b9c38f3..273cc72 100644 --- a/src/grafana_service.rs +++ b/src/datasources/grafana.rs @@ -1,3 +1,4 @@ +use crate::metric::Metric; use crate::{metric::MetricResult, types}; use hyper::{Body, Client, Method, Request, StatusCode}; @@ -8,16 +9,16 @@ mod prometheus; use serde_json; -use crate::metric::Metric; -pub struct GrafanaService { + +pub struct Grafana { url: String, api_key: String, } -impl GrafanaService { - pub fn new(url: String, api_key: String) -> GrafanaService { - GrafanaService { api_key, url } +impl Grafana { + pub fn new(url: String, api_key: String) -> Grafana { + Grafana { api_key, url } } pub async fn test_connection(&self) -> types::Result<()> { diff --git a/src/grafana_service/prometheus.rs b/src/datasources/grafana/prometheus.rs similarity index 93% rename from src/grafana_service/prometheus.rs rename to src/datasources/grafana/prometheus.rs index 90d8b27..fcd59bb 100644 --- a/src/grafana_service/prometheus.rs +++ b/src/datasources/grafana/prometheus.rs @@ -11,12 +11,12 @@ use serde_derive::{Deserialize, Serialize}; use serde_qs as qs; -use super::GrafanaService; +use super::Grafana; pub struct Prometheus<'a> { url: String, query: String, - grafana_service: &'a GrafanaService, + grafana_service: &'a Grafana, } #[derive(Deserialize, Serialize)] @@ -28,7 +28,7 @@ struct Query { } impl<'a> Prometheus<'a> { - pub fn new(grafana_service: &'a GrafanaService, url: &str, query: &str) -> Prometheus<'a> { + pub fn new(grafana_service: &'a Grafana, url: &str, query: &str) -> Prometheus<'a> { Prometheus { url: url.to_owned(), grafana_service, diff --git a/src/lib.rs b/src/lib.rs index 096b3f8..78d3609 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,3 @@ -pub mod grafana_service; +pub mod datasources; pub mod metric; pub mod types; diff --git a/src/main.rs b/src/main.rs index 5880f9b..e172aa5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use subbeat::grafana_service; +use subbeat::datasources::grafana; mod cli; mod types; @@ -7,7 +7,7 @@ mod types; async fn main() -> types::Result<()> { let cli = cli::CLI::new(); - let gs = grafana_service::GrafanaService::new(cli.url.to_string(), cli.key.to_string()); + let gs = grafana::Grafana::new(cli.url.to_string(), cli.key.to_string()); // gs.test_connection().await?; // gs.get_datasources().await?;