Skip to content

Commit

Permalink
Add Aspire
Browse files Browse the repository at this point in the history
  • Loading branch information
zimbres committed Dec 7, 2024
1 parent 586199d commit 308a0d4
Show file tree
Hide file tree
Showing 13 changed files with 245 additions and 22 deletions.
12 changes: 12 additions & 0 deletions UptimeKumaRemoteProbe.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UptimeKumaRemoteProbe", "src\UptimeKumaRemoteProbe\UptimeKumaRemoteProbe.csproj", "{291D4A53-0E98-4E7B-861D-C43973C0B5D1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UKRP.AppHost", "src\UKRP.AppHost\UKRP.AppHost.csproj", "{07875E62-655F-44E9-8781-1F24DB832BA1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UKRP.ServiceDefaults", "src\UKRP.ServiceDefaults\UKRP.ServiceDefaults.csproj", "{03B064F8-A9A3-4380-9F77-2D025C51185E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -25,6 +29,14 @@ Global
{291D4A53-0E98-4E7B-861D-C43973C0B5D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{291D4A53-0E98-4E7B-861D-C43973C0B5D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{291D4A53-0E98-4E7B-861D-C43973C0B5D1}.Release|Any CPU.Build.0 = Release|Any CPU
{07875E62-655F-44E9-8781-1F24DB832BA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07875E62-655F-44E9-8781-1F24DB832BA1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07875E62-655F-44E9-8781-1F24DB832BA1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07875E62-655F-44E9-8781-1F24DB832BA1}.Release|Any CPU.Build.0 = Release|Any CPU
{03B064F8-A9A3-4380-9F77-2D025C51185E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{03B064F8-A9A3-4380-9F77-2D025C51185E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{03B064F8-A9A3-4380-9F77-2D025C51185E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{03B064F8-A9A3-4380-9F77-2D025C51185E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 5 additions & 0 deletions src/UKRP.AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var builder = DistributedApplication.CreateBuilder(args);

builder.AddProject<Projects.UptimeKumaRemoteProbe>("uptimekumaremoteprobe");

builder.Build().Run();
30 changes: 30 additions & 0 deletions src/UKRP.AppHost/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17047;http://localhost:15113",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21296",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22162"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15113",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19132",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20111",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
}
}
}
25 changes: 25 additions & 0 deletions src/UKRP.AppHost/UKRP.AppHost.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<Sdk Name="Aspire.AppHost.Sdk" Version="9.0.0" />

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>9b25896d-67a2-4379-9411-47b0e205791d</UserSecretsId>
<AssemblyVersion>$(PackageVersion)</AssemblyVersion>
<FileVersion>$(PackageVersion)</FileVersion>
<Version>1.0.0.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\UptimeKumaRemoteProbe\UptimeKumaRemoteProbe.csproj" />
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions src/UKRP.AppHost/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions src/UKRP.AppHost/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}
118 changes: 118 additions & 0 deletions src/UKRP.ServiceDefaults/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Logging;
using OpenTelemetry;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;

namespace Microsoft.Extensions.Hosting;

// Adds common .NET Aspire services: service discovery, resilience, health checks, and OpenTelemetry.
// This project should be referenced by each service project in your solution.
// To learn more about using this project, see https://aka.ms/dotnet/aspire/service-defaults
public static class Extensions
{
public static TBuilder AddServiceDefaults<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{
builder.ConfigureOpenTelemetry();

builder.AddDefaultHealthChecks();

builder.Services.AddServiceDiscovery();

builder.Services.ConfigureHttpClientDefaults(http =>
{
// Turn on resilience by default
http.AddStandardResilienceHandler();

// Turn on service discovery by default
http.AddServiceDiscovery();
});

// Uncomment the following to restrict the allowed schemes for service discovery.
// builder.Services.Configure<ServiceDiscoveryOptions>(options =>
// {
// options.AllowedSchemes = ["https"];
// });

return builder;
}

public static TBuilder ConfigureOpenTelemetry<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{
builder.Logging.AddOpenTelemetry(logging =>
{
logging.IncludeFormattedMessage = true;
logging.IncludeScopes = true;
});

builder.Services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
metrics.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRuntimeInstrumentation();
})
.WithTracing(tracing =>
{
tracing.AddSource(builder.Environment.ApplicationName)
.AddAspNetCoreInstrumentation()
// Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
//.AddGrpcClientInstrumentation()
.AddHttpClientInstrumentation();
});

builder.AddOpenTelemetryExporters();

return builder;
}

private static TBuilder AddOpenTelemetryExporters<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{
var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);

if (useOtlpExporter)
{
builder.Services.AddOpenTelemetry().UseOtlpExporter();
}

// Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.AspNetCore package)
//if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]))
//{
// builder.Services.AddOpenTelemetry()
// .UseAzureMonitor();
//}

return builder;
}

public static TBuilder AddDefaultHealthChecks<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{
builder.Services.AddHealthChecks()
// Add a default liveness check to ensure app is responsive
.AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]);

return builder;
}

public static WebApplication MapDefaultEndpoints(this WebApplication app)
{
// Adding health checks endpoints to applications in non-development environments has security implications.
// See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments.
if (app.Environment.IsDevelopment())
{
// All health checks must pass for app to be considered ready to accept traffic after starting
app.MapHealthChecks("/health");

// Only health checks tagged with the "live" tag must pass for app to be considered alive
app.MapHealthChecks("/alive", new HealthCheckOptions
{
Predicate = r => r.Tags.Contains("live")
});
}

return app;
}
}
25 changes: 25 additions & 0 deletions src/UKRP.ServiceDefaults/UKRP.ServiceDefaults.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireSharedProject>true</IsAspireSharedProject>
<AssemblyVersion>$(PackageVersion)</AssemblyVersion>
<FileVersion>$(PackageVersion)</FileVersion>
<Version>1.0.0.0</Version>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />

<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="9.0.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.10.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.10.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.10.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.10.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/UptimeKumaRemoteProbe/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
Expand Down
2 changes: 1 addition & 1 deletion src/UptimeKumaRemoteProbe/Dockerfile.multiarch
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
fi \
&& dotnet publish "src/UptimeKumaRemoteProbe/UptimeKumaRemoteProbe.csproj" -c Release -o /app/publish -r $RID --self-contained false

FROM mcr.microsoft.com/dotnet/runtime:8.0 AS final
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
WORKDIR /app
COPY --from=build /app/publish .

Expand Down
2 changes: 2 additions & 0 deletions src/UptimeKumaRemoteProbe/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var builder = Host.CreateApplicationBuilder(args);

builder.AddServiceDefaults();
builder.Services.AddHttpClient("Default");
builder.Services.AddHttpClient("IgnoreSSL")
.ConfigurePrimaryHttpMessageHandler(() =>
Expand Down
6 changes: 5 additions & 1 deletion src/UptimeKumaRemoteProbe/UptimeKumaRemoteProbe.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ApplicationIcon>uptime-kuma.ico</ApplicationIcon>
<AssemblyVersion>$(PackageVersion)</AssemblyVersion>
<FileVersion>$(PackageVersion)</FileVersion>
<Version>6.0.1.1</Version>
<Version>6.0.1.2</Version>
<Copyright>Zimbres.Com</Copyright>
<PackageProjectUrl>https://github.com/zimbres/UptimeKumaRemoteProbe</PackageProjectUrl>
<RepositoryUrl>https://github.com/zimbres/UptimeKumaRemoteProbe</RepositoryUrl>
Expand Down Expand Up @@ -45,4 +45,8 @@
<PackageReference Include="System.Formats.Asn1" Version="9.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\UKRP.ServiceDefaults\UKRP.ServiceDefaults.csproj" />
</ItemGroup>
</Project>
23 changes: 4 additions & 19 deletions src/UptimeKumaRemoteProbe/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,13 @@
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
},
"Console": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
},
"FormatterName": "json",
"FormatterOptions": {
"SingleLine": true,
"IncludeScopes": false,
"TimestampFormat": "dd/MM/yyyy HH:mm:ss",
"UseUtcTimestamp": false,
"JsonWriterOptions": {
"Indented": false
}
}
"Microsoft.Hosting.Lifetime": "Information",
"System.Net.Http.HttpClient": "Warning",
"Polly": "Warning"
}
},
"Configurations": {
"Url": "http://localhost:3001/",
"Url": "http://192.168.100.190:3001/",
"Username": "admin",
"Password": "Admin123",
"ProbeName": "Home",
Expand Down

0 comments on commit 308a0d4

Please sign in to comment.