diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..45bf872 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,16 @@ +name: CI + +on: + push: + pull_request: + workflow_dispatch: + +jobs: + ci: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: cargo build --verbose + - run: cargo test --verbose + - run: cargo clippy --verbose + - run: cargo fmt --verbose diff --git a/src/main.rs b/src/main.rs index 4e4eb1d..5014359 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,11 +20,11 @@ struct AppsignalMetric { } impl AppsignalMetric { - pub fn new(metric_name: &str, node_name: &str, value: &serde_json::Value) -> AppsignalMetric { - // Create tags - let mut tags = HashMap::with_capacity(1); - tags.insert("node".to_owned(), node_name.to_owned()); - + pub fn new( + metric_name: &str, + tags: HashMap, + value: &serde_json::Value, + ) -> AppsignalMetric { // See if we can use value let value = match value { Value::Number(value) => match value.as_f64() { @@ -49,7 +49,7 @@ async fn main() -> Result<(), Error> { let mut interval = tokio::time::interval(duration); loop { - interval.tick().await; + interval.tick().await; run().await.expect("Failed to extract metrics.") } } @@ -69,12 +69,13 @@ async fn run() -> Result<(), Error> { .request::(kube_request) .await?; - extract_metrics(kube_response, &name, &mut out); + extract_node_metrics(kube_response, &name, &mut out); } let json = serde_json::to_string(&out).expect("Could not serialize JSON"); - let endpoint = env::var("APPSIGNAL_ENDPOINT").unwrap_or("https://appsignal-endpoint.net".to_owned()); + let endpoint = + env::var("APPSIGNAL_ENDPOINT").unwrap_or("https://appsignal-endpoint.net".to_owned()); let api_key = env::var("APPSIGNAL_API_KEY").expect("APPSIGNAL_API_KEY not set"); let base = Url::parse(&endpoint).expect("Could not parse endpoint"); let path = format!("metrics/json?api_key={}", api_key); @@ -93,7 +94,7 @@ async fn run() -> Result<(), Error> { Ok(()) } -fn extract_metrics(results: Value, node_name: &str, out: &mut Vec) { +fn extract_node_metrics(results: Value, node_name: &str, out: &mut Vec) { for (metric_name, metric_value) in [ ( "node_cpu_usage_nano_cores", @@ -166,30 +167,37 @@ fn extract_metrics(results: Value, node_name: &str, out: &mut Vec