diff --git a/sdk/monitor/azure-monitor-query/CHANGELOG.md b/sdk/monitor/azure-monitor-query/CHANGELOG.md index a131d7117939..79ecf6bb3414 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 d34c6b37881c..330e3416aaa1 100644 --- a/sdk/monitor/azure-monitor-query/README.md +++ b/sdk/monitor/azure-monitor-query/README.md @@ -194,19 +194,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 f0a0617e6cd0..f9149e81e3c9 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 e8d926dd268b..a559fcd29ce3 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