Skip to content

Commit

Permalink
chore: trying to refactor metric data query generation
Browse files Browse the repository at this point in the history
  • Loading branch information
pgautier404 committed May 16, 2024
1 parent 5a0a19e commit af4a338
Showing 1 changed file with 54 additions and 32 deletions.
86 changes: 54 additions & 32 deletions momento/src/commands/cloud_linter/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,49 @@ where
}
}

async fn get_metric_stat_query(
metric_target: MetricTarget,
metric: &&str,
stat_type: &str,
) -> Result<MetricDataQuery, CliError> {
let dimensions: Vec<Dimension> = metric_target
.dimensions
.into_iter()
.map(|(name, value)| Dimension::builder().name(name).value(value).build())
.collect();
Ok(
MetricDataQuery::builder()
.metric_stat(
MetricStat::builder()
.metric(
CloudwatchMetric::builder()
.metric_name(metric.to_string())
.namespace(metric_target.namespace.clone())
.set_dimensions(Some(dimensions.clone()))
.build(),
)
.period(60 * 60 * 24)
.stat(stat_type.to_string())
.build(),
)
.id(format!(
"{}_{}",
metric.to_lowercase(),
stat_type.to_lowercase()
))
.build()
)
}

async fn query_metrics_for_target(
client: &Client,
limiter: Arc<DefaultDirectRateLimiter>,
metric_target: MetricTarget,
) -> Result<Vec<Metric>, CliError> {
let mut metric_results: Vec<Metric> = Vec::new();
if metric_target.expression.is_empty() {
println!("No expression for metric target");
if !metric_target.expression.is_empty() {
println!("Expression for metric target");
return Ok(metric_results);
} else {
println!("Will query metric expression: {}", metric_target.expression);
}
// let dimensions: Vec<Dimension> = metric_target
// .dimensions
Expand All @@ -86,35 +118,25 @@ async fn query_metrics_for_target(
for (stat_type, metrics) in metric_target.targets.entries() {
let mut metric_data_queries: Vec<MetricDataQuery> = Vec::with_capacity(metrics.len());
for metric in *metrics {
println!("Querying metric: {}", metric);
println!("expression is {}", metric_target.expression);
// println!("Querying metric: {}", metric);
// println!("expression is {}", metric_target.expression);
// TODO: support max/avg
let search_expression = format!("SEARCH(\' {} \', \'{}\')", metric_target.expression, "Sum");
println!("search expression is {}", search_expression);
println!("stat type is {}", stat_type);
let metric_data_query = MetricDataQuery::builder()
// .metric_stat(
// MetricStat::builder()
// .metric(
// CloudwatchMetric::builder()
// .metric_name(metric.to_string())
// .namespace(metric_target.namespace.clone())
// .set_dimensions(Some(dimensions.clone()))
// .build(),
// )
// .period(60 * 60 * 24)
// .stat(stat_type.to_string())
// .build(),
// )
.expression(search_expression)
.period(60 * 60 * 24)
.return_data(true)
.id(format!(
"{}_{}",
metric.to_lowercase(),
stat_type.to_lowercase()
))
.build();
// let search_expression = format!("SEARCH(\' {} \', \'{}\')", metric_target.expression, "Sum");
// println!("search expression is {}", search_expression);
// println!("stat type is {}", stat_type);
let metric_data_query = get_metric_stat_query(
metric_target, metric, stat_type
).await?;

// .expression(search_expression)
// .period(60 * 60 * 24)
// .return_data(true)
// .id(format!(
// "{}_{}",
// metric.to_lowercase(),
// stat_type.to_lowercase()
// ))
// .build();
metric_data_queries.push(metric_data_query);
}

Expand Down

0 comments on commit af4a338

Please sign in to comment.