How best to manage/switch remote configuration for proxying(recording) versus matching(mocking) ? #410

Closed
opened 2025-12-29 08:27:35 +01:00 by adam · 17 comments
Owner

Originally created by @PrzemekScott on GitHub (Mar 15, 2022).

After some local experiments with WM, now I started some with WM running as a Kubernetes pod.
When in local, each time I wanted to use WM for proxying or for matching I was simply restarting it with configuration changed appropriately. Mappings were kept on local folder so sucha a restart wasn’t a problem - mappings were not lost.

Yet now, when WM running as a pod its space for keeping folders/files will be vanished each time WM will be redeployed with changed configuration.



So, @StefH could you please share if it is possible to change the configuration on the fly? - the /settings endpoint does not reach to Proxy settings.

Originally created by @PrzemekScott on GitHub (Mar 15, 2022). After some local experiments with WM, now I started some with WM running as a Kubernetes pod. When in local, each time I wanted to use WM for proxying or for matching I was simply restarting it with configuration changed appropriately. Mappings were kept on local folder so sucha a restart wasn’t a problem - mappings were not lost. Yet now, when WM running as a pod its space for keeping folders/files will be vanished each time WM will be redeployed with changed configuration.

 So, @StefH could you please share if it is possible to change the configuration on the fly? - the /settings endpoint does not reach to Proxy settings.
adam added the question label 2025-12-29 08:27:35 +01:00
adam closed this issue 2025-12-29 08:27:35 +01:00
Author
Owner

@StefH commented on GitHub (Mar 15, 2022):

@PrzemekScott
In case of proxy mode; I could ignore all calls made to /__admin/***.

Would that help you?

@StefH commented on GitHub (Mar 15, 2022): @PrzemekScott In case of proxy mode; I could ignore all calls made to `/__admin/***`. Would that help you?
Author
Owner

@PrzemekScott commented on GitHub (Mar 16, 2022):

@StefH
hm... not sure

your context = thorough knowledge of WM
my context = still very basic knowledge of WM

so can you please elaborate more on your idea?
You mean "ignore all calls made to /__admin/*** " from being saved to mappings?

P.S. I've tried to change settings on the fly - when WM is running as a pod - with POST /__admin/settings.
WM is running with "AllowPartialMapping": false,
so I've sent "AllowPartialMapping": true,
I got response 200 "Status": "Settings updated"
yet when sending GET /__admin/settings
unfortunately got still "AllowPartialMapping": false

@PrzemekScott commented on GitHub (Mar 16, 2022): @StefH hm... not sure your context = thorough knowledge of WM my context = still very basic knowledge of WM so can you please elaborate more on your idea? You mean "ignore all calls made to /__admin/*** " from being saved to mappings? P.S. I've tried to change settings on the fly - when WM is running as a pod - with POST /__admin/settings. WM is running with "AllowPartialMapping": false, so I've sent "AllowPartialMapping": true, I got response 200 "Status": "Settings updated" yet when sending GET /__admin/settings unfortunately got still "AllowPartialMapping": false
Author
Owner

@StefH commented on GitHub (Mar 18, 2022):

What I mean is that when WireMock.Net is running in proxy mode, it should still allow you to change the configuration by allowing calls to /__admin/settings. (This requires a change in the code.)

@StefH commented on GitHub (Mar 18, 2022): What I mean is that when WireMock.Net is running in proxy mode, it should still allow you to change the configuration by allowing calls to `/__admin/settings`. (This requires a change in the code.)
Author
Owner

@PrzemekScott commented on GitHub (Mar 18, 2022):

Ok, yes, that would be great.

Maybe I missconcept something, so please @StefH correct me.
But I understand that the best way to work with WM when testing is to create mappings (less often usage) during proxying/recording, and then to switch WM to matching mode (most of the time usage).

So I can configure it to work as proxy for recording (example below) - less often:



"WireMockServerSettings": {
    "StartAdminInterface": true,
    "Urls": [
      "http://localhost:8080/"
    ],
    "AllowPartialMapping": false,
    "HandleRequestsSynchronously": true,
    "ThrowExceptionWhenMatcherFails": true,
    "ProxyAndRecordSettings": {
      "Url": “some url to proxy”,
      "SaveMapping": true,
      "SaveMappingToFile": true
    }
}

Or I can configure it to work as a matcher (example below) - most of the time:

"WireMockServerSettings": {
    "StartAdminInterface": true,
    "Urls": [
      "http://localhost:8080/"
    ],
    "AllowPartialMapping": false,
    "HandleRequestsSynchronously": true,
    "ThrowExceptionWhenMatcherFails": true,
    "ReadStaticMappings": true,
    "ProxyAndRecordSettings": {
    }
}



When WM is run remotely, as mine, as a Kubernetes pod, deployed from Azure as a web application, when initialised it reads configuration from appsettings.json file.

But it would be great to have option to switch between these ^ configurations when service is running, so by the usage of some endpoint, without a need of redeploying WM cause then all files and folders will be vanished, so one would need first to download them, then upload again etc. Well, this downloading and uploading is still doable.



Also maybe you see a different way of approaching this case (configuring WM), which I do not see cause still learning about WM options, so please share. Thanks!

@PrzemekScott commented on GitHub (Mar 18, 2022): Ok, yes, that would be great. Maybe I missconcept something, so please @StefH correct me. But I understand that the best way to work with WM when testing is to create mappings (less often usage) during proxying/recording, and then to switch WM to matching mode (most of the time usage). So I can configure it to work as proxy for recording (example below) - less often:

 ``` json "WireMockServerSettings": { "StartAdminInterface": true, "Urls": [ "http://localhost:8080/" ], "AllowPartialMapping": false, "HandleRequestsSynchronously": true, "ThrowExceptionWhenMatcherFails": true, "ProxyAndRecordSettings": { "Url": “some url to proxy”, "SaveMapping": true, "SaveMappingToFile": true } } ``` Or I can configure it to work as a matcher (example below) - most of the time: ``` json "WireMockServerSettings": { "StartAdminInterface": true, "Urls": [ "http://localhost:8080/" ], "AllowPartialMapping": false, "HandleRequestsSynchronously": true, "ThrowExceptionWhenMatcherFails": true, "ReadStaticMappings": true, "ProxyAndRecordSettings": { } } ``` 

When WM is run remotely, as mine, as a Kubernetes pod, deployed from Azure as a web application, when initialised it reads configuration from appsettings.json file. But it would be great to have option to switch between these ^ configurations when service is running, so by the usage of some endpoint, without a need of redeploying WM cause then all files and folders will be vanished, so one would need first to download them, then upload again etc. Well, this downloading and uploading is still doable. 

Also maybe you see a different way of approaching this case (configuring WM), which I do not see cause still learning about WM options, so please share. Thanks!
Author
Owner

@PrzemekScott commented on GitHub (Mar 24, 2022):

Hey @StefH have you had a chance to work on this ^, or if not when do you think you could? thanks

@PrzemekScott commented on GitHub (Mar 24, 2022): Hey @StefH have you had a chance to work on this ^, or if not when do you think you could? thanks
Author
Owner

@PrzemekScott commented on GitHub (Mar 29, 2022):

Hey @StefH . We went with solution of deploying WM with different settings each time its needed.

@PrzemekScott commented on GitHub (Mar 29, 2022): Hey @StefH . We went with solution of deploying WM with different settings each time its needed.
Author
Owner

@StefH commented on GitHub (Apr 3, 2022):

I noticed that when running WM in Proxy, you can GET and UPDATE the settings via the admin interface (WM still responds to calls to the _admin endpoint).

However, I found a small bug that not all settings were retrieved.

And there is no way yet to GET or SET the ProxyAndRecordSettings, I'll need to update the code to support these settings also.

@StefH commented on GitHub (Apr 3, 2022): I noticed that when running WM in Proxy, you can GET and UPDATE the settings via the admin interface (WM still responds to calls to the `_admin` endpoint). However, I found a small bug that not all settings were retrieved. And there is no way yet to GET or SET the **ProxyAndRecordSettings**, I'll need to update the code to support these settings also.
Author
Owner

@StefH commented on GitHub (Apr 4, 2022):

@PrzemekScott

I've changed the code so that you now can get / post the (proxy)settings to a running WireMock instance.

You need preview version 1.4.40-ci-16011 for that.

@StefH commented on GitHub (Apr 4, 2022): @PrzemekScott I've changed the code so that you now can get / post the (proxy)settings to a running WireMock instance. You need preview version `1.4.40-ci-16011` for that.
Author
Owner

@jatin-prusty-travelport commented on GitHub (Apr 12, 2022):

@StefH I was checking the preview version and found that post was able to update the proxy settings correctly. But after that when I try to mock a call I get error. So here is the sequence of steps:

  1. Ran the mock server with proxy mode enabled (with ProxyAndRecordSettings)
  2. Captured one mappings by calling the proxy URL
  3. Used the API to update settings and got rid of ProxyAndRecordSettings
  4. Made the same proxy URL call again expecting the response to be served from the mapping
    But then I received this error response:
    {
    "Status": "Object reference not set to an instance of an object."
    }

Can you please check?
cc: @PrzemekScott

@jatin-prusty-travelport commented on GitHub (Apr 12, 2022): @StefH I was checking the preview version and found that post was able to update the proxy settings correctly. But after that when I try to mock a call I get error. So here is the sequence of steps: 1) Ran the mock server with proxy mode enabled (with ProxyAndRecordSettings) 2) Captured one mappings by calling the proxy URL 3) Used the API to update settings and got rid of ProxyAndRecordSettings 4) Made the same proxy URL call again expecting the response to be served from the mapping But then I received this error response: { "Status": "Object reference not set to an instance of an object." } Can you please check? cc: @PrzemekScott
Author
Owner

@StefH commented on GitHub (Apr 14, 2022):

Please check preview version 1.4.40-ci-16018

@StefH commented on GitHub (Apr 14, 2022): Please check preview version 1.4.40-ci-16018
Author
Owner

@StefH commented on GitHub (Apr 16, 2022):

@jatin-prusty-travelport
@PrzemekScott

I think the functionality works fine now:

  1. Ran the mock server with proxy mode enabled (with ProxyAndRecordSettings)
  2. Captured one mappings by calling the proxy URL
  3. Used the API to update settings and got rid of ProxyAndRecordSettings
  4. Made the same call again and it's served from the mapping

Please try version 1.4.40-ci-16022.

@StefH commented on GitHub (Apr 16, 2022): @jatin-prusty-travelport @PrzemekScott I think the functionality works fine now: 1. Ran the mock server with proxy mode enabled (with ProxyAndRecordSettings) 2. Captured one mappings by calling the proxy URL 3. Used the API to update settings and got rid of ProxyAndRecordSettings 4. Made the same call again and it's served from the mapping Please try version `1.4.40-ci-16022`.
Author
Owner

@StefH commented on GitHub (Apr 21, 2022):

@jatin-prusty-travelport
@PrzemekScott

Did you have time to test ?

@StefH commented on GitHub (Apr 21, 2022): @jatin-prusty-travelport @PrzemekScott Did you have time to test ?
Author
Owner

@jatin-prusty-travelport commented on GitHub (Apr 21, 2022):

@StefH I tested the versions today. It works fine in 1.4.40-ci-16018 but it's broken in 1.4.40-ci-16022.
cc: @PrzemekScott

@jatin-prusty-travelport commented on GitHub (Apr 21, 2022): @StefH I tested the versions today. It works fine in 1.4.40-ci-16018 but it's broken in 1.4.40-ci-16022. cc: @PrzemekScott
Author
Owner

@StefH commented on GitHub (Apr 21, 2022):

Broken means incorrect behavior?
Or 'Object reference not set to an instance of an object.'?

@StefH commented on GitHub (Apr 21, 2022): Broken means incorrect behavior? Or 'Object reference not set to an instance of an object.'?
Author
Owner

@jatin-prusty-travelport commented on GitHub (Apr 21, 2022):

Apologies @StefH. I checked again and both the version are working fine. Probably last time the nuget packages weren't restored correctly.
Thanks for all the help!
cc: @PrzemekScott

@jatin-prusty-travelport commented on GitHub (Apr 21, 2022): Apologies @StefH. I checked again and both the version are working fine. Probably last time the nuget packages weren't restored correctly. Thanks for all the help! cc: @PrzemekScott
Author
Owner

@StefH commented on GitHub (Apr 21, 2022):

Cool.

I'll merge this branch today and create a new official version.

@StefH commented on GitHub (Apr 21, 2022): Cool. I'll merge this branch today and create a new official version.
Author
Owner

@PrzemekScott commented on GitHub (Apr 21, 2022):

Thanks @StefH !

@PrzemekScott commented on GitHub (Apr 21, 2022): Thanks @StefH !
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#410