diff --git a/plugins/azure/fix_plugin_azure/resource/base.py b/plugins/azure/fix_plugin_azure/resource/base.py index e3c8eaa1a..e3d7fdf37 100644 --- a/plugins/azure/fix_plugin_azure/resource/base.py +++ b/plugins/azure/fix_plugin_azure/resource/base.py @@ -1026,8 +1026,9 @@ class AzureMetricQuery: metric_id: str aggregation: Tuple[str, ...] normalization: MetricNormalization - custom_period: Optional[timedelta] = None - custom_start_time: Optional[datetime] = None + # Optional `start_time` and `period` override defaults for query timespan and interval. + period: Optional[timedelta] = None + start_time: Optional[datetime] = None unit: str = "Count" @staticmethod @@ -1041,8 +1042,8 @@ def create( normalization: MetricNormalization, aggregation: Tuple[str, ...], unit: str = "Count", - custom_start_time: Optional[datetime] = None, - custom_period: Optional[timedelta] = None, + start_time: Optional[datetime] = None, + period: Optional[timedelta] = None, metric_id: Optional[str] = None, ) -> "AzureMetricQuery": metric_id = f"{instance_id}/providers/Microsoft.Insights/metrics/{metric_name}" @@ -1057,8 +1058,8 @@ def create( ref_id=ref_id, unit=unit, normalization=normalization, - custom_period=custom_period, - custom_start_time=custom_start_time, + period=period, + start_time=start_time, ) diff --git a/plugins/azure/fix_plugin_azure/resource/metrics.py b/plugins/azure/fix_plugin_azure/resource/metrics.py index f879c0c31..d91221d7a 100644 --- a/plugins/azure/fix_plugin_azure/resource/metrics.py +++ b/plugins/azure/fix_plugin_azure/resource/metrics.py @@ -220,8 +220,8 @@ def _query_for_single( # Retrieve metric data from the API 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.custom_period or builder.metrics_delta) + timespan = f"{utc_str(query.start_time or start_time)}/{utc_str(end_time)}" + interval = AzureMetricData.compute_interval(query.period or builder.metrics_delta) part = builder.client.list( local_api_spec, metricnames=query.metric_name, diff --git a/plugins/azure/fix_plugin_azure/resource/storage.py b/plugins/azure/fix_plugin_azure/resource/storage.py index f6c085c7a..ae19c8fa0 100644 --- a/plugins/azure/fix_plugin_azure/resource/storage.py +++ b/plugins/azure/fix_plugin_azure/resource/storage.py @@ -948,7 +948,7 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery] start = builder.metrics_start now = builder.created_at delta = builder.metrics_delta - # # Minimum interval and time range for storage metrics is 1H + # Minimum interval and time range for storage metrics is 1H if delta.total_seconds() < 3600: delta = timedelta(hours=1) start = now - delta @@ -968,8 +968,8 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery] ref_id=account_id, unit="Bytes", normalization=NormalizerFactory.bytes, - custom_period=delta, - custom_start_time=start, + period=delta, + start_time=start, ) ) queries.append( @@ -982,8 +982,8 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery] ref_id=account_id, unit="Bytes", normalization=NormalizerFactory.bytes, - custom_period=delta, - custom_start_time=start, + period=delta, + start_time=start, ) ) queries.append( @@ -996,8 +996,8 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery] ref_id=account_id, unit="Count", normalization=NormalizerFactory.count, - custom_period=delta, - custom_start_time=start, + period=delta, + start_time=start, ) ) queries.append( @@ -1010,8 +1010,8 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery] ref_id=account_id, unit="Bytes", normalization=NormalizerFactory.bytes, - custom_period=delta, - custom_start_time=start, + period=delta, + start_time=start, ) ) queries.append( @@ -1024,8 +1024,8 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery] ref_id=account_id, unit="Count", normalization=NormalizerFactory.count, - custom_period=delta, - custom_start_time=start, + period=delta, + start_time=start, ) ) queries.append( @@ -1038,8 +1038,8 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery] ref_id=account_id, unit="Bytes", normalization=NormalizerFactory.bytes, - custom_period=delta, - custom_start_time=start, + period=delta, + start_time=start, ) ) queries.append( @@ -1052,8 +1052,8 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery] ref_id=account_id, unit="Count", normalization=NormalizerFactory.count, - custom_period=delta, - custom_start_time=start, + period=delta, + start_time=start, ) ) queries.append( @@ -1066,8 +1066,8 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery] ref_id=account_id, unit="Bytes", normalization=NormalizerFactory.bytes, - custom_period=delta, - custom_start_time=start, + period=delta, + start_time=start, ) ) queries.append( @@ -1080,8 +1080,8 @@ def collect_usage_metrics(self, builder: GraphBuilder) -> List[AzureMetricQuery] ref_id=account_id, unit="Count", normalization=NormalizerFactory.count, - custom_period=delta, - custom_start_time=start, + period=delta, + start_time=start, ) ) diff --git a/plugins/azure/test/metric_test.py b/plugins/azure/test/metric_test.py index 0c04ae331..313a562da 100644 --- a/plugins/azure/test/metric_test.py +++ b/plugins/azure/test/metric_test.py @@ -18,7 +18,7 @@ def test_metric(builder: GraphBuilder) -> None: metric_namespace="Microsoft.Compute/virtualMachines", metric_normalization_name=MetricName.DiskWrite, normalization=NormalizerFactory.iops, - custom_period=delta, + period=delta, instance_id=resource_id, ref_id=resource_id, aggregation=("average", "minimum", "maximum"),