From f74421ce9cfbc19b5a97145d4ff883ecfdc19ff4 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Mon, 9 Aug 2021 17:04:42 -0700 Subject: [PATCH 1/2] Rename Visualization attribute --- sdk/monitor/azure-monitor-query/CHANGELOG.md | 4 +++ sdk/monitor/azure-monitor-query/README.md | 2 +- .../azure/monitor/query/_logs_query_client.py | 10 +++---- .../azure/monitor/query/_models.py | 26 +++++++++---------- .../query/aio/_logs_query_client_async.py | 10 +++---- .../tests/async/test_logs_client_async.py | 25 ++++++++++++++++++ .../tests/test_logs_client.py | 23 ++++++++++++++++ 7 files changed, 76 insertions(+), 24 deletions(-) diff --git a/sdk/monitor/azure-monitor-query/CHANGELOG.md b/sdk/monitor/azure-monitor-query/CHANGELOG.md index 9a18197b3a0d..90c1edbeb985 100644 --- a/sdk/monitor/azure-monitor-query/CHANGELOG.md +++ b/sdk/monitor/azure-monitor-query/CHANGELOG.md @@ -8,9 +8,13 @@ - Rename `batch_query` to `query_batch`. - Rename `LogsBatchQueryRequest` to `LogsBatchQuery`. +- `include_render` is now renamed to `include_visualization` in the query API. +- `LogsQueryResult` and `LogsBatchQueryResult` now return `visualization` instead of `render`. ### Bugs Fixed +- `include_statistics` and `include_visualization` args can now work together. + ### Other Changes ## 1.0.0b3 (2021-08-09) diff --git a/sdk/monitor/azure-monitor-query/README.md b/sdk/monitor/azure-monitor-query/README.md index 74c40110734d..6ba734f6bd96 100644 --- a/sdk/monitor/azure-monitor-query/README.md +++ b/sdk/monitor/azure-monitor-query/README.md @@ -223,7 +223,7 @@ LogsQueryResult / LogsBatchQueryResult |---id (this exists in `LogsBatchQueryResult` object only) |---status (this exists in `LogsBatchQueryResult` object only) |---statistics -|---render +|---visualization |---error |---tables (list of `LogsQueryResultTable` objects) |---name 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 05b5d83a8d3e..7f037c18e5e9 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 @@ -74,7 +74,7 @@ def query(self, workspace_id, query, duration=None, **kwargs): :keyword int server_timeout: the server timeout in seconds. The default timeout is 3 minutes, and the maximum timeout is 10 minutes. :keyword bool include_statistics: To get information about query statistics. - :keyword bool include_render: In the query language, it is possible to specify different render options. + :keyword bool include_visualization: In the query language, it is possible to specify different visualization options. By default, the API does not return information regarding the type of visualization to show. If your client requires this information, specify the preference :keyword additional_workspaces: A list of workspaces that are included in the query. @@ -97,7 +97,7 @@ def query(self, workspace_id, query, duration=None, **kwargs): end = kwargs.pop('end_time', None) timespan = construct_iso8601(start, end, duration) include_statistics = kwargs.pop("include_statistics", False) - include_render = kwargs.pop("include_render", False) + include_visualization = kwargs.pop("include_visualization", False) server_timeout = kwargs.pop("server_timeout", None) workspaces = kwargs.pop("additional_workspaces", None) @@ -106,11 +106,11 @@ def query(self, workspace_id, query, duration=None, **kwargs): prefer += "wait=" + str(server_timeout) if include_statistics: if len(prefer) > 0: - prefer += " " + prefer += "," prefer += "include-statistics=true" - if include_render: + if include_visualization: if len(prefer) > 0: - prefer += " " + prefer += "," prefer += "include-render=true" body = LogsQueryBody( 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 4c17370450fb..9a680f8bf61a 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py @@ -72,9 +72,9 @@ class LogsQueryResult(object): :ivar statistics: This will include a statistics property in the response that describes various performance statistics such as query execution time and resource usage. :vartype statistics: object - :ivar render: This will include a render property in the response that specifies the type of + :ivar visualization: This will include a visualization property in the response that specifies the type of visualization selected by the query and any properties for that visualization. - :vartype render: object + :vartype visualization: object :ivar error: Any error info. :vartype error: object """ @@ -82,7 +82,7 @@ def __init__(self, **kwargs): # type: (Any) -> None self.tables = kwargs.get("tables", None) self.statistics = kwargs.get("statistics", None) - self.render = kwargs.get("render", None) + self.visualization = kwargs.get("visualization", None) self.error = kwargs.get("error", None) @classmethod @@ -99,7 +99,7 @@ def _from_generated(cls, generated): return cls( tables=tables, statistics=generated.statistics, - render=generated.render, + visualization=generated.render, error=generated.error ) @@ -173,7 +173,7 @@ class LogsBatchQuery(object): :keyword int server_timeout: the server timeout. The default timeout is 3 minutes, and the maximum timeout is 10 minutes. :keyword bool include_statistics: To get information about query statistics. - :keyword bool include_render: In the query language, it is possible to specify different render options. + :keyword bool include_visualization: In the query language, it is possible to specify different visualization options. By default, the API does not return information regarding the type of visualization to show. :keyword headers: Dictionary of :code:``. :paramtype headers: dict[str, str] @@ -182,18 +182,18 @@ class LogsBatchQuery(object): def __init__(self, query, workspace_id, duration=None, **kwargs): #pylint: disable=super-init-not-called # type: (str, str, Optional[str], Any) -> None include_statistics = kwargs.pop("include_statistics", False) - include_render = kwargs.pop("include_render", False) + include_visualization = kwargs.pop("include_visualization", False) server_timeout = kwargs.pop("server_timeout", None) prefer = "" if server_timeout: prefer += "wait=" + str(server_timeout) if include_statistics: if len(prefer) > 0: - prefer += " " + prefer += "," prefer += "include-statistics=true" - if include_render: + if include_visualization: if len(prefer) > 0: - prefer += " " + prefer += "," prefer += "include-render=true" headers = kwargs.get("headers", None) @@ -232,9 +232,9 @@ class LogsBatchQueryResult(object): :ivar statistics: This will include a statistics property in the response that describes various performance statistics such as query execution time and resource usage. :vartype statistics: object - :ivar render: This will include a render property in the response that specifies the type of + :ivar visualization: This will include a visualization property in the response that specifies the type of visualization selected by the query and any properties for that visualization. - :vartype render: object + :vartype visualization: object :ivar error: Any error info. :vartype error: object """ @@ -247,7 +247,7 @@ def __init__( self.tables = kwargs.get('tables', None) self.error = kwargs.get('error', None) self.statistics = kwargs.get('statistics', None) - self.render = kwargs.get('render', None) + self.visualization = kwargs.get('visualization', None) @classmethod def _from_generated(cls, generated): @@ -265,7 +265,7 @@ def _from_generated(cls, generated): status=generated.status, tables=tables, statistics=generated.body.statistics, - render=generated.body.render, + visualization=generated.body.render, error=generated.body.error ) 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 2557ef11d44e..e9171a7105fa 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 @@ -67,7 +67,7 @@ async def query( :keyword int server_timeout: the server timeout. The default timeout is 3 minutes, and the maximum timeout is 10 minutes. :keyword bool include_statistics: To get information about query statistics. - :keyword bool include_render: In the query language, it is possible to specify different render options. + :keyword bool include_visualization: In the query language, it is possible to specify different visualization options. By default, the API does not return information regarding the type of visualization to show. If your client requires this information, specify the preference :keyword additional_workspaces: A list of workspaces that are included in the query. @@ -81,7 +81,7 @@ async def query( end = kwargs.pop('end_time', None) timespan = construct_iso8601(start, end, duration) include_statistics = kwargs.pop("include_statistics", False) - include_render = kwargs.pop("include_render", False) + include_visualization = kwargs.pop("include_visualization", False) server_timeout = kwargs.pop("server_timeout", None) additional_workspaces = kwargs.pop("additional_workspaces", None) @@ -90,11 +90,11 @@ async def query( prefer += "wait=" + str(server_timeout) if include_statistics: if len(prefer) > 0: - prefer += ";" + prefer += "," prefer += "include-statistics=true" - if include_render: + if include_visualization: if len(prefer) > 0: - prefer += ";" + prefer += "," prefer += "include-render=true" body = LogsQueryBody( 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 ec67406b13d2..4568d2caf48c 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 @@ -114,3 +114,28 @@ async def test_logs_query_batch_additional_workspaces(): for resp in response: assert len(resp.tables[0].rows) == 2 + +@pytest.mark.live_test_only +@pytest.mark.asyncio +async def test_logs_single_query_with_render(): + credential = _credential() + client = LogsQueryClient(credential) + query = """AppRequests""" + + # returns LogsQueryResult + response = await client.query(os.environ['LOG_WORKSPACE_ID'], query, include_visualization=True) + + assert response.visualization is not None + +@pytest.mark.live_test_only +@pytest.mark.asyncio +async def test_logs_single_query_with_render_and_stats(): + credential = _credential() + client = LogsQueryClient(credential) + query = """AppRequests""" + + # returns LogsQueryResult + response = await client.query(os.environ['LOG_WORKSPACE_ID'], query, include_visualization=True, include_statistics=True) + + assert response.visualization is not None + assert response.statistics is not None 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 08c605fff41b..2f46e16b74d8 100644 --- a/sdk/monitor/azure-monitor-query/tests/test_logs_client.py +++ b/sdk/monitor/azure-monitor-query/tests/test_logs_client.py @@ -97,6 +97,29 @@ def test_logs_single_query_with_statistics(): assert response.statistics is not None +@pytest.mark.live_test_only +def test_logs_single_query_with_render(): + credential = _credential() + client = LogsQueryClient(credential) + query = """AppRequests""" + + # returns LogsQueryResult + response = client.query(os.environ['LOG_WORKSPACE_ID'], query, include_visualization=True) + + assert response.visualization is not None + +@pytest.mark.live_test_only +def test_logs_single_query_with_render_and_stats(): + credential = _credential() + client = LogsQueryClient(credential) + query = """AppRequests""" + + # returns LogsQueryResult + response = client.query(os.environ['LOG_WORKSPACE_ID'], query, include_visualization=True, include_statistics=True) + + assert response.visualization is not None + assert response.statistics is not None + @pytest.mark.live_test_only def test_logs_query_batch_with_statistics_in_some(): client = LogsQueryClient(_credential()) From 3677328455d061644d1d464f33e3076e7f6ccfe0 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Tue, 10 Aug 2021 09:43:54 -0700 Subject: [PATCH 2/2] lint --- .../azure/monitor/query/_logs_query_client.py | 6 +++--- .../azure-monitor-query/azure/monitor/query/_models.py | 5 +++-- .../azure/monitor/query/aio/_logs_query_client_async.py | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) 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 7f037c18e5e9..f23157cfca03 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 @@ -74,9 +74,9 @@ def query(self, workspace_id, query, duration=None, **kwargs): :keyword int server_timeout: the server timeout in seconds. The default timeout is 3 minutes, and the maximum timeout is 10 minutes. :keyword bool include_statistics: To get information about query statistics. - :keyword bool include_visualization: In the query language, it is possible to specify different visualization options. - By default, the API does not return information regarding the type of visualization to show. - If your client requires this information, specify the preference + :keyword bool include_visualization: In the query language, it is possible to specify different + visualization options. By default, the API does not return information regarding the type of + visualization to show. If your client requires this information, specify the preference :keyword additional_workspaces: A list of workspaces that are included in the query. These can be qualified workspace names, workspace Ids, or Azure resource Ids. :paramtype additional_workspaces: list[str] 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 9a680f8bf61a..6f3372a2f53d 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py @@ -173,8 +173,9 @@ class LogsBatchQuery(object): :keyword int server_timeout: the server timeout. The default timeout is 3 minutes, and the maximum timeout is 10 minutes. :keyword bool include_statistics: To get information about query statistics. - :keyword bool include_visualization: In the query language, it is possible to specify different visualization options. - By default, the API does not return information regarding the type of visualization to show. + :keyword bool include_visualization: In the query language, it is possible to specify different + visualization options. By default, the API does not return information regarding the type of + visualization to show. :keyword headers: Dictionary of :code:``. :paramtype headers: dict[str, str] """ 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 e9171a7105fa..e68cf4f3983b 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 @@ -67,9 +67,9 @@ async def query( :keyword int server_timeout: the server timeout. The default timeout is 3 minutes, and the maximum timeout is 10 minutes. :keyword bool include_statistics: To get information about query statistics. - :keyword bool include_visualization: In the query language, it is possible to specify different visualization options. - By default, the API does not return information regarding the type of visualization to show. - If your client requires this information, specify the preference + :keyword bool include_visualization: In the query language, it is possible to specify different + visualization options. By default, the API does not return information regarding the type of + visualization to show. If your client requires this information, specify the preference :keyword additional_workspaces: A list of workspaces that are included in the query. These can be qualified workspace names, workspsce Ids or Azure resource Ids. :paramtype additional_workspaces: list[str]