-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtrace.go
45 lines (39 loc) · 1.15 KB
/
trace.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
package ecsta
import (
"context"
"fmt"
"time"
"github.com/fujiwara/tracer"
)
type TraceOption struct {
ID string `help:"task ID"`
Duration time.Duration `help:"duration to trace" short:"d" default:"1m"`
SNSTopicArn string `help:"SNS topic ARN"`
Family *string `help:"task definition family name"`
Service *string `help:"ECS service name"`
JSON bool `help:"output JSON lines" short:"j"`
}
func (app *Ecsta) RunTrace(ctx context.Context, opt *TraceOption) error {
if err := app.SetCluster(ctx); err != nil {
return err
}
task, err := app.findTask(ctx, &optionFindTask{id: opt.ID, family: opt.Family, service: opt.Service})
if err != nil {
return fmt.Errorf("failed to select tasks: %w", err)
}
tr, err := tracer.NewWithConfig(app.awscfg)
if err != nil {
return fmt.Errorf("failed to create tracer: %w", err)
}
if app.Config.Output == "json" {
opt.JSON = true
}
tracerOpt := &tracer.RunOption{
Stdout: true,
Duration: opt.Duration,
SNSTopicArn: opt.SNSTopicArn,
JSON: opt.JSON,
}
tr.SetOutput(app.w)
return tr.Run(ctx, app.cluster, *task.TaskArn, tracerOpt)
}