Skip to content

Commit

Permalink
Test cleanup. Add sz test, restore commented out and fix e2e
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Elliott <number101010@gmail.com>
  • Loading branch information
joe-elliott committed Nov 22, 2024
1 parent 17a581f commit d8b73f9
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 16 deletions.
3 changes: 3 additions & 0 deletions integration/e2e/limits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ func TestQueryLimits(t *testing.T) {
batch.Spans = allSpans[i : i+1]
require.NoError(t, c.EmitBatch(context.Background(), batch))
util.CallFlush(t, tempo)
// this push along with the double flush is required to forget the too large trace
require.NoError(t, c.EmitBatch(context.Background(), util.MakeThriftBatchWithSpanCount(1)))
util.CallFlush(t, tempo)
time.Sleep(2 * time.Second) // trace idle and flush time are both 1ms
}

Expand Down
46 changes: 46 additions & 0 deletions modules/generator/processor/localblocks/livetraces_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package localblocks

import (
"math/rand/v2"
"testing"
"time"

"github.com/grafana/tempo/pkg/util/test"
"github.com/stretchr/testify/require"
)

func TestLiveTracesSizesAndLen(t *testing.T) {
lt := newLiveTraces()

expectedSz := uint64(0)
expectedLen := uint64(0)

for i := 0; i < 100; i++ {
id := test.ValidTraceID(nil)
tr := test.MakeTrace(rand.IntN(5)+1, id)

cutTime := time.Now()

// add some traces and confirm size/len
expectedLen++
for _, rs := range tr.ResourceSpans {
expectedSz += uint64(rs.Size())
lt.Push(id, rs, 0)
}

require.Equal(t, expectedSz, lt.Size())
require.Equal(t, expectedLen, lt.Len())

// cut some traces and confirm size/len
cutTraces := lt.CutIdle(cutTime, false)
for _, tr := range cutTraces {
for _, rs := range tr.Batches {
expectedSz -= uint64(rs.Size())
}
expectedLen--
}

require.Equal(t, expectedSz, lt.Size())
require.Equal(t, expectedLen, lt.Len())
}
}
3 changes: 1 addition & 2 deletions modules/ingester/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ func (i *instance) push(ctx context.Context, id, traceBytes []byte) error {
return err
}

// increase live trace bytes (jpe test)
i.traceSizeBytes += uint64(reqSize)

return nil
Expand Down Expand Up @@ -545,7 +544,7 @@ func (i *instance) tracesToCut(cutoff time.Duration, immediate bool) []*liveTrac

// Set this before cutting to give a more accurate number.
metricLiveTraces.WithLabelValues(i.instanceID).Set(float64(len(i.traces)))
metricLiveTraceBytes.WithLabelValues(i.instanceID).Set(float64(i.traceSizeBytes)) // jpe some val
metricLiveTraceBytes.WithLabelValues(i.instanceID).Set(float64(i.traceSizeBytes))

cutoffTime := time.Now().Add(cutoff)
tracesToCut := make([]*liveTrace, 0, len(i.traces))
Expand Down
34 changes: 20 additions & 14 deletions modules/ingester/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,20 @@ func (m *ringCountMock) HealthyInstancesCount() int {

func TestInstance(t *testing.T) {
request := makeRequest([]byte{})
requestSz := uint64(0)
for _, b := range request.Traces {
requestSz += uint64(len(b.Slice))
}

i, ingester := defaultInstance(t)

response := i.PushBytesRequest(context.Background(), request)
require.NotNil(t, response)
require.Equal(t, requestSz, i.traceSizeBytes)

err := i.CutCompleteTraces(0, true)
require.NoError(t, err)
require.Equal(t, uint64(0), i.traceSizeBytes)

blockID, err := i.CutBlockIfReady(0, 0, false)
require.NoError(t, err, "unexpected error cutting block")
Expand Down Expand Up @@ -235,20 +241,20 @@ func TestInstanceLimits(t *testing.T) {
name string
pushes []push
}{
// {
// name: "bytes - succeeds",
// pushes: []push{
// {
// req: makeRequestWithByteLimit(300, []byte{}),
// },
// {
// req: makeRequestWithByteLimit(500, []byte{}),
// },
// {
// req: makeRequestWithByteLimit(100, []byte{}),
// },
// },
// },
{
name: "bytes - succeeds",
pushes: []push{
{
req: makeRequestWithByteLimit(300, []byte{}),
},
{
req: makeRequestWithByteLimit(500, []byte{}),
},
{
req: makeRequestWithByteLimit(100, []byte{}),
},
},
},
{
name: "bytes - one fails",
pushes: []push{
Expand Down

0 comments on commit d8b73f9

Please sign in to comment.