wiremock / wiremock-state-extension

Adds support for transporting state across different API mock stubs
Apache License 2.0
16 stars 5 forks source link

Add option to control state expiration #101

Open Tunduk opened 11 months ago

Tunduk commented 11 months ago

Proposal

In my case of usage, 60 min is too long. We run wiremock in k8s with pretty narrow memory limits and we have memory leaks. I fixed my problem with deleteState but it would be great to have the ability to control state expiration. I think 2 kinds of settings are needed:

  1. Global setting (something like --state-expiration for run args)
  2. By context name. Just a new property for the recordState action. Both kinds of settings should use seconds as an input value

Of course, I would like to help with it. Let me know if I can open a PR

References

No response

dirkbolte commented 11 months ago

That's a good idea and any contribution is highly welcome.

WRT implementation: the extension has no internal knowledge about the characteristics of the store, and it should stay that way in order to make it replaceable. Thus having a context-specific expiration might be difficult - at least on stub-configuration level. For the global configuration, I'm looking for a way to make this fit nicely into the architecture. Alternatively, as backup: with the latest update you can delete multiple contexts. So creating an artificial endpoint to remove all contexts might be a mitigation as well:

"serveEventListeners": [
    {
      "name": "deleteState",
      "parameters": {
        "contextsMatching": ".*"
      }
    }
  ]