Skip to content

Commit

Permalink
Adhere to goconst lint rule
Browse files Browse the repository at this point in the history
  • Loading branch information
zalegrala committed Jul 18, 2023
1 parent a5c0cce commit bf87c46
Showing 1 changed file with 49 additions and 18 deletions.
67 changes: 49 additions & 18 deletions modules/ingester/instance_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ import (
"github.com/grafana/tempo/pkg/util/test"
)

const (
foo = "foo"
bar = "bar"
)

func TestInstanceSearch(t *testing.T) {
i, ingester, tempDir := defaultInstanceAndTmpDir(t)

tagKey := "foo"
tagValue := "bar"
tagKey := foo
tagValue := bar
ids, _ := writeTracesForSearch(t, i, tagKey, tagValue, false)

req := &tempopb.SearchRequest{
Expand Down Expand Up @@ -164,8 +169,8 @@ func TestInstanceSearchTraceQL(t *testing.T) {
func TestInstanceSearchWithStartAndEnd(t *testing.T) {
i, ingester, _ := defaultInstanceAndTmpDir(t)

tagKey := "foo"
tagValue := "bar"
tagKey := foo
tagValue := bar
ids, _ := writeTracesForSearch(t, i, tagKey, tagValue, false)

search := func(req *tempopb.SearchRequest, start, end uint32) *tempopb.SearchResponse {
Expand Down Expand Up @@ -241,7 +246,7 @@ func TestInstanceSearchTags(t *testing.T) {

// add dummy search data
tagKey := "foo"
tagValue := "bar"
tagValue := bar

_, expectedTagValues := writeTracesForSearch(t, i, tagKey, tagValue, true)

Expand Down Expand Up @@ -276,7 +281,11 @@ func testSearchTagsAndValues(t *testing.T, ctx context.Context, i *instance, tag

sr, err = i.SearchTags(ctx, "resource")
require.NoError(t, err)
assert.NotContains(t, sr.TagNames, tagName) // tags are added to h the spans and not resources so they should not be returned
assert.NotContains(
t,
sr.TagNames,
tagName,
) // tags are added to h the spans and not resources so they should not be returned

srv, err := i.SearchTagValues(ctx, tagName)
require.NoError(t, err)
Expand All @@ -292,8 +301,8 @@ func TestInstanceSearchTagAndValuesV2(t *testing.T) {

// add dummy search data
var (
tagKey = "foo"
tagValue = "bar"
tagKey = foo
tagValue = bar
queryThatMatches = `{ .service.name = "test-service" }`
queryThatDoesNotMatch = `{ .uuuuu = "aaaaa" }`
)
Expand All @@ -304,7 +313,14 @@ func TestInstanceSearchTagAndValuesV2(t *testing.T) {

// Test after appending to WAL
testSearchTagsAndValuesV2(t, userCtx, i, tagKey, queryThatMatches, expectedTagValues) // Matches the expected tag values
testSearchTagsAndValuesV2(t, userCtx, i, tagKey, queryThatDoesNotMatch, []string{}) // Does not match the expected tag values
testSearchTagsAndValuesV2(
t,
userCtx,
i,
tagKey,
queryThatDoesNotMatch,
[]string{},
) // Does not match the expected tag values

// Test after cutting new headblock
blockID, err := i.CutBlockIfReady(0, 0, true)
Expand All @@ -321,7 +337,13 @@ func TestInstanceSearchTagAndValuesV2(t *testing.T) {
}

// nolint:revive,unparam
func testSearchTagsAndValuesV2(t *testing.T, ctx context.Context, i *instance, tagName, query string, expectedTagValues []string) {
func testSearchTagsAndValuesV2(
t *testing.T,
ctx context.Context,
i *instance,
tagName, query string,
expectedTagValues []string,
) {
tagsResp, err := i.SearchTags(ctx, "none")
require.NoError(t, err)

Expand Down Expand Up @@ -354,7 +376,11 @@ func TestInstanceSearchTagsSpecialCases(t *testing.T) {

resp, err = i.SearchTags(userCtx, "intrinsic")
require.NoError(t, err)
require.Equal(t, []string{"duration", "kind", "name", "status", "traceDuration", "rootServiceName", "rootName"}, resp.TagNames)
require.Equal(
t,
[]string{"duration", "kind", "name", "status", "traceDuration", "rootServiceName", "rootName"},
resp.TagNames,
)
}

// TestInstanceSearchMaxBytesPerTagValuesQueryReturnsPartial confirms that SearchTagValues returns
Expand All @@ -373,8 +399,8 @@ func TestInstanceSearchMaxBytesPerTagValuesQueryReturnsPartial(t *testing.T) {
i, err := ingester.getOrCreateInstance("fake")
assert.NoError(t, err, "unexpected error creating new instance")

tagKey := "foo"
tagValue := "bar"
tagKey := foo
tagValue := bar

_, _ = writeTracesForSearch(t, i, tagKey, tagValue, true)

Expand All @@ -400,9 +426,10 @@ func TestInstanceSearchMaxBlocksPerTagValuesQueryReturnsPartial(t *testing.T) {
i, err := ingester.getOrCreateInstance("fake")
assert.NoError(t, err, "unexpected error creating new instance")

tagKey := "foo"
tagKey := foo
tagValue := bar

_, _ = writeTracesForSearch(t, i, tagKey, "bar", true)
_, _ = writeTracesForSearch(t, i, tagKey, tagValue, true)

// Cut the headblock
blockID, err := i.CutBlockIfReady(0, 0, true)
Expand Down Expand Up @@ -464,7 +491,10 @@ func writeTracesForSearch(t *testing.T, i *instance, tagKey string, tagValue str
ids = append(ids, id)

testTrace := test.MakeTrace(10, id)
testTrace.Batches[0].ScopeSpans[0].Spans[0].Attributes = append(testTrace.Batches[0].ScopeSpans[0].Spans[0].Attributes, kv)
testTrace.Batches[0].ScopeSpans[0].Spans[0].Attributes = append(
testTrace.Batches[0].ScopeSpans[0].Spans[0].Attributes,
kv,
)
trace.SortTrace(testTrace)

traceBytes, err := dec.PrepareForWrite(testTrace, 0, 0)
Expand Down Expand Up @@ -506,7 +536,7 @@ func TestInstanceSearchDoesNotRace(t *testing.T) {
dec := model.MustNewSegmentDecoder(model.CurrentEncoding)

// add dummy search data
tagKey := "foo"
tagKey := foo
tagValue := "bar"

req := &tempopb.SearchRequest{
Expand Down Expand Up @@ -797,7 +827,8 @@ func BenchmarkInstanceSearchUnderLoad(b *testing.B) {
time.Sleep(time.Duration(b.N) * time.Millisecond)
elapsed := time.Since(start)

fmt.Printf("Instance search throughput under load: %v elapsed %.2f MB = %.2f MiB/s throughput inspected %.2f traces/s pushed %.2f traces/s %.2f searches/s %.2f cuts/s\n",
fmt.Printf(
"Instance search throughput under load: %v elapsed %.2f MB = %.2f MiB/s throughput inspected %.2f traces/s pushed %.2f traces/s %.2f searches/s %.2f cuts/s\n",
elapsed,
float64(bytesInspected.Load())/(1024*1024),
float64(bytesInspected.Load())/(elapsed.Seconds())/(1024*1024),
Expand Down

0 comments on commit bf87c46

Please sign in to comment.