Put metrics in CouchDB, fix the proxy, fix list validation

This commit is contained in:
Timothy Baldridge 2022-06-22 15:11:26 -06:00
parent 98b7437aa8
commit f446a967a0
4 changed files with 26 additions and 16 deletions

View File

@ -265,7 +265,7 @@ public class ValidateLists : IVerb
private async Task<(RelativePath SmallImage, RelativePath LargeImage)> ProcessModlistImage(AbsolutePath reports, ModlistMetadata validatedList,
CancellationToken token)
{
_logger.LogInformation("Processing Modlist Image");
_logger.LogInformation("Processing Modlist Image for {MachineUrl}", validatedList.NamespacedName);
var baseFolder = reports.Combine(validatedList.NamespacedName);
baseFolder.CreateDirectory();

View File

@ -46,7 +46,8 @@ public class DownloadDispatcher
public async Task<Archive> MaybeProxy(Archive a, CancellationToken token)
{
if (a.State is not IProxyable p) return a;
var downloader = Downloader(a);
if (downloader is not IProxyable p) return a;
var uri = p.UnParse(a.State);
var newUri = await _wjClient.MakeProxyUrl(a, uri);
@ -107,6 +108,10 @@ public class DownloadDispatcher
{
try
{
if (a.Name.Contains("HorseReplacer"))
{
}
a = await MaybeProxy(a, token);
var downloader = Downloader(a);
using var job = await _limiter.Begin($"Verifying {a.State.PrimaryKeyString}", -1, token);

View File

@ -75,15 +75,17 @@ public class MetricsController : ControllerBase
if (value is "Default" or "untitled" || subject == "failed_download" || Guid.TryParse(value, out _))
return new Result {Timestamp = date};
await _metricsStore.Ingest(new Metric
await _db.AddAsync(new Metric
{
Timestamp = DateTime.UtcNow,
Action = subject,
Subject = value,
Timestamp = date,
Action = subject,
Subject = value,
MetricsKey = metricsKey,
UserAgent = Request.Headers.UserAgent.FirstOrDefault() ?? "<unknown>",
Ip = Request.Headers["cf-connecting-ip"].FirstOrDefault() ?? (Request.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "")
Ip = Request.Headers["cf-connecting-ip"].FirstOrDefault() ??
(Request.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "")
});
return new Result {Timestamp = date};
}

View File

@ -101,10 +101,13 @@ public class Startup
services.AddAllSingleton<ITokenProvider<WabbajackApiState>, WabbajackApiTokenProvider>();
services.AddAllSingleton<IResource, IResource<DownloadDispatcher>>(s => new Resource<DownloadDispatcher>("Downloads", 12));
services.AddAllSingleton<IResource, IResource<FileHashCache>>(s => new Resource<FileHashCache>("File Hashing", 12));
services.AddAllSingleton<IResource, IResource<Wabbajack.Networking.WabbajackClientApi.Client>>(s =>
new Resource<Wabbajack.Networking.WabbajackClientApi.Client>("Wabbajack Client", 4));
services.AddSingleton(s =>
new FileHashCache(KnownFolders.AppDataLocal.Combine("Wabbajack", "GlobalHashCache.sqlite"),
s.GetService<IResource<FileHashCache>>()!));
services.AddAllSingleton<ITokenProvider<NexusApiState>, NexusApiTokenProvider>();
services.AddAllSingleton<IResource, IResource<HttpClient>>(s => new Resource<HttpClient>("Web Requests", 12));
// Application Info
@ -146,26 +149,26 @@ public class Startup
// CouchDB
services.AddSingleton(s =>
{
var settings = s.GetRequiredService<AppSettings>();
var client = new CouchClient(settings.CesiDB.Endpoint, b =>
var settings = s.GetRequiredService<AppSettings>().CesiDB;
var client = new CouchClient(settings.Endpoint, b =>
{
b.UseBasicAuthentication("cesi", "password");
b.UseBasicAuthentication(settings.Username, settings.Password);
b.SetPropertyCase(PropertyCaseType.None);
b.SetJsonNullValueHandling(NullValueHandling.Ignore);
});
return client.GetDatabase<Analyzed>("cesi");
return client.GetDatabase<Analyzed>(settings.Database);
});
services.AddSingleton(s =>
{
var settings = s.GetRequiredService<AppSettings>();
var client = new CouchClient(settings.CesiDB.Endpoint, b =>
var settings = s.GetRequiredService<AppSettings>().MetricsDB;
var client = new CouchClient(settings.Endpoint, b =>
{
b.UseBasicAuthentication("wabbajack", "password");
b.UseBasicAuthentication(settings.Username, settings.Password);
b.SetPropertyCase(PropertyCaseType.None);
b.SetJsonNullValueHandling(NullValueHandling.Ignore);
});
return client.GetDatabase<Metric>("cesi");
return client.GetDatabase<Metric>(settings.Database);
});
services.AddMvc();