Skip to content

Commit

Permalink
feat: 🎸 Swap to embedded metric format
Browse files Browse the repository at this point in the history
(Will provide another commit to fix broken/commented out tests)
  • Loading branch information
Clete2 committed Dec 19, 2023
1 parent fcb10eb commit 2acbaab
Show file tree
Hide file tree
Showing 9 changed files with 1,257 additions and 1,047 deletions.
335 changes: 311 additions & 24 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ serde = "1.0"
cached = { version = "0.46", features = ["async"] }
env_logger = "0.10"
aws-sdk-cloudwatchlogs = "0.37"
aws-sdk-cloudwatch = "0.37"
aws-config = "0.100"
aws-smithy-types = "0.100"
async-trait = "0.1"
metrics_cloudwatch_embedded = "0.4"
tracing = "0.1"
metrics = "0.21"
chrono = "0.4.31"

[dev-dependencies]
insta = { version = "1.34", features = ["filters"] }
Expand Down
884 changes: 444 additions & 440 deletions src/bin/global_retention_setter.rs

Large diffs are not rendered by default.

47 changes: 0 additions & 47 deletions src/cloudwatch_metrics_traits.rs

This file was deleted.

11 changes: 0 additions & 11 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::fmt::Display;

use serde::Serialize;

use aws_sdk_cloudwatch::Error as CloudWatchError;
use aws_sdk_cloudwatchlogs::Error as CloudWatchLogsError;

#[derive(Debug, Serialize)]
Expand All @@ -25,16 +24,6 @@ impl Display for Error {
}
}

// TODO: Can we find a common trait to implement From<> for instead of implementing for each client?
impl From<CloudWatchError> for Error {
fn from(e: CloudWatchError) -> Self {
Self {
message: e.to_string(),
severity: Severity::Error,
}
}
}

impl From<CloudWatchLogsError> for Error {
fn from(e: CloudWatchLogsError) -> Self {
Self {
Expand Down
19 changes: 2 additions & 17 deletions src/global.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
use std::{collections::HashMap, time::Duration};

use aws_config::{BehaviorVersion, SdkConfig};
use aws_sdk_cloudwatch::Client as CloudWatchMetricsClient;
use aws_sdk_cloudwatchlogs::Client as CloudWatchLogsClient;
use aws_smithy_types::retry::{RetryConfig, RetryMode};
use cached::proc_macro::cached;

use crate::{cloudwatch_logs_traits::CloudWatchLogs, cloudwatch_metrics_traits::CloudWatchMetrics};
use crate::cloudwatch_logs_traits::CloudWatchLogs;

#[cached]
pub async fn cloudwatch_logs() -> CloudWatchLogs {
let sdk_config = sdk_config().await;
CloudWatchLogs::new(CloudWatchLogsClient::new(&sdk_config))
}

#[cached]
pub async fn cloudwatch_metrics() -> CloudWatchMetrics {
let sdk_config = sdk_config().await;
CloudWatchMetrics::new(CloudWatchMetricsClient::new(&sdk_config))
}

#[cached]
async fn sdk_config() -> SdkConfig {
let retry_config = RetryConfig::standard()
Expand Down Expand Up @@ -64,7 +57,7 @@ mod tests {

use crate::global::retention;

use super::{cloudwatch_logs, cloudwatch_metrics, initialize_logger, log_group_tags};
use super::{cloudwatch_logs, initialize_logger, log_group_tags};

#[tokio::test]
async fn test_cw_logs_client() {
Expand All @@ -74,14 +67,6 @@ mod tests {
cloudwatch_logs().await;
}

#[tokio::test]
async fn test_cw_metrics_client() {
std::env::set_var("AWS_ACCESS_KEY_ID", "AKIAASDASDQWEF");
std::env::set_var("AWS_SECRET_ACCESS_KEY", "ASIAAFQWEFWEIFJ");

cloudwatch_metrics().await;
}

#[test]
fn test_retention() {
std::env::set_var("log_retention_in_days", "1");
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod cloudwatch_logs_traits;
pub mod cloudwatch_metrics_traits;
pub mod error;
pub mod event;
pub mod global;
Expand Down
Loading

0 comments on commit 2acbaab

Please sign in to comment.