diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-01-17 16:30:57 -0600 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-01-17 16:30:57 -0600 |
| commit | ae99e0b92a092e74590c4ea0143cfb5584c36fe1 (patch) | |
| tree | 0c51d70f71174ee29504d5b039fdf34524d854a9 /src | |
| parent | 52a6cb47b7dd5944a9f0f5048f93eaf4d822a57c (diff) | |
| download | slskd-ae99e0b92a092e74590c4ea0143cfb5584c36fe1.tar.gz | |
instrument search responses
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Application.cs | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index a93afafe..ba9755c0 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -1552,6 +1552,9 @@ namespace slskd Metrics.Search.RequestsReceived.Inc(1); Metrics.Search.CurrentRequestReceiveRate.CountUp(1); + var sw = new Stopwatch(); + sw.Start(); + if (Users.IsBlacklisted(username)) { return null; @@ -1569,21 +1572,23 @@ namespace slskd return null; } + var filterLatency = sw.ElapsedMilliseconds; + Metrics.Search.Filter.Latency.Observe(filterLatency); + Metrics.Search.Filter.CurrentLatency.Update(filterLatency); + try { - var sw = new Stopwatch(); - sw.Start(); - // append the list of excluded search phrases supplied by the server // see https://github.com/jpdillingham/Soulseek.NET/issues/803 var queryWithExclusionsApplied = new SearchQuery(terms: query.Terms, exclusions: query.Exclusions.Concat(ExcludedSearchPhrases).Distinct()); var results = await Shares.SearchAsync(queryWithExclusionsApplied); - sw.Stop(); + var queryLatency = sw.ElapsedMilliseconds - filterLatency; + Metrics.Search.Query.Latency.Observe(queryLatency); + Metrics.Search.Query.CurrentLatency.Update(queryLatency); - Metrics.Search.ResponseLatency.Observe(sw.ElapsedMilliseconds); - Metrics.Search.CurrentResponseLatency.Update(sw.ElapsedMilliseconds); + SearchResponse response = null; if (results.Any()) { @@ -1611,7 +1616,7 @@ namespace slskd Metrics.Search.ResponsesSent.Inc(1); - return new SearchResponse( + response = new SearchResponse( Client.Username, token, uploadSpeed: State.CurrentValue.User.Statistics.AverageSpeed, @@ -1620,9 +1625,20 @@ namespace slskd fileList: results); } + sw.Stop(); + + Metrics.Search.ResponseLatency.Observe(sw.ElapsedMilliseconds); + Metrics.Search.CurrentResponseLatency.Update(sw.ElapsedMilliseconds); + + if (response is not null) + { + Metrics.Search.ResponsesSent.Inc(1); + Metrics.Search.CurrentResponseSendRate.CountUp(1); + } + // if no results, either return null or an instance of SearchResponse with a fileList of length 0 in either case, no // response will be sent to the requestor. - return null; + return response; } catch (Exception ex) { |
