Skip to content

Cliquery#2775

Merged
ie-pham merged 25 commits intografana:mainfrom
ie-pham:cliquery
Aug 22, 2023
Merged

Cliquery#2775
ie-pham merged 25 commits intografana:mainfrom
ie-pham:cliquery

Conversation

@ie-pham
Copy link
Copy Markdown
Contributor

@ie-pham ie-pham commented Aug 9, 2023

What this PR does:

Which issue(s) this PR fixes:
Fixes #

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

spanCount := 0
firstStartTime := combinedTrace.Batches[0].ScopeSpans[0].Spans[0].StartTimeUnixNano
lastEndTime := combinedTrace.Batches[0].ScopeSpans[0].Spans[0].EndTimeUnixNano
rootSpan := combinedTrace.Batches[0].ScopeSpans[0].Spans[0]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the root span is not always the first. as you're iterating through all the spans below look for one with no parent span id

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of grabbing this first span like this we should init firstStartTime/lastEndTime/rootSpan/rootResource to better first values. something like this diff:

@@ -4,11 +4,14 @@ import (
        "bytes"
        "context"
        "fmt"
+       "math"
        "sort"
 
        "github.com/gogo/protobuf/jsonpb"
 
        "github.com/grafana/tempo/pkg/model/trace"
+       v1resource "github.com/grafana/tempo/pkg/tempopb/resource/v1"
+       v1 "github.com/grafana/tempo/pkg/tempopb/trace/v1"
        "github.com/grafana/tempo/pkg/util"
 )
 
@@ -47,15 +50,16 @@ func (cmd *queryBlocksSummaryCmd) Run(ctx *globalOptions) error {
        }
 
        combinedTrace, _ := combiner.Result()
+
+       var rootSpan *v1.Span
+       var rootSpanResource *v1resource.Resource
        size := 0
        spanCount := 0
-       firstStartTime := combinedTrace.Batches[0].ScopeSpans[0].Spans[0].StartTimeUnixNano
-       lastEndTime := combinedTrace.Batches[0].ScopeSpans[0].Spans[0].EndTimeUnixNano
-       rootSpan := combinedTrace.Batches[0].ScopeSpans[0].Spans[0]
-       rootSpanResource := combinedTrace.Batches[0].Resource
+       firstStartTime := uint64(math.MaxUint64)
+       lastEndTime := uint64(0)
+
        rootServiceName := ""
        serviceNameMap := make(map[string]int)
-
        for _, b := range combinedTrace.Batches {
                size += b.Size()
                for _, attr := range b.Resource.Attributes {

Comment thread cmd/tempo-cli/cmd-query-blocks-summary.go Outdated

// get top 5 most frequent service names
lowest := 0
topFiveName := make([]string, 5)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would probably just put all of the key/value pairs in a slice and sort it. it won't be as efficient, but it will be clearer and this CLI command doesn't need to be super efficient.

@ie-pham ie-pham marked this pull request as ready for review August 9, 2023 18:50
Copy link
Copy Markdown
Collaborator

@joe-elliott joe-elliott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heading the right way. we need:

  • changelog
  • docs

i also don't like the command name, but it does nicely match the query blocks command.

Comment thread cmd/tempo-cli/cmd-query-blocks-summary.go Outdated
spanCount := 0
firstStartTime := combinedTrace.Batches[0].ScopeSpans[0].Spans[0].StartTimeUnixNano
lastEndTime := combinedTrace.Batches[0].ScopeSpans[0].Spans[0].EndTimeUnixNano
rootSpan := combinedTrace.Batches[0].ScopeSpans[0].Spans[0]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of grabbing this first span like this we should init firstStartTime/lastEndTime/rootSpan/rootResource to better first values. something like this diff:

@@ -4,11 +4,14 @@ import (
        "bytes"
        "context"
        "fmt"
+       "math"
        "sort"
 
        "github.com/gogo/protobuf/jsonpb"
 
        "github.com/grafana/tempo/pkg/model/trace"
+       v1resource "github.com/grafana/tempo/pkg/tempopb/resource/v1"
+       v1 "github.com/grafana/tempo/pkg/tempopb/trace/v1"
        "github.com/grafana/tempo/pkg/util"
 )
 
@@ -47,15 +50,16 @@ func (cmd *queryBlocksSummaryCmd) Run(ctx *globalOptions) error {
        }
 
        combinedTrace, _ := combiner.Result()
+
+       var rootSpan *v1.Span
+       var rootSpanResource *v1resource.Resource
        size := 0
        spanCount := 0
-       firstStartTime := combinedTrace.Batches[0].ScopeSpans[0].Spans[0].StartTimeUnixNano
-       lastEndTime := combinedTrace.Batches[0].ScopeSpans[0].Spans[0].EndTimeUnixNano
-       rootSpan := combinedTrace.Batches[0].ScopeSpans[0].Spans[0]
-       rootSpanResource := combinedTrace.Batches[0].Resource
+       firstStartTime := uint64(math.MaxUint64)
+       lastEndTime := uint64(0)
+
        rootServiceName := ""
        serviceNameMap := make(map[string]int)
-
        for _, b := range combinedTrace.Batches {
                size += b.Size()
                for _, attr := range b.Resource.Attributes {

@knylander-grafana
Copy link
Copy Markdown
Contributor

@ie-pham This looks like a useful tool. Should we add some doc for this?

@ie-pham ie-pham requested a review from joe-elliott August 21, 2023 20:11
Comment thread cmd/tempo-cli/cmd-query-trace-summary.go
// get top 5 most frequent service names
topFiveSortedPL := sortServiceNames(serviceNameMap)
topFiveServiceName := make([]string, 5)
length := len(topFiveSortedPL)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if length is less than 5? i think this panics

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we are iterating through the actual list of service names using its length (or if it's longer than 5 use 5), even if it's less than 3, we wouldn't get to out of range. It just prints out a weird looking array with extra spaces

[a b c ]

@ie-pham ie-pham requested a review from joe-elliott August 22, 2023 14:24
@ie-pham ie-pham merged commit 8357aff into grafana:main Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants