-
Notifications
You must be signed in to change notification settings - Fork 332
/
AzureLogAnalyticsWorkspaceExtensions.cs
61 lines (53 loc) · 3.33 KB
/
AzureLogAnalyticsWorkspaceExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics.CodeAnalysis;
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Azure;
using Azure.Provisioning.OperationalInsights;
using Azure.ResourceManager.OperationalInsights.Models;
namespace Aspire.Hosting;
/// <summary>
/// Provides extension methods for adding the Azure Log Analytics Workspace resources to the application model.
/// </summary>
public static class AzureLogAnalyticsWorkspaceExtensions
{
/// <summary>
/// Adds an Azure Application Insights resource to the application model.
/// </summary>
/// <param name="builder">The <see cref="IDistributedApplicationBuilder"/>.</param>
/// <param name="name">The name of the resource. This name will be used as the connection string name when referenced in a dependency.</param>
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
public static IResourceBuilder<AzureLogAnalyticsWorkspaceResource> AddAzureLogAnalyticsWorkspace(this IDistributedApplicationBuilder builder, string name)
{
#pragma warning disable AZPROVISION001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
return builder.AddAzureLogAnalyticsWorkspace(name, (_, _, _) => { });
#pragma warning restore AZPROVISION001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
}
/// <summary>
/// Adds an Azure Log Analytics Workspace resource to the application model.
/// </summary>
/// <param name="builder">The builder for the distributed application.</param>
/// <param name="name">The name of the resource.</param>
/// <param name="configureResource">Optional callback to configure the Azure Log Analytics Workspace resource.</param>
/// <returns></returns>
[Experimental("AZPROVISION001", UrlFormat = "https://aka.ms/dotnet/aspire/diagnostics#{0}")]
public static IResourceBuilder<AzureLogAnalyticsWorkspaceResource> AddAzureLogAnalyticsWorkspace(this IDistributedApplicationBuilder builder, string name, Action<IResourceBuilder<AzureLogAnalyticsWorkspaceResource>, ResourceModuleConstruct, OperationalInsightsWorkspace>? configureResource)
{
builder.AddAzureProvisioning();
var configureConstruct = (ResourceModuleConstruct construct) =>
{
var workspace = new OperationalInsightsWorkspace(construct, name: name, sku: new OperationalInsightsWorkspaceSku(OperationalInsightsWorkspaceSkuName.PerGB2018));
workspace.Properties.Tags["aspire-resource-name"] = construct.Resource.Name;
workspace.AddOutput("logAnalyticsWorkspaceId", p => p.Id);
if (configureResource != null)
{
var resource = (AzureLogAnalyticsWorkspaceResource)construct.Resource;
var resourceBuilder = builder.CreateResourceBuilder(resource);
configureResource(resourceBuilder, construct, workspace);
}
};
var resource = new AzureLogAnalyticsWorkspaceResource(name, configureConstruct);
return builder.AddResource(resource)
.WithManifestPublishingCallback(resource.WriteToManifest);
}
}