Skip to content
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

Dumb implementation for support --port and --host for hooks server #712

Closed

Conversation

ddelnano
Copy link
Contributor

@ddelnano ddelnano commented Feb 8, 2017

🚀 Why this change?

To allow compliant hooks servers to listen on different ports and ip addresses

📝 Related issues and Pull Requests

apiaryio/dredd-hooks-template#11
apiaryio/dredd-hooks-template#17

✅ What didn't I forget?

Still very much WIP since I believe there will need to be a discussion on what flags the hooks servers should look for (php already uses --port and --host but this can be up for discussion), how to stage these changes amongst the projects, etc. I just wanted to get the simplest thing done so that I could run the dredd-hooks-php cucumber tests with this new test to validate it works properly.

Copy link
Contributor

@honzajavorek honzajavorek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much! Especially for discovering the discrepancy in Dredd's universe. I like the change, but several things need to be resolved first:

@@ -163,9 +163,10 @@ class HooksWorkerClient
callback()

spawnHandler: (callback) ->
pathGlobs = [].concat @runner.hooks?.configuration?.options?.hookfiles
pathGlobs = [].concat ["--port", "#{@handlerPort}", "--host", "#{@handlerHost}"], @runner.hooks?.configuration?.options?.hookfiles
console.info pathGlobs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a debugging leftover? Maybe it was meant as logger.info?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, removed it.

@@ -163,9 +163,10 @@ class HooksWorkerClient
callback()

spawnHandler: (callback) ->
pathGlobs = [].concat @runner.hooks?.configuration?.options?.hookfiles
pathGlobs = [].concat ["--port", "#{@handlerPort}", "--host", "#{@handlerHost}"], @runner.hooks?.configuration?.options?.hookfiles
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, I'd probably call the variable args instead of pathGlobs (with subsequent changes in the code below).

Copy link
Contributor

@honzajavorek honzajavorek Feb 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, lately I tend to prefer to have all Dredd options in the GNU-style --option=value format, consistently. In the case of Dredd itself, both formats should work, I just wanted to choose one way to go and stick with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated both of these.

@ddelnano
Copy link
Contributor Author

ddelnano commented Feb 21, 2017

Todo

  • Find out impact for existing hook servers
    • php: compliant on most recent release (1.1.5), prior to that would have been unaffected.
    • go: would break existing hook servers.
    • ruby: should be ok (need to verify with test since I'm not confident with my ruby knowledge :) ) Update: verified it is good.
    • python: should be ok -- passes argv to glob which should ignore the new flags (need to verify but I'm more confident than the ruby one)
    • perl: @ungrim97 can you help out? Literally know nothing about perl. Also you might want to checkout this if you haven't seen it already.
  • Finish discussion on if this is what we want. I like the idea of Dredd being able to discover if hooks support these flags at runtime but this is a much bigger change.

@ungrim97
Copy link
Contributor

ungrim97 commented Feb 21, 2017

Will require an update to the perl hook script to support the port/host arguments. Passing them in to the current version shouldn't break anything. (it will look for hookfiles files called --port=1234 and --host=127.0.0.1 but obviously won't find one and will skip them)

Will make an update to accept the new params

@ungrim97
Copy link
Contributor

ungrim97/Dredd-Hooks#7 should cover whats needed to make the Perl version work for this

@ddelnano ddelnano force-pushed the support-hook-handler-port-and-host branch from c293998 to 47369b8 Compare February 21, 2017 11:00
@w-vi
Copy link
Member

w-vi commented Feb 21, 2017

I'll check Python hooks and see if I can implement this feature quickly.

@ddelnano ddelnano force-pushed the support-hook-handler-port-and-host branch from 47369b8 to bf2e480 Compare February 21, 2017 16:49
@ddelnano
Copy link
Contributor Author

@honzajavorek @w-vi @ungrim97 so looks like all existing hooks servers will not be affected by this change except the Go ones. How do we want to handle that? I can get those updated soon but wanted to understand better what the plan was.

@w-vi
Copy link
Member

w-vi commented Feb 21, 2017

Python hooks won't do anything bad, will skip the args so no issue here.

@ddelnano
Copy link
Contributor Author

But what I mean is do we want to continue down this path? It's going to cause existing go hook servers problems. All other hooks seem fine but still.

@honzajavorek
Copy link
Contributor

honzajavorek commented Feb 27, 2017

I'm sorry for not being prompt in answering (got sick). @ddelnano thanks very much for checking all the hooks! This is amazing work.

I see three options how to proceed:

  • Let the older Go hooks installations crash. I don't like it very much, but I can't decide, since I have very little insight into how many people use the Go hooks, how prompt they are in upgrading to newer versions, etc. Probably up to @ddelnano and @snikch to consider.
  • The features event mentioned by @w-vi in Add test for configurable port dredd-hooks-template#17 (comment) I like the idea, but implementing it would involve a lot of coding - both on hooks and Dredd sides. I'd prefer to have this as a future improvement instead of an instant solution. (I turned it into a separate issue: Hook handlers could provide Dredd with a list of supported features #723)
  • Hardcoded check. Is there a way we could hard code a simple check for Go hooks version? It's the least visually appealing solution, but doesn't involve much coding, doesn't make anything crash, and gets the job done.

What do you think?

@ddelnano ddelnano closed this Feb 27, 2017
@ddelnano ddelnano reopened this Feb 27, 2017
@ddelnano
Copy link
Contributor Author

@honzajavorek I definitely want to avoid option 1 :). And since the features event seems like alot more work than what we need for now some type of hard coded check will be necessary. I am going to brainstorm some ideas the rest of today and post back some potential ideas.

@ddelnano
Copy link
Contributor Author

@honzajavorek sorry for the long delay, had an unexpected hospital trip but I'm doing much better.

Another way we could check the hooks server that I thought of that would be very dumb but get the job done. We could have dredd try and run the hooks server with the --host and --port arguments and if it fails try it without the --host and --port flags. The drawback is that unrelated failures will probably fail twice. For the hardcoded version check on the Go hooks how would we accomplish that? There is no way to check the version using the go hook binary.

@honzajavorek
Copy link
Contributor

@ddelnano Whoa! 🚑 Whatever it was, I wish you to get better quickly!

The fact there is no way we can hardcode a check for go hooks version is unfortunate. I'll think about the trial & error approach. At first sight, I don't like it very much, but at the same time, it can be the only way we're left with to save the situation 🙂

@ddelnano
Copy link
Contributor Author

@honzajavorek thanks, things are back to normal now :).

One thing I didn't think of for the hardcoded check. In the next version of the go hooks we could add a command to output the version and then if it doesn't support the version command we can assume that it won't support the --host and --port.

@honzajavorek
Copy link
Contributor

@ddelnano What is the current behavior of go hooks if they're provided with --version? Do they start and wait for connection, do they crash, ...?

@ddelnano
Copy link
Contributor Author

It's going to crash...

@honzajavorek
Copy link
Contributor

honzajavorek commented Mar 24, 2017

Then I think we're okay with what you proposed in #712 (comment). Dredd could try to run the hook handler with options and if it crashes, it tries to run it without the options. If it doesn't crash, Dredd respects the test results.

@ddelnano
Copy link
Contributor Author

Ok. Yea obviously not ideal but there aren't many options unfortunately. This weekend I will have some time I'll give that a shot. And work on getting the go hooks updated to use the new flags.

@honzajavorek
Copy link
Contributor

I'm very sorry we were not able to get back to this. I need to close this as we're going to work on #705 first, which requires having no pending Pull Requests. We'll get back to this proposal as soon as we're addressing #917. Finishing this PR is listed on #917 as one of the necessary steps, so it shouldn't get forgotten. Thank you for the contribution! I hope we'll have the chance to tidy up the template soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants