-
Notifications
You must be signed in to change notification settings - Fork 509
/
cmd_gather_traces.go
53 lines (46 loc) · 1.45 KB
/
cmd_gather_traces.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
package cli
import (
"fmt"
"github.com/spf13/cobra"
"github.com/telepresenceio/telepresence/rpc/v2/connector"
"github.com/telepresenceio/telepresence/v2/pkg/client/cli/ann"
"github.com/telepresenceio/telepresence/v2/pkg/client/cli/util"
"github.com/telepresenceio/telepresence/v2/pkg/client/errcat"
)
func GatherTracesCommand() *cobra.Command {
tr := connector.TracesRequest{}
cmd := &cobra.Command{
Use: "gather-traces",
Args: cobra.NoArgs,
Short: "Gather Traces",
RunE: func(cmd *cobra.Command, _ []string) error {
return gatherTraces(cmd, &tr)
},
Annotations: map[string]string{
ann.RootDaemon: ann.Required,
ann.UserDaemon: ann.Required,
},
SilenceUsage: true,
SilenceErrors: true,
}
cmd.Flags().Int32VarP(&tr.RemotePort, "port", "p", 15766,
"The remote port where traffic manager and agent are exposing traces."+
"Corresponds to tracing.grpcPort in the helm chart values")
cmd.Flags().StringVarP(&tr.TracingFile, "output-file", "o", "./traces.gz", "The gzip to be created with binary trace data")
return cmd
}
func gatherTraces(cmd *cobra.Command, request *connector.TracesRequest) error {
if err := util.InitCommand(cmd); err != nil {
return err
}
ctx := cmd.Context()
r, err := util.GetUserDaemon(ctx).GatherTraces(ctx, request)
if err != nil {
return err
}
if err = errcat.FromResult(r); err != nil {
return err
}
fmt.Fprintf(cmd.OutOrStdout(), "Traces saved as %s\n", request.TracingFile)
return nil
}