Skip to content

Commit cf5be5a

Browse files
committed
Remove cross query ambiguous cases.
1 parent a31778b commit cf5be5a

File tree

2 files changed

+15
-45
lines changed

2 files changed

+15
-45
lines changed

articles/azure-monitor/logs/cross-workspace-query.md

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: This article describes how you can query against resources from mul
44
ms.topic: conceptual
55
author: bwren
66
ms.author: bwren
7-
ms.date: 04/28/2022
7+
ms.date: 04/01/2023
88

99
---
1010

@@ -32,66 +32,36 @@ There are two methods to query data that's stored in multiple workspaces and app
3232
To reference another workspace in your query, use the [workspace](../logs/workspace-expression.md) identifier. For an app from Application Insights, use the [app](./app-expression.md) identifier.
3333

3434
### Identify workspace resources
35-
The following examples demonstrate queries across Log Analytics workspaces to return summarized counts of logs from the Update table on a workspace named `contosoretail-it`.
3635

3736
You can identify a workspace in one of several ways:
3837

39-
* **Resource name**: This human-readable name of the workspace is sometimes referred to as the *component name*.
40-
41-
>[!IMPORTANT]
42-
>Because app and workspace names aren't unique, this identifier might be ambiguous. We recommend that the reference uses a qualified name, workspace ID, or Azure Resource ID.
43-
44-
`workspace("contosoretail-it").Update | count`
45-
46-
* **Qualified name**: This "full name" of the workspace is composed of the subscription name, resource group, and component name in the format *subscriptionName/resourceGroup/componentName*.
47-
48-
`workspace('contoso/contosoretail/contosoretail-it').Update | count`
49-
50-
>[!NOTE]
51-
>Because Azure subscription names aren't unique, this identifier might be ambiguous.
52-
5338
* **Workspace ID**: A workspace ID is the unique, immutable, identifier assigned to each workspace represented as a globally unique identifier (GUID).
5439

55-
`workspace("b459b4u5-912x-46d5-9cb1-p43069212nb4").Update | count`
40+
`workspace("00000000-0000-0000-0000-000000000000").Update | count`
5641

5742
* **Azure Resource ID**: This ID is the Azure-defined unique identity of the workspace. You use the Resource ID when the resource name is ambiguous. For workspaces, the format is */subscriptions/subscriptionId/resourcegroups/resourceGroup/providers/microsoft.OperationalInsights/workspaces/componentName*.
5843

5944
For example:
6045

6146
```
62-
workspace("/subscriptions/e427519-5645-8x4e-1v67-3b84b59a1985/resourcegroups/ContosoAzureHQ/providers/Microsoft.OperationalInsights/workspaces/contosoretail-it").Update | count
47+
workspace("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/ContosoAzureHQ/providers/Microsoft.OperationalInsights/workspaces/contosoretail-it").Update | count
6348
```
6449
6550
### Identify an application
6651
The following examples return a summarized count of requests made against an app named *fabrikamapp* in Application Insights.
6752
6853
You can identify an application in Application Insights with the `app(Identifier)` expression. The `Identifier` argument specifies the app by using one of the following names or IDs:
6954
70-
* **Resource name**: This human readable name of the app is sometimes referred to as the *component name*.
71-
72-
`app("fabrikamapp")`
73-
74-
>[!NOTE]
75-
>Identifying an application by name assumes uniqueness across all accessible subscriptions. If you have multiple applications with the specified name, the query fails because of the ambiguity. In this case, you must use one of the other identifiers.
76-
77-
* **Qualified name**: This "full name" of the app is composed of the subscription name, resource group, and component name in the format *subscriptionName/resourceGroup/componentName*.
78-
79-
`app("AI-Prototype/Fabrikam/fabrikamapp").requests | count`
80-
81-
>[!NOTE]
82-
>Because Azure subscription names aren't unique, this identifier might be ambiguous.
83-
>
84-
8555
* **ID**: This ID is the app GUID of the application.
8656
87-
`app("b459b4f6-912x-46d5-9cb1-b43069212ab4").requests | count`
57+
`app("00000000-0000-0000-0000-000000000000").requests | count`
8858
8959
* **Azure Resource ID**: This ID is the Azure-defined unique identity of the app. You use the resource ID when the resource name is ambiguous. The format is */subscriptions/subscriptionId/resourcegroups/resourceGroup/providers/microsoft.OperationalInsights/components/componentName*.
9060
9161
For example:
9262
9363
```
94-
app("/subscriptions/b459b4f6-912x-46d5-9cb1-b43069212ab4/resourcegroups/Fabrikam/providers/microsoft.insights/components/fabrikamapp").requests | count
64+
app("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/Fabrikam/providers/microsoft.insights/components/fabrikamapp").requests | count
9565
```
9666
9767
### Perform a query across multiple resources
@@ -100,7 +70,9 @@ You can query multiple resources from any of your resource instances. These reso
10070
Example for a query across two workspaces:
10171
10272
```
103-
union Update, workspace("contosoretail-it").Update, workspace("b459b4u5-912x-46d5-9cb1-p43069212nb4").Update
73+
union
74+
Update,
75+
workspace("").Update, workspace("00000000-0000-0000-0000-000000000000").Update
10476
| where TimeGenerated >= ago(1h)
10577
| where UpdateState == "Needed"
10678
| summarize dcount(Computer) by Classification
@@ -114,11 +86,11 @@ Create a query like the following example that references the scope of Applicati
11486
```Kusto
11587
// crossResource function that scopes my Application Insights resources
11688
union withsource= SourceApp
117-
app('Contoso-app1').requests,
118-
app('Contoso-app2').requests,
119-
app('Contoso-app3').requests,
120-
app('Contoso-app4').requests,
121-
app('Contoso-app5').requests
89+
app('00000000-0000-0000-0000-000000000000').requests,
90+
app('00000000-0000-0000-0000-000000000001').requests,
91+
app('00000000-0000-0000-0000-000000000002').requests,
92+
app('00000000-0000-0000-0000-000000000003').requests,
93+
app('00000000-0000-0000-0000-000000000004').requests
12294
```
12395

12496
You can now [use this function](./functions.md#use-a-function) in a cross-resource query like the following example. The function alias `applicationsScoping` returns the union of the requests table from all the defined applications. The query then filters for failed requests and visualizes the trends by application. The `parse` operator is optional in this example. It extracts the application name from the `SourceApp` property.
@@ -127,16 +99,14 @@ You can now [use this function](./functions.md#use-a-function) in a cross-resour
12799
applicationsScoping
128100
| where timestamp > ago(12h)
129101
| where success == 'False'
130-
| parse SourceApp with * '(' applicationName ')' *
131-
| summarize count() by applicationName, bin(timestamp, 1h)
102+
| parse SourceApp with * '(' applicationId ')' *
103+
| summarize count() by applicationId, bin(timestamp, 1h)
132104
| render timechart
133105
```
134106

135107
>[!NOTE]
136108
> This method can't be used with log alerts because the access validation of the alert rule resources, including workspaces and applications, is performed at alert creation time. Adding new resources to the function after the alert creation isn't supported. If you prefer to use a function for resource scoping in log alerts, you must edit the alert rule in the portal or with an Azure Resource Manager template to update the scoped resources. Alternatively, you can include the list of resources in the log alert query.
137109
138-
![Screenshot that shows a time chart.](media/cross-workspace-query/chart.png)
139-
140110
## Next steps
141111

142112
See [Analyze log data in Azure Monitor](./log-query-overview.md) for an overview of log queries and how Azure Monitor log data is structured.
Binary file not shown.

0 commit comments

Comments
 (0)