Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sdk/monitor/azure-monitor-query/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion sdk/monitor/azure-monitor-query/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_render: In the query language, it is possible to specify different render 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]
Expand All @@ -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)

Expand All @@ -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(
Expand Down
29 changes: 15 additions & 14 deletions sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ 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
"""
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
Expand All @@ -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
)

Expand Down Expand Up @@ -173,27 +173,28 @@ 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.
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:`<string>`.
:paramtype headers: dict[str, str]
"""

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)
Expand Down Expand Up @@ -232,9 +233,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
"""
Expand All @@ -247,7 +248,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):
Expand All @@ -265,7 +266,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
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_render: In the query language, it is possible to specify different render 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]
Expand All @@ -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)

Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 23 additions & 0 deletions sdk/monitor/azure-monitor-query/tests/test_logs_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down