-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove responses and return a list #19872
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b5bda09
Remove responses and return a list
rakshith91 e778f4e
lint
rakshith91 660343f
Sample to fetch response in key-value form
rakshith91 1bf36a6
fix test
rakshith91 340205d
Update sdk/monitor/azure-monitor-query/tests/test_logs_client.py
084fdac
Update sdk/monitor/azure-monitor-query/tests/test_logs_client.py
53b207f
flay
rakshith91 3b05c10
skip https://github.com/Azure/azure-sdk-for-python/issues/19917
rakshith91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,8 @@ | |
from ._generated._monitor_query_client import MonitorQueryClient | ||
|
||
from ._generated.models import BatchRequest, QueryBody as LogsQueryBody | ||
from ._helpers import get_authentication_policy, process_error, construct_iso8601 | ||
from ._models import LogsQueryResults, LogsQueryRequest, LogsBatchResults | ||
from ._helpers import get_authentication_policy, process_error, construct_iso8601, order_results | ||
from ._models import LogsQueryResults, LogsQueryRequest, LogsQueryResult | ||
|
||
if TYPE_CHECKING: | ||
from azure.core.credentials import TokenCredential | ||
|
@@ -131,7 +131,7 @@ 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) -> LogsBatchResults | ||
# type: (Union[Sequence[Dict], Sequence[LogsQueryRequest]], Any) -> Sequence[LogsQueryResult] | ||
"""Execute a list of analytics queries. Each request can be either a LogQueryRequest | ||
object or an equivalent serialized model. | ||
|
||
|
@@ -140,7 +140,7 @@ def batch_query(self, queries, **kwargs): | |
:param queries: The list of queries that should be processed | ||
:type queries: list[dict] or list[~azure.monitor.query.LogsQueryRequest] | ||
:return: BatchResponse, or the result of cls(response) | ||
:rtype: ~azure.monitor.query.LogsBatchResults | ||
:rtype: ~list[~azure.monitor.query.LogsQueryResult] | ||
:raises: ~azure.core.exceptions.HttpResponseError | ||
|
||
.. admonition:: Example: | ||
|
@@ -162,9 +162,11 @@ def batch_query(self, queries, **kwargs): | |
request_order = [req['id'] for req in queries] | ||
batch = BatchRequest(requests=queries) | ||
generated = self._query_op.batch(batch, **kwargs) | ||
return LogsBatchResults._from_generated( # pylint: disable=protected-access | ||
generated, request_order | ||
) | ||
return order_results( | ||
request_order, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if the id in request_order does not exist in results? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it will always exist - it's a 1:1 mapping |
||
[ | ||
LogsQueryResult._from_generated(rsp) for rsp in generated.responses # pylint: disable=protected-access | ||
]) | ||
|
||
def close(self): | ||
# type: () -> None | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
sdk/monitor/azure-monitor-query/samples/sample_logs_query_key_value_form.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import os | ||
import pandas as pd | ||
from datetime import datetime, timedelta | ||
from msrest.serialization import UTC | ||
from azure.monitor.query import LogsQueryClient | ||
from azure.identity import DefaultAzureCredential | ||
|
||
credential = DefaultAzureCredential() | ||
client = LogsQueryClient(credential) | ||
|
||
# Response time trend | ||
# request duration over the last 12 hours. | ||
query = """AppRequests | | ||
summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""" | ||
|
||
end_time = datetime.now(UTC()) | ||
|
||
# returns LogsQueryResults | ||
response = client.query(os.environ['LOG_WORKSPACE_ID'], query, duration=timedelta(days=1), end_time=end_time) | ||
|
||
if not response.tables: | ||
print("No results for the query") | ||
|
||
for table in response.tables: | ||
pd.json_normalize | ||
df = pd.DataFrame(table.rows, columns=[col.name for col in table.columns]) | ||
key_value = df.to_dict(orient='records') | ||
print(key_value) | ||
|
||
""" | ||
[ | ||
{ | ||
'TimeGenerated': '2021-07-21T04:40:00Z', | ||
'_ResourceId': '/subscriptions/faa080af....', | ||
'avgRequestDuration': 19.7987 | ||
}, | ||
{ | ||
'TimeGenerated': '2021-07-21T04:50:00Z', | ||
'_ResourceId': '/subscriptions/faa08....', | ||
'avgRequestDuration': 33.9654 | ||
}, | ||
{ | ||
'TimeGenerated': '2021-07-21T05:00:00Z', | ||
'_ResourceId': '/subscriptions/faa080....', | ||
'avgRequestDuration': 44.13115 | ||
} | ||
] | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it return a pageable object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no - service doesn't support paging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think our guideline is even service does not support page, we should wrap the return into pageable results?
@annatisch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we talked to the architects and they were fine in this case with not supporting both paging and LRO
as service is not planning to ever support it on these endpoints
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i have created this issue for september milestone to follow up again #19942