From d6d63e86ecab89c4c9ee1e287e8c2613657ae1d3 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Fri, 30 Jul 2021 13:13:56 -0700 Subject: [PATCH 1/2] Add Logs Batch query results --- sdk/monitor/azure-monitor-query/CHANGELOG.md | 1 + .../azure-monitor-query/azure/monitor/query/__init__.py | 2 ++ .../azure/monitor/query/_log_query_client.py | 8 ++++---- .../azure-monitor-query/azure/monitor/query/_models.py | 4 ++-- .../azure/monitor/query/aio/_log_query_client_async.py | 8 ++++---- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/sdk/monitor/azure-monitor-query/CHANGELOG.md b/sdk/monitor/azure-monitor-query/CHANGELOG.md index 79ecf6bb3414..aff5aee5071e 100644 --- a/sdk/monitor/azure-monitor-query/CHANGELOG.md +++ b/sdk/monitor/azure-monitor-query/CHANGELOG.md @@ -6,6 +6,7 @@ ### Features Added - Added enum `AggregationType` which can be used to specify aggregations in the query API. +- Added `LogsBatchQueryResult` model that is returned for a logs batch query. ### Breaking Changes diff --git a/sdk/monitor/azure-monitor-query/azure/monitor/query/__init__.py b/sdk/monitor/azure-monitor-query/azure/monitor/query/__init__.py index 0c2645e40759..46ec6a594bef 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/__init__.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/__init__.py @@ -9,6 +9,7 @@ from ._models import ( AggregationType, + LogsBatchQueryResult, LogsQueryResults, LogsQueryResultTable, LogsQueryResultColumn, @@ -29,6 +30,7 @@ __all__ = [ "AggregationType", "LogsQueryClient", + "LogsBatchQueryResult", "LogsBatchResultError", "LogsQueryResults", "LogsQueryResultColumn", diff --git a/sdk/monitor/azure-monitor-query/azure/monitor/query/_log_query_client.py b/sdk/monitor/azure-monitor-query/azure/monitor/query/_log_query_client.py index f9149e81e3c9..9ddb793288ce 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/_log_query_client.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/_log_query_client.py @@ -12,7 +12,7 @@ from ._generated.models import BatchRequest, QueryBody as LogsQueryBody from ._helpers import get_authentication_policy, process_error, construct_iso8601, order_results -from ._models import LogsQueryResults, LogsBatchQueryRequest, LogsQueryResult +from ._models import LogsQueryResults, LogsBatchQueryRequest, LogsBatchQueryResult if TYPE_CHECKING: from azure.core.credentials import TokenCredential @@ -131,7 +131,7 @@ def query(self, workspace_id, query, duration=None, **kwargs): process_error(e) def batch_query(self, queries, **kwargs): - # type: (Union[Sequence[Dict], Sequence[LogsBatchQueryRequest]], Any) -> Sequence[LogsQueryResult] + # type: (Union[Sequence[Dict], Sequence[LogsBatchQueryRequest]], Any) -> Sequence[LogsBatchQueryResult] """Execute a list of analytics queries. Each request can be either a LogQueryRequest object or an equivalent serialized model. @@ -140,7 +140,7 @@ def batch_query(self, queries, **kwargs): :param queries: The list of queries that should be processed :type queries: list[dict] or list[~azure.monitor.query.LogsBatchQueryRequest] :return: BatchResponse, or the result of cls(response) - :rtype: ~list[~azure.monitor.query.LogsQueryResult] + :rtype: ~list[~azure.monitor.query.LogsBatchQueryResult] :raises: ~azure.core.exceptions.HttpResponseError .. admonition:: Example: @@ -165,7 +165,7 @@ def batch_query(self, queries, **kwargs): return order_results( request_order, [ - LogsQueryResult._from_generated(rsp) for rsp in generated.responses # pylint: disable=protected-access + LogsBatchQueryResult._from_generated(rsp) for rsp in generated.responses # pylint: disable=protected-access ]) def close(self): diff --git a/sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py b/sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py index a559fcd29ce3..5f1849c8993c 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py @@ -206,8 +206,8 @@ def __init__(self, query, workspace_id, duration=None, **kwargs): #pylint: disab self.headers = headers self.workspace = workspace_id -class LogsQueryResult(object): - """The LogsQueryResult. +class LogsBatchQueryResult(object): + """The LogsBatchQueryResult. :param id: :type id: str diff --git a/sdk/monitor/azure-monitor-query/azure/monitor/query/aio/_log_query_client_async.py b/sdk/monitor/azure-monitor-query/azure/monitor/query/aio/_log_query_client_async.py index 83cb0224ea46..c2a585984678 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/aio/_log_query_client_async.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/aio/_log_query_client_async.py @@ -12,7 +12,7 @@ from .._generated.models import BatchRequest, QueryBody as LogsQueryBody from .._helpers import process_error, construct_iso8601, order_results -from .._models import LogsQueryResults, LogsBatchQueryRequest, LogsQueryResult +from .._models import LogsQueryResults, LogsBatchQueryRequest, LogsBatchQueryResult from ._helpers_asyc import get_authentication_policy if TYPE_CHECKING: @@ -118,7 +118,7 @@ async def batch_query( self, queries: Union[Sequence[Dict], Sequence[LogsBatchQueryRequest]], **kwargs: Any - ) -> Sequence[LogsQueryResult]: + ) -> Sequence[LogsBatchQueryResult]: """Execute a list of analytics queries. Each request can be either a LogQueryRequest object or an equivalent serialized model. @@ -127,7 +127,7 @@ async def batch_query( :param queries: The list of queries that should be processed :type queries: list[dict] or list[~azure.monitor.query.LogsBatchQueryRequest] :return: BatchResponse, or the result of cls(response) - :rtype: ~list[~azure.monitor.query.LogsQueryResult] + :rtype: ~list[~azure.monitor.query.LogsBatchQueryResult] :raises: ~azure.core.exceptions.HttpResponseError """ try: @@ -143,7 +143,7 @@ async def batch_query( return order_results( request_order, [ - LogsQueryResult._from_generated(rsp) for rsp in generated.responses # pylint: disable=protected-access + LogsBatchQueryResult._from_generated(rsp) for rsp in generated.responses # pylint: disable=protected-access ]) async def __aenter__(self) -> "LogsQueryClient": From db2209e5936b511ef8ded64ac10d6ffd4bf111e8 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Fri, 30 Jul 2021 13:25:10 -0700 Subject: [PATCH 2/2] logs query results to result --- sdk/monitor/azure-monitor-query/CHANGELOG.md | 1 + sdk/monitor/azure-monitor-query/README.md | 2 +- .../azure-monitor-query/azure/monitor/query/__init__.py | 4 ++-- .../azure/monitor/query/_log_query_client.py | 8 ++++---- .../azure-monitor-query/azure/monitor/query/_models.py | 6 +++--- .../azure/monitor/query/aio/_log_query_client_async.py | 8 ++++---- .../async_samples/sample_log_query_client_async.py | 2 +- .../samples/sample_log_query_client.py | 2 +- .../samples/sample_log_query_client_without_pandas.py | 2 +- .../samples/sample_log_query_multiple_workspaces.py | 2 +- .../samples/sample_logs_query_key_value_form.py | 2 +- .../tests/async/test_logs_client_async.py | 4 ++-- sdk/monitor/azure-monitor-query/tests/test_logs_client.py | 6 +++--- .../azure-monitor-query/tests/test_logs_timespans.py | 2 +- 14 files changed, 26 insertions(+), 25 deletions(-) diff --git a/sdk/monitor/azure-monitor-query/CHANGELOG.md b/sdk/monitor/azure-monitor-query/CHANGELOG.md index aff5aee5071e..bb72a5d73ad0 100644 --- a/sdk/monitor/azure-monitor-query/CHANGELOG.md +++ b/sdk/monitor/azure-monitor-query/CHANGELOG.md @@ -14,6 +14,7 @@ - `batch_query` API now returns a list of responses. - `LogsBatchResults` model is now removed. - `LogsQueryRequest` is renamed to `LogsBatchQueryRequest` +- `LogsQueryResults` is now renamed to `LogsQueryResult` ### Bugs Fixed diff --git a/sdk/monitor/azure-monitor-query/README.md b/sdk/monitor/azure-monitor-query/README.md index 330e3416aaa1..a6e04bc7b829 100644 --- a/sdk/monitor/azure-monitor-query/README.md +++ b/sdk/monitor/azure-monitor-query/README.md @@ -131,7 +131,7 @@ client = LogsQueryClient(credential) query = """AppRequests | summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""" -# returns LogsQueryResults +# returns LogsQueryResult response = client.query( os.environ['LOG_WORKSPACE_ID'], query, diff --git a/sdk/monitor/azure-monitor-query/azure/monitor/query/__init__.py b/sdk/monitor/azure-monitor-query/azure/monitor/query/__init__.py index 46ec6a594bef..2eb2c828061b 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/__init__.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/__init__.py @@ -10,7 +10,7 @@ from ._models import ( AggregationType, LogsBatchQueryResult, - LogsQueryResults, + LogsQueryResult, LogsQueryResultTable, LogsQueryResultColumn, MetricsResult, @@ -32,7 +32,7 @@ "LogsQueryClient", "LogsBatchQueryResult", "LogsBatchResultError", - "LogsQueryResults", + "LogsQueryResult", "LogsQueryResultColumn", "LogsQueryResultTable", "LogsBatchQueryRequest", diff --git a/sdk/monitor/azure-monitor-query/azure/monitor/query/_log_query_client.py b/sdk/monitor/azure-monitor-query/azure/monitor/query/_log_query_client.py index 9ddb793288ce..0cad4adeecea 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/_log_query_client.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/_log_query_client.py @@ -12,7 +12,7 @@ from ._generated.models import BatchRequest, QueryBody as LogsQueryBody from ._helpers import get_authentication_policy, process_error, construct_iso8601, order_results -from ._models import LogsQueryResults, LogsBatchQueryRequest, LogsBatchQueryResult +from ._models import LogsQueryResult, LogsBatchQueryRequest, LogsBatchQueryResult if TYPE_CHECKING: from azure.core.credentials import TokenCredential @@ -50,7 +50,7 @@ def __init__(self, credential, **kwargs): self._query_op = self._client.query def query(self, workspace_id, query, duration=None, **kwargs): - # type: (str, str, Optional[timedelta], Any) -> LogsQueryResults + # type: (str, str, Optional[timedelta], Any) -> LogsQueryResult """Execute an Analytics query. Executes an Analytics query for data. @@ -81,7 +81,7 @@ def query(self, workspace_id, query, duration=None, **kwargs): 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) - :rtype: ~azure.monitor.query.LogsQueryResults + :rtype: ~azure.monitor.query.LogsQueryResult :raises: ~azure.core.exceptions.HttpResponseError .. admonition:: Example: @@ -121,7 +121,7 @@ def query(self, workspace_id, query, duration=None, **kwargs): ) try: - return LogsQueryResults._from_generated(self._query_op.execute( # pylint: disable=protected-access + return LogsQueryResult._from_generated(self._query_op.execute( # pylint: disable=protected-access workspace_id=workspace_id, body=body, prefer=prefer, diff --git a/sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py b/sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py index 5f1849c8993c..b635ebd7f5e2 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py @@ -64,7 +64,7 @@ def __init__(self, **kwargs): self.type = kwargs.get("type", None) -class LogsQueryResults(object): +class LogsQueryResult(object): """Contains the tables, columns & rows resulting from a query. :keyword tables: The list of tables, columns and rows. @@ -214,7 +214,7 @@ class LogsBatchQueryResult(object): :param status: :type status: int :param body: Contains the tables, columns & rows resulting from a query. - :type body: ~azure.monitor.query.LogsQueryResults + :type body: ~azure.monitor.query.LogsQueryResult """ def __init__( self, @@ -231,7 +231,7 @@ def _from_generated(cls, generated): return cls( id=generated.id, status=generated.status, - body=LogsQueryResults._from_generated(generated.body) # pylint: disable=protected-access + body=LogsQueryResult._from_generated(generated.body) # pylint: disable=protected-access ) diff --git a/sdk/monitor/azure-monitor-query/azure/monitor/query/aio/_log_query_client_async.py b/sdk/monitor/azure-monitor-query/azure/monitor/query/aio/_log_query_client_async.py index c2a585984678..66e7fe6b3fe0 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/aio/_log_query_client_async.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/aio/_log_query_client_async.py @@ -12,7 +12,7 @@ from .._generated.models import BatchRequest, QueryBody as LogsQueryBody from .._helpers import process_error, construct_iso8601, order_results -from .._models import LogsQueryResults, LogsBatchQueryRequest, LogsBatchQueryResult +from .._models import LogsQueryResult, LogsBatchQueryRequest, LogsBatchQueryResult from ._helpers_asyc import get_authentication_policy if TYPE_CHECKING: @@ -43,7 +43,7 @@ async def query( workspace_id: str, query: str, duration: Optional[timedelta] = None, - **kwargs: Any) -> LogsQueryResults: + **kwargs: Any) -> LogsQueryResult: """Execute an Analytics query. Executes an Analytics query for data. @@ -74,7 +74,7 @@ async def query( These can be qualified workspace names, workspsce Ids or Azure resource Ids. :paramtype additional_workspaces: list[str] :return: QueryResults, or the result of cls(response) - :rtype: ~azure.monitor.query.LogsQueryResults + :rtype: ~azure.monitor.query.LogsQueryResult :raises: ~azure.core.exceptions.HttpResponseError """ start = kwargs.pop('start_time', None) @@ -105,7 +105,7 @@ async def query( ) try: - return LogsQueryResults._from_generated(await self._query_op.execute( # pylint: disable=protected-access + return LogsQueryResult._from_generated(await self._query_op.execute( # pylint: disable=protected-access workspace_id=workspace_id, body=body, prefer=prefer, diff --git a/sdk/monitor/azure-monitor-query/samples/async_samples/sample_log_query_client_async.py b/sdk/monitor/azure-monitor-query/samples/async_samples/sample_log_query_client_async.py index 30514de86a56..51d16b614467 100644 --- a/sdk/monitor/azure-monitor-query/samples/async_samples/sample_log_query_client_async.py +++ b/sdk/monitor/azure-monitor-query/samples/async_samples/sample_log_query_client_async.py @@ -22,7 +22,7 @@ async def logs_query(): where TimeGenerated > ago(12h) | summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""" - # returns LogsQueryResults + # returns LogsQueryResult async with client: response = await client.query(os.environ['LOG_WORKSPACE_ID'], query) diff --git a/sdk/monitor/azure-monitor-query/samples/sample_log_query_client.py b/sdk/monitor/azure-monitor-query/samples/sample_log_query_client.py index 040d96323f57..dc2cf6ea361e 100644 --- a/sdk/monitor/azure-monitor-query/samples/sample_log_query_client.py +++ b/sdk/monitor/azure-monitor-query/samples/sample_log_query_client.py @@ -22,7 +22,7 @@ end_time = datetime.now(UTC()) -# returns LogsQueryResults +# returns LogsQueryResult response = client.query(os.environ['LOG_WORKSPACE_ID'], query, duration=timedelta(days=1), end_time=end_time) if not response.tables: diff --git a/sdk/monitor/azure-monitor-query/samples/sample_log_query_client_without_pandas.py b/sdk/monitor/azure-monitor-query/samples/sample_log_query_client_without_pandas.py index 191a16f68b76..89a55899e5d6 100644 --- a/sdk/monitor/azure-monitor-query/samples/sample_log_query_client_without_pandas.py +++ b/sdk/monitor/azure-monitor-query/samples/sample_log_query_client_without_pandas.py @@ -18,7 +18,7 @@ end_time = datetime.now(UTC()) -# returns LogsQueryResults +# returns LogsQueryResult response = client.query(os.environ['LOG_WORKSPACE_ID'], query, duration=timedelta(hours=1), end_time=end_time) if not response.tables: diff --git a/sdk/monitor/azure-monitor-query/samples/sample_log_query_multiple_workspaces.py b/sdk/monitor/azure-monitor-query/samples/sample_log_query_multiple_workspaces.py index f4c90e079523..28bae17ecea2 100644 --- a/sdk/monitor/azure-monitor-query/samples/sample_log_query_multiple_workspaces.py +++ b/sdk/monitor/azure-monitor-query/samples/sample_log_query_multiple_workspaces.py @@ -18,7 +18,7 @@ end_time = datetime.now(UTC()) -# returns LogsQueryResults +# returns LogsQueryResult response = client.query( os.environ['LOG_WORKSPACE_ID'], query, diff --git a/sdk/monitor/azure-monitor-query/samples/sample_logs_query_key_value_form.py b/sdk/monitor/azure-monitor-query/samples/sample_logs_query_key_value_form.py index bff5aa4b12ce..2989f5e453bd 100644 --- a/sdk/monitor/azure-monitor-query/samples/sample_logs_query_key_value_form.py +++ b/sdk/monitor/azure-monitor-query/samples/sample_logs_query_key_value_form.py @@ -18,7 +18,7 @@ end_time = datetime.now(UTC()) -# returns LogsQueryResults +# returns LogsQueryResult response = client.query(os.environ['LOG_WORKSPACE_ID'], query, duration=timedelta(days=1), end_time=end_time) if not response.tables: diff --git a/sdk/monitor/azure-monitor-query/tests/async/test_logs_client_async.py b/sdk/monitor/azure-monitor-query/tests/async/test_logs_client_async.py index 44b21442e4d5..ab55eb0bb444 100644 --- a/sdk/monitor/azure-monitor-query/tests/async/test_logs_client_async.py +++ b/sdk/monitor/azure-monitor-query/tests/async/test_logs_client_async.py @@ -21,7 +21,7 @@ async def test_logs_auth(): where TimeGenerated > ago(12h) | summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""" - # returns LogsQueryResults + # returns LogsQueryResult response = await client.query(os.environ['LOG_WORKSPACE_ID'], query) assert response is not None @@ -72,7 +72,7 @@ async def test_logs_single_query_additional_workspaces_async(): client = LogsQueryClient(credential) query = "union * | where TimeGenerated > ago(100d) | project TenantId | summarize count() by TenantId" - # returns LogsQueryResults + # returns LogsQueryResult response = await client.query( os.environ['LOG_WORKSPACE_ID'], query, diff --git a/sdk/monitor/azure-monitor-query/tests/test_logs_client.py b/sdk/monitor/azure-monitor-query/tests/test_logs_client.py index 4b4c628fcbee..e2686c8c6ddd 100644 --- a/sdk/monitor/azure-monitor-query/tests/test_logs_client.py +++ b/sdk/monitor/azure-monitor-query/tests/test_logs_client.py @@ -20,7 +20,7 @@ def test_logs_single_query(): where TimeGenerated > ago(12h) | summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""" - # returns LogsQueryResults + # returns LogsQueryResult response = client.query(os.environ['LOG_WORKSPACE_ID'], query) assert response is not None @@ -92,7 +92,7 @@ def test_logs_single_query_with_statistics(): client = LogsQueryClient(credential) query = """AppRequests""" - # returns LogsQueryResults + # returns LogsQueryResult response = client.query(os.environ['LOG_WORKSPACE_ID'], query, include_statistics=True) assert response.statistics is not None @@ -133,7 +133,7 @@ def test_logs_single_query_additional_workspaces(): client = LogsQueryClient(credential) query = "union * | where TimeGenerated > ago(100d) | project TenantId | summarize count() by TenantId" - # returns LogsQueryResults + # returns LogsQueryResult response = client.query( os.environ['LOG_WORKSPACE_ID'], query, diff --git a/sdk/monitor/azure-monitor-query/tests/test_logs_timespans.py b/sdk/monitor/azure-monitor-query/tests/test_logs_timespans.py index 0d62b5d28ba1..0f561d5f07f9 100644 --- a/sdk/monitor/azure-monitor-query/tests/test_logs_timespans.py +++ b/sdk/monitor/azure-monitor-query/tests/test_logs_timespans.py @@ -29,7 +29,7 @@ def test_query_no_duration(): def callback(request): dic = json.loads(request.http_request.body) assert dic.get('timespan') is None - # returns LogsQueryResults + # returns LogsQueryResult client.query(os.environ['LOG_WORKSPACE_ID'], query) @pytest.mark.live_test_only