Update nats-queue-worker package to 0.4.7

This package version supports running OpenFaas on hosts the contain `.`
in their hostname i.e. computer-a.acme.com

Signed-off-by: Edward Wilde <ewilde@gmail.com>
This commit is contained in:
Edward Wilde 2018-06-21 20:30:28 +01:00 committed by Alex Ellis
parent 08d57de1f6
commit e39dbd9584
6 changed files with 37 additions and 6 deletions

6
gateway/Gopkg.lock generated
View File

@ -75,8 +75,8 @@
[[projects]]
name = "github.com/openfaas/nats-queue-worker"
packages = ["handler"]
revision = "62e8dcfe87fc01de8b94156f3e4291370c0c84a8"
version = "0.4.6"
revision = "15287c9b2af293cee0c545ccc014a68e1f0a4424"
version = "0.4.7"
[[projects]]
name = "github.com/prometheus/client_golang"
@ -112,6 +112,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "181fb3c695e3b12e0a8e967135ef717ea83d9525c7c31b92f641d7a963d26254"
inputs-digest = "f6e74bc55788e9ad6ea33f02d2be398013705f4606c29bbead71ac41a3c19514"
solver-name = "gps-cdcl"
solver-version = 1

View File

@ -14,7 +14,7 @@ ignored = ["github.com/openfaas/faas/gateway/queue"]
[[constraint]]
name = "github.com/openfaas/nats-queue-worker"
version = "0.4.5"
version = "0.4.7"
[[constraint]]
name = "github.com/prometheus/client_golang"

View File

@ -17,7 +17,7 @@ install:
- echo "Please don't go get"
script:
- cd queue-worker && ./build.sh
- ./build.sh
after_success:
- if [ ! -z "$TRAVIS_TAG" ] ; then

View File

@ -33,6 +33,10 @@
name = "github.com/openfaas/faas"
version = "0.8.2"
[[constraint]]
name = "github.com/nats-io/go-nats"
version = "v1.5.0"
[prune]
go-tests = true
unused-packages = true

View File

@ -8,6 +8,7 @@ import (
"github.com/nats-io/go-nats-streaming"
"github.com/openfaas/faas/gateway/queue"
"regexp"
)
// NatsQueue queue for work
@ -22,9 +23,11 @@ type NatsConfig interface {
type DefaultNatsConfig struct {
}
var supportedCharacters, _ = regexp.Compile("[^a-zA-Z0-9-_]+")
func (DefaultNatsConfig) GetClientID() string {
val, _ := os.Hostname()
return "faas-publisher-" + val
return getClientId(val)
}
// CreateNatsQueue ready for asynchronous processing
@ -58,3 +61,7 @@ func (q *NatsQueue) Queue(req *queue.Request) error {
return err
}
func getClientId(hostname string) string {
return "faas-publisher-" + supportedCharacters.ReplaceAllString(hostname, "_")
}

View File

@ -17,3 +17,23 @@ func Test_GetClientID_ContainsHostname(t *testing.T) {
t.Fail()
}
}
func TestCreateClientId(t *testing.T) {
clientId := getClientId("computer-a")
expected := "faas-publisher-computer-a"
if clientId != expected {
t.Logf("Expected client id `%s` actual `%s`\n", expected, clientId)
t.Fail()
}
}
func TestCreateClientIdWhenHostHasUnsupportedCharacters(t *testing.T) {
clientId := getClientId("computer-a.acme.com")
expected := "faas-publisher-computer-a_acme_com"
if clientId != expected {
t.Logf("Expected client id `%s` actual `%s`\n", expected, clientId)
t.Fail()
}
}