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

Add GatewayPort configuration #67

Merged
merged 8 commits into from Oct 11, 2019
Merged

Add GatewayPort configuration #67

merged 8 commits into from Oct 11, 2019

Conversation

jonatasbaldin
Copy link
Contributor

Description

Allows the User to configure a custom GatewayPort in nats-queue-worker. Fixes #59.

Motivation and Context

  • I have raised an issue to propose this change (required)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have signed-off my commits with git commit -s
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Jonatas Baldin added 3 commits September 7, 2019 08:07
Signed-off-by: Jonatas Baldin <jonatas.baldin@gmail.com>
Signed-off-by: Jonatas Baldin <jonatas.baldin@gmail.com>
Signed-off-by: Jonatas Baldin <jonatas.baldin@gmail.com>
@derek derek bot added the new-contributor label Sep 7, 2019
Copy link

@acornies acornies left a comment

Choose a reason for hiding this comment

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

This looks good to me.

Copy link
Member

@alexellis alexellis left a comment

Choose a reason for hiding this comment

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

Sorry, just noticed these comments were pending and not sent yet.

readconfig.go Outdated
@@ -114,6 +120,7 @@ func (ReadConfig) Read() QueueWorkerConfig {
type QueueWorkerConfig struct {
NatsAddress string
GatewayAddress string
GatewayPort string
Copy link
Member

Choose a reason for hiding this comment

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

Please read as an int

Choose a reason for hiding this comment

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

Good catch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

cfg.GatewayPort = val
} else {
cfg.GatewayPort = "8080"
}
Copy link
Member

Choose a reason for hiding this comment

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

We could probably concatenate the value once here instead of passing two arguments everywhere.

I think the new env var makes sense to prevent issues upgrading versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

main.go Outdated
pathVal,
qs)

if config.GatewayInvoke {
functionURL = fmt.Sprintf("http://%s:8080/function/%s%s%s",
functionURL = fmt.Sprintf("http://%s:%s/function/%s%s%s",

Choose a reason for hiding this comment

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

We should probably make the entire url configurable and do something like url.Parse(). Opens the door for https etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's nice!

We could add yet a new variable called cfg.GatewayProtocol with http as the default value for backwards compatibility. What do you think?

Also, should we open a new issue/PR for that?

Jonatas Baldin added 2 commits September 11, 2019 18:19
Signed-off-by: Jonatas Baldin <jonatas.baldin@gmail.com>
Signed-off-by: Jonatas Baldin <jonatas.baldin@gmail.com>
@jonatasbaldin
Copy link
Contributor Author

I closed the PR by mistake 🤦‍♂ @alexellis, could you re run the build, please?

Also, you'll note that since I'm concatenating the cfg.GatewayAddress and cfg.GatewayPort I needed to change the test_gatewayaddr test to accommodate the port as well. It looks a bit odd, but it's working.

@jonatasbaldin
Copy link
Contributor Author

hey @alexellis, any comments on this? ✨ could u run the build again? hehe 🏃

@acornies
Copy link

acornies commented Oct 7, 2019

@alexellis please advise

@alexellis
Copy link
Member

Retrying the build.

main.go Outdated
@@ -30,14 +30,15 @@ func makeFunctionURL(req *queue.Request, config *QueueWorkerConfig, path, queryS
if len(path) > 0 {
pathVal = path
}
functionURL := fmt.Sprintf("http://%s%s:8080%s%s",
functionURL := fmt.Sprintf("http://%s%s:%d%s%s",
Copy link
Member

Choose a reason for hiding this comment

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

This has been changed incorrectly.

This line does not invoke via the gateway.

Copy link
Member

Choose a reason for hiding this comment

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

@acornies FYI ^

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

@@ -76,12 +77,18 @@ func Test_ReadConfig(t *testing.T) {
t.Fail()
}

expected = "test_gatewayaddr"
expected = "test_gatewayaddr:8080"
Copy link
Member

Choose a reason for hiding this comment

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

Can you use the word want instead of expected and gotinstead ofactual`? Thank you, see: https://blog.alexellis.io/golang-writing-unit-tests/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should then refactor the whole test file, since all tests are using expected and actual and we should do this in another PR. Do you agree?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but this is not refactoring, it's naming. Please go ahead.

Copy link
Member

@alexellis alexellis left a comment

Choose a reason for hiding this comment

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

Found a potential bug in the implementation, please see comment.

Signed-off-by: Jonatas Baldin <jonatas.baldin@gmail.com>
Copy link
Contributor Author

@jonatasbaldin jonatasbaldin left a comment

Choose a reason for hiding this comment

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

Comments answered 🎉

main.go Outdated
@@ -30,14 +30,15 @@ func makeFunctionURL(req *queue.Request, config *QueueWorkerConfig, path, queryS
if len(path) > 0 {
pathVal = path
}
functionURL := fmt.Sprintf("http://%s%s:8080%s%s",
functionURL := fmt.Sprintf("http://%s%s:%d%s%s",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

@@ -76,12 +77,18 @@ func Test_ReadConfig(t *testing.T) {
t.Fail()
}

expected = "test_gatewayaddr"
expected = "test_gatewayaddr:8080"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should then refactor the whole test file, since all tests are using expected and actual and we should do this in another PR. Do you agree?

Copy link
Member

@alexellis alexellis left a comment

Choose a reason for hiding this comment

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

Sending comments from mobile

if config.GatewayAddress != expected {
t.Logf("Expected GatewayAddress `%s` actual `%s`\n", expected, config.GatewayAddress)
t.Fail()
}

expectedGatewayPort := 8080
if config.GatewayPort != expectedGatewayPort {
t.Logf("Expected GatewayPort `%d` actual `%d`\n", expectedGatewayPort, config.GatewayPort)
Copy link
Member

Choose a reason for hiding this comment

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

I.e. GatewayPort want %d, got %d

Jonatas Baldin added 2 commits October 10, 2019 07:19
Signed-off-by: Jonatas Baldin <jonatas.baldin@gmail.com>
Signed-off-by: Jonatas Baldin <jonatas.baldin@gmail.com>
Copy link
Member

@alexellis alexellis left a comment

Choose a reason for hiding this comment

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

LGTM

@alexellis alexellis merged commit d35631d into openfaas:master Oct 11, 2019
@alexellis alexellis mentioned this pull request Nov 25, 2019
10 tasks
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.

Allow alternate port for gateway to invoke functions
3 participants