-
-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathformat.go
More file actions
117 lines (102 loc) · 2.94 KB
/
Copy pathformat.go
File metadata and controls
117 lines (102 loc) · 2.94 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package ecspresso
import (
"encoding/json"
"fmt"
"log/slog"
"strings"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
aasTypes "github.com/aws/aws-sdk-go-v2/service/applicationautoscaling/types"
logsTypes "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types"
"github.com/aws/aws-sdk-go-v2/service/ecs/types"
"github.com/fujiwara/sloghandler"
)
var EventTimeFormat = sloghandler.TimeFormat
type genericLogEvent struct {
Time time.Time `json:"time"`
Level string `json:"level"`
Msg string `json:"msg"`
}
func formatDeployment(dp types.Deployment) string {
return fmt.Sprintf(
"%8s %s desired:%d pending:%d running:%d %s(%s)",
aws.ToString(dp.Status),
arnToName(aws.ToString(dp.TaskDefinition)),
dp.DesiredCount, dp.PendingCount, dp.RunningCount,
dp.RolloutState, aws.ToString(dp.RolloutStateReason),
)
}
func formatTaskSet(ts types.TaskSet) string {
return fmt.Sprintf(
"%8s %s desired:%d pending:%d running:%d %s",
aws.ToString(ts.Status),
arnToName(aws.ToString(ts.TaskDefinition)),
ts.ComputedDesiredCount, ts.PendingCount, ts.RunningCount,
ts.StabilityStatus,
)
}
func formatExpress(ex *types.ECSExpressGatewayService) string {
var b strings.Builder
fmt.Fprintf(&b, spcIndent+"Status: %s %s\n", ex.Status.StatusCode, aws.ToString(ex.Status.StatusReason))
if len(ex.ActiveConfigurations) > 0 {
ac := ex.ActiveConfigurations[0]
if len(ac.IngressPaths) > 0 {
fmt.Fprintln(&b, spcIndent+"IngressPaths:")
}
for _, p := range ac.IngressPaths {
fmt.Fprintf(&b, spcIndent+spcIndent+"%s %s\n", p.AccessType, aws.ToString(p.Endpoint))
}
}
return b.String()
}
type serviceEvent types.ServiceEvent
func (e serviceEvent) String() string {
return fmt.Sprintf("%s %s",
e.CreatedAt.In(time.Local).Format(EventTimeFormat),
*e.Message,
)
}
func (e serviceEvent) JSON() string {
t := e.CreatedAt.In(time.Local)
b, _ := json.Marshal(genericLogEvent{
Time: t,
Level: slog.LevelInfo.String(),
Msg: *e.Message,
})
return string(b)
}
type logEvent logsTypes.OutputLogEvent
func (e logEvent) String() string {
t := time.Unix((*e.Timestamp / int64(1000)), 0)
return fmt.Sprintf("%s %s",
t.In(time.Local).Format(EventTimeFormat),
*e.Message,
)
}
func (e logEvent) JSON() string {
t := time.Unix((*e.Timestamp / int64(1000)), 0).In(time.Local)
b, _ := json.Marshal(genericLogEvent{
Time: t,
Level: slog.LevelInfo.String(),
Msg: *e.Message,
})
return string(b)
}
func formatScalableTarget(t aasTypes.ScalableTarget) string {
return strings.Join([]string{
fmt.Sprintf(
spcIndent+"Capacity min:%d max:%d",
*t.MinCapacity,
*t.MaxCapacity,
),
fmt.Sprintf(
spcIndent+"Suspended in:%t out:%t scheduled:%t",
*t.SuspendedState.DynamicScalingInSuspended,
*t.SuspendedState.DynamicScalingOutSuspended,
*t.SuspendedState.ScheduledScalingSuspended,
),
}, "\n")
}
func formatScalingPolicy(p aasTypes.ScalingPolicy) string {
return fmt.Sprintf(" Policy name:%s type:%s", *p.PolicyName, p.PolicyType)
}