-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.go
More file actions
95 lines (86 loc) · 2.51 KB
/
Copy pathtypes.go
File metadata and controls
95 lines (86 loc) · 2.51 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
package main
import (
"encoding/json"
"time"
)
type InvocationSummary struct {
RequestID string
StartTime time.Time
Duration string
BilledMs string
MemorySizeMB string
MaxMemoryUsedMB string
IsError bool
ErrorLines []string
LogLines []string
}
type Snapshot struct {
FunctionName string `json:"function_name"`
LogGroup string `json:"log_group"`
CapturedAt string `json:"captured_at"`
Label string `json:"label"`
Invocations []InvocationRecord `json:"invocations"`
}
type InvocationRecord struct {
RequestID string
Timestamp string
Duration string
BilledMs string
MemorySizeMB string
MaxMemoryUsedMB string
IsError bool
ErrorLines []string
LogLines []string
}
type invocationRecordJSON struct {
RequestID string `json:"request_id"`
Timestamp string `json:"timestamp"`
Duration string `json:"duration"`
BilledMs string `json:"billed_ms"`
MemorySizeMB string `json:"memory_size_mb,omitempty"`
MaxMemoryUsedMB string `json:"max_memory_used_mb,omitempty"`
LegacyMemUsedMB string `json:"mem_used_mb,omitempty"`
LegacyMaxMemMB string `json:"max_mem_mb,omitempty"`
IsError bool `json:"is_error"`
ErrorLines []string `json:"error_lines,omitempty"`
LogLines []string `json:"log_lines"`
}
func (r InvocationRecord) MarshalJSON() ([]byte, error) {
return json.Marshal(invocationRecordJSON{
RequestID: r.RequestID,
Timestamp: r.Timestamp,
Duration: r.Duration,
BilledMs: r.BilledMs,
MemorySizeMB: r.MemorySizeMB,
MaxMemoryUsedMB: r.MaxMemoryUsedMB,
IsError: r.IsError,
ErrorLines: r.ErrorLines,
LogLines: r.LogLines,
})
}
func (r *InvocationRecord) UnmarshalJSON(data []byte) error {
var raw invocationRecordJSON
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
*r = InvocationRecord{
RequestID: raw.RequestID,
Timestamp: raw.Timestamp,
Duration: raw.Duration,
BilledMs: raw.BilledMs,
MemorySizeMB: firstNonEmpty(raw.MemorySizeMB, raw.LegacyMemUsedMB),
MaxMemoryUsedMB: firstNonEmpty(raw.MaxMemoryUsedMB, raw.LegacyMaxMemMB),
IsError: raw.IsError,
ErrorLines: raw.ErrorLines,
LogLines: raw.LogLines,
}
return nil
}
func firstNonEmpty(values ...string) string {
for _, value := range values {
if value != "" {
return value
}
}
return ""
}