Repository navigation
Add near-miss diagnostics and request count/unmatched endpoints to the admin API - #1521
Merged
StefH merged 2 commits intoOct 23, 2026
Merged
Conversation
…wiremock#171) Add IWireMockServer.FindUnmatchedLogEntries, FindNearMisses and FindNearMissesForUnmatchedRequests, which rank the mappings that partially match a request by score. Expose them through the admin API (POST requests/count, GET requests/unmatched, GET requests/unmatched/near-misses and GET requests/{guid}/near-misses), the RestClient and the OpenAPI document.
The two *_StateTransitions_BeforeDelayCompletes tests waited a fixed 100 ms for the scenario state to change, which fails on a cold server. Poll server.Scenarios until the expected state is reached instead.
Collaborator
|
@Quattordici Just curious ; which AI did you use to create this PR? |
Collaborator
This was referenced Oct 24, 2026
Closed
This was referenced Oct 26, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relates to #171
Before
When a request don't match the stub you expect, WireMock.Net only tell you "No matching mapping found". The log entry hold at most one partial match. There is no way to ask "which mappings came closest, and which matcher failed?", to list only the unmatched requests, or to count requests matching a pattern without downloading them all (#171).
A near miss is a mapping that partially matches a request: at least one matcher scores above 0, but it isn't a perfect match.
After
New admin endpoints:
POST/__admin/requests/count{ "Count": n }for aRequestModelfilter (same filter as/requests/find)GET/__admin/requests/unmatchedGET/__admin/requests/unmatched/near-misses?maxResults=3GET/__admin/requests/{guid}/near-misses?maxResults=3The same functionality is available in code on
IWireMockServer:The RestClient (
IWireMockAdminApi) getsCountRequestsAsync,GetUnmatchedRequestsAsync,GetNearMissesForUnmatchedRequestsAsyncandGetNearMissesForRequestAsync. The admin OpenAPI document (wiremock.net-openapi.yml) describes the new endpoints and theNearMissModelandRequestCountModelschemas.How
IMappingMatcher.FindNearMisses(IRequestMessage, int)scores every non-admin, enabled, time-valid mapping against the request, using the existingIMapping.GetRequestMatchResultand the current scenario state. It ignoresProbability, so a mapping skipped by chance still shows up, and it skips mappings whose matchers throw. It excludes perfect matches and mappings scoring 0, then orders the rest best first, using the existingRequestMatchResultcomparison, then priority, then most recently updated.WireMockServerimplements the newIWireMockServermembers by mapping those results toNearMiss. A log entry counts as unmatched when its request isn't an admin request and it has no perfect match. This is the same ruleSaveUnmatchedRequestsalready uses, so requests served by a partial match underAllowPartialMappingcount as unmatched too.NearMiss(WireMock.Net.Abstractions,WireMock.Matchers.Request), plusNearMissModelandRequestCountModel(WireMock.Admin.Requests).LogEntryMappergainsMap(NearMiss). Its request mapping is extracted intoMapRequest, so log entries and near misses serialize requests the same way./requests/findand/requests/countshare oneFindLogEntriesByRequestModelhelper./requests/findbehaves the same as before.maxResultsdefaults to 3. A value that isn't a positive integer returns400from the admin API and throwsArgumentExceptionfrom the C# API. An unknown request GUID returns404.Notes:
IWireMockServerbreaks any custom implementation of that interface. In this repository onlyWireMockServerimplements it.Open question for reviewers:
requests/unmatched/near-missesreturns one flat item per near miss, so each request (including its body) is repeated once per near miss. With 1000 unmatched requests and 200 mappings the response was about 5.7 MB. Would you prefer the admin responses grouped by request instead (one item per request, holding itsNearMisses)? These endpoints aren't released yet, so changing the shape now wouldn't be a breaking change. The C# API would stay flat either way, since there the request is shared by reference rather than copied.Tests
MappingMatcherTests: near misses exclude perfect matches and mismatches and are ordered best first;maxResults;Probabilityis ignored; mappings that throw are skipped.WireMockServerTests.NearMisses: unmatched filtering, including partial matches underAllowPartialMapping; ordering and match details; perfect matches excluded; disabled mappings excluded;maxResults; invalidmaxResultsthrows; the log-entry overload; near misses per unmatched request.WireMockAdminApiTests.NearMisses: all four endpoints throughIWireMockAdminApi, including perfect matches excluded, admin requests not counted,400for an invalidmaxResults, and404for an unknown request.Constants.NumAdminMappingsgoes from 39 to 43 for the four new admin routes.Also in this PR: scenario delay test fix
A separate commit fixes two existing tests,
Scenarios_FirstRequestWithDelay_StateTransitions_BeforeDelayCompletesandScenarios_WithGlobalRequestProcessingDelay_StateTransitions_BeforeDelayCompletes. They waited a fixed 100 ms for the scenario state to change, so they failed whenever they ran on a cold server, for example when run on their own (on master too). They now pollserver.Scenariosuntil the expected state is reached, with a 5 second timeout, and assert that the first request is still being delayed. Only test code changes.