MCPcopy
hub / github.com/grafana/tempo / Run

Method Run

cmd/tempo-cli/cmd-query-blocks.go:37–86  ·  view source on GitHub ↗
(ctx *globalOptions)

Source from the content-addressed store, hash-verified

35}
36
37func (cmd *queryBlocksCmd) Run(ctx *globalOptions) error {
38 r, _, c, err := loadBackend(&cmd.backendOptions, ctx)
39 if err != nil {
40 return err
41 }
42
43 id, err := util.HexStringToTraceID(cmd.TraceID)
44 if err != nil {
45 return err
46 }
47
48 results, err := queryBucket(context.Background(), cmd.Percentage, r, c, cmd.TenantID, id)
49 if err != nil {
50 return err
51 }
52
53 var (
54 combiner = trace.NewCombiner(0, true)
55 marshaller = new(jsonpb.Marshaler)
56 jsonBytes = bytes.Buffer{}
57 )
58
59 fmt.Println()
60 for i, result := range results {
61 fmt.Println(result.blockID, ":")
62
63 err := marshaller.Marshal(&jsonBytes, result.trace)
64 if err != nil {
65 fmt.Println("failed to marshal to json: ", err)
66 continue
67 }
68
69 fmt.Println(jsonBytes.String())
70 jsonBytes.Reset()
71 _, err = combiner.ConsumeWithFinal(result.trace, i == len(results)-1)
72 if err != nil {
73 return fmt.Errorf("error combining trace: %w", err)
74 }
75 }
76
77 combinedTrace, _ := combiner.Result()
78 fmt.Println("combined:")
79 err = marshaller.Marshal(&jsonBytes, combinedTrace)
80 if err != nil {
81 fmt.Println("failed to marshal to json: ", err)
82 return nil
83 }
84 fmt.Println(jsonBytes.String())
85 return nil
86}
87
88func queryBucket(ctx context.Context, percentage float32, r backend.Reader, c backend.Compactor, tenantID string, traceID common.ID) ([]queryResults, error) {
89 blockIDs, compactedBlockIDs, err := r.Blocks(context.Background(), tenantID)

Callers

nothing calls this directly

Calls 9

HexStringToTraceIDFunction · 0.92
NewCombinerFunction · 0.92
loadBackendFunction · 0.85
queryBucketFunction · 0.85
MarshalMethod · 0.65
ResetMethod · 0.65
ResultMethod · 0.65
StringMethod · 0.45
ConsumeWithFinalMethod · 0.45

Tested by

no test coverage detected