hoverfly icon indicating copy to clipboard operation
hoverfly copied to clipboard

Simulate and capture-on-miss mode

Open WouldYouKindly opened this issue 5 years ago • 12 comments

Hi!

I have a long workflow where I call multiple services. Sometimes I add or modify a call in the middle. I want to update my simulations, and have to re-record everything. It is very time-consuming to prepare real services for capturing.

It would be great to have a mode when Hoverfly simulates the requests that match, while passing the ones that don't to real services. It would allow me to upload a simulation (maybe having removed the changed requests from it beforehand), start my test, and have an updated simulation at the end.

WouldYouKindly avatar Jul 11 '19 11:07 WouldYouKindly

Do you know if mock-server or wiremock have this feature?

crorodriguezro avatar Jul 11 '19 12:07 crorodriguezro

Hoverfly has a spy mode that does simulate or pass through, so we can add a flag to change the not-found behaviour to capture, something like this:

hoverctl mode spy --capture-on-miss

or making it a string flag to support other on-miss behaviours in the future.

hoverctl mode spy --on-miss=capture

I don't think mock-server or wiremock has this feature. Hoverfly is a MITM proxy supports both HTTP/HTTPS, it's more flexible in terms of forward proxying.

tommysitu avatar Jul 11 '19 14:07 tommysitu

We have a somewhat different use-case where I believe such a capture-on-miss feature could be useful.

We are using Hoverfly (for Java) to auto-mock requests to other services, in a micro-service architecture.

For example, one of our dependent services, D, will call another of our services, S, which in turn depend on some external service X.

When writing tests for service S, we would like to Simulate (or Spy) requests to service X from a previously captured file specific to service X. At the same time (while running these tests) we want to Capture the requests to service S (the service under test), so this capture file can later be used for auto mocking in the tests for service D.

Simulating and Capturing at the same time with a single Hoverfly instance would be very useful here, I believe?

larsthorup avatar Nov 27 '19 13:11 larsthorup

@larsthorup I think only simulating the direct dependencies for each SUT is easier. For example,

  1. Test X by simulating S
  2. Then test S by simulating D.

tommysitu avatar Nov 27 '19 22:11 tommysitu

Thank you @tommysitu.

I think I might have been unclear in my explanation of the direction of dependencies between the services.

Going with your reply, the services would call each other like this:

X -> S -> D

(so: X call S, and S call D)

In your step 2 we would AT THE SAME TIME capture the test-requests to S WHILE simulating the requests to D, because we would then later in step 1 while testing X use those previously captured requests to S to simulate S.

As far as I can see, this require us to do capture and simulate simultaneously, currently requiring us to orchestrate two Hoverfly instances.

And for this case, wouldn't hoverctl mode spy --on-miss=capture be a more elegant solution?

larsthorup avatar Nov 28 '19 14:11 larsthorup

haven't thought of that, but it seems like a fair use case. The only problem is that you will be mixing two simulations in one file.

tommysitu avatar Dec 02 '19 22:12 tommysitu

@tommysitu How big a task do you think this would be? Would you be interested in pull-requests to implement this feature?

larsthorup avatar Dec 13 '19 08:12 larsthorup

Hi. I also come up to nearly similar issue (start with spy mode, capture and write response to simulation.json if request is not found in simulation.json). I really liked this solution, hoverctl mode spy --capture-on-miss but seems that it has not been implemented(at least I didn't found something similar in reference/docs). Will you consider it or I should go with larsthorup's workaround?

odorT avatar May 13 '22 20:05 odorT

@tommysitu are we still looking out to build this feature?

kapishmalik avatar Mar 03 '23 16:03 kapishmalik

@odorT @WouldYouKindly I have raised PR for this feature. Probably in couple of days, we should have this feature.

kapishmalik avatar Mar 10 '23 10:03 kapishmalik

When will this feature be available? Thanks.

ayyasaran avatar Jul 12 '23 21:07 ayyasaran

@tommysitu lot of folks are looking out for this feature.

kapishmalik avatar Apr 21 '24 03:04 kapishmalik

This feature is now available in release v1.9.2.

kapishmalik avatar May 06 '24 09:05 kapishmalik

You can enable capture on miss flag using hoverctl command line or while starting hoverfly.

kapishmalik avatar May 06 '24 09:05 kapishmalik

You can enable capture on miss flag using hoverctl command line or while starting hoverfly.

So hoverctl mode spy --capture-on-miss works for me, but I can't seem to make it work with calling hoverfly directly:

$ hoverfly -spy -capture-on-miss -listen-on-host 0.0.0.0 -log-level error -log-no-color -logs json
flag provided but not defined: -capture-on-miss

Also, the flag is listed in the help command for hoverctl mode, but not with hoverfly.

Did I misunderstand or am I doing it wrong?

johenning avatar May 06 '24 10:05 johenning

@johenning oh yes, my bad. We have not added here. We can enable via Admin API by passing argument with mode and hoverctl cmd for now.

kapishmalik avatar May 06 '24 10:05 kapishmalik

@kapishmalik all good, just wanted to make sure I'm understanding it right. I'm just going to set the flag via the REST API:

PUT /api/v2/hoverfly/mode
{
    "mode": "spy",
    "arguments": {
        "captureOnMiss": true
    }
}

johenning avatar May 06 '24 10:05 johenning

@johenning yea correct. We will be soon adding documentation.

kapishmalik avatar May 06 '24 10:05 kapishmalik