Skip to content

Commit

Permalink
Address API view issues (#20407)
Browse files Browse the repository at this point in the history
* logs client

* lc-2

* models changes

* more changes

* more changes

* more arch changes

* changelog

* tests

* lint

* fix tests

* timespan
  • Loading branch information
Rakshith Bhyravabhotla authored Aug 25, 2021
1 parent 8920509 commit 37cb22c
Show file tree
Hide file tree
Showing 17 changed files with 496 additions and 171 deletions.
5 changes: 5 additions & 0 deletions sdk/monitor/azure-monitor-query/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Added a `MetricClass` enum to provide the class of a metric.
- Added a `metric_class` attribute to the `MetricDefinition` type.
- Added a `MetricNamespaceClassification` enum to support the `namespace_classification` attribute on `MetricNamespace` type.
- Added a `MetricUnit` enum to describe the unit of the metric.

### Breaking Changes

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

### Bugs Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
LogsBatchQueryResult,
LogsQueryResult,
LogsTable,
LogsTableColumn,
MetricsResult,
LogsBatchQuery,
MetricNamespace,
MetricNamespaceClassification,
MetricDefinition,
MetricUnit,
TimeSeriesElement,
Metric,
MetricValue,
Expand All @@ -32,13 +32,13 @@
"LogsQueryClient",
"LogsBatchQueryResult",
"LogsQueryResult",
"LogsTableColumn",
"LogsTable",
"LogsBatchQuery",
"MetricsQueryClient",
"MetricNamespace",
"MetricNamespaceClassification",
"MetricDefinition",
"MetricUnit",
"MetricsResult",
"TimeSeriesElement",
"Metric",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ def native_col_type(col_type, value):
return value

def process_row(col_types, row):
return [native_col_type(col_types[ind].type, val) for ind, val in enumerate(row)]
return [native_col_type(col_types[ind], val) for ind, val in enumerate(row)]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# license information.
# --------------------------------------------------------------------------

from typing import TYPE_CHECKING, Any, Union, Sequence, Dict, Optional
from typing import TYPE_CHECKING, Any, Union, Sequence, Dict, List
from azure.core.exceptions import HttpResponseError
from azure.core.tracing.decorator import distributed_trace

Expand All @@ -17,7 +17,7 @@

if TYPE_CHECKING:
from azure.core.credentials import TokenCredential
from datetime import timedelta
from datetime import timedelta, datetime


class LogsQueryClient(object):
Expand Down Expand Up @@ -51,8 +51,8 @@ def __init__(self, credential, **kwargs):
self._query_op = self._client.query

@distributed_trace
def query(self, workspace_id, query, timespan=None, **kwargs):
# type: (str, str, Optional[timedelta], Any) -> LogsQueryResult
def query(self, workspace_id, query, **kwargs):
# type: (str, str, Any) -> LogsQueryResult
"""Execute an Analytics query.
Executes an Analytics query for data.
Expand All @@ -63,9 +63,9 @@ def query(self, workspace_id, query, timespan=None, **kwargs):
:param query: The Analytics query. Learn more about the `Analytics query syntax
<https://azure.microsoft.com/documentation/articles/app-insights-analytics-reference/>`_.
:type query: str
:param timespan: The timespan for which to query the data. This can be a timedelta,
:keyword timespan: The timespan for which to query the data. This can be a timedelta,
a timedelta and a start datetime, or a start datetime/end datetime.
:type timespan: ~datetime.timedelta or tuple[~datetime.datetime, ~datetime.timedelta]
:paramtype timespan: ~datetime.timedelta or tuple[~datetime.datetime, ~datetime.timedelta]
or tuple[~datetime.datetime, ~datetime.datetime]
:keyword int server_timeout: the server timeout in seconds. The default timeout is 3 minutes,
and the maximum timeout is 10 minutes.
Expand All @@ -76,7 +76,7 @@ def query(self, workspace_id, query, timespan=None, **kwargs):
:keyword additional_workspaces: A list of workspaces that are included in the query.
These can be qualified workspace names, workspace Ids, or Azure resource Ids.
:paramtype additional_workspaces: list[str]
:return: QueryResults, or the result of cls(response)
:return: LogsQueryResult, or the result of cls(response)
:rtype: ~azure.monitor.query.LogsQueryResult
:raises: ~azure.core.exceptions.HttpResponseError
Expand All @@ -89,7 +89,9 @@ def query(self, workspace_id, query, timespan=None, **kwargs):
:dedent: 0
:caption: Get a response for a single Log Query
"""
timespan = construct_iso8601(timespan)
if 'timespan' not in kwargs:
raise TypeError("query() missing 1 required keyword-only argument: 'timespan'")
timespan = construct_iso8601(kwargs.pop('timespan'))
include_statistics = kwargs.pop("include_statistics", False)
include_visualization = kwargs.pop("include_visualization", False)
server_timeout = kwargs.pop("server_timeout", None)
Expand Down Expand Up @@ -126,7 +128,7 @@ def query(self, workspace_id, query, timespan=None, **kwargs):

@distributed_trace
def query_batch(self, queries, **kwargs):
# type: (Union[Sequence[Dict], Sequence[LogsBatchQuery]], Any) -> Sequence[LogsBatchQueryResult]
# type: (Union[Sequence[Dict], Sequence[LogsBatchQuery]], Any) -> List[LogsBatchQueryResult]
"""Execute a list of analytics queries. Each request can be either a LogQueryRequest
object or an equivalent serialized model.
Expand All @@ -135,7 +137,7 @@ def query_batch(self, queries, **kwargs):
:param queries: The list of queries that should be processed
:type queries: list[dict] or list[~azure.monitor.query.LogsBatchQuery]
:return: List of LogsBatchQueryResult, or the result of cls(response)
:rtype: ~list[~azure.monitor.query.LogsBatchQueryResult]
:rtype: list[~azure.monitor.query.LogsBatchQueryResult]
:raises: ~azure.core.exceptions.HttpResponseError
.. admonition:: Example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# pylint: disable=anomalous-backslash-in-string

from typing import TYPE_CHECKING, Any, Optional
from msrest.serialization import Serializer
from azure.core.tracing.decorator import distributed_trace

from ._generated._monitor_query_client import (
Expand Down Expand Up @@ -59,9 +60,6 @@ def query(self, resource_uri, metric_names, **kwargs):
# type: (str, list, Optional[timedelta], Any) -> MetricsResult
"""Lists the metric values for a resource.
**Note**: Although the start_time, end_time, duration are optional parameters, it is highly
recommended to specify the timespan. If not, the entire dataset is queried.
:param resource_uri: The identifier of the resource.
:type resource_uri: str
:param metric_names: The names of the metrics to retrieve.
Expand Down Expand Up @@ -93,9 +91,6 @@ def query(self, resource_uri, metric_names, **kwargs):
‘c1’**\ :code:`<br>`- Return all time series where A = a1:code:`<br>`\ **$filter=A eq ‘a1’ and
B eq ‘\ *’ and C eq ‘*\ ’**.
:paramtype filter: str
:keyword result_type: Reduces the set of data collected. The syntax allowed depends on the
operation. See the operation's description for details.
:paramtype result_type: str or ~monitor_query_client.models.ResultType
:keyword metric_namespace: Metric namespace to query metric definitions for.
:paramtype metric_namespace: str
:return: Response, or the result of cls(response)
Expand Down Expand Up @@ -131,15 +126,19 @@ def list_metric_namespaces(self, resource_uri, **kwargs):
:param resource_uri: The identifier of the resource.
:type resource_uri: str
:keyword start_time: The ISO 8601 conform Date start time from which to query for metric
namespaces.
:paramtype start_time: str
:keyword start_time: The start time from which to query for metric
namespaces. This should be provided as a datetime object.
:paramtype start_time: ~datetime.datetime
:return: An iterator like instance of either MetricNamespace or the result of cls(response)
:rtype: ~azure.core.paging.ItemPaged[~azure.monitor.query.MetricNamespace]
:raises: ~azure.core.exceptions.HttpResponseError
"""
start_time = kwargs.pop('start_time', None)
if start_time:
start_time = Serializer.serialize_iso(start_time)
return self._namespace_op.list(
resource_uri,
start_time,
cls=kwargs.pop(
"cls",
lambda objs: [
Expand All @@ -155,12 +154,13 @@ def list_metric_definitions(self, resource_uri, metric_namespace=None, **kwargs)
:param resource_uri: The identifier of the resource.
:type resource_uri: str
:param metric_namespace: Metric namespace to query metric definitions for.
:type metric_namespace: str
:keyword namespace: Metric namespace to query metric definitions for.
:paramtype namespace: str
:return: An iterator like instance of either MetricDefinitionCollection or the result of cls(response)
:rtype: ~azure.core.paging.ItemPaged[~azure.monitor.query.MetricDefinition]
:raises: ~azure.core.exceptions.HttpResponseError
"""
metric_namespace = kwargs.pop('namespace', None)
return self._definitions_op.list(
resource_uri,
metric_namespace,
Expand Down
Loading

0 comments on commit 37cb22c

Please sign in to comment.