Skip to content

Commit

Permalink
Fixes int overflow issue for large TTL values (#3367)
Browse files Browse the repository at this point in the history
  • Loading branch information
vy8 authored Dec 6, 2023
1 parent e661025 commit 68c4949
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2020 The OpenZipkin Authors
* Copyright 2015-2021 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -125,7 +125,7 @@ static SelectTraceIdsFromSpan.Factory initialiseSelectTraceIdsFromSpan(CqlSessio
@Override public Call<List<List<Span>>> getTraces(QueryRequest request) {
if (!searchEnabled) return Call.emptyList();

TimestampRange timestampRange = timestampRange(request);
TimestampRange timestampRange = timestampRange(request, indexTtl);
// If we have to make multiple queries, over fetch on indexes as they don't return distinct
// (trace id, timestamp) rows. This mitigates intersection resulting in < limit traces
final int traceIndexFetchSize = request.limit() * indexFetchMultiplier;
Expand Down Expand Up @@ -305,8 +305,8 @@ static final class TimestampRange {
UUID endUUID;
}

TimestampRange timestampRange(QueryRequest request) {
long oldestData = Math.max(System.currentTimeMillis() - indexTtl * 1000, 0); // >= 1970
TimestampRange timestampRange(QueryRequest request, int indexTtl) {
long oldestData = Math.max(System.currentTimeMillis() - indexTtl * 1000L, 0); // >= 1970
TimestampRange result = new TimestampRange();
result.startMillis = Math.max((request.endTs() - request.lookback()), oldestData);
result.startUUID = Uuids.startOf(result.startMillis);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2020 The OpenZipkin Authors
* Copyright 2015-2021 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -33,6 +33,13 @@ public class CassandraSpanStoreTest {
CassandraSpanStore spanStore = spanStore(CassandraStorage.newBuilder());
QueryRequest.Builder queryBuilder = QueryRequest.newBuilder().endTs(TODAY).lookback(DAY).limit(5);

@Test public void timestampRange_withIndexTtlProvidedAvoidsOverflow() {
QueryRequest query = QueryRequest.newBuilder().endTs(TODAY).lookback(TODAY).limit(5).build();
CassandraSpanStore.TimestampRange timestampRange = spanStore.timestampRange(query, 7890000);

assertThat(timestampRange.startMillis).isLessThan(timestampRange.endMillis);
}

@Test public void getTraces_fansOutAgainstServices() {
Call<List<List<Span>>> call = spanStore.getTraces(queryBuilder.build());

Expand Down

0 comments on commit 68c4949

Please sign in to comment.