in fc/invoke_loop.go [102:177]
func convertInvokeRequest(invokeInstance *invoke) (*messages.InvokeRequest, error) {
deadlineEpochMS, err := strconv.ParseInt(invokeInstance.headers.Get(headerDeadlineMS), 10, 64)
if err != nil {
return nil, fmt.Errorf("failed to parse contents of header: %s", headerDeadlineMS)
}
deadlineS := deadlineEpochMS / msPerS
deadlineNS := (deadlineEpochMS % msPerS) * nsPerMS
functionTimeoutSec, err := strconv.Atoi(invokeInstance.headers.Get(headerFunctionTimeout))
if err != nil {
return nil, fmt.Errorf("failed to parse contents of header: %s", headerFunctionTimeout)
}
retryCount := 0
if retryCountStr := invokeInstance.headers.Get(headerRetryCount); retryCountStr != "" {
retryCount, err = strconv.Atoi(retryCountStr)
if err != nil {
return nil, fmt.Errorf("failed to parse contents of header: %s", headerFunctionTimeout)
}
}
spanBaggages := make(map[string]string)
if base64SpanBaggages := invokeInstance.headers.Get(headerOpenTracingSpanBaggages); base64SpanBaggages != "" {
spanBaggagesByte, err := base64.StdEncoding.DecodeString(base64SpanBaggages)
if err != nil {
return nil, fmt.Errorf("failed to parse contents of header %s: %s", headerOpenTracingSpanContext, base64SpanBaggages)
}
if err := json.Unmarshal(spanBaggagesByte, &spanBaggages); err != nil {
return nil, fmt.Errorf("failed to parse contents of header %s: %s", headerOpenTracingSpanContext, base64SpanBaggages)
}
}
res := &messages.InvokeRequest{
RequestId: invokeInstance.id,
Deadline: messages.InvokeRequest_Timestamp{
Seconds: deadlineS,
Nanos: deadlineNS,
},
Payload: invokeInstance.payload,
Context: fccontext.FcContext{
RequestID: invokeInstance.id,
Credentials: fccontext.Credentials{
AccessKeyId: invokeInstance.headers.Get(headerAccessKeyId),
AccessKeySecret: invokeInstance.headers.Get(headerAccessKeySecret),
SecurityToken: invokeInstance.headers.Get(headerSecurityToken),
},
Function: fccontext.Function{
Name: invokeInstance.headers.Get(headerFunctionName),
Handler: invokeInstance.headers.Get(headerFunctionHandler),
Memory: invokeInstance.headers.Get(headerFunctionMemory),
Timeout: functionTimeoutSec,
},
Service: fccontext.Service{
Name: invokeInstance.headers.Get(headerServiceName),
LogProject: invokeInstance.headers.Get(headerServiceLogproject),
LogStore: invokeInstance.headers.Get(headerServiceLogstore),
Qualifier: invokeInstance.headers.Get(headerQualifier),
VersionId: invokeInstance.headers.Get(headerVersionId),
},
Tracing: fccontext.Tracing{
OpenTracingSpanContext: invokeInstance.headers.Get(headerOpenTracingSpanContext),
OpenTracingSpanBaggages: spanBaggages,
JaegerEndpoint: invokeInstance.headers.Get(headerJaegerEndpoint),
},
Region: invokeInstance.headers.Get(headerRegion),
AccountId: invokeInstance.headers.Get(headerAccountId),
RetryCount: retryCount,
},
}
if httpParams := invokeInstance.headers.Get(headerHttpParams); httpParams != "" {
res.HttpParams = &httpParams
}
return res, nil
}