-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGrafanaStackResource.cs
50 lines (43 loc) · 1.97 KB
/
GrafanaStackResource.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
namespace ShadowShop.AppHost.Resources;
public class GrafanaStackResource(string name): ContainerResource(name), IResourceWithServiceDiscovery
{
public const string GrafanaEndpointName = "grafana";
public const int DefaultGrafanaEndpointPort = 3000;
public const string OtelEndpointName = "otel";
public const int DefaultOtelEndpointPort = 4317;
public const string Platform = "linux/amd64";
}
public static class GrafanaStackBuilderExtensions
{
public static IResourceBuilder<GrafanaStackResource> AddGrafanaStack(this IDistributedApplicationBuilder builder,
string name, int? grafanaPort = null, int? otelPort = null)
{
var grafanaStack = new GrafanaStackResource(name);
return builder.AddResource(grafanaStack)
.WithImage("grafana/otel-lgtm")
.WithImageTag("latest")
.WithImageRegistry("docker.io")
.WithHttpEndpoint(
port: grafanaPort,
targetPort: GrafanaStackResource.DefaultGrafanaEndpointPort,
name: GrafanaStackResource.GrafanaEndpointName
)
.WithHttpEndpoint(
port: otelPort,
targetPort: GrafanaStackResource.DefaultOtelEndpointPort,
name: GrafanaStackResource.OtelEndpointName
)
.WithContainerRuntimeArgs("--platform", GrafanaStackResource.Platform)
.ExcludeFromManifest();
}
public static IResourceBuilder<TDestination> WithReference<TDestination>(
this IResourceBuilder<TDestination> builder, IResourceBuilder<GrafanaStackResource> source)
where TDestination : IResourceWithEnvironment
{
builder.WithReference(source as IResourceBuilder<IResourceWithServiceDiscovery>);
return builder.WithEnvironment(ctx =>
{
ctx.EnvironmentVariables["OTEL_EXPORTER_OTLP_ENDPOINT"] = source.Resource.GetEndpoint(GrafanaStackResource.OtelEndpointName);
});
}
}