Added metrics to rss endpoints
This commit is contained in:
parent
a64e16f681
commit
ac9a2f3970
|
@ -6,12 +6,13 @@
|
|||
using Microsoft.Extensions.Options;
|
||||
using Wave.Data;
|
||||
using Wave.Utilities;
|
||||
using Wave.Utilities.Metrics;
|
||||
|
||||
namespace Wave.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("/[controller]")]
|
||||
public class RssController(IOptions<Customization> customizations, ApplicationDbContext context, IOptions<Features> features) : ControllerBase {
|
||||
public class RssController(IOptions<Customization> customizations, ApplicationDbContext context, IOptions<Features> features, RssMetrics metrics) : ControllerBase {
|
||||
private ApplicationDbContext Context { get; } = context;
|
||||
private IOptions<Customization> Customizations { get; } = customizations;
|
||||
private IOptions<Features> Features { get; } = features;
|
||||
|
@ -22,6 +23,8 @@ public class RssController(IOptions<Customization> customizations, ApplicationDb
|
|||
public async Task<IActionResult> GetRssFeedAsync(string? category = null, Guid? author = null) {
|
||||
if (!Features.Value.Rss) return new JsonResult("RSS is disabled") {StatusCode = StatusCodes.Status401Unauthorized};
|
||||
|
||||
metrics.RssRequestReceived("application/rss+xml", category, author?.ToString());
|
||||
|
||||
if (category is not null || author.HasValue)
|
||||
Response.Headers.Append("x-robots-tag", "noindex");
|
||||
|
||||
|
@ -36,6 +39,8 @@ public class RssController(IOptions<Customization> customizations, ApplicationDb
|
|||
public async Task<IActionResult> GetAtomFeedAsync(string? category = null, Guid? author = null) {
|
||||
if (!Features.Value.Rss) return new JsonResult("RSS is disabled") {StatusCode = StatusCodes.Status401Unauthorized};
|
||||
|
||||
metrics.RssRequestReceived("application/atom+xml", category, author?.ToString());
|
||||
|
||||
if (category is not null || author.HasValue)
|
||||
Response.Headers.Append("x-robots-tag", "noindex");
|
||||
|
||||
|
|
|
@ -294,6 +294,7 @@
|
|||
.AddMeter("Microsoft.AspNetCore.Http.Routing")
|
||||
.AddMeter("Microsoft.AspNetCore.Diagnostics")
|
||||
.AddMeter("Wave.Api")
|
||||
.AddMeter("Wave.Rss")
|
||||
.AddPrometheusExporter());
|
||||
|
||||
// Jaeger etc.
|
||||
|
@ -305,6 +306,7 @@
|
|||
});
|
||||
}
|
||||
|
||||
builder.Services.AddSingleton<RssMetrics>();
|
||||
builder.Services.AddSingleton<ApiMetrics>();
|
||||
}
|
||||
|
||||
|
|
21
Wave/Utilities/Metrics/RssMetrics.cs
Normal file
21
Wave/Utilities/Metrics/RssMetrics.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System.Diagnostics.Metrics;
|
||||
|
||||
namespace Wave.Utilities.Metrics;
|
||||
|
||||
public class RssMetrics {
|
||||
private Counter<int> RssRequestCounter { get; }
|
||||
|
||||
public RssMetrics(IMeterFactory meterFactory) {
|
||||
var meter = meterFactory.Create("Wave.Rss");
|
||||
|
||||
RssRequestCounter = meter.CreateCounter<int>("wave.rss.requests", "{requests}",
|
||||
"Counts incoming requests processed on RSS endpoints");
|
||||
}
|
||||
|
||||
public void RssRequestReceived(string type, string? category, string? author) {
|
||||
RssRequestCounter.Add(1,
|
||||
new KeyValuePair<string, object?>("wave.rss.type", type),
|
||||
new KeyValuePair<string, object?>("wave.rss.category", category),
|
||||
new KeyValuePair<string, object?>("wave.rss.author", author));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue