From a8b75033d67865739919084bd0277eccd59bce57 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Mon, 9 Aug 2021 14:28:44 -0700 Subject: [PATCH 1/2] Rename LogsBatchQueryRequest to LogsBatchQuery --- sdk/monitor/azure-monitor-query/README.md | 4 ++-- .../azure/monitor/query/_logs_query_client.py | 2 +- .../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 +- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/sdk/monitor/azure-monitor-query/README.md b/sdk/monitor/azure-monitor-query/README.md index 25bacc3dc438..87516f5c1b88 100644 --- a/sdk/monitor/azure-monitor-query/README.md +++ b/sdk/monitor/azure-monitor-query/README.md @@ -183,12 +183,12 @@ credential = DefaultAzureCredential() client = LogsQueryClient(credential) requests = [ - LogsBatchQueryRequest( + LogsBatchQuery( query="AzureActivity | summarize count()", duration=timedelta(hours=1), workspace_id=os.environ['LOG_WORKSPACE_ID'] ), - LogsBatchQueryRequest( + LogsBatchQuery( query= """AppRequests | take 10 | summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""", duration=timedelta(hours=1), diff --git a/sdk/monitor/azure-monitor-query/azure/monitor/query/_logs_query_client.py b/sdk/monitor/azure-monitor-query/azure/monitor/query/_logs_query_client.py index 3c5b6fa9ada4..4cff572909b4 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/_logs_query_client.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/_logs_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 LogsQueryResult, LogsBatchQueryRequest, LogsBatchQueryResult +from ._models import LogsQueryResult, LogsBatchQuery, LogsBatchQueryResult if TYPE_CHECKING: from azure.core.credentials import TokenCredential 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 82a176aca43a..ca22df7b6dc2 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, LogsBatchQueryRequest +from azure.monitor.query import LogsQueryClient, LogsBatchQuery from azure.identity import DefaultAzureCredential @@ -14,19 +14,19 @@ # [START send_batch_query] requests = [ - LogsBatchQueryRequest( + LogsBatchQuery( query="AzureActivity | summarize count()", duration=timedelta(hours=1), workspace_id= os.environ['LOG_WORKSPACE_ID'] ), - LogsBatchQueryRequest( + LogsBatchQuery( 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'] ), - LogsBatchQueryRequest( + LogsBatchQuery( query= "AppRequestss | 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 1050949bc33c..1fce1a9dc48c 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 LogsBatchQueryRequest +from azure.monitor.query import LogsBatchQuery from azure.monitor.query.aio import LogsQueryClient def _credential(): @@ -44,18 +44,18 @@ async def test_logs_batch_query(): client = LogsQueryClient(_credential()) requests = [ - LogsBatchQueryRequest( + LogsBatchQuery( query="AzureActivity | summarize count()", timespan="PT1H", workspace_id= os.environ['LOG_WORKSPACE_ID'] ), - LogsBatchQueryRequest( + LogsBatchQuery( query= """AppRequests | take 10 | summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""", timespan="PT1H", workspace_id= os.environ['LOG_WORKSPACE_ID'] ), - LogsBatchQueryRequest( + LogsBatchQuery( 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 = [ - LogsBatchQueryRequest( + LogsBatchQuery( query, timespan="PT1H", workspace_id= os.environ['LOG_WORKSPACE_ID'], additional_workspaces=[os.environ['SECONDARY_WORKSPACE_ID']] ), - LogsBatchQueryRequest( + LogsBatchQuery( query, timespan="PT1H", workspace_id= os.environ['LOG_WORKSPACE_ID'], additional_workspaces=[os.environ['SECONDARY_WORKSPACE_ID']] ), - LogsBatchQueryRequest( + LogsBatchQuery( 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 245a6758b57e..a6751fc8794d 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, LogsBatchQueryRequest +from azure.monitor.query import LogsQueryClient, LogsBatchQuery def _credential(): credential = ClientSecretCredential( @@ -66,18 +66,18 @@ def test_logs_batch_query(): client = LogsQueryClient(_credential()) requests = [ - LogsBatchQueryRequest( + LogsBatchQuery( query="AzureActivity | summarize count()", timespan="PT1H", workspace_id= os.environ['LOG_WORKSPACE_ID'] ), - LogsBatchQueryRequest( + LogsBatchQuery( query= """AppRequests | take 10 | summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""", timespan="PT1H", workspace_id= os.environ['LOG_WORKSPACE_ID'] ), - LogsBatchQueryRequest( + LogsBatchQuery( 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 = [ - LogsBatchQueryRequest( + LogsBatchQuery( query="AzureActivity | summarize count()", timespan="PT1H", workspace_id= os.environ['LOG_WORKSPACE_ID'] ), - LogsBatchQueryRequest( + LogsBatchQuery( query= """AppRequests| summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""", timespan="PT1H", workspace_id= os.environ['LOG_WORKSPACE_ID'], include_statistics=True ), - LogsBatchQueryRequest( + LogsBatchQuery( 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 = [ - LogsBatchQueryRequest( + LogsBatchQuery( query, timespan="PT1H", workspace_id= os.environ['LOG_WORKSPACE_ID'], additional_workspaces=[os.environ['SECONDARY_WORKSPACE_ID']] ), - LogsBatchQueryRequest( + LogsBatchQuery( query, timespan="PT1H", workspace_id= os.environ['LOG_WORKSPACE_ID'], additional_workspaces=[os.environ['SECONDARY_WORKSPACE_ID']] ), - LogsBatchQueryRequest( + LogsBatchQuery( 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 0f561d5f07f9..5045ebe78125 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, LogsBatchQueryRequest +from azure.monitor.query import LogsQueryClient, LogsBatchQuery from azure.monitor.query._helpers import construct_iso8601 From 3c08e0f3c730979c63c6f2f9617e89556c4c079f Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Mon, 9 Aug 2021 15:16:08 -0700 Subject: [PATCH 2/2] rename batch query to query batch --- sdk/monitor/azure-monitor-query/CHANGELOG.md | 3 +++ sdk/monitor/azure-monitor-query/README.md | 2 +- .../azure/monitor/query/__init__.py | 4 ++-- .../azure/monitor/query/_logs_query_client.py | 12 ++++++------ .../azure/monitor/query/_models.py | 2 +- .../monitor/query/aio/_logs_query_client_async.py | 10 +++++----- .../samples/sample_batch_query.py | 6 +++--- .../samples/sample_batch_query_serialized.py | 2 +- .../tests/async/test_logs_client_async.py | 8 ++++---- .../tests/perfstress_tests/batch_query.py | 4 ++-- .../azure-monitor-query/tests/test_logs_client.py | 12 ++++++------ 11 files changed, 34 insertions(+), 31 deletions(-) diff --git a/sdk/monitor/azure-monitor-query/CHANGELOG.md b/sdk/monitor/azure-monitor-query/CHANGELOG.md index 1b58d121087f..9a18197b3a0d 100644 --- a/sdk/monitor/azure-monitor-query/CHANGELOG.md +++ b/sdk/monitor/azure-monitor-query/CHANGELOG.md @@ -6,6 +6,9 @@ ### Breaking Changes +- Rename `batch_query` to `query_batch`. +- Rename `LogsBatchQueryRequest` to `LogsBatchQuery`. + ### Bugs Fixed ### Other Changes diff --git a/sdk/monitor/azure-monitor-query/README.md b/sdk/monitor/azure-monitor-query/README.md index 87516f5c1b88..74c40110734d 100644 --- a/sdk/monitor/azure-monitor-query/README.md +++ b/sdk/monitor/azure-monitor-query/README.md @@ -200,7 +200,7 @@ requests = [ workspace_id=os.environ['LOG_WORKSPACE_ID'] ), ] -response = client.batch_query(requests) +response = client.query_batch(requests) for rsp in response: body = rsp.body 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 a0d12433709a..e3ceb3cbd419 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/__init__.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/__init__.py @@ -15,7 +15,7 @@ LogsQueryResultColumn, MetricsResult, LogsBatchResultError, - LogsBatchQueryRequest, + LogsBatchQuery, MetricNamespace, MetricDefinition, MetricsMetadataValue, @@ -35,7 +35,7 @@ "LogsQueryResult", "LogsQueryResultColumn", "LogsQueryResultTable", - "LogsBatchQueryRequest", + "LogsBatchQuery", "MetricsQueryClient", "MetricNamespace", "MetricDefinition", diff --git a/sdk/monitor/azure-monitor-query/azure/monitor/query/_logs_query_client.py b/sdk/monitor/azure-monitor-query/azure/monitor/query/_logs_query_client.py index 4cff572909b4..05b5d83a8d3e 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/_logs_query_client.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/_logs_query_client.py @@ -130,15 +130,15 @@ def query(self, workspace_id, query, duration=None, **kwargs): except HttpResponseError as e: process_error(e) - def batch_query(self, queries, **kwargs): - # type: (Union[Sequence[Dict], Sequence[LogsBatchQueryRequest]], Any) -> Sequence[LogsBatchQueryResult] + def query_batch(self, queries, **kwargs): + # type: (Union[Sequence[Dict], Sequence[LogsBatchQuery]], Any) -> Sequence[LogsBatchQueryResult] """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.LogsBatchQueryRequest] + :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] :raises: ~azure.core.exceptions.HttpResponseError @@ -146,14 +146,14 @@ def batch_query(self, queries, **kwargs): .. admonition:: Example: .. literalinclude:: ../samples/sample_batch_query.py - :start-after: [START send_batch_query] - :end-before: [END send_batch_query] + :start-after: [START send_query_batch] + :end-before: [END send_query_batch] :language: python :dedent: 0 :caption: Get a response for multiple Log Queries. """ try: - queries = [LogsBatchQueryRequest(**q) for q in queries] + queries = [LogsBatchQuery(**q) for q in queries] except (KeyError, TypeError): pass queries = [q._to_generated() for q in queries] # pylint: disable=protected-access 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 1f6553aa3bb7..4c17370450fb 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py @@ -148,7 +148,7 @@ def _from_generated(cls, generated): metrics=[Metric._from_generated(m) for m in generated.value] # pylint: disable=protected-access ) -class LogsBatchQueryRequest(object): +class LogsBatchQuery(object): """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/_logs_query_client_async.py b/sdk/monitor/azure-monitor-query/azure/monitor/query/aio/_logs_query_client_async.py index 7f1185ec1977..2557ef11d44e 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/aio/_logs_query_client_async.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/aio/_logs_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 LogsQueryResult, LogsBatchQueryRequest, LogsBatchQueryResult +from .._models import LogsQueryResult, LogsBatchQuery, LogsBatchQueryResult from ._helpers_asyc import get_authentication_policy if TYPE_CHECKING: @@ -114,9 +114,9 @@ async def query( except HttpResponseError as e: process_error(e) - async def batch_query( + async def query_batch( self, - queries: Union[Sequence[Dict], Sequence[LogsBatchQueryRequest]], + queries: Union[Sequence[Dict], Sequence[LogsBatchQuery]], **kwargs: Any ) -> Sequence[LogsBatchQueryResult]: """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.LogsBatchQueryRequest] + :type queries: list[dict] or list[~azure.monitor.query.LogsBatchQuery] :return: BatchResponse, or the result of cls(response) :rtype: ~list[~azure.monitor.query.LogsBatchQueryResult] :raises: ~azure.core.exceptions.HttpResponseError """ try: - queries = [LogsBatchQueryRequest(**q) for q in queries] + queries = [LogsBatchQuery(**q) for q in queries] except (KeyError, TypeError): pass queries = [q._to_generated() for q in queries] # pylint: disable=protected-access 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 ca22df7b6dc2..c7e1ec025b93 100644 --- a/sdk/monitor/azure-monitor-query/samples/sample_batch_query.py +++ b/sdk/monitor/azure-monitor-query/samples/sample_batch_query.py @@ -12,7 +12,7 @@ client = LogsQueryClient(credential) -# [START send_batch_query] +# [START send_query_batch] requests = [ LogsBatchQuery( query="AzureActivity | summarize count()", @@ -32,7 +32,7 @@ include_statistics=True ), ] -responses = client.batch_query(requests) +responses = client.query_batch(requests) for response in responses: try: @@ -42,4 +42,4 @@ except TypeError: print(response.error) -# [END send_batch_query] \ No newline at end of file +# [END send_query_batch] \ No newline at end of file diff --git a/sdk/monitor/azure-monitor-query/samples/sample_batch_query_serialized.py b/sdk/monitor/azure-monitor-query/samples/sample_batch_query_serialized.py index 91d8a50473d4..6c06b03d34b3 100644 --- a/sdk/monitor/azure-monitor-query/samples/sample_batch_query_serialized.py +++ b/sdk/monitor/azure-monitor-query/samples/sample_batch_query_serialized.py @@ -39,7 +39,7 @@ "workspace": os.environ['LOG_WORKSPACE_ID'] } ] -responses = client.batch_query(requests) +responses = client.query_batch(requests) for response in responses: try: 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 1fce1a9dc48c..ec67406b13d2 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 @@ -40,7 +40,7 @@ async def test_logs_server_timeout(): assert e.message.contains('Gateway timeout') @pytest.mark.live_test_only -async def test_logs_batch_query(): +async def test_logs_query_batch(): client = LogsQueryClient(_credential()) requests = [ @@ -60,7 +60,7 @@ async def test_logs_batch_query(): workspace_id= os.environ['LOG_WORKSPACE_ID'] ), ] - response = await client.batch_query(requests) + response = await client.query_batch(requests) assert len(response) == 3 @@ -85,7 +85,7 @@ async def test_logs_single_query_additional_workspaces_async(): @pytest.mark.skip('https://github.com/Azure/azure-sdk-for-python/issues/19382') @pytest.mark.live_test_only @pytest.mark.asyncio -async def test_logs_batch_query_additional_workspaces(): +async def test_logs_query_batch_additional_workspaces(): client = LogsQueryClient(_credential()) query = "union * | where TimeGenerated > ago(100d) | project TenantId | summarize count() by TenantId" @@ -108,7 +108,7 @@ async def test_logs_batch_query_additional_workspaces(): additional_workspaces=[os.environ['SECONDARY_WORKSPACE_ID']] ), ] - response = await client.batch_query(requests) + response = await client.query_batch(requests) assert len(response) == 3 diff --git a/sdk/monitor/azure-monitor-query/tests/perfstress_tests/batch_query.py b/sdk/monitor/azure-monitor-query/tests/perfstress_tests/batch_query.py index caa250dfdc6b..a59420e5ab81 100644 --- a/sdk/monitor/azure-monitor-query/tests/perfstress_tests/batch_query.py +++ b/sdk/monitor/azure-monitor-query/tests/perfstress_tests/batch_query.py @@ -65,7 +65,7 @@ def run_sync(self): Avoid putting any ancilliary logic (e.g. generating UUIDs), and put this in the setup/init instead so that we're only measuring the client API call. """ - self.logs_client.batch_query( + self.logs_client.query_batch( self.requests ) @@ -76,6 +76,6 @@ async def run_async(self): Avoid putting any ancilliary logic (e.g. generating UUIDs), and put this in the setup/init instead so that we're only measuring the client API call. """ - await self.async_logs_client.batch_query( + await self.async_logs_client.query_batch( self.requests ) 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 a6751fc8794d..08c605fff41b 100644 --- a/sdk/monitor/azure-monitor-query/tests/test_logs_client.py +++ b/sdk/monitor/azure-monitor-query/tests/test_logs_client.py @@ -62,7 +62,7 @@ def test_logs_server_timeout(): assert 'Gateway timeout' in e.value.message @pytest.mark.live_test_only -def test_logs_batch_query(): +def test_logs_query_batch(): client = LogsQueryClient(_credential()) requests = [ @@ -82,7 +82,7 @@ def test_logs_batch_query(): workspace_id= os.environ['LOG_WORKSPACE_ID'] ), ] - response = client.batch_query(requests) + response = client.query_batch(requests) assert len(response) == 3 @@ -98,7 +98,7 @@ def test_logs_single_query_with_statistics(): assert response.statistics is not None @pytest.mark.live_test_only -def test_logs_batch_query_with_statistics_in_some(): +def test_logs_query_batch_with_statistics_in_some(): client = LogsQueryClient(_credential()) requests = [ @@ -120,7 +120,7 @@ def test_logs_batch_query_with_statistics_in_some(): include_statistics=True ), ] - response = client.batch_query(requests) + response = client.query_batch(requests) assert len(response) == 3 assert response[0].statistics is None @@ -145,7 +145,7 @@ def test_logs_single_query_additional_workspaces(): @pytest.mark.live_test_only @pytest.mark.skip('https://github.com/Azure/azure-sdk-for-python/issues/19382') -def test_logs_batch_query_additional_workspaces(): +def test_logs_query_batch_additional_workspaces(): client = LogsQueryClient(_credential()) query = "union * | where TimeGenerated > ago(100d) | project TenantId | summarize count() by TenantId" @@ -168,7 +168,7 @@ def test_logs_batch_query_additional_workspaces(): additional_workspaces=[os.environ['SECONDARY_WORKSPACE_ID']] ), ] - response = client.batch_query(requests) + response = client.query_batch(requests) for resp in response: assert len(resp.tables[0].rows) == 2