Skip to content

Commit 37cb22c

Browse files
author
Rakshith Bhyravabhotla
authored
Address API view issues (#20407)
* logs client * lc-2 * models changes * more changes * more changes * more arch changes * changelog * tests * lint * fix tests * timespan
1 parent 8920509 commit 37cb22c

17 files changed

+496
-171
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Added a `MetricClass` enum to provide the class of a metric.
99
- Added a `metric_class` attribute to the `MetricDefinition` type.
1010
- Added a `MetricNamespaceClassification` enum to support the `namespace_classification` attribute on `MetricNamespace` type.
11+
- Added a `MetricUnit` enum to describe the unit of the metric.
1112

1213
### Breaking Changes
1314

@@ -30,6 +31,10 @@
3031
- Removed `LogsBatchResultError` type.
3132
- `LogsQueryResultTable` is named to `LogsTable`
3233
- `LogsQueryResultColumn` is renamed to `LogsTableColumn`
34+
- `LogsTableColumn` is now removed. Column labels are strings instead.
35+
- `start_time` in `list_metric_namespaces` API is now a datetime.
36+
- The order of params in `LogsBatchQuery` is changed. Also, `headers` is no longer accepted.
37+
- `timespan` is now a required keyword-only argument in logs APIs.
3338

3439
### Bugs Fixed
3540

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
LogsBatchQueryResult,
1313
LogsQueryResult,
1414
LogsTable,
15-
LogsTableColumn,
1615
MetricsResult,
1716
LogsBatchQuery,
1817
MetricNamespace,
1918
MetricNamespaceClassification,
2019
MetricDefinition,
20+
MetricUnit,
2121
TimeSeriesElement,
2222
Metric,
2323
MetricValue,
@@ -32,13 +32,13 @@
3232
"LogsQueryClient",
3333
"LogsBatchQueryResult",
3434
"LogsQueryResult",
35-
"LogsTableColumn",
3635
"LogsTable",
3736
"LogsBatchQuery",
3837
"MetricsQueryClient",
3938
"MetricNamespace",
4039
"MetricNamespaceClassification",
4140
"MetricDefinition",
41+
"MetricUnit",
4242
"MetricsResult",
4343
"TimeSeriesElement",
4444
"Metric",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@ def native_col_type(col_type, value):
9090
return value
9191

9292
def process_row(col_types, row):
93-
return [native_col_type(col_types[ind].type, val) for ind, val in enumerate(row)]
93+
return [native_col_type(col_types[ind], val) for ind, val in enumerate(row)]

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

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

8-
from typing import TYPE_CHECKING, Any, Union, Sequence, Dict, Optional
8+
from typing import TYPE_CHECKING, Any, Union, Sequence, Dict, List
99
from azure.core.exceptions import HttpResponseError
1010
from azure.core.tracing.decorator import distributed_trace
1111

@@ -17,7 +17,7 @@
1717

1818
if TYPE_CHECKING:
1919
from azure.core.credentials import TokenCredential
20-
from datetime import timedelta
20+
from datetime import timedelta, datetime
2121

2222

2323
class LogsQueryClient(object):
@@ -51,8 +51,8 @@ def __init__(self, credential, **kwargs):
5151
self._query_op = self._client.query
5252

5353
@distributed_trace
54-
def query(self, workspace_id, query, timespan=None, **kwargs):
55-
# type: (str, str, Optional[timedelta], Any) -> LogsQueryResult
54+
def query(self, workspace_id, query, **kwargs):
55+
# type: (str, str, Any) -> LogsQueryResult
5656
"""Execute an Analytics query.
5757
5858
Executes an Analytics query for data.
@@ -63,9 +63,9 @@ def query(self, workspace_id, query, timespan=None, **kwargs):
6363
:param query: The Analytics query. Learn more about the `Analytics query syntax
6464
<https://azure.microsoft.com/documentation/articles/app-insights-analytics-reference/>`_.
6565
:type query: str
66-
:param timespan: The timespan for which to query the data. This can be a timedelta,
66+
:keyword timespan: The timespan for which to query the data. This can be a timedelta,
6767
a timedelta and a start datetime, or a start datetime/end datetime.
68-
:type timespan: ~datetime.timedelta or tuple[~datetime.datetime, ~datetime.timedelta]
68+
:paramtype timespan: ~datetime.timedelta or tuple[~datetime.datetime, ~datetime.timedelta]
6969
or tuple[~datetime.datetime, ~datetime.datetime]
7070
:keyword int server_timeout: the server timeout in seconds. The default timeout is 3 minutes,
7171
and the maximum timeout is 10 minutes.
@@ -76,7 +76,7 @@ def query(self, workspace_id, query, timespan=None, **kwargs):
7676
:keyword additional_workspaces: A list of workspaces that are included in the query.
7777
These can be qualified workspace names, workspace Ids, or Azure resource Ids.
7878
:paramtype additional_workspaces: list[str]
79-
:return: QueryResults, or the result of cls(response)
79+
:return: LogsQueryResult, or the result of cls(response)
8080
:rtype: ~azure.monitor.query.LogsQueryResult
8181
:raises: ~azure.core.exceptions.HttpResponseError
8282
@@ -89,7 +89,9 @@ def query(self, workspace_id, query, timespan=None, **kwargs):
8989
:dedent: 0
9090
:caption: Get a response for a single Log Query
9191
"""
92-
timespan = construct_iso8601(timespan)
92+
if 'timespan' not in kwargs:
93+
raise TypeError("query() missing 1 required keyword-only argument: 'timespan'")
94+
timespan = construct_iso8601(kwargs.pop('timespan'))
9395
include_statistics = kwargs.pop("include_statistics", False)
9496
include_visualization = kwargs.pop("include_visualization", False)
9597
server_timeout = kwargs.pop("server_timeout", None)
@@ -126,7 +128,7 @@ def query(self, workspace_id, query, timespan=None, **kwargs):
126128

127129
@distributed_trace
128130
def query_batch(self, queries, **kwargs):
129-
# type: (Union[Sequence[Dict], Sequence[LogsBatchQuery]], Any) -> Sequence[LogsBatchQueryResult]
131+
# type: (Union[Sequence[Dict], Sequence[LogsBatchQuery]], Any) -> List[LogsBatchQueryResult]
130132
"""Execute a list of analytics queries. Each request can be either a LogQueryRequest
131133
object or an equivalent serialized model.
132134
@@ -135,7 +137,7 @@ def query_batch(self, queries, **kwargs):
135137
:param queries: The list of queries that should be processed
136138
:type queries: list[dict] or list[~azure.monitor.query.LogsBatchQuery]
137139
:return: List of LogsBatchQueryResult, or the result of cls(response)
138-
:rtype: ~list[~azure.monitor.query.LogsBatchQueryResult]
140+
:rtype: list[~azure.monitor.query.LogsBatchQueryResult]
139141
:raises: ~azure.core.exceptions.HttpResponseError
140142
141143
.. admonition:: Example:

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# pylint: disable=anomalous-backslash-in-string
99

1010
from typing import TYPE_CHECKING, Any, Optional
11+
from msrest.serialization import Serializer
1112
from azure.core.tracing.decorator import distributed_trace
1213

1314
from ._generated._monitor_query_client import (
@@ -59,9 +60,6 @@ def query(self, resource_uri, metric_names, **kwargs):
5960
# type: (str, list, Optional[timedelta], Any) -> MetricsResult
6061
"""Lists the metric values for a resource.
6162
62-
**Note**: Although the start_time, end_time, duration are optional parameters, it is highly
63-
recommended to specify the timespan. If not, the entire dataset is queried.
64-
6563
:param resource_uri: The identifier of the resource.
6664
:type resource_uri: str
6765
:param metric_names: The names of the metrics to retrieve.
@@ -93,9 +91,6 @@ def query(self, resource_uri, metric_names, **kwargs):
9391
‘c1’**\ :code:`<br>`- Return all time series where A = a1:code:`<br>`\ **$filter=A eq ‘a1’ and
9492
B eq ‘\ *’ and C eq ‘*\ ’**.
9593
:paramtype filter: str
96-
:keyword result_type: Reduces the set of data collected. The syntax allowed depends on the
97-
operation. See the operation's description for details.
98-
:paramtype result_type: str or ~monitor_query_client.models.ResultType
9994
:keyword metric_namespace: Metric namespace to query metric definitions for.
10095
:paramtype metric_namespace: str
10196
:return: Response, or the result of cls(response)
@@ -131,15 +126,19 @@ def list_metric_namespaces(self, resource_uri, **kwargs):
131126
132127
:param resource_uri: The identifier of the resource.
133128
:type resource_uri: str
134-
:keyword start_time: The ISO 8601 conform Date start time from which to query for metric
135-
namespaces.
136-
:paramtype start_time: str
129+
:keyword start_time: The start time from which to query for metric
130+
namespaces. This should be provided as a datetime object.
131+
:paramtype start_time: ~datetime.datetime
137132
:return: An iterator like instance of either MetricNamespace or the result of cls(response)
138133
:rtype: ~azure.core.paging.ItemPaged[~azure.monitor.query.MetricNamespace]
139134
:raises: ~azure.core.exceptions.HttpResponseError
140135
"""
136+
start_time = kwargs.pop('start_time', None)
137+
if start_time:
138+
start_time = Serializer.serialize_iso(start_time)
141139
return self._namespace_op.list(
142140
resource_uri,
141+
start_time,
143142
cls=kwargs.pop(
144143
"cls",
145144
lambda objs: [
@@ -155,12 +154,13 @@ def list_metric_definitions(self, resource_uri, metric_namespace=None, **kwargs)
155154
156155
:param resource_uri: The identifier of the resource.
157156
:type resource_uri: str
158-
:param metric_namespace: Metric namespace to query metric definitions for.
159-
:type metric_namespace: str
157+
:keyword namespace: Metric namespace to query metric definitions for.
158+
:paramtype namespace: str
160159
:return: An iterator like instance of either MetricDefinitionCollection or the result of cls(response)
161160
:rtype: ~azure.core.paging.ItemPaged[~azure.monitor.query.MetricDefinition]
162161
:raises: ~azure.core.exceptions.HttpResponseError
163162
"""
163+
metric_namespace = kwargs.pop('namespace', None)
164164
return self._definitions_op.list(
165165
resource_uri,
166166
metric_namespace,

0 commit comments

Comments
 (0)