-
Notifications
You must be signed in to change notification settings - Fork 288
/
actions.go
161 lines (125 loc) · 3.49 KB
/
actions.go
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package store
import (
"fmt"
"time"
"github.com/windmilleng/wmclient/pkg/analytics"
v1 "k8s.io/api/core/v1"
"github.com/windmilleng/tilt/internal/k8s"
"github.com/windmilleng/tilt/pkg/logger"
"github.com/windmilleng/tilt/pkg/model"
"github.com/windmilleng/tilt/pkg/model/logstore"
)
type ErrorAction struct {
Error error
}
func (ErrorAction) Action() {}
func NewErrorAction(err error) ErrorAction {
return ErrorAction{Error: err}
}
type LogAction struct {
mn model.ManifestName
spanID logstore.SpanID
timestamp time.Time
fields logger.Fields
msg []byte
level logger.Level
}
func (LogAction) Action() {}
func (le LogAction) ManifestName() model.ManifestName {
return le.mn
}
func (le LogAction) Level() logger.Level {
return le.level
}
func (le LogAction) Time() time.Time {
return le.timestamp
}
func (le LogAction) Fields() logger.Fields {
return le.fields
}
func (le LogAction) Message() []byte {
return le.msg
}
func (le LogAction) SpanID() logstore.SpanID {
return le.spanID
}
func (le LogAction) String() string {
return fmt.Sprintf("manifest: %s, spanID: %s, msg: %q", le.mn, le.spanID, le.msg)
}
func NewLogAction(mn model.ManifestName, spanID logstore.SpanID, level logger.Level, fields logger.Fields, b []byte) LogAction {
return LogAction{
mn: mn,
spanID: spanID,
level: level,
timestamp: time.Now(),
msg: append([]byte{}, b...),
fields: fields,
}
}
func NewGlobalLogAction(level logger.Level, b []byte) LogAction {
return LogAction{
mn: "",
spanID: "",
level: level,
timestamp: time.Now(),
msg: append([]byte{}, b...),
}
}
type K8sEventAction struct {
Event *v1.Event
ManifestName model.ManifestName
}
func (K8sEventAction) Action() {}
func NewK8sEventAction(event *v1.Event, manifestName model.ManifestName) K8sEventAction {
return K8sEventAction{event, manifestName}
}
func (kEvt K8sEventAction) ToLogAction(mn model.ManifestName) LogAction {
msg := fmt.Sprintf("[K8s EVENT: %s] %s\n",
objRefHumanReadable(kEvt.Event.InvolvedObject), kEvt.Event.Message)
return LogAction{
mn: mn,
spanID: logstore.SpanID(fmt.Sprintf("events:%s", mn)),
level: logger.InfoLvl,
timestamp: kEvt.Event.LastTimestamp.Time,
msg: []byte(msg),
}
}
func objRefHumanReadable(obj v1.ObjectReference) string {
s := fmt.Sprintf("%s %s", obj.Kind, obj.Name)
if obj.Namespace != "" {
s += fmt.Sprintf(" (ns: %s)", obj.Namespace)
}
return s
}
type AnalyticsUserOptAction struct {
Opt analytics.Opt
}
func (AnalyticsUserOptAction) Action() {}
type AnalyticsNudgeSurfacedAction struct{}
func (AnalyticsNudgeSurfacedAction) Action() {}
type TiltCloudStatusReceivedAction struct {
Found bool
Username string
IsPostRegistrationLookup bool
}
func (TiltCloudStatusReceivedAction) Action() {}
type UserStartedTiltCloudRegistrationAction struct{}
func (UserStartedTiltCloudRegistrationAction) Action() {}
// The user can indicate "yes, I know the pod restarted N times, stop showing me"
type PodResetRestartsAction struct {
PodID k8s.PodID
ManifestName model.ManifestName
VisibleRestarts int
}
func NewPodResetRestartsAction(podID k8s.PodID, mn model.ManifestName, visibleRestarts int) PodResetRestartsAction {
return PodResetRestartsAction{
PodID: podID,
ManifestName: mn,
VisibleRestarts: visibleRestarts,
}
}
func (PodResetRestartsAction) Action() {}
type PanicAction struct {
Err error
}
func (PanicAction) Action() {}