Skip to content

Commit

Permalink
Merge pull request #15548 from TinfoilSubmarine/fix/386-test-failures
Browse files Browse the repository at this point in the history
test: fixes for 32-bit archs
  • Loading branch information
beorn7 authored Dec 18, 2024
2 parents b8c0907 + 5271dab commit 318d6bc
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- uses: prometheus/promci@52c7012f5f0070d7281b8db4a119e21341d43c91 # v0.4.5
- uses: ./.github/promci/actions/setup_environment
- run: go test --tags=dedupelabels ./...
- run: GOARCH=386 go test ./cmd/prometheus
- run: GOARCH=386 go test ./...
- uses: ./.github/promci/actions/check_proto
with:
version: "3.15.8"
Expand Down
4 changes: 2 additions & 2 deletions model/histogram/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ func GenerateBigTestHistograms(numHistograms, numBuckets int) []*Histogram {
bucketsPerSide := numBuckets / 2
spanLength := uint32(bucketsPerSide / numSpans)
// Given all bucket deltas are 1, sum bucketsPerSide + 1.
observationCount := bucketsPerSide * (1 + bucketsPerSide)
observationCount := uint64(bucketsPerSide) * (1 + uint64(bucketsPerSide))

var histograms []*Histogram
for i := 0; i < numHistograms; i++ {
h := &Histogram{
Count: uint64(i + observationCount),
Count: uint64(i) + observationCount,
ZeroCount: uint64(i),
ZeroThreshold: 1e-128,
Sum: 18.4 * float64(i+1),
Expand Down
18 changes: 9 additions & 9 deletions promql/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1352,17 +1352,17 @@ func (ev *evaluator) rangeEvalAgg(ctx context.Context, aggExpr *parser.Aggregate
}
groups := make([]groupedAggregation, groupCount)

var k int
var k int64
var ratio float64
var seriess map[uint64]Series
switch aggExpr.Op {
case parser.TOPK, parser.BOTTOMK, parser.LIMITK:
if !convertibleToInt64(param) {
ev.errorf("Scalar value %v overflows int64", param)
}
k = int(param)
if k > len(inputMatrix) {
k = len(inputMatrix)
k = int64(param)
if k > int64(len(inputMatrix)) {
k = int64(len(inputMatrix))
}
if k < 1 {
return nil, warnings
Expand Down Expand Up @@ -3172,7 +3172,7 @@ func (ev *evaluator) aggregation(e *parser.AggregateExpr, q float64, inputMatrix
// seriesToResult maps inputMatrix indexes to groups indexes.
// For an instant query, returns a Matrix in descending order for topk or ascending for bottomk, or without any order for limitk / limit_ratio.
// For a range query, aggregates output in the seriess map.
func (ev *evaluator) aggregationK(e *parser.AggregateExpr, k int, r float64, inputMatrix Matrix, seriesToResult []int, groups []groupedAggregation, enh *EvalNodeHelper, seriess map[uint64]Series) (Matrix, annotations.Annotations) {
func (ev *evaluator) aggregationK(e *parser.AggregateExpr, k int64, r float64, inputMatrix Matrix, seriesToResult []int, groups []groupedAggregation, enh *EvalNodeHelper, seriess map[uint64]Series) (Matrix, annotations.Annotations) {
op := e.Op
var s Sample
var annos annotations.Annotations
Expand Down Expand Up @@ -3243,7 +3243,7 @@ seriesLoop:
case s.H != nil:
// Ignore histogram sample and add info annotation.
annos.Add(annotations.NewHistogramIgnoredInAggregationInfo("topk", e.PosRange))
case len(group.heap) < k:
case int64(len(group.heap)) < k:
heap.Push(&group.heap, &s)
case group.heap[0].F < s.F || (math.IsNaN(group.heap[0].F) && !math.IsNaN(s.F)):
// This new element is bigger than the previous smallest element - overwrite that.
Expand All @@ -3259,7 +3259,7 @@ seriesLoop:
case s.H != nil:
// Ignore histogram sample and add info annotation.
annos.Add(annotations.NewHistogramIgnoredInAggregationInfo("bottomk", e.PosRange))
case len(group.heap) < k:
case int64(len(group.heap)) < k:
heap.Push((*vectorByReverseValueHeap)(&group.heap), &s)
case group.heap[0].F > s.F || (math.IsNaN(group.heap[0].F) && !math.IsNaN(s.F)):
// This new element is smaller than the previous biggest element - overwrite that.
Expand All @@ -3270,13 +3270,13 @@ seriesLoop:
}

case parser.LIMITK:
if len(group.heap) < k {
if int64(len(group.heap)) < k {
heap.Push(&group.heap, &s)
}
// LIMITK optimization: early break if we've added K elem to _every_ group,
// especially useful for large timeseries where the user is exploring labels via e.g.
// limitk(10, my_metric)
if !group.groupAggrComplete && len(group.heap) == k {
if !group.groupAggrComplete && int64(len(group.heap)) == k {
group.groupAggrComplete = true
groupsRemaining--
if groupsRemaining == 0 {
Expand Down
2 changes: 1 addition & 1 deletion scrape/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ func findSamplesForMetric(floats []floatSample, metricName string) (ret []floatS
// generateTestHistogram generates the same thing as tsdbutil.GenerateTestHistogram,
// but in the form of dto.Histogram.
func generateTestHistogram(i int) *dto.Histogram {
helper := tsdbutil.GenerateTestHistogram(i)
helper := tsdbutil.GenerateTestHistogram(int64(i))
h := &dto.Histogram{}
h.SampleCount = proto.Uint64(helper.Count)
h.SampleSum = proto.Float64(helper.Sum)
Expand Down
4 changes: 2 additions & 2 deletions storage/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,13 @@ func TestMergeChunkQuerierWithNoVerticalChunkSeriesMerger(t *testing.T) {
}

func histogramSample(ts int64, hint histogram.CounterResetHint) hSample {
h := tsdbutil.GenerateTestHistogram(int(ts + 1))
h := tsdbutil.GenerateTestHistogram(ts + 1)
h.CounterResetHint = hint
return hSample{t: ts, h: h}
}

func floatHistogramSample(ts int64, hint histogram.CounterResetHint) fhSample {
fh := tsdbutil.GenerateTestFloatHistogram(int(ts + 1))
fh := tsdbutil.GenerateTestFloatHistogram(ts + 1)
fh.CounterResetHint = hint
return fhSample{t: ts, fh: fh}
}
Expand Down
2 changes: 1 addition & 1 deletion storage/remote/queue_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2077,7 +2077,7 @@ func createTimeseriesWithOldSamples(numSamples, numSeries int, extraLabels ...la
for j := 0; j < numSamples/2; j++ {
sample := record.RefSample{
Ref: chunks.HeadSeriesRef(i),
T: int64(int(time.Now().UnixMilli()) + j),
T: time.Now().UnixMilli() + int64(j),
V: float64(i),
}
samples = append(samples, sample)
Expand Down
40 changes: 20 additions & 20 deletions tsdb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4101,7 +4101,7 @@ func TestOOOWALWrite(t *testing.T) {
},
"integer histogram": {
appendSample: func(app storage.Appender, l labels.Labels, mins int64) (storage.SeriesRef, error) {
seriesRef, err := app.AppendHistogram(0, l, minutes(mins), tsdbutil.GenerateTestHistogram(int(mins)), nil)
seriesRef, err := app.AppendHistogram(0, l, minutes(mins), tsdbutil.GenerateTestHistogram(mins), nil)
require.NoError(t, err)
return seriesRef, nil
},
Expand Down Expand Up @@ -4192,7 +4192,7 @@ func TestOOOWALWrite(t *testing.T) {
},
"float histogram": {
appendSample: func(app storage.Appender, l labels.Labels, mins int64) (storage.SeriesRef, error) {
seriesRef, err := app.AppendHistogram(0, l, minutes(mins), nil, tsdbutil.GenerateTestFloatHistogram(int(mins)))
seriesRef, err := app.AppendHistogram(0, l, minutes(mins), nil, tsdbutil.GenerateTestFloatHistogram(mins))
require.NoError(t, err)
return seriesRef, nil
},
Expand Down Expand Up @@ -4736,12 +4736,12 @@ func TestMultipleEncodingsCommitOrder(t *testing.T) {
return sample{t: ts, f: float64(ts)}
}
if valType == chunkenc.ValHistogram {
h := tsdbutil.GenerateTestHistogram(int(ts))
h := tsdbutil.GenerateTestHistogram(ts)
_, err := app.AppendHistogram(0, labels.FromStrings("foo", "bar1"), ts, h, nil)
require.NoError(t, err)
return sample{t: ts, h: h}
}
fh := tsdbutil.GenerateTestFloatHistogram(int(ts))
fh := tsdbutil.GenerateTestFloatHistogram(ts)
_, err := app.AppendHistogram(0, labels.FromStrings("foo", "bar1"), ts, nil, fh)
require.NoError(t, err)
return sample{t: ts, fh: fh}
Expand Down Expand Up @@ -5427,37 +5427,37 @@ func TestQuerierOOOQuery(t *testing.T) {
},
"integer histogram": {
appendFunc: func(app storage.Appender, ts int64, counterReset bool) (storage.SeriesRef, error) {
h := tsdbutil.GenerateTestHistogram(int(ts))
h := tsdbutil.GenerateTestHistogram(ts)
if counterReset {
h.CounterResetHint = histogram.CounterReset
}
return app.AppendHistogram(0, labels.FromStrings("foo", "bar1"), ts, h, nil)
},
sampleFunc: func(ts int64) chunks.Sample {
return sample{t: ts, h: tsdbutil.GenerateTestHistogram(int(ts))}
return sample{t: ts, h: tsdbutil.GenerateTestHistogram(ts)}
},
},
"float histogram": {
appendFunc: func(app storage.Appender, ts int64, counterReset bool) (storage.SeriesRef, error) {
fh := tsdbutil.GenerateTestFloatHistogram(int(ts))
fh := tsdbutil.GenerateTestFloatHistogram(ts)
if counterReset {
fh.CounterResetHint = histogram.CounterReset
}
return app.AppendHistogram(0, labels.FromStrings("foo", "bar1"), ts, nil, fh)
},
sampleFunc: func(ts int64) chunks.Sample {
return sample{t: ts, fh: tsdbutil.GenerateTestFloatHistogram(int(ts))}
return sample{t: ts, fh: tsdbutil.GenerateTestFloatHistogram(ts)}
},
},
"integer histogram counter resets": {
// Adding counter reset to all histograms means each histogram will have its own chunk.
appendFunc: func(app storage.Appender, ts int64, counterReset bool) (storage.SeriesRef, error) {
h := tsdbutil.GenerateTestHistogram(int(ts))
h := tsdbutil.GenerateTestHistogram(ts)
h.CounterResetHint = histogram.CounterReset // For this scenario, ignore the counterReset argument.
return app.AppendHistogram(0, labels.FromStrings("foo", "bar1"), ts, h, nil)
},
sampleFunc: func(ts int64) chunks.Sample {
return sample{t: ts, h: tsdbutil.GenerateTestHistogram(int(ts))}
return sample{t: ts, h: tsdbutil.GenerateTestHistogram(ts)}
},
},
}
Expand Down Expand Up @@ -5743,37 +5743,37 @@ func TestChunkQuerierOOOQuery(t *testing.T) {
},
"integer histogram": {
appendFunc: func(app storage.Appender, ts int64, counterReset bool) (storage.SeriesRef, error) {
h := tsdbutil.GenerateTestHistogram(int(ts))
h := tsdbutil.GenerateTestHistogram(ts)
if counterReset {
h.CounterResetHint = histogram.CounterReset
}
return app.AppendHistogram(0, labels.FromStrings("foo", "bar1"), ts, h, nil)
},
sampleFunc: func(ts int64) chunks.Sample {
return sample{t: ts, h: tsdbutil.GenerateTestHistogram(int(ts))}
return sample{t: ts, h: tsdbutil.GenerateTestHistogram(ts)}
},
},
"float histogram": {
appendFunc: func(app storage.Appender, ts int64, counterReset bool) (storage.SeriesRef, error) {
fh := tsdbutil.GenerateTestFloatHistogram(int(ts))
fh := tsdbutil.GenerateTestFloatHistogram(ts)
if counterReset {
fh.CounterResetHint = histogram.CounterReset
}
return app.AppendHistogram(0, labels.FromStrings("foo", "bar1"), ts, nil, fh)
},
sampleFunc: func(ts int64) chunks.Sample {
return sample{t: ts, fh: tsdbutil.GenerateTestFloatHistogram(int(ts))}
return sample{t: ts, fh: tsdbutil.GenerateTestFloatHistogram(ts)}
},
},
"integer histogram counter resets": {
// Adding counter reset to all histograms means each histogram will have its own chunk.
appendFunc: func(app storage.Appender, ts int64, counterReset bool) (storage.SeriesRef, error) {
h := tsdbutil.GenerateTestHistogram(int(ts))
h := tsdbutil.GenerateTestHistogram(ts)
h.CounterResetHint = histogram.CounterReset // For this scenario, ignore the counterReset argument.
return app.AppendHistogram(0, labels.FromStrings("foo", "bar1"), ts, h, nil)
},
sampleFunc: func(ts int64) chunks.Sample {
return sample{t: ts, h: tsdbutil.GenerateTestHistogram(int(ts))}
return sample{t: ts, h: tsdbutil.GenerateTestHistogram(ts)}
},
},
"integer histogram with recode": {
Expand Down Expand Up @@ -6908,15 +6908,15 @@ func TestOOOHistogramCompactionWithCounterResets(t *testing.T) {
app := db.Appender(context.Background())
tsMs := ts * time.Minute.Milliseconds()
if floatHistogram {
h := tsdbutil.GenerateTestFloatHistogram(val)
h := tsdbutil.GenerateTestFloatHistogram(int64(val))
h.CounterResetHint = hint
_, err = app.AppendHistogram(0, l, tsMs, nil, h)
require.NoError(t, err)
require.NoError(t, app.Commit())
return sample{t: tsMs, fh: h.Copy()}
}

h := tsdbutil.GenerateTestHistogram(val)
h := tsdbutil.GenerateTestHistogram(int64(val))
h.CounterResetHint = hint
_, err = app.AppendHistogram(0, l, tsMs, h, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -7267,14 +7267,14 @@ func TestInterleavedInOrderAndOOOHistogramCompactionWithCounterResets(t *testing
app := db.Appender(context.Background())
tsMs := ts
if floatHistogram {
h := tsdbutil.GenerateTestFloatHistogram(val)
h := tsdbutil.GenerateTestFloatHistogram(int64(val))
_, err = app.AppendHistogram(0, l, tsMs, nil, h)
require.NoError(t, err)
require.NoError(t, app.Commit())
return sample{t: tsMs, fh: h.Copy()}
}

h := tsdbutil.GenerateTestHistogram(val)
h := tsdbutil.GenerateTestHistogram(int64(val))
_, err = app.AppendHistogram(0, l, tsMs, h, nil)
require.NoError(t, err)
require.NoError(t, app.Commit())
Expand Down
4 changes: 2 additions & 2 deletions tsdb/head_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4732,7 +4732,7 @@ func TestOOOHistogramCounterResetHeaders(t *testing.T) {

// OOO histogram
for i := 1; i <= 5; i++ {
appendHistogram(100+int64(i), tsdbutil.GenerateTestHistogram(1000+i))
appendHistogram(100+int64(i), tsdbutil.GenerateTestHistogram(1000+int64(i)))
}
// Nothing mmapped yet.
checkOOOExpCounterResetHeader()
Expand Down Expand Up @@ -4820,7 +4820,7 @@ func TestOOOHistogramCounterResetHeaders(t *testing.T) {
appendHistogram(300, tsdbutil.SetHistogramCounterReset(tsdbutil.GenerateTestHistogram(3000)))

for i := 1; i <= 4; i++ {
appendHistogram(300+int64(i), tsdbutil.GenerateTestHistogram(3000+i))
appendHistogram(300+int64(i), tsdbutil.GenerateTestHistogram(3000+int64(i)))
}

// One mmapped chunk with (ts, val) [(300, 3000), (301, 3001), (302, 3002), (303, 3003), (350, 4000)].
Expand Down
8 changes: 4 additions & 4 deletions tsdb/ooo_head_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ func TestOOOInsert(t *testing.T) {
},
"integer histogram": {
sampleFunc: func(ts int64) sample {
return sample{t: ts, h: tsdbutil.GenerateTestHistogram(int(ts))}
return sample{t: ts, h: tsdbutil.GenerateTestHistogram(ts)}
},
},
"float histogram": {
sampleFunc: func(ts int64) sample {
return sample{t: ts, fh: tsdbutil.GenerateTestFloatHistogram(int(ts))}
return sample{t: ts, fh: tsdbutil.GenerateTestFloatHistogram(ts)}
},
},
}
Expand Down Expand Up @@ -118,12 +118,12 @@ func TestOOOInsertDuplicate(t *testing.T) {
},
"integer histogram": {
sampleFunc: func(ts int64) sample {
return sample{t: ts, h: tsdbutil.GenerateTestHistogram(int(ts))}
return sample{t: ts, h: tsdbutil.GenerateTestHistogram(ts)}
},
},
"float histogram": {
sampleFunc: func(ts int64) sample {
return sample{t: ts, fh: tsdbutil.GenerateTestFloatHistogram(int(ts))}
return sample{t: ts, fh: tsdbutil.GenerateTestFloatHistogram(ts)}
},
},
}
Expand Down
12 changes: 6 additions & 6 deletions tsdb/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1826,12 +1826,12 @@ func checkCurrVal(t *testing.T, valType chunkenc.ValueType, it *populateWithDelS
ts, h := it.AtHistogram(nil)
require.Equal(t, int64(expectedTs), ts)
h.CounterResetHint = histogram.UnknownCounterReset
require.Equal(t, tsdbutil.GenerateTestHistogram(expectedValue), h)
require.Equal(t, tsdbutil.GenerateTestHistogram(int64(expectedValue)), h)
case chunkenc.ValFloatHistogram:
ts, h := it.AtFloatHistogram(nil)
require.Equal(t, int64(expectedTs), ts)
h.CounterResetHint = histogram.UnknownCounterReset
require.Equal(t, tsdbutil.GenerateTestFloatHistogram(expectedValue), h)
require.Equal(t, tsdbutil.GenerateTestFloatHistogram(int64(expectedValue)), h)
default:
panic("unexpected value type")
}
Expand Down Expand Up @@ -3588,16 +3588,16 @@ func TestQueryWithDeletedHistograms(t *testing.T) {
ctx := context.Background()
testcases := map[string]func(int) (*histogram.Histogram, *histogram.FloatHistogram){
"intCounter": func(i int) (*histogram.Histogram, *histogram.FloatHistogram) {
return tsdbutil.GenerateTestHistogram(i), nil
return tsdbutil.GenerateTestHistogram(int64(i)), nil
},
"intgauge": func(i int) (*histogram.Histogram, *histogram.FloatHistogram) {
return tsdbutil.GenerateTestGaugeHistogram(rand.Int() % 1000), nil
return tsdbutil.GenerateTestGaugeHistogram(rand.Int63() % 1000), nil
},
"floatCounter": func(i int) (*histogram.Histogram, *histogram.FloatHistogram) {
return nil, tsdbutil.GenerateTestFloatHistogram(i)
return nil, tsdbutil.GenerateTestFloatHistogram(int64(i))
},
"floatGauge": func(i int) (*histogram.Histogram, *histogram.FloatHistogram) {
return nil, tsdbutil.GenerateTestGaugeFloatHistogram(rand.Int() % 1000)
return nil, tsdbutil.GenerateTestGaugeFloatHistogram(rand.Int63() % 1000)
},
}

Expand Down
Loading

0 comments on commit 318d6bc

Please sign in to comment.