From d863522b360ba1ea1f7c6bf00c35bc9c556b03bb Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Mon, 26 Jul 2021 17:40:33 -0700 Subject: [PATCH 1/3] Rename logs query request --- sdk/monitor/azure-monitor-query/CHANGELOG.md | 2 ++ sdk/monitor/azure-monitor-query/README.md | 8 ++++---- .../azure/monitor/query/__init__.py | 4 ++-- .../azure/monitor/query/_log_query_client.py | 8 ++++---- .../azure/monitor/query/_models.py | 2 +- .../query/aio/_log_query_client_async.py | 8 ++++---- .../samples/sample_batch_query.py | 8 ++++---- .../tests/async/test_logs_client_async.py | 14 ++++++------- .../tests/test_logs_client.py | 20 +++++++++---------- .../tests/test_logs_timespans.py | 2 +- 10 files changed, 39 insertions(+), 37 deletions(-) diff --git a/sdk/monitor/azure-monitor-query/CHANGELOG.md b/sdk/monitor/azure-monitor-query/CHANGELOG.md index 96b6f1deb205..68cb26eb9f5f 100644 --- a/sdk/monitor/azure-monitor-query/CHANGELOG.md +++ b/sdk/monitor/azure-monitor-query/CHANGELOG.md @@ -1,5 +1,6 @@ # Release History + ## 1.0.0b3 (Unreleased) ### Features Added @@ -11,6 +12,7 @@ - `aggregation` param in the query API is renamed to `aggregations` - `batch_query` API now returns a list of responses. - `LogsBatchResults` model is now removed. +- `LogsQueryRequest` is renamed to `LogsBatchQueryRequest` ### Bugs Fixed diff --git a/sdk/monitor/azure-monitor-query/README.md b/sdk/monitor/azure-monitor-query/README.md index e7acaf4e1305..40dd99c387d7 100644 --- a/sdk/monitor/azure-monitor-query/README.md +++ b/sdk/monitor/azure-monitor-query/README.md @@ -161,7 +161,7 @@ This sample shows sending multiple queries at the same time using batch query AP import os from datetime import timedelta import pandas as pd -from azure.monitor.query import LogsQueryClient, LogsQueryRequest +from azure.monitor.query import LogsQueryClient, LogsBatchQueryRequest from azure.identity import DefaultAzureCredential @@ -170,19 +170,19 @@ credential = DefaultAzureCredential() client = LogsQueryClient(credential) requests = [ - LogsQueryRequest( + LogsBatchQueryRequest( query="AzureActivity | summarize count()", duration=timedelta(hours=1), workspace_id=os.environ['LOG_WORKSPACE_ID'] ), - LogsQueryRequest( + LogsBatchQueryRequest( query= """AppRequests | take 10 | summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""", duration=timedelta(hours=1), start_time=datetime(2021, 6, 2), workspace_id=os.environ['LOG_WORKSPACE_ID'] ), - LogsQueryRequest( + LogsBatchQueryRequest( query= "AppRequests | take 2", workspace_id=os.environ['LOG_WORKSPACE_ID'] ), 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 09c1dd8bb86d..0c2645e40759 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/__init__.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/__init__.py @@ -14,7 +14,7 @@ LogsQueryResultColumn, MetricsResult, LogsBatchResultError, - LogsQueryRequest, + LogsBatchQueryRequest, MetricNamespace, MetricDefinition, MetricsMetadataValue, @@ -33,7 +33,7 @@ "LogsQueryResults", "LogsQueryResultColumn", "LogsQueryResultTable", - "LogsQueryRequest", + "LogsBatchQueryRequest", "MetricsQueryClient", "MetricNamespace", "MetricDefinition", 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 861dcff276cf..719e9c2c147c 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, LogsQueryRequest, LogsQueryResult +from ._models import LogsQueryResults, LogsBatchQueryRequest, LogsQueryResult if TYPE_CHECKING: from azure.core.credentials import TokenCredential @@ -131,14 +131,14 @@ def query(self, workspace_id, query, duration=None, **kwargs): process_error(e) def batch_query(self, queries, **kwargs): - # type: (Union[Sequence[Dict], Sequence[LogsQueryRequest]], Any) -> Sequence[LogsQueryResult] + # type: (Union[Sequence[Dict], Sequence[LogsBatchQueryRequest]], Any) -> Sequence[LogsQueryResult] """Execute a list of analytics queries. Each request can be either a LogQueryRequest object or an equivalent serialized model. The response is returned in the same order as that of the requests sent. :param queries: The list of queries that should be processed - :type queries: list[dict] or list[~azure.monitor.query.LogsQueryRequest] + :type queries: list[dict] or list[~azure.monitor.query.LogsBatchQueryRequest] :return: BatchResponse, or the result of cls(response) :rtype: ~list[~azure.monitor.query.LogsQueryResult] :raises: ~azure.core.exceptions.HttpResponseError @@ -153,7 +153,7 @@ def batch_query(self, queries, **kwargs): :caption: Get a response for multiple Log Queries. """ try: - queries = [LogsQueryRequest(**q) for q in queries] + queries = [LogsBatchQueryRequest(**q) for q in queries] except (KeyError, TypeError): pass try: 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 dc22c7e5908b..24283ec63135 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py @@ -142,7 +142,7 @@ def _from_generated(cls, generated): metrics=[Metric._from_generated(m) for m in generated.value] # pylint: disable=protected-access ) -class LogsQueryRequest(InternalLogQueryRequest): +class LogsBatchQueryRequest(InternalLogQueryRequest): """A single request in a batch. Variables are only populated by the server, and will be ignored when sending a request. 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 bafa51be1efb..83cb0224ea46 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, LogsQueryRequest, LogsQueryResult +from .._models import LogsQueryResults, LogsBatchQueryRequest, LogsQueryResult from ._helpers_asyc import get_authentication_policy if TYPE_CHECKING: @@ -116,7 +116,7 @@ async def query( async def batch_query( self, - queries: Union[Sequence[Dict], Sequence[LogsQueryRequest]], + queries: Union[Sequence[Dict], Sequence[LogsBatchQueryRequest]], **kwargs: Any ) -> Sequence[LogsQueryResult]: """Execute a list of analytics queries. Each request can be either a LogQueryRequest @@ -125,13 +125,13 @@ async def batch_query( The response is returned in the same order as that of the requests sent. :param queries: The list of queries that should be processed - :type queries: list[dict] or list[~azure.monitor.query.LogsQueryRequest] + :type queries: list[dict] or list[~azure.monitor.query.LogsBatchQueryRequest] :return: BatchResponse, or the result of cls(response) :rtype: ~list[~azure.monitor.query.LogsQueryResult] :raises: ~azure.core.exceptions.HttpResponseError """ try: - queries = [LogsQueryRequest(**q) for q in queries] + queries = [LogsBatchQueryRequest(**q) for q in queries] except (KeyError, TypeError): pass try: diff --git a/sdk/monitor/azure-monitor-query/samples/sample_batch_query.py b/sdk/monitor/azure-monitor-query/samples/sample_batch_query.py index 3afc3a8d351c..465063ce9819 100644 --- a/sdk/monitor/azure-monitor-query/samples/sample_batch_query.py +++ b/sdk/monitor/azure-monitor-query/samples/sample_batch_query.py @@ -4,7 +4,7 @@ from datetime import datetime, timedelta import os import pandas as pd -from azure.monitor.query import LogsQueryClient, LogsQueryRequest +from azure.monitor.query import LogsQueryClient, LogsBatchQueryRequest from azure.identity import DefaultAzureCredential @@ -14,19 +14,19 @@ # [START send_batch_query] requests = [ - LogsQueryRequest( + LogsBatchQueryRequest( query="AzureActivity | summarize count()", duration=timedelta(hours=1), workspace_id= os.environ['LOG_WORKSPACE_ID'] ), - LogsQueryRequest( + LogsBatchQueryRequest( query= """AppRequests | take 10 | summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""", duration=timedelta(hours=1), start_time=datetime(2021, 6, 2), workspace_id= os.environ['LOG_WORKSPACE_ID'] ), - LogsQueryRequest( + LogsBatchQueryRequest( query= "AppRequests | take 5", workspace_id= os.environ['LOG_WORKSPACE_ID'], include_statistics=True 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 ab089a004e86..44b21442e4d5 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 @@ -2,7 +2,7 @@ import os from azure.identity.aio import ClientSecretCredential from azure.core.exceptions import HttpResponseError -from azure.monitor.query import LogsQueryRequest +from azure.monitor.query import LogsBatchQueryRequest from azure.monitor.query.aio import LogsQueryClient def _credential(): @@ -44,18 +44,18 @@ async def test_logs_batch_query(): client = LogsQueryClient(_credential()) requests = [ - LogsQueryRequest( + LogsBatchQueryRequest( query="AzureActivity | summarize count()", timespan="PT1H", workspace_id= os.environ['LOG_WORKSPACE_ID'] ), - LogsQueryRequest( + LogsBatchQueryRequest( query= """AppRequests | take 10 | summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""", timespan="PT1H", workspace_id= os.environ['LOG_WORKSPACE_ID'] ), - LogsQueryRequest( + LogsBatchQueryRequest( query= "AppRequests | take 2", workspace_id= os.environ['LOG_WORKSPACE_ID'] ), @@ -90,19 +90,19 @@ async def test_logs_batch_query_additional_workspaces(): query = "union * | where TimeGenerated > ago(100d) | project TenantId | summarize count() by TenantId" requests = [ - LogsQueryRequest( + LogsBatchQueryRequest( query, timespan="PT1H", workspace_id= os.environ['LOG_WORKSPACE_ID'], additional_workspaces=[os.environ['SECONDARY_WORKSPACE_ID']] ), - LogsQueryRequest( + LogsBatchQueryRequest( query, timespan="PT1H", workspace_id= os.environ['LOG_WORKSPACE_ID'], additional_workspaces=[os.environ['SECONDARY_WORKSPACE_ID']] ), - LogsQueryRequest( + LogsBatchQueryRequest( query, workspace_id= os.environ['LOG_WORKSPACE_ID'], additional_workspaces=[os.environ['SECONDARY_WORKSPACE_ID']] 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 8dc945f4b380..4b4c628fcbee 100644 --- a/sdk/monitor/azure-monitor-query/tests/test_logs_client.py +++ b/sdk/monitor/azure-monitor-query/tests/test_logs_client.py @@ -2,7 +2,7 @@ import os from azure.identity import ClientSecretCredential from azure.core.exceptions import HttpResponseError -from azure.monitor.query import LogsQueryClient, LogsQueryRequest +from azure.monitor.query import LogsQueryClient, LogsBatchQueryRequest def _credential(): credential = ClientSecretCredential( @@ -66,18 +66,18 @@ def test_logs_batch_query(): client = LogsQueryClient(_credential()) requests = [ - LogsQueryRequest( + LogsBatchQueryRequest( query="AzureActivity | summarize count()", timespan="PT1H", workspace_id= os.environ['LOG_WORKSPACE_ID'] ), - LogsQueryRequest( + LogsBatchQueryRequest( query= """AppRequests | take 10 | summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""", timespan="PT1H", workspace_id= os.environ['LOG_WORKSPACE_ID'] ), - LogsQueryRequest( + LogsBatchQueryRequest( query= "AppRequests | take 2", workspace_id= os.environ['LOG_WORKSPACE_ID'] ), @@ -102,19 +102,19 @@ def test_logs_batch_query_with_statistics_in_some(): client = LogsQueryClient(_credential()) requests = [ - LogsQueryRequest( + LogsBatchQueryRequest( query="AzureActivity | summarize count()", timespan="PT1H", workspace_id= os.environ['LOG_WORKSPACE_ID'] ), - LogsQueryRequest( + LogsBatchQueryRequest( query= """AppRequests| summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""", timespan="PT1H", workspace_id= os.environ['LOG_WORKSPACE_ID'], include_statistics=True ), - LogsQueryRequest( + LogsBatchQueryRequest( query= "AppRequests", workspace_id= os.environ['LOG_WORKSPACE_ID'], include_statistics=True @@ -150,19 +150,19 @@ def test_logs_batch_query_additional_workspaces(): query = "union * | where TimeGenerated > ago(100d) | project TenantId | summarize count() by TenantId" requests = [ - LogsQueryRequest( + LogsBatchQueryRequest( query, timespan="PT1H", workspace_id= os.environ['LOG_WORKSPACE_ID'], additional_workspaces=[os.environ['SECONDARY_WORKSPACE_ID']] ), - LogsQueryRequest( + LogsBatchQueryRequest( query, timespan="PT1H", workspace_id= os.environ['LOG_WORKSPACE_ID'], additional_workspaces=[os.environ['SECONDARY_WORKSPACE_ID']] ), - LogsQueryRequest( + LogsBatchQueryRequest( query, workspace_id= os.environ['LOG_WORKSPACE_ID'], additional_workspaces=[os.environ['SECONDARY_WORKSPACE_ID']] 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 5a584edd93ac..0d62b5d28ba1 100644 --- a/sdk/monitor/azure-monitor-query/tests/test_logs_timespans.py +++ b/sdk/monitor/azure-monitor-query/tests/test_logs_timespans.py @@ -6,7 +6,7 @@ from azure.identity import ClientSecretCredential from azure.core.exceptions import HttpResponseError -from azure.monitor.query import LogsQueryClient, LogsQueryRequest +from azure.monitor.query import LogsQueryClient, LogsBatchQueryRequest from azure.monitor.query._helpers import construct_iso8601 From 6d5474169b5458afd9a5ae6ae20de4eb40f0a95b Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Mon, 26 Jul 2021 17:44:23 -0700 Subject: [PATCH 2/3] rename LogsQueryResults --- sdk/monitor/azure-monitor-query/CHANGELOG.md | 3 ++- 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, 27 insertions(+), 26 deletions(-) diff --git a/sdk/monitor/azure-monitor-query/CHANGELOG.md b/sdk/monitor/azure-monitor-query/CHANGELOG.md index 68cb26eb9f5f..6a66e4c1bb39 100644 --- a/sdk/monitor/azure-monitor-query/CHANGELOG.md +++ b/sdk/monitor/azure-monitor-query/CHANGELOG.md @@ -12,7 +12,8 @@ - `aggregation` param in the query API is renamed to `aggregations` - `batch_query` API now returns a list of responses. - `LogsBatchResults` model is now removed. -- `LogsQueryRequest` is renamed to `LogsBatchQueryRequest` +- `LogsQueryRequest` is renamed to `LogsBatchQueryRequest`. +- `LogsQueryResults` is renamed to `LogsBatchQueryResults`. ### Bugs Fixed diff --git a/sdk/monitor/azure-monitor-query/README.md b/sdk/monitor/azure-monitor-query/README.md index 40dd99c387d7..4a20518399cf 100644 --- a/sdk/monitor/azure-monitor-query/README.md +++ b/sdk/monitor/azure-monitor-query/README.md @@ -124,7 +124,7 @@ client = LogsQueryClient(credential) query = """AppRequests | summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""" -# returns LogsQueryResults +# returns LogsBatchQueryResults 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 0c2645e40759..f6d9d853ba1b 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/__init__.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/__init__.py @@ -9,7 +9,7 @@ from ._models import ( AggregationType, - LogsQueryResults, + LogsBatchQueryResults, LogsQueryResultTable, LogsQueryResultColumn, MetricsResult, @@ -30,7 +30,7 @@ "AggregationType", "LogsQueryClient", "LogsBatchResultError", - "LogsQueryResults", + "LogsBatchQueryResults", "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 719e9c2c147c..a3b98ccba063 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 LogsBatchQueryResults, LogsBatchQueryRequest, LogsQueryResult 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) -> LogsBatchQueryResults """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, 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.LogsBatchQueryResults :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 LogsBatchQueryResults._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 24283ec63135..1a653cb591ec 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 LogsBatchQueryResults(object): """Contains the tables, columns & rows resulting from a query. :keyword tables: The list of tables, columns and rows. @@ -214,7 +214,7 @@ class LogsQueryResult(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.LogsBatchQueryResults """ 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=LogsBatchQueryResults._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 83cb0224ea46..b99766ef1fd8 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 LogsBatchQueryResults, LogsBatchQueryRequest, LogsQueryResult 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) -> LogsBatchQueryResults: """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.LogsBatchQueryResults :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 LogsBatchQueryResults._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..13056a657dbd 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 LogsBatchQueryResults 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..594db17eecd7 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 LogsBatchQueryResults 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..dffb8d853d37 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 LogsBatchQueryResults 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..3587282de9e2 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 LogsBatchQueryResults 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..2f1e0e7523d4 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 LogsBatchQueryResults 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..376798edeca1 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 LogsBatchQueryResults 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 LogsBatchQueryResults 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..b7549dcca961 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 LogsBatchQueryResults 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 LogsBatchQueryResults 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 LogsBatchQueryResults 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..82d0943c10ce 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 LogsBatchQueryResults client.query(os.environ['LOG_WORKSPACE_ID'], query) @pytest.mark.live_test_only From 476ff109ea728e348b856d3b7b0e3ffefce30abe Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Mon, 26 Jul 2021 17:45:58 -0700 Subject: [PATCH 3/3] Revert "rename LogsQueryResults" This reverts commit 6d5474169b5458afd9a5ae6ae20de4eb40f0a95b. --- sdk/monitor/azure-monitor-query/CHANGELOG.md | 3 +-- 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(+), 27 deletions(-) diff --git a/sdk/monitor/azure-monitor-query/CHANGELOG.md b/sdk/monitor/azure-monitor-query/CHANGELOG.md index 6a66e4c1bb39..68cb26eb9f5f 100644 --- a/sdk/monitor/azure-monitor-query/CHANGELOG.md +++ b/sdk/monitor/azure-monitor-query/CHANGELOG.md @@ -12,8 +12,7 @@ - `aggregation` param in the query API is renamed to `aggregations` - `batch_query` API now returns a list of responses. - `LogsBatchResults` model is now removed. -- `LogsQueryRequest` is renamed to `LogsBatchQueryRequest`. -- `LogsQueryResults` is renamed to `LogsBatchQueryResults`. +- `LogsQueryRequest` is renamed to `LogsBatchQueryRequest` ### Bugs Fixed diff --git a/sdk/monitor/azure-monitor-query/README.md b/sdk/monitor/azure-monitor-query/README.md index 4a20518399cf..40dd99c387d7 100644 --- a/sdk/monitor/azure-monitor-query/README.md +++ b/sdk/monitor/azure-monitor-query/README.md @@ -124,7 +124,7 @@ client = LogsQueryClient(credential) query = """AppRequests | summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""" -# returns LogsBatchQueryResults +# returns LogsQueryResults 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 f6d9d853ba1b..0c2645e40759 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/__init__.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/__init__.py @@ -9,7 +9,7 @@ from ._models import ( AggregationType, - LogsBatchQueryResults, + LogsQueryResults, LogsQueryResultTable, LogsQueryResultColumn, MetricsResult, @@ -30,7 +30,7 @@ "AggregationType", "LogsQueryClient", "LogsBatchResultError", - "LogsBatchQueryResults", + "LogsQueryResults", "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 a3b98ccba063..719e9c2c147c 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 LogsBatchQueryResults, LogsBatchQueryRequest, LogsQueryResult +from ._models import LogsQueryResults, LogsBatchQueryRequest, LogsQueryResult 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) -> LogsBatchQueryResults + # type: (str, str, Optional[timedelta], Any) -> LogsQueryResults """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, workspsce Ids or Azure resource Ids. :paramtype additional_workspaces: list[str] :return: QueryResults, or the result of cls(response) - :rtype: ~azure.monitor.query.LogsBatchQueryResults + :rtype: ~azure.monitor.query.LogsQueryResults :raises: ~azure.core.exceptions.HttpResponseError .. admonition:: Example: @@ -121,7 +121,7 @@ def query(self, workspace_id, query, duration=None, **kwargs): ) try: - return LogsBatchQueryResults._from_generated(self._query_op.execute( # pylint: disable=protected-access + return LogsQueryResults._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 1a653cb591ec..24283ec63135 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 LogsBatchQueryResults(object): +class LogsQueryResults(object): """Contains the tables, columns & rows resulting from a query. :keyword tables: The list of tables, columns and rows. @@ -214,7 +214,7 @@ class LogsQueryResult(object): :param status: :type status: int :param body: Contains the tables, columns & rows resulting from a query. - :type body: ~azure.monitor.query.LogsBatchQueryResults + :type body: ~azure.monitor.query.LogsQueryResults """ def __init__( self, @@ -231,7 +231,7 @@ def _from_generated(cls, generated): return cls( id=generated.id, status=generated.status, - body=LogsBatchQueryResults._from_generated(generated.body) # pylint: disable=protected-access + body=LogsQueryResults._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 b99766ef1fd8..83cb0224ea46 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 LogsBatchQueryResults, LogsBatchQueryRequest, LogsQueryResult +from .._models import LogsQueryResults, LogsBatchQueryRequest, LogsQueryResult 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) -> LogsBatchQueryResults: + **kwargs: Any) -> LogsQueryResults: """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.LogsBatchQueryResults + :rtype: ~azure.monitor.query.LogsQueryResults :raises: ~azure.core.exceptions.HttpResponseError """ start = kwargs.pop('start_time', None) @@ -105,7 +105,7 @@ async def query( ) try: - return LogsBatchQueryResults._from_generated(await self._query_op.execute( # pylint: disable=protected-access + return LogsQueryResults._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 13056a657dbd..30514de86a56 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 LogsBatchQueryResults + # returns LogsQueryResults 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 594db17eecd7..040d96323f57 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 LogsBatchQueryResults +# returns LogsQueryResults 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 dffb8d853d37..191a16f68b76 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 LogsBatchQueryResults +# returns LogsQueryResults 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 3587282de9e2..f4c90e079523 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 LogsBatchQueryResults +# returns LogsQueryResults 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 2f1e0e7523d4..bff5aa4b12ce 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 LogsBatchQueryResults +# returns LogsQueryResults 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 376798edeca1..44b21442e4d5 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 LogsBatchQueryResults + # returns LogsQueryResults 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 LogsBatchQueryResults + # returns LogsQueryResults 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 b7549dcca961..4b4c628fcbee 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 LogsBatchQueryResults + # returns LogsQueryResults 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 LogsBatchQueryResults + # returns LogsQueryResults 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 LogsBatchQueryResults + # returns LogsQueryResults 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 82d0943c10ce..0d62b5d28ba1 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 LogsBatchQueryResults + # returns LogsQueryResults client.query(os.environ['LOG_WORKSPACE_ID'], query) @pytest.mark.live_test_only