Skip to content

Commit

Permalink
Add metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMacocian committed Aug 9, 2024
1 parent 8f033e4 commit 9131911
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Replace secrets in configuration
shell: pwsh
run: |
$jsonContent = Get-Content -Raw -Path GuildWarsPartySearch\Config.Release.json | ConvertFrom-Json
$jsonContent = Get-Content -Raw -Path GuildWarsPartySearch\Config.Production.json | ConvertFrom-Json
$trimmedIps = "${{ secrets.COMMA_SEPARATED_IPS }}" -split ',' | ForEach-Object { $_.Trim() }
$newAddressesArray = $jsonContent.IpWhitelistOptions.Addresses + $trimmedIps
$jsonContent.IpWhitelistOptions.Addresses = $newAddressesArray
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-Server
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ WORKDIR /build
RUN git clone https://github.com/gwdevhub/GuildWarsPartySearch

RUN cd GuildWarsPartySearch && \
dotnet publish GuildWarsPartySearch/GuildWarsPartySearch.Server.csproj -c Release -r linux-x64 -o Publish && \
dotnet publish GuildWarsPartySearch/GuildWarsPartySearch.Server.csproj -c Production -r linux-x64 -o Publish && \
cp -r GuildWarsPartySearch.FrontEnd/Content Publish/Content && \
cp GuildWarsPartySearch/Config.Release.json Publish/Config.json

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Configurations>Debug;Release;Local</Configurations>
<Configurations>Debug;Production;Local</Configurations>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Configurations>Debug;Production</Configurations>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<Configurations>Debug;Release;Local</Configurations>
<Configurations>Debug;Production;Local</Configurations>
</PropertyGroup>

<ItemGroup>
Expand Down
36 changes: 18 additions & 18 deletions GuildWarsPartySearch.sln
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ Global
Debug|x64 = Debug|x64
Local|Any CPU = Local|Any CPU
Local|x64 = Local|x64
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Production|Any CPU = Production|Any CPU
Production|x64 = Production|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3469E092-73C7-44D1-83CD-677E22DC054B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand All @@ -52,10 +52,10 @@ Global
{3469E092-73C7-44D1-83CD-677E22DC054B}.Local|Any CPU.Build.0 = Local|Any CPU
{3469E092-73C7-44D1-83CD-677E22DC054B}.Local|x64.ActiveCfg = Local|Any CPU
{3469E092-73C7-44D1-83CD-677E22DC054B}.Local|x64.Build.0 = Local|Any CPU
{3469E092-73C7-44D1-83CD-677E22DC054B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3469E092-73C7-44D1-83CD-677E22DC054B}.Release|Any CPU.Build.0 = Release|Any CPU
{3469E092-73C7-44D1-83CD-677E22DC054B}.Release|x64.ActiveCfg = Release|Any CPU
{3469E092-73C7-44D1-83CD-677E22DC054B}.Release|x64.Build.0 = Release|Any CPU
{3469E092-73C7-44D1-83CD-677E22DC054B}.Production|Any CPU.ActiveCfg = Production|Any CPU
{3469E092-73C7-44D1-83CD-677E22DC054B}.Production|Any CPU.Build.0 = Production|Any CPU
{3469E092-73C7-44D1-83CD-677E22DC054B}.Production|x64.ActiveCfg = Production|Any CPU
{3469E092-73C7-44D1-83CD-677E22DC054B}.Production|x64.Build.0 = Production|Any CPU
{04737A61-0E1C-4121-8012-AD55B3D3E03E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{04737A61-0E1C-4121-8012-AD55B3D3E03E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{04737A61-0E1C-4121-8012-AD55B3D3E03E}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand All @@ -64,10 +64,10 @@ Global
{04737A61-0E1C-4121-8012-AD55B3D3E03E}.Local|Any CPU.Build.0 = Local|Any CPU
{04737A61-0E1C-4121-8012-AD55B3D3E03E}.Local|x64.ActiveCfg = Local|Any CPU
{04737A61-0E1C-4121-8012-AD55B3D3E03E}.Local|x64.Build.0 = Local|Any CPU
{04737A61-0E1C-4121-8012-AD55B3D3E03E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{04737A61-0E1C-4121-8012-AD55B3D3E03E}.Release|Any CPU.Build.0 = Release|Any CPU
{04737A61-0E1C-4121-8012-AD55B3D3E03E}.Release|x64.ActiveCfg = Release|Any CPU
{04737A61-0E1C-4121-8012-AD55B3D3E03E}.Release|x64.Build.0 = Release|Any CPU
{04737A61-0E1C-4121-8012-AD55B3D3E03E}.Production|Any CPU.ActiveCfg = Production|Any CPU
{04737A61-0E1C-4121-8012-AD55B3D3E03E}.Production|Any CPU.Build.0 = Production|Any CPU
{04737A61-0E1C-4121-8012-AD55B3D3E03E}.Production|x64.ActiveCfg = Production|Any CPU
{04737A61-0E1C-4121-8012-AD55B3D3E03E}.Production|x64.Build.0 = Production|Any CPU
{9FCED959-3EE9-40B7-B6A8-AF13FAB54B9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9FCED959-3EE9-40B7-B6A8-AF13FAB54B9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9FCED959-3EE9-40B7-B6A8-AF13FAB54B9C}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand All @@ -76,10 +76,10 @@ Global
{9FCED959-3EE9-40B7-B6A8-AF13FAB54B9C}.Local|Any CPU.Build.0 = Local|Any CPU
{9FCED959-3EE9-40B7-B6A8-AF13FAB54B9C}.Local|x64.ActiveCfg = Local|Any CPU
{9FCED959-3EE9-40B7-B6A8-AF13FAB54B9C}.Local|x64.Build.0 = Local|Any CPU
{9FCED959-3EE9-40B7-B6A8-AF13FAB54B9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9FCED959-3EE9-40B7-B6A8-AF13FAB54B9C}.Release|Any CPU.Build.0 = Release|Any CPU
{9FCED959-3EE9-40B7-B6A8-AF13FAB54B9C}.Release|x64.ActiveCfg = Release|Any CPU
{9FCED959-3EE9-40B7-B6A8-AF13FAB54B9C}.Release|x64.Build.0 = Release|Any CPU
{9FCED959-3EE9-40B7-B6A8-AF13FAB54B9C}.Production|Any CPU.ActiveCfg = Production|Any CPU
{9FCED959-3EE9-40B7-B6A8-AF13FAB54B9C}.Production|Any CPU.Build.0 = Production|Any CPU
{9FCED959-3EE9-40B7-B6A8-AF13FAB54B9C}.Production|x64.ActiveCfg = Production|Any CPU
{9FCED959-3EE9-40B7-B6A8-AF13FAB54B9C}.Production|x64.Build.0 = Production|Any CPU
{3BC53FC6-A022-4D14-B917-5A679AF41EC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3BC53FC6-A022-4D14-B917-5A679AF41EC6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3BC53FC6-A022-4D14-B917-5A679AF41EC6}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand All @@ -88,10 +88,10 @@ Global
{3BC53FC6-A022-4D14-B917-5A679AF41EC6}.Local|Any CPU.Build.0 = Debug|Any CPU
{3BC53FC6-A022-4D14-B917-5A679AF41EC6}.Local|x64.ActiveCfg = Debug|Any CPU
{3BC53FC6-A022-4D14-B917-5A679AF41EC6}.Local|x64.Build.0 = Debug|Any CPU
{3BC53FC6-A022-4D14-B917-5A679AF41EC6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3BC53FC6-A022-4D14-B917-5A679AF41EC6}.Release|Any CPU.Build.0 = Release|Any CPU
{3BC53FC6-A022-4D14-B917-5A679AF41EC6}.Release|x64.ActiveCfg = Release|Any CPU
{3BC53FC6-A022-4D14-B917-5A679AF41EC6}.Release|x64.Build.0 = Release|Any CPU
{3BC53FC6-A022-4D14-B917-5A679AF41EC6}.Production|Any CPU.ActiveCfg = Production|Any CPU
{3BC53FC6-A022-4D14-B917-5A679AF41EC6}.Production|Any CPU.Build.0 = Production|Any CPU
{3BC53FC6-A022-4D14-B917-5A679AF41EC6}.Production|x64.ActiveCfg = Production|Any CPU
{3BC53FC6-A022-4D14-B917-5A679AF41EC6}.Production|x64.Build.0 = Production|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion GuildWarsPartySearch/Config.Debug.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}
},
"EnvironmentOptions": {
"Name": "Debug"
"Name": "Development"
},
"ServerOptions": {
"InactivityTimeout": "0:0:5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}
},
"EnvironmentOptions": {
"Name": "Release"
"Name": "Production"
},
"ServerOptions": {
"InactivityTimeout": "0:0:5",
Expand Down
3 changes: 2 additions & 1 deletion GuildWarsPartySearch/GuildWarsPartySearch.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<InvariantGlobalization>true</InvariantGlobalization>
<Configurations>Debug;Release;Local</Configurations>
<Configurations>Debug;Production;Local</Configurations>
</PropertyGroup>

<ItemGroup>
<None Remove="Services\BotStatus\BotStatusService.cs~RFec2479f.TMP" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="App.Metrics.AspNetCore.All" Version="4.3.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.7" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.7.0" />
Expand Down
46 changes: 36 additions & 10 deletions GuildWarsPartySearch/Launch/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// See https://aka.ms/new-console-template for more information
using App.Metrics;
using GuildWarsPartySearch.Server.Options;
using Microsoft.Extensions.FileProviders;
using Microsoft.OpenApi.Models;
using System.Core.Extensions;
using System.Net;
using System.Text.Json;

Expand All @@ -17,13 +19,35 @@ private static async Task Main()
.SetupConfiguration()
.Build();

var builder = WebApplication.CreateBuilder()
.SetupOptions()
.SetupHostedServices();

builder.Configuration.AddConfiguration(config);

var options = builder.Configuration.GetRequiredSection(nameof(ServerOptions)).Get<ServerOptions>();
var environmentOptions = builder.Configuration.GetRequiredSection(nameof(EnvironmentOptions)).Get<EnvironmentOptions>()!;
var contentOptions = builder.Configuration.GetRequiredSection(nameof(ContentOptions)).Get<ContentOptions>()!;

builder.Environment.EnvironmentName = environmentOptions.Name?.ThrowIfNull()!;

var jsonOptions = new JsonSerializerOptions();
jsonOptions.Converters.SetupConverters();
jsonOptions.AllowTrailingCommas = true;

var builder = WebApplication.CreateBuilder()
.SetupOptions()
.SetupHostedServices();
var metrics = AppMetrics.CreateDefaultBuilder()
.OutputMetrics.AsPlainText()
.Configuration.Configure(options =>
{
if (options.GlobalTags.TryGetValue("env", out var metricsEnv))
{
options.GlobalTags.Remove("env");
}

options.GlobalTags.Add("env", environmentOptions.Name);
})
.Build();

builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Guild Wars Party Search API", Version = "v1" });
Expand All @@ -34,16 +58,16 @@ private static async Task Main()
builder.Logging.SetupLogging();
builder.Services.SetupServices();
builder.Services.AddControllers();
builder.Configuration.AddConfiguration(config);
builder.Services.AddMetrics(metrics);
builder.Services.AddMetricsEndpoints();
builder.Services.AddMetricsTrackingMiddleware();
builder.WebHost.ConfigureKestrel(kestrelOptions =>
{
var options = builder.Configuration.GetRequiredSection(nameof(ServerOptions)).Get<ServerOptions>();
kestrelOptions.Listen(IPAddress.Any, options?.Port ?? 80, listenOptions =>
{
});
kestrelOptions.AllowSynchronousIO = true;
kestrelOptions.Listen(IPAddress.Any, options?.Port ?? 80);
});

var contentOptions = builder.Configuration.GetRequiredSection(nameof(ContentOptions)).Get<ContentOptions>()!;

var contentDirectory = new DirectoryInfo(
Path.Combine(
Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly()?.Location) ?? throw new InvalidOperationException("Unable to get content staging folder"), contentOptions.StagingFolder));
Expand All @@ -60,6 +84,8 @@ private static async Task Main()
{
endpoints.MapControllers();
})
.UseMetricsAllMiddleware()
.UseMetricsAllEndpoints()
.UseSwaggerUI(c => c.SwaggerEndpoint("v1/swagger.json", "Guild Wars Party Search API"))
.UseStaticFiles(new StaticFileOptions
{
Expand Down

0 comments on commit 9131911

Please sign in to comment.