MCPcopy Create free account
hub / github.com/baidu/EasyFaaS / Invoke

Method Invoke

pkg/controller/client/call.go:40–89  ·  view source on GitHub ↗
(ir *api.InvokeRequest)

Source from the content-addressed store, hash-verified

38}
39
40func (mc *ControllerCallClient) Invoke(ir *api.InvokeRequest) (response *api.InvokeResponse, err error) {
41 h := make(map[string]string, 0)
42 reqID := id.GetRequestID()
43
44 clientMode := controller.ClientModeHTTPTrigger
45 ctx := controller.InvokeContext{
46 RunOptions: mc.runOptions,
47 ExternalRequestID: ir.RequestID,
48 RequestID: reqID,
49 AccountID: ir.UserID,
50 Authorization: ir.Authorization,
51 Clients: mc.controllerClient.NewClients(clientMode),
52 Response: api.NewInvokeProxyResponseWithRequestID(ir.RequestID),
53 Logger: logs.NewLogger().WithField("request_id", reqID).
54 WithField("external_request_id", ir.RequestID),
55 FunctionBRN: ir.FunctionBRN,
56 Qualifier: ir.Qualifier,
57 WithStreamMode: ir.WithBodyStream,
58 InvokeType: api.InvokeTypeHttpTrigger,
59 TriggerType: api.TriggerTypeHTTP,
60 }
61
62 if ir.WithBodyStream {
63 ctx.Request = api.NewInvokeProxyRequest(h, nil, ir.BodyStream)
64 } else {
65 ctx.Request = api.NewInvokeProxyRequest(h, []byte(*ir.Body), nil)
66 }
67
68 if mc.runOptions.RecommendedOptions.Features.EnableMetrics {
69 ctx.Metrics = controller.NewInvokeMetrics(ir.RequestID)
70 }
71
72 mc.controllerClient.Do(&ctx)
73
74 response = api.NewInvokeResponse()
75 response.SetStatusCode(ctx.Response.StatusCode)
76 response.SetHeaders(&ctx.Response.Headers)
77 if ctx.WithStreamMode {
78 response.SetBodyStream(ctx.Response.BodyStream)
79 } else {
80 response.SetBody(ctx.Response.Body)
81 }
82
83 if ctx.Metrics != nil {
84 ctx.Metrics.Overall()
85 ctx.Metrics.WriteSummary(mc.runOptions.RecommendedOptions.Features.SummaryOverheadMs)
86 }
87
88 return response, nil
89}

Callers 1

Calls 15

GetRequestIDFunction · 0.92
NewLoggerFunction · 0.92
NewInvokeProxyRequestFunction · 0.92
NewInvokeMetricsFunction · 0.92
NewInvokeResponseFunction · 0.92
WithFieldMethod · 0.80
SetHeadersMethod · 0.80
SetBodyStreamMethod · 0.80
OverallMethod · 0.80
WriteSummaryMethod · 0.80
NewClientsMethod · 0.65

Tested by 1