Change default function timeout to 60 seconds and pass context to executor from router (#2169)
Patch changes default function timeout to 60 seconds. Also, we are propagating context from router to executor in a proper way.
This commit is contained in:
@@ -113,7 +113,7 @@ var (
|
|||||||
FnLogReverseQuery = Flag{Type: Bool, Name: flagkey.FnLogReverseQuery, Short: "r", Usage: "Specify the log reverse query base on time, it will be invalid if the 'follow' flag is specified"}
|
FnLogReverseQuery = Flag{Type: Bool, Name: flagkey.FnLogReverseQuery, Short: "r", Usage: "Specify the log reverse query base on time, it will be invalid if the 'follow' flag is specified"}
|
||||||
FnLogCount = Flag{Type: Int, Name: flagkey.FnLogCount, Usage: "Get N most recent log records", DefaultValue: 20}
|
FnLogCount = Flag{Type: Int, Name: flagkey.FnLogCount, Usage: "Get N most recent log records", DefaultValue: 20}
|
||||||
FnTestBody = Flag{Type: String, Name: flagkey.FnTestBody, Short: "b", Usage: "Request body"}
|
FnTestBody = Flag{Type: String, Name: flagkey.FnTestBody, Short: "b", Usage: "Request body"}
|
||||||
FnTestTimeout = Flag{Type: Duration, Name: flagkey.FnTestTimeout, Short: "t", Usage: "Length of time to wait for the response. If set to zero or negative number, no timeout is set", DefaultValue: 30 * time.Second}
|
FnTestTimeout = Flag{Type: Duration, Name: flagkey.FnTestTimeout, Short: "t", Usage: "Length of time to wait for the response. If set to zero or negative number, no timeout is set", DefaultValue: 60 * time.Second}
|
||||||
FnTestHeader = Flag{Type: StringSlice, Name: flagkey.FnTestHeader, Short: "H", Usage: "Request headers"}
|
FnTestHeader = Flag{Type: StringSlice, Name: flagkey.FnTestHeader, Short: "H", Usage: "Request headers"}
|
||||||
FnTestQuery = Flag{Type: StringSlice, Name: flagkey.FnTestQuery, Short: "q", Usage: "Request query parameters: -q key1=value1 -q key2=value2"}
|
FnTestQuery = Flag{Type: StringSlice, Name: flagkey.FnTestQuery, Short: "q", Usage: "Request query parameters: -q key1=value1 -q key2=value2"}
|
||||||
FnIdleTimeout = Flag{Type: Int, Name: flagkey.FnIdleTimeout, Usage: "The length of time (in seconds) that a function is idle before pod(s) are eligible for recycling", DefaultValue: 120}
|
FnIdleTimeout = Flag{Type: Int, Name: flagkey.FnIdleTimeout, Usage: "The length of time (in seconds) that a function is idle before pod(s) are eligible for recycling", DefaultValue: 120}
|
||||||
|
|||||||
@@ -651,16 +651,21 @@ func (fh functionHandler) removeServiceEntryFromCache() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fh functionHandler) getServiceEntryFromExecutor() (serviceUrl *url.URL, err error) {
|
func (fh functionHandler) getServiceEntryFromExecutor(ctx context.Context) (serviceUrl *url.URL, err error) {
|
||||||
// send a request to executor to specialize a new pod
|
// send a request to executor to specialize a new pod
|
||||||
fh.logger.Debug("function timeout specified", zap.Int("timeout", fh.function.Spec.FunctionTimeout))
|
fh.logger.Debug("function timeout specified", zap.Int("timeout", fh.function.Spec.FunctionTimeout))
|
||||||
timeout := 30 * time.Second
|
|
||||||
|
var fContext context.Context
|
||||||
if fh.function.Spec.FunctionTimeout > 0 {
|
if fh.function.Spec.FunctionTimeout > 0 {
|
||||||
timeout = time.Second * time.Duration(fh.function.Spec.FunctionTimeout)
|
timeout := time.Second * time.Duration(fh.function.Spec.FunctionTimeout)
|
||||||
|
f, cancel := context.WithTimeout(ctx, timeout)
|
||||||
|
fContext = f
|
||||||
|
defer cancel()
|
||||||
|
} else {
|
||||||
|
fContext = ctx
|
||||||
}
|
}
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
|
||||||
defer cancel()
|
service, err := fh.executor.GetServiceForFunction(fContext, fh.function)
|
||||||
service, err := fh.executor.GetServiceForFunction(ctx, fh.function)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
statusCode, errMsg := ferror.GetHTTPError(err)
|
statusCode, errMsg := ferror.GetHTTPError(err)
|
||||||
fh.logger.Error("error from GetServiceForFunction",
|
fh.logger.Error("error from GetServiceForFunction",
|
||||||
@@ -684,7 +689,7 @@ func (fh functionHandler) getServiceEntryFromExecutor() (serviceUrl *url.URL, er
|
|||||||
// getServiceEntryFromExecutor returns service url entry returns from executor
|
// getServiceEntryFromExecutor returns service url entry returns from executor
|
||||||
func (fh functionHandler) getServiceEntry(ctx context.Context) (svcURL *url.URL, cacheHit bool, err error) {
|
func (fh functionHandler) getServiceEntry(ctx context.Context) (svcURL *url.URL, cacheHit bool, err error) {
|
||||||
if fh.function.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType == fv1.ExecutorTypePoolmgr {
|
if fh.function.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType == fv1.ExecutorTypePoolmgr {
|
||||||
svcURL, err = fh.getServiceEntryFromExecutor()
|
svcURL, err = fh.getServiceEntryFromExecutor(ctx)
|
||||||
return svcURL, false, err
|
return svcURL, false, err
|
||||||
}
|
}
|
||||||
// Check if service URL present in cache
|
// Check if service URL present in cache
|
||||||
@@ -706,7 +711,7 @@ func (fh functionHandler) getServiceEntry(ctx context.Context) (svcURL *url.URL,
|
|||||||
}
|
}
|
||||||
return svcEntryRecord{svcURL: svcURL, cacheHit: true}, err
|
return svcEntryRecord{svcURL: svcURL, cacheHit: true}, err
|
||||||
}
|
}
|
||||||
svcURL, err = fh.getServiceEntryFromExecutor()
|
svcURL, err = fh.getServiceEntryFromExecutor(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user