Skip to content

Commit

Permalink
adjusted metrics period to the standarts
Browse files Browse the repository at this point in the history
  • Loading branch information
1101-1 committed May 27, 2024
1 parent b68ea6b commit 795368c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 24 deletions.
27 changes: 15 additions & 12 deletions plugins/aws/fix_plugin_aws/resource/cloudwatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,18 +644,21 @@ def query_for_multiple(
)
)

# Retrieve results from submitted queries and populate the result dictionary
for future in as_completed(futures):
try:
metric_query_result = future.result()
for metric, metric_id in metric_query_result:
if metric is not None and metric_id is not None:
query_result = lookup.get(metric_id)
if query_result:
result[query_result] = metric
except Exception as e:
log.warning(f"An error occurred while processing a metric query: {e}")
raise e
try:

Check notice on line 647 in plugins/aws/fix_plugin_aws/resource/cloudwatch.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

plugins/aws/fix_plugin_aws/resource/cloudwatch.py#L647

Too many nested blocks (6/5)
# Retrieve results from submitted queries with a timeout limit
for future in as_completed(futures, 60):
try:
metric_query_result = future.result()
for metric, metric_id in metric_query_result:
if metric is not None and metric_id is not None:
query_result = lookup.get(metric_id)
if query_result:
result[query_result] = metric
except Exception as e:
log.warning(f"An error occurred while processing a metric query: {e}")
raise e
except TimeoutError as e:
log.warning(f"An error ocurred while waiting futures: {e}")

return result

Expand Down
7 changes: 3 additions & 4 deletions plugins/aws/fix_plugin_aws/resource/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AwsCloudwatchQuer
queries: List[AwsCloudwatchQuery] = []
delta = builder.metrics_delta

period = min(timedelta(minutes=5), delta)
period = timedelta(minutes=5)

queries.extend(
[
Expand Down Expand Up @@ -1403,9 +1403,8 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AwsCloudwatchQuer
return []
queries: List[AwsCloudwatchQuery] = []
delta_since_last_scan = builder.metrics_delta
# for metrics which are expressed as sum, we want the period to be
# 5 minutes or less if the last scan was less than 5 minutes ago
period = min(timedelta(minutes=5), delta_since_last_scan)
# for metrics which are expressed as sum, we want the period to be 5 minutes
period = timedelta(minutes=5)

queries.extend(
[
Expand Down
2 changes: 1 addition & 1 deletion plugins/aws/fix_plugin_aws/resource/elb.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AwsCloudwatchQuer
queries: List[AwsCloudwatchQuery] = []
delta = builder.metrics_delta

period = min(timedelta(minutes=5), delta)
period = timedelta(minutes=5)

queries.extend(
[
Expand Down
6 changes: 3 additions & 3 deletions plugins/aws/fix_plugin_aws/resource/elbv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AwsCloudwatchQuer
queries: List[AwsCloudwatchQuery] = []
delta = builder.metrics_delta

period = min(timedelta(minutes=5), delta)
period = timedelta(minutes=1)

lb_id = "/".join((self.arn or "").split("/")[-3:])
queries.extend(
Expand Down Expand Up @@ -465,7 +465,7 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AwsCloudwatchQuer
AwsCloudwatchQuery.create(
metric_name="TargetResponseTime",
namespace="AWS/ApplicationELB",
period=period,
period=delta,
ref_id=self.id,
metric_normalizer_name=MetricName.TargetResponseTime,
metric_normalization=normalizer_factory.seconds,
Expand Down Expand Up @@ -693,7 +693,7 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AwsCloudwatchQuer
queries: List[AwsCloudwatchQuery] = []
delta = builder.metrics_delta

period = min(timedelta(minutes=5), delta)
period = timedelta(minutes=1)

tg_arn_id = (self.arn or "").split(":")[-1]
lb_arn_id = "/".join(self.alb_lb_arns[0].split("/")[-3:])
Expand Down
3 changes: 2 additions & 1 deletion plugins/aws/fix_plugin_aws/resource/lambda_.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AwsCloudwatchQuer
return []
queries: List[AwsCloudwatchQuery] = []
delta = builder.metrics_delta
period = min(timedelta(minutes=5), delta)
# Lambda metrics support a 1-minute interval
period = timedelta(minutes=1)

queries.extend(
[
Expand Down
5 changes: 2 additions & 3 deletions plugins/aws/fix_plugin_aws/resource/sns.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AwsCloudwatchQuer
return []
queries: List[AwsCloudwatchQuery] = []
delta = builder.metrics_delta

period = min(timedelta(minutes=5), delta)

# SNS metrics are available at a 1-minute interval
period = timedelta(minutes=1)
queries.extend(
[
AwsCloudwatchQuery.create(
Expand Down

0 comments on commit 795368c

Please sign in to comment.