-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Workspaces must be a single param #19344
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
from ._helpers import order_results, construct_iso8601 | ||
from ._generated.models import ( | ||
Column as InternalColumn, | ||
QueryBody as InternalQueryBody, | ||
LogQueryRequest as InternalLogQueryRequest, | ||
ErrorDetails as InternalErrorDetails | ||
) | ||
|
@@ -151,6 +150,8 @@ class LogsQueryRequest(InternalLogQueryRequest): | |
|
||
Variables are only populated by the server, and will be ignored when sending a request. | ||
|
||
:param workspace_id: Workspace Id to be included in the query. | ||
:type workspace_id: str | ||
:param query: The Analytics query. Learn more about the `Analytics query syntax | ||
<https://azure.microsoft.com/documentation/articles/app-insights-analytics-reference/>`_. | ||
:type query: str | ||
|
@@ -161,60 +162,30 @@ class LogsQueryRequest(InternalLogQueryRequest): | |
with either end_time or duration. | ||
:keyword datetime end_time: The end time till which to query the data. This should be accompanied | ||
with either start_time or duration. | ||
:param workspace: Workspace Id to be included in the query. | ||
:type workspace: str | ||
: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] | ||
:keyword request_id: The error details. | ||
:paramtype request_id: str | ||
:keyword headers: Dictionary of :code:`<string>`. | ||
:paramtype headers: dict[str, str] | ||
""" | ||
|
||
def __init__(self, query, workspace, duration=None, **kwargs): | ||
def __init__(self, query, workspace_id, duration=None, **kwargs): | ||
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. Do we need to add it into changelog? 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. good catch - yes |
||
# type: (str, str, Optional[str], Any) -> None | ||
super(LogsQueryRequest, self).__init__(**kwargs) | ||
start = kwargs.pop('start_time', None) | ||
end = kwargs.pop('end_time', None) | ||
timespan = construct_iso8601(start, end, duration) | ||
additional_workspaces = kwargs.pop("additional_workspaces", None) | ||
self.id = kwargs.get("request_id", str(uuid.uuid4())) | ||
self.headers = kwargs.get("headers", None) | ||
self.body = { | ||
"query": query, "timespan": timespan | ||
"query": query, "timespan": timespan, "workspaces": additional_workspaces | ||
} | ||
self.workspace = workspace | ||
self.workspace = workspace_id | ||
|
||
|
||
class LogsQueryBody(InternalQueryBody): | ||
"""The Analytics query. Learn more about the | ||
`Analytics query syntax <https://azure.microsoft.com/documentation/articles/app-insights-analytics-reference/>`_. | ||
|
||
All required parameters must be populated in order to send to Azure. | ||
|
||
:param query: Required. The query to execute. | ||
:type query: str | ||
:keyword timespan: Optional. The timespan over which to query data. This is an ISO8601 time | ||
period value. This timespan is applied in addition to any that are specified in the query | ||
expression. | ||
:paramtype timespan: str | ||
:keyword workspaces: A list of workspaces that are included in the query. | ||
:paramtype workspaces: list[str] | ||
:keyword qualified_names: A list of qualified workspace names that are included in the query. | ||
:paramtype qualified_names: list[str] | ||
:keyword workspace_ids: A list of workspace IDs that are included in the query. | ||
:paramtype workspace_ids: list[str] | ||
:keyword azure_resource_ids: A list of Azure resource IDs that are included in the query. | ||
:paramtype azure_resource_ids: list[str] | ||
""" | ||
|
||
def __init__(self, query, timespan=None, **kwargs): | ||
# type: (str, Optional[str], Any) -> None | ||
kwargs.setdefault("query", query) | ||
kwargs.setdefault("timespan", timespan) | ||
super(LogsQueryBody, self).__init__(**kwargs) | ||
self.workspaces = kwargs.get("workspaces", None) | ||
self.qualified_names = kwargs.get("qualified_names", None) | ||
self.workspace_ids = kwargs.get("workspace_ids", None) | ||
self.azure_resource_ids = kwargs.get("azure_resource_ids", None) | ||
|
||
class LogsQueryResult(object): | ||
"""The LogsQueryResult. | ||
|
||
|
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
38 changes: 38 additions & 0 deletions
38
sdk/monitor/azure-monitor-query/samples/sample_log_query_multiple_workspaces.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,38 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import os | ||
import pandas as pd | ||
from datetime import datetime | ||
from msrest.serialization import UTC | ||
from azure.monitor.query import LogsQueryClient | ||
from azure.identity import ClientSecretCredential | ||
|
||
credential = ClientSecretCredential( | ||
client_id = os.environ['AZURE_CLIENT_ID'], | ||
client_secret = os.environ['AZURE_CLIENT_SECRET'], | ||
tenant_id = os.environ['AZURE_TENANT_ID'] | ||
) | ||
|
||
client = LogsQueryClient(credential) | ||
|
||
# Response time trend | ||
# request duration over the last 12 hours. | ||
query = "union * | where TimeGenerated > ago(100d) | project TenantId | summarize count() by TenantId" | ||
|
||
end_time = datetime.now(UTC()) | ||
|
||
# returns LogsQueryResults | ||
response = client.query( | ||
os.environ['LOG_WORKSPACE_ID'], | ||
query, | ||
additional_workspaces=[os.environ["SECONDARY_WORKSPACE_ID"]], | ||
) | ||
|
||
if not response.tables: | ||
print("No results for the query") | ||
|
||
for table in response.tables: | ||
df = pd.DataFrame(table.rows, columns=[col.name for col in table.columns]) | ||
print(df) | ||
|
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
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.
no-
workspace_id
is the primary workspace id andadditional_workpspaces
is an optional kwarg - the document has both (line 153, line 165)