Skip to content

Commit

Permalink
Add metric for user agent requests (#1288)
Browse files Browse the repository at this point in the history
  • Loading branch information
karashiiro authored Jul 18, 2024
1 parent 2363944 commit b2f1dae
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Prometheus;
using Universalis.Application.Common;
using Universalis.Application.Views.V1;
using Universalis.DataTransformations;
Expand All @@ -16,6 +17,9 @@ namespace Universalis.Application.Controllers;

public class CurrentlyShownControllerBase : WorldDcRegionControllerBase
{
protected static readonly Counter UserAgentRequestCount =
Metrics.CreateCounter("universalis_request_count_user_agents", "", "Controller", "Family");

protected readonly ICurrentlyShownDbAccess CurrentlyShown;
protected readonly IHistoryDbAccess History;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public async Task<IActionResult> Get(
var parsedUserAgent = Parser.GetDefault().ParseUserAgent(userAgent);
var userAgentFamily = parsedUserAgent.Family;
activity?.AddTag("userAgent", userAgentFamily);

// TODO: pull controller name extraction out to a util
UserAgentRequestCount.Labels("CurrentlyShown", userAgentFamily).Inc();
}

if (itemIds == null || worldDcRegion == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public async Task<IActionResult> Get(
var parsedUserAgent = Parser.GetDefault().ParseUserAgent(userAgent);
var userAgentFamily = parsedUserAgent.Family;
activity?.AddTag("userAgent", userAgentFamily);
UserAgentRequestCount.Labels("CurrentlyShown", userAgentFamily).Inc();
}

if (itemIds == null || worldDcRegion == null)
Expand Down

0 comments on commit b2f1dae

Please sign in to comment.