mirror of
https://github.com/openfaas/faas.git
synced 2025-06-18 12:06:37 +00:00
Publish to multiple topics
Enables publishing to various topics according to annotations on the functions. The function cache is moved up one level so that it can be shared between the scale from zero code and the queue proxy. Unit tests added for new internal methods. Tested e2e with arkade and the newest queue-worker and RC gateway image with two queues and an annotation on one of the functions of com.openfaas.queue. It worked as expected including with multiple namespace support. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
committed by
Alex Ellis
parent
a7c6c39200
commit
2bfca6d848
@ -16,12 +16,26 @@ import (
|
||||
"time"
|
||||
|
||||
types "github.com/openfaas/faas-provider/types"
|
||||
"github.com/openfaas/faas/gateway/handlers"
|
||||
middleware "github.com/openfaas/faas/gateway/pkg/middleware"
|
||||
"github.com/openfaas/faas/gateway/scaling"
|
||||
)
|
||||
|
||||
// ExternalServiceQuery proxies service queries to external plugin via HTTP
|
||||
type ExternalServiceQuery struct {
|
||||
URL url.URL
|
||||
ProxyClient http.Client
|
||||
AuthInjector middleware.AuthInjector
|
||||
}
|
||||
|
||||
// ScaleServiceRequest request scaling of replica
|
||||
type ScaleServiceRequest struct {
|
||||
ServiceName string `json:"serviceName"`
|
||||
ServiceNamespace string `json:"serviceNamespace"`
|
||||
Replicas uint64 `json:"replicas"`
|
||||
}
|
||||
|
||||
// NewExternalServiceQuery proxies service queries to external plugin via HTTP
|
||||
func NewExternalServiceQuery(externalURL url.URL, authInjector handlers.AuthInjector) scaling.ServiceQuery {
|
||||
func NewExternalServiceQuery(externalURL url.URL, authInjector middleware.AuthInjector) scaling.ServiceQuery {
|
||||
timeout := 3 * time.Second
|
||||
|
||||
proxyClient := http.Client{
|
||||
@ -45,20 +59,6 @@ func NewExternalServiceQuery(externalURL url.URL, authInjector handlers.AuthInje
|
||||
}
|
||||
}
|
||||
|
||||
// ExternalServiceQuery proxies service queries to external plugin via HTTP
|
||||
type ExternalServiceQuery struct {
|
||||
URL url.URL
|
||||
ProxyClient http.Client
|
||||
AuthInjector handlers.AuthInjector
|
||||
}
|
||||
|
||||
// ScaleServiceRequest request scaling of replica
|
||||
type ScaleServiceRequest struct {
|
||||
ServiceName string `json:"serviceName"`
|
||||
ServiceNamespace string `json:"serviceNamespace"`
|
||||
Replicas uint64 `json:"replicas"`
|
||||
}
|
||||
|
||||
// GetReplicas replica count for function
|
||||
func (s ExternalServiceQuery) GetReplicas(serviceName, serviceNamespace string) (scaling.ServiceQueryResponse, error) {
|
||||
start := time.Now()
|
||||
@ -126,6 +126,7 @@ func (s ExternalServiceQuery) GetReplicas(serviceName, serviceNamespace string)
|
||||
MinReplicas: minReplicas,
|
||||
ScalingFactor: scalingFactor,
|
||||
AvailableReplicas: availableReplicas,
|
||||
Annotations: function.Annotations,
|
||||
}, err
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/openfaas/faas/gateway/handlers"
|
||||
middleware "github.com/openfaas/faas/gateway/pkg/middleware"
|
||||
"github.com/openfaas/faas/gateway/scaling"
|
||||
)
|
||||
|
||||
@ -47,7 +47,7 @@ func TestGetReplicasNonExistentFn(t *testing.T) {
|
||||
}))
|
||||
defer testServer.Close()
|
||||
|
||||
var injector handlers.AuthInjector
|
||||
var injector middleware.AuthInjector
|
||||
url, _ := url.Parse(testServer.URL + "/")
|
||||
|
||||
esq := NewExternalServiceQuery(*url, injector)
|
||||
@ -77,7 +77,7 @@ func TestGetReplicasExistentFn(t *testing.T) {
|
||||
AvailableReplicas: 0,
|
||||
}
|
||||
|
||||
var injector handlers.AuthInjector
|
||||
var injector middleware.AuthInjector
|
||||
url, _ := url.Parse(testServer.URL + "/")
|
||||
|
||||
esq := NewExternalServiceQuery(*url, injector)
|
||||
@ -102,7 +102,7 @@ func TestSetReplicasNonExistentFn(t *testing.T) {
|
||||
}))
|
||||
defer testServer.Close()
|
||||
|
||||
var injector handlers.AuthInjector
|
||||
var injector middleware.AuthInjector
|
||||
url, _ := url.Parse(testServer.URL + "/")
|
||||
esq := NewExternalServiceQuery(*url, injector)
|
||||
|
||||
@ -124,7 +124,7 @@ func TestSetReplicasExistentFn(t *testing.T) {
|
||||
}))
|
||||
defer testServer.Close()
|
||||
|
||||
var injector handlers.AuthInjector
|
||||
var injector middleware.AuthInjector
|
||||
|
||||
url, _ := url.Parse(testServer.URL + "/")
|
||||
esq := NewExternalServiceQuery(*url, injector)
|
||||
|
Reference in New Issue
Block a user