From a92fa750dd80c931673b2c752746d4088116f726 Mon Sep 17 00:00:00 2001 From: Matthew Fisher <40250218+MicroFish91@users.noreply.github.com> Date: Thu, 6 Jun 2024 09:46:03 -0700 Subject: [PATCH] Always try to return a log analytics workspace ID when running `deployWorkspaceProject` (#686) --- .../getDeployWorkspaceProjectResults.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/commands/deployWorkspaceProject/getDeployWorkspaceProjectResults.ts b/src/commands/deployWorkspaceProject/getDeployWorkspaceProjectResults.ts index 319eefb7..00195e9b 100644 --- a/src/commands/deployWorkspaceProject/getDeployWorkspaceProjectResults.ts +++ b/src/commands/deployWorkspaceProject/getDeployWorkspaceProjectResults.ts @@ -4,6 +4,9 @@ *--------------------------------------------------------------------------------------------*/ import { type RegistryPassword } from "@azure/arm-containerregistry"; +import { type Workspace } from "@azure/arm-operationalinsights"; +import { uiUtils } from "@microsoft/vscode-azext-azureutils"; +import { createOperationalInsightsManagementClient } from "../../utils/azureClients"; import type * as api from "../api/vscode-azurecontainerapps.api"; import { listCredentialsFromRegistry } from "../image/imageSource/containerRegistry/acr/listCredentialsFromRegistry"; import { type DeployWorkspaceProjectContext } from "./DeployWorkspaceProjectContext"; @@ -14,6 +17,8 @@ export async function getDeployWorkspaceProjectResults(context: DeployWorkspaceP const registryCredentials: { username: string, password: RegistryPassword } | undefined = context.registry ? await listCredentialsFromRegistry(context, context.registry) : undefined; + context.logAnalyticsWorkspace ??= await tryGetLogAnalyticsWorkspace(context); + return { resourceGroupId: context.resourceGroup?.id, logAnalyticsWorkspaceId: context.logAnalyticsWorkspace?.id, @@ -26,3 +31,16 @@ export async function getDeployWorkspaceProjectResults(context: DeployWorkspaceP imageName: context.imageName }; } + +export async function tryGetLogAnalyticsWorkspace(context: DeployWorkspaceProjectContext): Promise { + const resourceGroupName = context.resourceGroup?.name; + const logAnalyticsCustomerId = context.managedEnvironment?.appLogsConfiguration?.logAnalyticsConfiguration?.customerId; + + if (!resourceGroupName || !logAnalyticsCustomerId) { + return undefined; + } + + const client = await createOperationalInsightsManagementClient(context); + const workspaces: Workspace[] = await uiUtils.listAllIterator(client.workspaces.listByResourceGroup(resourceGroupName)); + return workspaces.find(w => w.customerId === logAnalyticsCustomerId); +}