-
Notifications
You must be signed in to change notification settings - Fork 502
/
cmd-query-search.go
53 lines (42 loc) · 1.12 KB
/
cmd-query-search.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 main
import (
"time"
"github.com/grafana/tempo/pkg/tempopb"
"github.com/grafana/tempo/pkg/util"
)
type querySearchCmd struct {
APIEndpoint string `arg:"" help:"tempo api endpoint"`
Tags string `arg:"" optional:"" help:"tags in logfmt format"`
Start string `arg:"" optional:"" help:"start time in ISO8601 format"`
End string `arg:"" optional:"" help:"end time in ISO8601 format"`
OrgID string `help:"optional orgID"`
}
func (cmd *querySearchCmd) Run(_ *globalOptions) error {
client := util.NewClient(cmd.APIEndpoint, cmd.OrgID)
var start, end int64
if cmd.Start != "" {
startDate, err := time.Parse(time.RFC3339, cmd.Start)
if err != nil {
return err
}
start = startDate.Unix()
}
if cmd.End != "" {
endDate, err := time.Parse(time.RFC3339, cmd.End)
if err != nil {
return err
}
end = endDate.Unix()
}
var tagValues *tempopb.SearchResponse
var err error
if start == 0 && end == 0 {
tagValues, err = client.Search(cmd.Tags)
} else {
tagValues, err = client.SearchWithRange(cmd.Tags, start, end)
}
if err != nil {
return err
}
return printAsJSON(tagValues)
}