-
Notifications
You must be signed in to change notification settings - Fork 53
/
extensions.go
63 lines (54 loc) · 1.31 KB
/
extensions.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
package v1
import (
"fmt"
"strings"
"github.com/ttacon/chalk"
"go.uber.org/zap/zapcore"
"google.golang.org/protobuf/types/known/timestamppb"
)
func (s *HealthStatus) Summary() string {
if s.Status == nil || s.Health == nil {
return "Unknown"
}
if !s.Status.Connected {
return "Disconnected"
}
if len(s.Health.Conditions) > 0 {
return fmt.Sprintf("Unhealthy: %s", strings.Join(s.Health.Conditions, ", "))
}
if !s.Health.Ready {
return fmt.Sprintf("Not ready (unknown reason)")
}
return "Healthy"
}
type TimestampedLog interface {
GetTimestamp() *timestamppb.Timestamp
GetMsg() string
GetLogLevel() zapcore.Level
}
var _ TimestampedLog = (*LogEntry)(nil)
var _ TimestampedLog = (*StateTransition)(nil)
func (s *LogEntry) GetLogLevel() zapcore.Level {
return zapcore.Level(s.Level)
}
func (s *StateTransition) GetLogLevel() zapcore.Level {
return zapcore.InfoLevel
}
func (s *StateTransition) GetMsg() string {
return fmt.Sprintf("State changed to %s",
stateColor(s.State).Color(s.State.String()))
}
func stateColor(state TaskState) chalk.Color {
switch state {
case TaskState_Pending:
return chalk.Yellow
case TaskState_Running:
return chalk.Blue
case TaskState_Failed, TaskState_Canceled:
return chalk.Red
case TaskState_Completed:
return chalk.Green
default:
return chalk.White
}
}