forked from aws/aws-lambda-runtime-interface-emulator
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdescription.go
More file actions
95 lines (77 loc) · 2.72 KB
/
description.go
File metadata and controls
95 lines (77 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package statejson
import (
"encoding/json"
log "github.com/sirupsen/logrus"
)
// ResponseMode are top-level constants used in combination with the various types of
// modes we have for responses, such as invoke's response mode and function's response mode.
// In the future we might have invoke's request mode or similar, so these help set the ground
// for consistency.
type ResponseMode string
const ResponseModeBuffered = "Buffered"
const ResponseModeStreaming = "Streaming"
type InvokeResponseMode string
const InvokeResponseModeBuffered InvokeResponseMode = ResponseModeBuffered
const InvokeResponseModeStreaming InvokeResponseMode = ResponseModeStreaming
// StateDescription ...
type StateDescription struct {
Name string `json:"name"`
LastModified int64 `json:"lastModified"`
ResponseTimeNs int64 `json:"responseTimeNs"`
}
// RuntimeDescription ...
type RuntimeDescription struct {
State StateDescription `json:"state"`
}
// ExtensionDescription ...
type ExtensionDescription struct {
Name string `json:"name"`
ID string
State StateDescription `json:"state"`
ErrorType string `json:"errorType"`
}
// InternalStateDescription describes internal state of runtime and extensions for debugging purposes
type InternalStateDescription struct {
Runtime *RuntimeDescription `json:"runtime"`
Extensions []ExtensionDescription `json:"extensions"`
FirstFatalError string `json:"firstFatalError"`
}
type ResponseMetricsDimensions struct {
InvokeResponseMode InvokeResponseMode `json:"invokeResponseMode"`
}
type ResponseMetrics struct {
RuntimeResponseLatencyMs float64 `json:"runtimeResponseLatencyMs"`
Dimensions ResponseMetricsDimensions `json:"dimensions"`
}
type ReleaseResponse struct {
*InternalStateDescription
ResponseMetrics ResponseMetrics `json:"responseMetrics"`
}
// ResetDescription describes fields of the response to an INVOKE API request
type ResetDescription struct {
ExtensionsResetMs int64 `json:"extensionsResetMs"`
ResponseMetrics ResponseMetrics `json:"responseMetrics"`
}
func (s *InternalStateDescription) AsJSON() []byte {
bytes, err := json.Marshal(s)
if err != nil {
log.Panicf("Failed to marshall internal states: %s", err)
}
return bytes
}
func (s *ResetDescription) AsJSON() []byte {
bytes, err := json.Marshal(s)
if err != nil {
log.Panicf("Failed to marshall reset description: %s", err)
}
return bytes
}
func (s *ReleaseResponse) AsJSON() []byte {
bytes, err := json.Marshal(s)
if err != nil {
log.Panicf("Failed to marshall release response: %s", err)
}
return bytes
}