Skip to content

Commit 29a1e09

Browse files
author
Rakshith Bhyravabhotla
authored
Consistency related changes (#20385)
* time stamp * Rename AggragationType to MetricAggregationType * Metric Class * logs batch result * MetricNamespaceClassification * LogsTable + LogsTableColumn * lint * more lint
1 parent e81050e commit 29a1e09

File tree

12 files changed

+86
-73
lines changed

12 files changed

+86
-73
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
### Features Added
66

77
- Added additional `display_description` attribute to the `Metric` type.
8+
- Added a `MetricClass` enum to provide the class of a metric.
9+
- Added a `metric_class` attribute to the `MetricDefinition` type.
10+
- Added a `MetricNamespaceClassification` enum to support the `namespace_classification` attribute on `MetricNamespace` type.
811

912
### Breaking Changes
1013

@@ -22,6 +25,11 @@
2225
- `LogsQueryResult` now returns `datetime` objects for a time values.
2326
- `LogsBatchQuery` doesn't accept a `request_id` anymore.
2427
- `MetricsMetadataValues` is removed. A dictionary is used instead.
28+
- `time_stamp` is renamed to `timestamp` in `MetricValue` type.
29+
- `AggregationType` is renamed to `MetricAggregationType`.
30+
- Removed `LogsBatchResultError` type.
31+
- `LogsQueryResultTable` is named to `LogsTable`
32+
- `LogsQueryResultColumn` is renamed to `LogsTableColumn`
2533

2634
### Bugs Fixed
2735

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,10 @@ LogsQueryResult / LogsBatchQueryResult
226226
|---statistics
227227
|---visualization
228228
|---error
229-
|---tables (list of `LogsQueryResultTable` objects)
229+
|---tables (list of `LogsTable` objects)
230230
|---name
231231
|---rows
232-
|---columns (list of `LogsQueryResultColumn` objects)
232+
|---columns (list of `LogsTableColumn` objects)
233233
|---name
234234
|---type
235235
```
@@ -313,7 +313,7 @@ MetricsResult
313313
```python
314314
import os
315315
from datetime import datetime, timedelta
316-
from azure.monitor.query import MetricsQueryClient, AggregationType
316+
from azure.monitor.query import MetricsQueryClient, MetricAggregationType
317317
from azure.identity import DefaultAzureCredential
318318

319319
credential = DefaultAzureCredential()
@@ -323,7 +323,7 @@ metrics_uri = os.environ['METRICS_RESOURCE_URI']
323323
response = client.query(
324324
metrics_uri,
325325
metric_names=["MatchedEventCount"],
326-
aggregations=[AggregationType.COUNT]
326+
aggregations=[MetricAggregationType.COUNT]
327327
)
328328

329329
for metric in response.metrics:

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,42 @@
88
from ._metrics_query_client import MetricsQueryClient
99

1010
from ._models import (
11-
AggregationType,
11+
MetricAggregationType,
1212
LogsBatchQueryResult,
1313
LogsQueryResult,
14-
LogsQueryResultTable,
15-
LogsQueryResultColumn,
14+
LogsTable,
15+
LogsTableColumn,
1616
MetricsResult,
17-
LogsBatchResultError,
1817
LogsBatchQuery,
1918
MetricNamespace,
19+
MetricNamespaceClassification,
2020
MetricDefinition,
2121
TimeSeriesElement,
2222
Metric,
2323
MetricValue,
24+
MetricClass,
2425
MetricAvailability
2526
)
2627

2728
from ._version import VERSION
2829

2930
__all__ = [
30-
"AggregationType",
31+
"MetricAggregationType",
3132
"LogsQueryClient",
3233
"LogsBatchQueryResult",
33-
"LogsBatchResultError",
3434
"LogsQueryResult",
35-
"LogsQueryResultColumn",
36-
"LogsQueryResultTable",
35+
"LogsTableColumn",
36+
"LogsTable",
3737
"LogsBatchQuery",
3838
"MetricsQueryClient",
3939
"MetricNamespace",
40+
"MetricNamespaceClassification",
4041
"MetricDefinition",
4142
"MetricsResult",
4243
"TimeSeriesElement",
4344
"Metric",
4445
"MetricValue",
46+
"MetricClass",
4547
"MetricAvailability"
4648
]
4749

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def query(self, resource_uri, metric_names, **kwargs):
7272
or tuple[~datetime.datetime, ~datetime.datetime]
7373
:keyword granularity: The granularity (i.e. timegrain) of the query.
7474
:paramtype granularity: ~datetime.timedelta
75-
:keyword aggregations: The list of aggregation types to retrieve. Use `azure.monitor.query.AggregationType`
76-
enum to get each aggregation type.
75+
:keyword aggregations: The list of aggregation types to retrieve. Use
76+
`azure.monitor.query.MetricAggregationType` enum to get each aggregation type.
7777
:paramtype aggregations: list[str]
7878
:keyword max_results: The maximum number of records to retrieve.
7979
Valid only if $filter is specified.
@@ -134,7 +134,7 @@ def list_metric_namespaces(self, resource_uri, **kwargs):
134134
:keyword start_time: The ISO 8601 conform Date start time from which to query for metric
135135
namespaces.
136136
:paramtype start_time: str
137-
:return: An iterator like instance of either MetricNamespaceCollection or the result of cls(response)
137+
:return: An iterator like instance of either MetricNamespace or the result of cls(response)
138138
:rtype: ~azure.core.paging.ItemPaged[~azure.monitor.query.MetricNamespace]
139139
:raises: ~azure.core.exceptions.HttpResponseError
140140
"""

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

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@
1616
)
1717

1818

19-
class LogsQueryResultTable(object):
19+
class LogsTable(object):
2020
"""Contains the columns and rows for one table in a query response.
2121
2222
All required parameters must be populated in order to send to Azure.
2323
2424
:param name: Required. The name of the table.
2525
:type name: str
2626
:param columns: Required. The list of columns in this table.
27-
:type columns: list[~azure.monitor.query.LogsQueryResultColumn]
27+
:type columns: list[~azure.monitor.query.LogsTableColumn]
2828
:param rows: Required. The resulting rows from this query.
2929
:type rows: list[list[str]]
3030
"""
3131
def __init__(self, name, columns, rows):
32-
# type: (str, List[LogsQueryResultColumn], List[List[str]]) -> None
32+
# type: (str, List[LogsTableColumn], List[List[str]]) -> None
3333
self.name = name
3434
self.columns = columns
3535
self.rows = [process_row(self.columns, row) for row in rows]
@@ -38,12 +38,12 @@ def __init__(self, name, columns, rows):
3838
def _from_generated(cls, generated):
3939
return cls(
4040
name=generated.name,
41-
columns=[LogsQueryResultColumn(name=col.name, type=col.type) for col in generated.columns],
41+
columns=[LogsTableColumn(name=col.name, type=col.type) for col in generated.columns],
4242
rows=generated.rows
4343
)
4444

4545

46-
class LogsQueryResultColumn(InternalColumn):
46+
class LogsTableColumn(InternalColumn):
4747
"""A column in a table.
4848
4949
:ivar name: The name of this column.
@@ -59,7 +59,7 @@ class LogsQueryResultColumn(InternalColumn):
5959

6060
def __init__(self, **kwargs):
6161
# type: (Any) -> None
62-
super(LogsQueryResultColumn, self).__init__(**kwargs)
62+
super(LogsTableColumn, self).__init__(**kwargs)
6363
self.name = kwargs.get("name", None)
6464
self.type = kwargs.get("type", None)
6565

@@ -68,7 +68,7 @@ class LogsQueryResult(object):
6868
"""Contains the tables, columns & rows resulting from a query.
6969
7070
:ivar tables: The list of tables, columns and rows.
71-
:vartype tables: list[~azure.monitor.query.LogsQueryResultTable]
71+
:vartype tables: list[~azure.monitor.query.LogsTable]
7272
:ivar statistics: This will include a statistics property in the response that describes various
7373
performance statistics such as query execution time and resource usage.
7474
:vartype statistics: object
@@ -92,7 +92,7 @@ def _from_generated(cls, generated):
9292
tables = None
9393
if generated.tables is not None:
9494
tables = [
95-
LogsQueryResultTable._from_generated( # pylint: disable=protected-access
95+
LogsTable._from_generated( # pylint: disable=protected-access
9696
table
9797
) for table in generated.tables
9898
]
@@ -222,7 +222,7 @@ class LogsBatchQueryResult(object):
222222
:ivar status: status code of the response.
223223
:vartype status: int
224224
:ivar tables: The list of tables, columns and rows.
225-
:vartype tables: list[~azure.monitor.query.LogsQueryResultTable]
225+
:vartype tables: list[~azure.monitor.query.LogsTable]
226226
:ivar statistics: This will include a statistics property in the response that describes various
227227
performance statistics such as query execution time and resource usage.
228228
:vartype statistics: object
@@ -250,7 +250,7 @@ def _from_generated(cls, generated):
250250
tables = None
251251
if generated.body.tables is not None:
252252
tables = [
253-
LogsQueryResultTable._from_generated( # pylint: disable=protected-access
253+
LogsTable._from_generated( # pylint: disable=protected-access
254254
table
255255
) for table in generated.body.tables
256256
]
@@ -264,31 +264,13 @@ def _from_generated(cls, generated):
264264
)
265265

266266

267-
class LogsBatchResultError(object):
268-
"""Error response for a batch request.
269-
270-
:ivar message: The error message describing the cause of the error.
271-
:vartype message: str
272-
:param code: The error code.
273-
:vartype code: str
274-
:param details: The details of the error.
275-
:vartype inner_error: list[~azure.monitor.query.ErrorDetails]
267+
class MetricNamespaceClassification(str, Enum):
268+
"""Kind of namespace
276269
"""
277-
def __init__(self, **kwargs):
278-
# type: (Any) -> None
279-
self.message = kwargs.get("message", None)
280-
self.code = kwargs.get("code", None)
281-
self.details = kwargs.get("details", None)
282270

283-
@classmethod
284-
def _from_generated(cls, generated):
285-
if not generated:
286-
return cls()
287-
return cls(
288-
message=generated.inner_error.message,
289-
code=generated.code,
290-
details=generated.inner_error.details
291-
)
271+
PLATFORM = "Platform"
272+
CUSTOM = "Custom"
273+
QOS = "Qos"
292274

293275

294276
class MetricNamespace(object):
@@ -302,6 +284,8 @@ class MetricNamespace(object):
302284
:paramtype name: str
303285
:keyword fully_qualified_namespace: The fully qualified namespace name.
304286
:paramtype fully_qualified_namespace: str
287+
:keyword namespace_classification: Kind of namespace. Possible values include: "Platform", "Custom", "Qos".
288+
:paramtype namespace_classification: str or ~azure.monitor.query.MetricNamespaceClassification
305289
"""
306290
def __init__(
307291
self,
@@ -311,6 +295,7 @@ def __init__(
311295
self.type = kwargs.get('type', None)
312296
self.name = kwargs.get('name', None)
313297
self.fully_qualified_namespace = kwargs.get('fully_qualified_namespace', None)
298+
self.namespace_classification = kwargs.get('namespace_classification', None)
314299

315300
@classmethod
316301
def _from_generated(cls, generated):
@@ -323,10 +308,23 @@ def _from_generated(cls, generated):
323308
id=generated.id,
324309
type=generated.type,
325310
name=generated.name,
326-
fully_qualified_namespace=fully_qualified_namespace
311+
fully_qualified_namespace=fully_qualified_namespace,
312+
namespace_classification=generated.classification
327313
)
328314

329-
class MetricDefinition(object):
315+
316+
class MetricClass(str, Enum):
317+
"""The class of the metric.
318+
"""
319+
320+
AVAILABILITY = "Availability"
321+
TRANSACTIONS = "Transactions"
322+
ERRORS = "Errors"
323+
LATENCY = "Latency"
324+
SATURATION = "Saturation"
325+
326+
327+
class MetricDefinition(object): #pylint: disable=too-many-instance-attributes
330328
"""Metric definition class specifies the metadata for a metric.
331329
332330
:keyword dimension_required: Flag to indicate whether the dimension is required.
@@ -344,12 +342,15 @@ class MetricDefinition(object):
344342
:keyword primary_aggregation_type: the primary aggregation type value defining how to use the
345343
values for display. Possible values include: "None", "Average", "Count", "Minimum", "Maximum",
346344
"Total".
347-
:paramtype primary_aggregation_type: str or ~monitor_query_client.models.AggregationType
345+
:paramtype primary_aggregation_type: str or ~azure.monitor.query.MetricAggregationType
346+
:keyword metric_class: The class of the metric. Possible values include: "Availability",
347+
"Transactions", "Errors", "Latency", "Saturation".
348+
:paramtype metric_class: str or ~azure.monitor.query.MetricClass
348349
:keyword supported_aggregation_types: the collection of what aggregation types are supported.
349-
:paramtype supported_aggregation_types: list[str or ~monitor_query_client.models.AggregationType]
350+
:paramtype supported_aggregation_types: list[str or ~azure.monitor.query.MetricAggregationType]
350351
:keyword metric_availabilities: the collection of what aggregation intervals are available to be
351352
queried.
352-
:paramtype metric_availabilities: list[~monitor_query_client.models.MetricAvailability]
353+
:paramtype metric_availabilities: list[~azure.monitor.query.MetricAvailability]
353354
:keyword id: the resource identifier of the metric definition.
354355
:paramtype id: str
355356
:keyword dimensions: the name and the display name of the dimension, i.e. it is a localizable
@@ -371,6 +372,7 @@ def __init__(
371372
self.metric_availabilities = kwargs.get('metric_availabilities', None) # type: List[MetricAvailability]
372373
self.id = kwargs.get('id', None) # type: Optional[str]
373374
self.dimensions = kwargs.get('dimensions', None) # type: Optional[List[str]]
375+
self.metric_class = kwargs.get('metric_class', None) # type: Optional[str]
374376

375377
@classmethod
376378
def _from_generated(cls, generated):
@@ -387,6 +389,7 @@ def _from_generated(cls, generated):
387389
unit=generated.unit,
388390
primary_aggregation_type=generated.primary_aggregation_type,
389391
supported_aggregation_types=generated.supported_aggregation_types,
392+
metric_class=generated.metric_class,
390393
metric_availabilities=[
391394
MetricAvailability._from_generated( # pylint: disable=protected-access
392395
val
@@ -401,8 +404,8 @@ class MetricValue(object):
401404
402405
All required parameters must be populated in order to send to Azure.
403406
404-
:ivar time_stamp: Required. The timestamp for the metric value in ISO 8601 format.
405-
:vartype time_stamp: ~datetime.datetime
407+
:ivar timestamp: Required. The timestamp for the metric value in ISO 8601 format.
408+
:vartype timestamp: ~datetime.datetime
406409
:ivar average: The average value in the time range.
407410
:vartype average: float
408411
:ivar minimum: The least value in the time range.
@@ -420,7 +423,7 @@ def __init__(
420423
**kwargs
421424
):
422425
# type: (Any) -> None
423-
self.time_stamp = kwargs['time_stamp']
426+
self.timestamp = kwargs['timestamp']
424427
self.average = kwargs.get('average', None)
425428
self.minimum = kwargs.get('minimum', None)
426429
self.maximum = kwargs.get('maximum', None)
@@ -432,7 +435,7 @@ def _from_generated(cls, generated):
432435
if not generated:
433436
return cls()
434437
return cls(
435-
time_stamp=generated.time_stamp,
438+
timestamp=generated.time_stamp,
436439
average=generated.average,
437440
minimum=generated.minimum,
438441
maximum=generated.maximum,
@@ -552,7 +555,7 @@ def _from_generated(cls, generated):
552555
)
553556

554557

555-
class AggregationType(str, Enum):
558+
class MetricAggregationType(str, Enum):
556559
"""The aggregation type of the metric.
557560
"""
558561

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ async def query(
6767
or tuple[~datetime.datetime, ~datetime.datetime]
6868
:keyword granularity: The interval (i.e. timegrain) of the query.
6969
:paramtype granularity: ~datetime.timedelta
70-
:keyword aggregations: The list of aggregation types to retrieve. Use `azure.monitor.query.AggregationType`
71-
enum to get each aggregation type.
70+
:keyword aggregations: The list of aggregation types to retrieve.
71+
Use `azure.monitor.query.MetricAggregationType` enum to get each aggregation type.
7272
:paramtype aggregations: list[str]
7373
:keyword max_results: The maximum number of records to retrieve.
7474
Valid only if $filter is specified.
@@ -118,7 +118,7 @@ def list_metric_namespaces(self, resource_uri: str, **kwargs: Any) -> AsyncItemP
118118
:keyword start_time: The ISO 8601 conform Date start time from which to query for metric
119119
namespaces.
120120
:paramtype start_time: str
121-
:return: An iterator like instance of either MetricNamespaceCollection or the result of cls(response)
121+
:return: An iterator like instance of either MetricNamespace or the result of cls(response)
122122
:rtype: ~azure.core.paging.ItemPaged[~azure.monitor.query.MetricNamespace]
123123
:raises: ~azure.core.exceptions.HttpResponseError
124124
"""

sdk/monitor/azure-monitor-query/samples/async_samples/sample_log_query_client_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async def logs_query():
4242

4343
# if you dont want to use pandas - here's how you can process it.
4444

45-
#response.tables is a LogsQueryResultTable
45+
#response.tables is a LogsTable
4646
for table in response.tables:
4747
for col in table.columns: #LogsQueryResultColumn
4848
print(col.name + "/"+ col.type + " | ", end="")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
if not response.tables:
2323
print("No results for the query")
2424

25-
#response.tables is a LogsQueryResultTable
25+
#response.tables is a LogsTable
2626
for table in response.tables:
2727
for col in table.columns: #LogsQueryResultColumn
2828
print(col.name + "/"+ col.type + " | ", end="")

0 commit comments

Comments
 (0)