Add function in payload instead of just metadata (#1919)
Passing information of function from router to executor is more efficient than calling the K8S API. This change does that instead of passing only metadata and then executor calling the K8S API again.
This commit is contained in:
+4
-16
@@ -28,8 +28,6 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"go.opencensus.io/plugin/ochttp"
|
||||
"go.uber.org/zap"
|
||||
k8serrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/core/v1"
|
||||
ferror "github.com/fission/fission/pkg/error"
|
||||
@@ -44,23 +42,13 @@ func (executor *Executor) getServiceForFunctionAPI(w http.ResponseWriter, r *htt
|
||||
}
|
||||
|
||||
// get function metadata
|
||||
m := metav1.ObjectMeta{}
|
||||
err = json.Unmarshal(body, &m)
|
||||
fn := &fv1.Function{}
|
||||
err = json.Unmarshal(body, &fn)
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to parse request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
fn, err := executor.fissionClient.CoreV1().Functions(m.Namespace).Get(m.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
if k8serrors.IsNotFound(err) {
|
||||
http.Error(w, "Failed to find function", http.StatusNotFound)
|
||||
} else {
|
||||
http.Error(w, "Failed to get function", http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
t := fn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType
|
||||
et, exists := executor.executorTypes[t]
|
||||
if !exists {
|
||||
@@ -88,7 +76,7 @@ func (executor *Executor) getServiceForFunctionAPI(w http.ResponseWriter, r *htt
|
||||
code, msg := ferror.GetHTTPError(err)
|
||||
executor.logger.Error("error getting service for function",
|
||||
zap.Error(err),
|
||||
zap.String("function", m.Name),
|
||||
zap.String("function", fn.ObjectMeta.Name),
|
||||
zap.String("fission_http_error", msg))
|
||||
http.Error(w, msg, code)
|
||||
return
|
||||
@@ -98,7 +86,7 @@ func (executor *Executor) getServiceForFunctionAPI(w http.ResponseWriter, r *htt
|
||||
if err != nil {
|
||||
executor.logger.Error(
|
||||
"error writing HTTP response",
|
||||
zap.String("function", m.Name),
|
||||
zap.String("function", fn.ObjectMeta.Name),
|
||||
zap.Error(err),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -70,10 +70,10 @@ func MakeClient(logger *zap.Logger, executorURL string) *Client {
|
||||
}
|
||||
|
||||
// GetServiceForFunction returns the service name for a given function.
|
||||
func (c *Client) GetServiceForFunction(ctx context.Context, metadata *metav1.ObjectMeta) (string, error) {
|
||||
func (c *Client) GetServiceForFunction(ctx context.Context, fn *fv1.Function) (string, error) {
|
||||
executorURL := c.executorURL + "/v2/getServiceForFunction"
|
||||
|
||||
body, err := json.Marshal(metadata)
|
||||
body, err := json.Marshal(fn)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "could not marshal request body for getting service for function")
|
||||
}
|
||||
|
||||
@@ -256,7 +256,7 @@ func TestExecutor(t *testing.T) {
|
||||
|
||||
// the main test: get a service for a given function
|
||||
t1 := time.Now()
|
||||
svc, err := poolmgrClient.GetServiceForFunction(context.Background(), &f.ObjectMeta)
|
||||
svc, err := poolmgrClient.GetServiceForFunction(context.Background(), f)
|
||||
if err != nil {
|
||||
log.Panicf("failed to get func svc: %v", err)
|
||||
}
|
||||
|
||||
@@ -528,7 +528,7 @@ func (fh functionHandler) getServiceEntryFromExecutor() (*url.URL, error) {
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
service, err := fh.executor.GetServiceForFunction(ctx, &fh.function.ObjectMeta)
|
||||
service, err := fh.executor.GetServiceForFunction(ctx, fh.function)
|
||||
if err != nil {
|
||||
statusCode, errMsg := ferror.GetHTTPError(err)
|
||||
fh.logger.Error("error from GetServiceForFunction",
|
||||
|
||||
Reference in New Issue
Block a user