Skip to content

Commit

Permalink
chore: renamed start_time and period and added comment
Browse files Browse the repository at this point in the history
  • Loading branch information
1101-1 committed Dec 11, 2024
1 parent 1065bb0 commit c8af5c7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
13 changes: 7 additions & 6 deletions plugins/azure/fix_plugin_azure/resource/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}"
Expand All @@ -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,
)


Expand Down
4 changes: 2 additions & 2 deletions plugins/azure/fix_plugin_azure/resource/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
38 changes: 19 additions & 19 deletions plugins/azure/fix_plugin_azure/resource/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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,
)
)

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,
custom_period=delta,
period=delta,
instance_id=resource_id,
ref_id=resource_id,
aggregation=("average", "minimum", "maximum"),
Expand Down

0 comments on commit c8af5c7

Please sign in to comment.