Skip to content

Commit

Permalink
feat: made period optional
Browse files Browse the repository at this point in the history
  • Loading branch information
1101-1 committed Dec 11, 2024
1 parent 8a937c0 commit ed4350b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 22 deletions.
6 changes: 3 additions & 3 deletions plugins/azure/fix_plugin_azure/resource/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,8 +1025,8 @@ class AzureMetricQuery:
instance_id: str
metric_id: str
aggregation: Tuple[str, ...]
period: timedelta
normalization: MetricNormalization
custom_period: Optional[timedelta] = None
custom_start_time: Optional[datetime] = None
unit: str = "Count"

Expand All @@ -1039,10 +1039,10 @@ def create(
instance_id: str,
ref_id: str,
normalization: MetricNormalization,
period: timedelta,
aggregation: Tuple[str, ...],
unit: str = "Count",
custom_start_time: Optional[datetime] = None,
custom_period: Optional[timedelta] = None,
metric_id: Optional[str] = None,
) -> "AzureMetricQuery":
metric_id = f"{instance_id}/providers/Microsoft.Insights/metrics/{metric_name}"
Expand All @@ -1057,7 +1057,7 @@ def create(
ref_id=ref_id,
unit=unit,
normalization=normalization,
period=period,
custom_period=custom_period,
custom_start_time=custom_start_time,
)

Expand Down
8 changes: 0 additions & 8 deletions plugins/azure/fix_plugin_azure/resource/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,6 @@ def collect_disk_types() -> None:
def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery]:
volume_id = self.id
queries = []
delta = builder.metrics_delta

queries.extend(
[
Expand All @@ -1109,7 +1108,6 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery]
aggregation=("average",),
ref_id=volume_id,
unit="BytesPerSecond",
period=delta,
normalization=NormalizerFactory.bytes,
)
for name, metric_name in [
Expand All @@ -1127,7 +1125,6 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery]
instance_id=volume_id,
aggregation=("average",),
ref_id=volume_id,
period=delta,
unit="CountPerSecond",
normalization=NormalizerFactory.iops,
)
Expand Down Expand Up @@ -2999,7 +2996,6 @@ def collect_vm_sizes() -> None:
def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery]:
vm_id = self.id
queries = []
delta = builder.metrics_delta

queries.append(
AzureMetricQuery.create(
Expand All @@ -3010,7 +3006,6 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery]
aggregation=("average", "minimum", "maximum"),
ref_id=vm_id,
unit="Percent",
period=delta,
normalization=NormalizerFactory.percent,
)
)
Expand All @@ -3024,7 +3019,6 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery]
aggregation=("average", "minimum", "maximum"),
ref_id=vm_id,
unit="Bytes",
period=delta,
normalization=NormalizerFactory.bytes,
)
for name, metric_name in [
Expand All @@ -3043,7 +3037,6 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery]
aggregation=("average", "minimum", "maximum"),
ref_id=vm_id,
unit="CountPerSecond",
period=delta,
normalization=NormalizerFactory.iops,
)
for name, metric_name in [
Expand All @@ -3062,7 +3055,6 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery]
aggregation=("average", "minimum", "maximum"),
ref_id=vm_id,
unit="Bytes",
period=delta,
normalization=NormalizerFactory.bytes,
)
for name, metric_name in [("Network In", MetricName.NetworkIn), ("Network Out", MetricName.NetworkOut)]
Expand Down
2 changes: 1 addition & 1 deletion plugins/azure/fix_plugin_azure/resource/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def _query_for_single(
aggregation = ",".join(query.aggregation)
# Define the timespan and interval for the query
timespan = f"{utc_str(query.custom_start_time or start_time)}/{utc_str(end_time)}"
interval = AzureMetricData.compute_interval(query.period)
interval = AzureMetricData.compute_interval(query.custom_period or builder.metrics_delta)
part = builder.client.list(
local_api_spec,
metricnames=query.metric_name,
Expand Down
18 changes: 9 additions & 9 deletions plugins/azure/fix_plugin_azure/resource/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery]
ref_id=account_id,
unit="Bytes",
normalization=NormalizerFactory.bytes,
period=delta,
custom_period=delta,
custom_start_time=start,
)
)
Expand All @@ -982,7 +982,7 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery]
ref_id=account_id,
unit="Bytes",
normalization=NormalizerFactory.bytes,
period=delta,
custom_period=delta,
custom_start_time=start,
)
)
Expand All @@ -996,7 +996,7 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery]
ref_id=account_id,
unit="Count",
normalization=NormalizerFactory.count,
period=delta,
custom_period=delta,
custom_start_time=start,
)
)
Expand All @@ -1010,7 +1010,7 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery]
ref_id=account_id,
unit="Bytes",
normalization=NormalizerFactory.bytes,
period=delta,
custom_period=delta,
custom_start_time=start,
)
)
Expand All @@ -1024,7 +1024,7 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery]
ref_id=account_id,
unit="Count",
normalization=NormalizerFactory.count,
period=delta,
custom_period=delta,
custom_start_time=start,
)
)
Expand All @@ -1038,7 +1038,7 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery]
ref_id=account_id,
unit="Bytes",
normalization=NormalizerFactory.bytes,
period=delta,
custom_period=delta,
custom_start_time=start,
)
)
Expand All @@ -1052,7 +1052,7 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery]
ref_id=account_id,
unit="Count",
normalization=NormalizerFactory.count,
period=delta,
custom_period=delta,
custom_start_time=start,
)
)
Expand All @@ -1066,7 +1066,7 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery]
ref_id=account_id,
unit="Bytes",
normalization=NormalizerFactory.bytes,
period=delta,
custom_period=delta,
custom_start_time=start,
)
)
Expand All @@ -1080,7 +1080,7 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery]
ref_id=account_id,
unit="Count",
normalization=NormalizerFactory.count,
period=delta,
custom_period=delta,
custom_start_time=start,
)
)
Expand Down
2 changes: 1 addition & 1 deletion plugins/azure/test/metric_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_metric(builder: GraphBuilder) -> None:
metric_namespace="Microsoft.Compute/virtualMachines",
metric_normalization_name=MetricName.DiskWrite,
normalization=NormalizerFactory.iops,
period=delta,
custom_period=delta,
instance_id=resource_id,
ref_id=resource_id,
aggregation=("average", "minimum", "maximum"),
Expand Down

0 comments on commit ed4350b

Please sign in to comment.