-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: admin API endpoints to find/remove unmatched stub mappings #2991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
302e68d to
3ae35e7
Compare
| }, | ||
| "after-pattern": { | ||
| "title": "Before datetime", | ||
| "title": "After datetime", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change (and the rest of the changes in this file) are unrelated and the result of running cd ui && npm run swagger to regenerate this file, so I assume somebody forgot to do that. Probably should automate that as part of the build process.
This integrates the functionality of https://github.com/MasonM/wiremock-unused-stubs-extension into WireMock proper, as requested in wiremock#615 (comment). Specifically, it adds two endpoints: * `GET /__admin/mappings/unmatched` - Retrieve stub mappings that haven't matched any requests in the journal. * `DELETE /__admin/mappings/unmatched` - Remove all such stub mappings. Note that the extension supports an additional `?remove_files=1` query parameter that I didn't include here because that introduces some additional complications: https://github.com/MasonM/wiremock-unused-stubs-extension/blob/424dfad1a21e25d588ac9230a46be820a579d7cf/src/main/java/com/github/masonm/wiremock/UnusedStubsAdminExtension.java#L71 I added that feature because it was requested in MasonM/wiremock-unused-stubs-extension#1, though I haven't personally used it much, so I'm not sure if it's worth porting. Signed-off-by: Mason Malone <651224+MasonM@users.noreply.github.com>
3ae35e7 to
74c40ed
Compare
| } | ||
|
|
||
| @Test | ||
| void findUnmatchedStubMappingsWithNoMappings() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it's probably best to split this up into separate test files for each endpoint or group (e.g. AdminApiMappingsTest, AdminApiRequestsTest, etc), since it's getting a bit hard to follow. I'm not sure where to put them, though. Maybe src/test/java/com/github/tomakehurst/wiremock/admin/acceptance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we could do that as a separate refactor PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could, but I don't know where to put these tests.
|
This looks great. Would it be possible to add a docs PR to explain how to use the new endpoint and update the API reference here - https://wiremock.org/docs/standalone/admin-api-reference/ |
This documents the functionality in wiremock/wiremock#2991, as requested by @leeturner. I wasn't able to get the dev environment running because of multiple different errors. For example, `yarn` failed to install or compile `node-sass` for some reason: ```console $ yarn yarn install v1.22.22 [1/5] Validating package.json... [2/5] Resolving packages... warning @redocly/cli > glob@7.2.3: Glob versions prior to v9 are no longer supported [3/5] Fetching packages... [4/5] Linking dependencies... warning " > redoc@2.1.5" has unmet peer dependency "core-js@^3.1.4". warning " > redoc@2.1.5" has unmet peer dependency "mobx@^6.0.4". warning " > redoc@2.1.5" has unmet peer dependency "react@^16.8.4 || ^17.0.0 || ^18.0.0". warning " > redoc@2.1.5" has unmet peer dependency "react-dom@^16.8.4 || ^17.0.0 || ^18.0.0". warning " > redoc@2.1.5" has unmet peer dependency "styled-components@^4.1.1 || ^5.1.1 || ^6.0.5". warning "redoc > @cfaester/enzyme-adapter-react-18@0.8.0" has unmet peer dependency "enzyme@^3.11.0". warning "redoc > @cfaester/enzyme-adapter-react-18@0.8.0" has unmet peer dependency "react@>=18". warning "redoc > @cfaester/enzyme-adapter-react-18@0.8.0" has unmet peer dependency "react-dom@>=18". warning "redoc > mobx-react@9.1.1" has unmet peer dependency "mobx@^6.9.0". warning "redoc > mobx-react@9.1.1" has unmet peer dependency "react@^16.8.0 || ^17 || ^18". warning "redoc > react-tabs@6.0.2" has unmet peer dependency "react@^18.0.0". warning "redoc > @cfaester/enzyme-adapter-react-18 > react-shallow-renderer@16.15.0" has unmet peer dependency "react@^16.0.0 || ^17.0.0 || ^18.0.0". warning "redoc > mobx-react > mobx-react-lite@4.0.7" has unmet peer dependency "mobx@^6.9.0". warning "redoc > mobx-react > mobx-react-lite@4.0.7" has unmet peer dependency "react@^16.8.0 || ^17 || ^18". warning "redoc > mobx-react > mobx-react-lite > use-sync-external-store@1.2.2" has unmet peer dependency "react@^16.8.0 || ^17.0.0 || ^18.0.0". warning "@redocly/cli > @redocly/respect-core > better-ajv-errors@1.2.0" has unmet peer dependency "ajv@4.11.8 - 8". [5/5] Building fresh packages... [1/4] ⡀ node-sass [2/4] ⡀ core-js [-/4] ⡀ waiting... error /home/masonm/src/wiremock.org/node_modules/node-sass: Command failed. Exit code: 1 Command: node scripts/build.js Arguments: Directory: /home/masonm/src/wiremock.org/node_modules/node-sass Output: Binary found at /home/masonm/src/wiremock.org/node_modules/node-sass/vendor/linux-x64-127/binding.node Testing binary Binary has a problem: Error: /home/masonm/src/wiremock.org/node_modules/node-sass/vendor/linux-x64-127/binding.node: file too short at Object..node (node:internal/modules/cjs/loader:1734:18) at Module.load (node:internal/modules/cjs/loader:1318:32) at Function._load (node:internal/modules/cjs/loader:1128:12) at TracingChannel.traceSync (node:diagnostics_channel:322:14) at wrapModuleLoad (node:internal/modules/cjs/loader:219:24) at Module.require (node:internal/modules/cjs/loader:1340:12) at require (node:internal/modules/helpers:138:16) at module.exports (/home/masonm/src/wiremock.org/node_modules/node-sass/lib/binding.js:19:10) at Object.<anonymous> (/home/masonm/src/wiremock.org/node_modules/node-sass/lib/index.js:13:35) at Module._compile (node:internal/modules/cjs/loader:1565:14) { code: 'ERR_DLOPEN_FAILED' } Building the binary locally Building: /home/masonm/.volta/tools/image/node/22.12.0/bin/node /home/masonm/src/wiremock.org/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library= <SNIP THOUSANDS OF LINES OF COMPILER ERRORS> ``` Also, Jekyll gave a different error: ```console $ bundle exec jekyll serve --config '_config.yml' Configuration file: /home/masonm/src/wiremock.org/_config.yml To use retry middleware with Faraday v2.0+, install `faraday-retry` gem Source: /home/masonm/src/wiremock.org Destination: /home/masonm/src/wiremock.org/_site Incremental build: disabled. Enable with --incremental Generating... Jekyll Feed: Generating feed for posts ------------------------------------------------ Jekyll 4.3.2 Please append `--trace` to the `serve` command for any additional information or backtrace. ------------------------------------------------ /home/masonm/src/wiremock.org/vendor/bundle/ruby/3.2.0/gems/json-1.8.6/lib/json/common.rb:155:in `initialize': wrong number of arguments (given 2, expected 1) (ArgumentError) Parser.new(source, opts).parse ^^^^^^^^^^^^ from /home/masonm/src/wiremock.org/vendor/bundle/ruby/3.2.0/gems/json-1.8.6/lib/json/common.rb:155:in `new' from /home/masonm/src/wiremock.org/vendor/bundle/ruby/3.2.0/gems/json-1.8.6/lib/json/common.rb:155:in `parse' ``` I'm guessing the Jekyll error is because I'm on Ruby 3.2, and I don't have Ruby 2.7 installed. If there's a Docker container for this, I can try that, but I really don't want to install more stuff on my host machine. Signed-off-by: Mason Malone <651224+MasonM@users.noreply.github.com>
|
@leeturner Sure, done: wiremock/wiremock.org#351 |
|
Many thanks for your contribution |
feat: admin API endpoints to find/remove unmatched stub mappings
This integrates the functionality of https://github.com/MasonM/wiremock-unused-stubs-extension into WireMock proper, as requested in #615 (comment).
Specifically, it adds two endpoints:
GET /__admin/mappings/unmatched- Retrieve stub mappings that haven't matched any requests in the journal.DELETE /__admin/mappings/unmatched- Remove all such stub mappings.Note that the extension supports an additional
?remove_files=1query parameter that I didn't include here because it introduces some additional complications (https://github.com/MasonM/wiremock-unused-stubs-extension/blob/424dfad1a21e25d588ac9230a46be820a579d7cf/src/main/java/com/github/masonm/wiremock/UnusedStubsAdminExtension.java#L71). I added that feature because it was requested in Calling DELETE /__admin/unused_mappings does not delete from __files MasonM/wiremock-unused-stubs-extension#1, but I haven't personally used it much, so I'm not sure if it's worth porting.References
Submitter checklist
#help-contributingor a project-specific channel like#wiremock-java