Skip to content

Commit 4480744

Browse files
author
Rakshith Bhyravabhotla
authored
Aggregations must be plural + inclue types (Azure#19762)
* Aggreagations * changelog
1 parent 004c25b commit 4480744

File tree

8 files changed

+37
-15
lines changed

8 files changed

+37
-15
lines changed

sdk/monitor/azure-monitor-query/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44

55
### Features Added
66

7+
- Added enum `AggragationType` which can be used to specify aggregations in the query API.
8+
79
### Breaking Changes
810

11+
- `aggregation` param in the query API is renamed to `aggregations`
12+
913
### Bugs Fixed
1014

1115
### Other Changes

sdk/monitor/azure-monitor-query/azure/monitor/query/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from ._metrics_query_client import MetricsQueryClient
99

1010
from ._models import (
11+
AggregationType,
1112
LogsQueryResults,
1213
LogsQueryResultTable,
1314
LogsQueryResultColumn,
@@ -27,6 +28,7 @@
2728
from ._version import VERSION
2829

2930
__all__ = [
31+
"AggregationType",
3032
"LogsQueryClient",
3133
"LogsBatchResults",
3234
"LogsBatchResultError",

sdk/monitor/azure-monitor-query/azure/monitor/query/_metrics_query_client.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ def query(self, resource_uri, metric_names, duration=None, **kwargs):
7373
with either start_time or duration.
7474
:keyword interval: The interval (i.e. timegrain) of the query.
7575
:paramtype interval: ~datetime.timedelta
76-
:keyword aggregation: The list of aggregation types to retrieve.
77-
:paramtype aggregation: list[str]
76+
:keyword aggregations: The list of aggregation types to retrieve. Use `azure.monitor.query.AggregationType`
77+
enum to get each aggregation type.
78+
:paramtype aggregations: list[str]
7879
:keyword top: The maximum number of records to retrieve.
7980
Valid only if $filter is specified.
8081
Defaults to 10.
@@ -113,9 +114,9 @@ def query(self, resource_uri, metric_names, duration=None, **kwargs):
113114
"""
114115
start = kwargs.pop('start_time', None)
115116
end = kwargs.pop('end_time', None)
116-
aggregation = kwargs.pop("aggregation", None)
117-
if aggregation:
118-
kwargs.setdefault("aggregation", ",".join(aggregation))
117+
aggregations = kwargs.pop("aggregations", None)
118+
if aggregations:
119+
kwargs.setdefault("aggregation", ",".join(aggregations))
119120
timespan = construct_iso8601(start, end, duration)
120121
kwargs.setdefault("metricnames", ",".join(metric_names))
121122
kwargs.setdefault("timespan", timespan)

sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# license information.
66
# --------------------------------------------------------------------------
77

8+
from enum import Enum
89
import uuid
910
from typing import Any, Optional, List
1011

@@ -566,3 +567,15 @@ def _from_generated(cls, generated):
566567
time_grain=generated.time_grain,
567568
retention=generated.retention
568569
)
570+
571+
572+
class AggregationType(str, Enum):
573+
"""the aggregation type of the metric.
574+
"""
575+
576+
NONE = "None"
577+
AVERAGE = "Average"
578+
COUNT = "Count"
579+
MINIMUM = "Minimum"
580+
MAXIMUM = "Maximum"
581+
TOTAL = "Total"

sdk/monitor/azure-monitor-query/azure/monitor/query/aio/_metrics_query_client_async.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ async def query(
6868
with either start_time or duration.
6969
:keyword interval: The interval (i.e. timegrain) of the query.
7070
:paramtype interval: ~datetime.timedelta
71-
:keyword aggregation: The list of aggregation types to retrieve.
72-
:paramtype aggregation: list[str]
71+
:keyword aggregations: The list of aggregation types to retrieve. Use `azure.monitor.query.AggregationType`
72+
enum to get each aggregation type.
73+
:paramtype aggregations: list[str]
7374
:keyword top: The maximum number of records to retrieve.
7475
Valid only if $filter is specified.
7576
Defaults to 10.
@@ -102,9 +103,9 @@ async def query(
102103
timespan = construct_iso8601(start, end, duration)
103104
kwargs.setdefault("metricnames", ",".join(metric_names))
104105
kwargs.setdefault("timespan", timespan)
105-
aggregation = kwargs.pop("aggregation", None)
106-
if aggregation:
107-
kwargs.setdefault("aggregation", ",".join(aggregation))
106+
aggregations = kwargs.pop("aggregations", None)
107+
if aggregations:
108+
kwargs.setdefault("aggregation", ",".join(aggregations))
108109
generated = await self._metrics_op.list(resource_uri, connection_verify=False, **kwargs)
109110
return MetricsResult._from_generated(generated) # pylint: disable=protected-access
110111

sdk/monitor/azure-monitor-query/samples/sample_metrics_query_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
from datetime import datetime, timedelta
66
import urllib3
7-
from azure.monitor.query import MetricsQueryClient
7+
from azure.monitor.query import MetricsQueryClient, AggregationType
88
from azure.identity import DefaultAzureCredential
99

1010
urllib3.disable_warnings()
@@ -22,7 +22,7 @@
2222
metric_names=["MatchedEventCount"],
2323
start_time=datetime(2021, 6, 21),
2424
duration=timedelta(days=1),
25-
aggregation=['Count']
25+
aggregations=[AggregationType.COUNT]
2626
)
2727

2828
for metric in response.metrics:

sdk/monitor/azure-monitor-query/tests/async/test_metrics_client_async.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pytest
33
import os
44
from azure.identity.aio import ClientSecretCredential
5+
from azure.monitor.query import AggregationType
56
from azure.monitor.query.aio import MetricsQueryClient
67

78
def _credential():
@@ -21,7 +22,7 @@ async def test_metrics_auth():
2122
metric_names=["MatchedEventCount"],
2223
start_time=datetime(2021, 6, 21),
2324
duration=timedelta(days=1),
24-
aggregation=['Count']
25+
aggregations=[AggregationType.COUNT]
2526
)
2627
assert response
2728
assert response.metrics

sdk/monitor/azure-monitor-query/tests/test_metrics_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
from datetime import datetime, timedelta
44
from azure.identity import ClientSecretCredential
5-
from azure.monitor.query import MetricsQueryClient
5+
from azure.monitor.query import MetricsQueryClient, AggregationType
66

77
def _credential():
88
credential = ClientSecretCredential(
@@ -21,7 +21,7 @@ def test_metrics_auth():
2121
metric_names=["MatchedEventCount"],
2222
start_time=datetime(2021, 6, 21),
2323
duration=timedelta(days=1),
24-
aggregation=['Count']
24+
aggregations=[AggregationType.COUNT]
2525
)
2626
assert response
2727
assert response.metrics

0 commit comments

Comments
 (0)