-
Notifications
You must be signed in to change notification settings - Fork 208
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
add bodyFile to response part of pair #893
Conversation
Good stuff! I'll review it this week. |
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.
It's a good try. Let me know if you need any help.
@tommysitu thanks for review. only 1 question for now. Does making v6 require copy pasting v5, renaming every struct to v6 and replacing v5 with v6 in all tests and other files? |
pretty much. also you need to add a function to upgrade v5 to v6 in |
@tommysitu ok, got it, but I'm curios :-) wouldn't it be much easier to maintain the project with only 1 schema and avoiding BC? And in case of BC, release new major version with a migration guide (or a tool to upgrade existing files)? |
It's a little bit extra work to do but we can ensure that existing users can benefit from hoverfly upgrades without breaking their tests and CI pipelines. It could spark lots of support issues which is what we try to avoid. |
@tommysitu Ok :-) Here we go again. |
Nice, will check it out soon |
I've added error handling when bodyFile is missing. |
@tommysitu any chance you can review it soon? so i'll get on docs and tests |
this weekends for sure |
@ns3777k Thank you for your patience. I've finally got a chance to test it thoroughly. Here is what I found:
|
I have fixed the comments above.
|
Regarding to the comments:
In the issue #815, @BrainStone proposed that the relative path could be relative to the Simulation file. I think that's a good idea, as you can keep these body files side-by-side to the simulation where they can be found easily. For example, you can store your simulation and body file with this structure:
and the
|
|
you're right, it won't work if hoverfly is remote. What about reading the bodyFile is done locally in |
I've got confused a little 😃 So, first off is to patch hoverctl to loop through all pairs, replacing bodyFile with body filled with files' contents. Would be a little tricky 'cause we should unmarshal simulation data, but no problems so far. Then patch hoverfly import cmd to do the same thing. Question is: should I keep v6 with bodyFile in schema? |
Not entirely sure if reading the
sorry for contradicting to what I said 😳 . I underestimated the challenges of adding this feature. So if we keep what you have done, then we must find a way to handle relative path. Any thoughts? Nevertheless, we should keep the v6 schema. |
Here's what I've tried:
|
that's correct because your cwd is not |
ok, it's relative to where the hoverfly binary is executed. |
It can find the file in That's usually |
race condition 😄 so, there are a couple things left here:
right? |
pretty much. If you can fix 1 that will be great. 🌟 feel free to do 2 and 3 in a separate PR |
According to removal the simulation on a file error. I think I've found one easy way to prevent this.
Pseudo code:
before: func (this *Hoverfly) DeleteSimulation() {
this.Simulation.DeleteMatchingPairs()
this.DeleteResponseDelays()
this.DeleteResponseDelaysLogNormal()
this.FlushCache()
} after: func (this *Hoverfly) RestoreSimulation(s *models.Simulation) {
this.Simulation.DeleteMatchingPairs()
this.Simulation.ResponseDelays = s.ResponseDelays
this.Simulation.ResponseDelaysLogNormal = s.ResponseDelaysLogNormal
pairs := s.GetMatchingPairs()
this.Simulation.AddPairs(pairs)
}
func (this *Hoverfly) DeleteSimulation() *models.Simulation {
pairs := this.Simulation.DeleteMatchingPairs()
delays := this.DeleteResponseDelays()
delaysLogNormal := this.DeleteResponseDelaysLogNormal()
this.FlushCache()
s := models.NewSimulation()
s.ResponseDelays = d1
s.ResponseDelaysLogNormal = d2
s.AddPairs(pairs)
return s
} In There is a thing I didn't figure out for now. From what I see, ResponseDelays and ResponseDelaysLogNormal can be written in and read from but they are not protected with a mutex. |
Sorry for the late reply, I was under the weather. Just looked at your proposed solution, I'm a bit wary about the potential performance impact. We were aware that some hoverfly users have huge simulation files loaded in. It would be great if none of the existing hoverfly users gets much penalty for upgrading. What about looping through the pair, and testing any presence of We already have |
After thinking more about the relative path, we could make it a config option for user to specify where the root path it's relative to. That should solve the problem when user wants to store the file somewhere else rather than the cwd of hoverfly binary. |
Actually, current |
ignore os.openfile, that was my brain fart. What about os.stat()? It only reads the file metadata. I can’t tell what the actual performance is without a benchmark. I’m suggesting that we should do something to avoid impacting existing users when they upgrade. Alternatively It can do the backup only when body file is used. |
os.stat does not check whether a file is able to be read by the process (e.g. permissions) it can only tell that a file exists. i'll dig deeper soon :-) |
Thanks for looking into this! |
…iles before dropping simulation
So, that's what I've come up with (latest commit):
I moved the body reading part into
|
what's the plan? 🕵️♂️ should i start on the docs and tests? or you need some time to review this (last commit should solve previous issues)? should i make a separate pr for tests and docs? |
No urgency. Just wanted to know the plan 😄 sounds cool |
We will get there. I'll find more spare time on this and getting v1.2 out in the next couple of weeks. 💪 |
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've tested it, it's working really well, especially you can load an image file without storing it in the simulation. Just nitpicking over some tiny details
dir, err := os.Getwd() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
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.
Is this needed? I thought if the root path is empty, the default resolving location will be the cwd?
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.
Yes 'cause getting the cwd can return an error (e.g. http://man7.org/linux/man-pages/man2/getcwd.2.html).
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.
But I'll double check if we can ignore the error and keep the dir
variable to be an empty string. Thus we just delay the error handling and it'll occur when a bodyFile is not able to be read from in case it contains a relative path.
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.
what I meant is:
ioutil.ReadFile(filepath.Join("", pair.Response.GetBodyFile()))
should read the file under the current working directory, right?
so setting the response-body-files-path
to "" should be equivalent to setting it to os.Getwd()
?
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.
Oh, yes. I used the os.Getwd
to show the current dir in --help
information, otherwise there will be an empty string there. Should I remove it?
Also I realized one more thing: you've loaded the file and put it in the |
Yes, that's exactly what I asked some days ago #893 (comment) 😄 I'll think what can be done to avoid this. |
This PR is on the right track, I quite like to merge it to the next release branch (https://github.com/SpectoLabs/hoverfly/tree/v1.2.0). Do you mind reopen this issue for merging into the v1.2.0 branch? Then we can tackle the export issue. Thanks! |
also it's quite a long thread, that's probably why I was losing track 😆 |
I've switched the base branch to |
Hey!
I'm working on #815 and decided to make a PR so you can tell me if I'm on the right track. Tests pass locally, not sure why they are not run on CI here.
I'll add new tests and update docs after successful review.
Thanks.