-
Notifications
You must be signed in to change notification settings - Fork 221
/
metrics.go
57 lines (44 loc) · 1.06 KB
/
metrics.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
package metrics
import (
"context"
"io"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/metrics"
"github.com/superfly/flyctl/iostreams"
)
func New() (cmd *cobra.Command) {
const (
short = "Commands that handle sending any metrics to flyctl-metrics"
long = short + "\n"
usage = "metrics <command>"
)
cmd = command.New(usage, short, long, nil)
cmd.Hidden = true
cmd.AddCommand(
newSend(),
)
return
}
func newSend() (cmd *cobra.Command) {
const (
short = "Send any metrics in stdin to flyctl-metrics"
long = short + "\n"
)
cmd = command.New("send", short, long, run, func(ctx context.Context) (context.Context, error) {
return metrics.WithDisableFlushMetrics(ctx), nil
})
cmd.Hidden = true
cmd.Args = cobra.NoArgs
return
}
func run(ctx context.Context) error {
iostream := iostreams.FromContext(ctx)
stdin := iostream.In
stdin_bytes, err := io.ReadAll(stdin)
if err != nil {
return err
}
stdin_value := string(stdin_bytes)
return metrics.SendMetrics(ctx, stdin_value)
}