Skip to content

Commit

Permalink
only lookback 1 kairosdb period for tags in rollups (#586)
Browse files Browse the repository at this point in the history
* only lookback 1 kairosdb period for tags in rollups
  • Loading branch information
BrandonArp authored Jan 14, 2024
1 parent b930e89 commit 58fb8d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 7 additions & 1 deletion app/com/arpnetworking/rollups/RollupGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public RollupGenerator(
final MetricsFactory metricsFactory,
@Named("RollupGeneratorTagger") final Tagger tagger
) {
_tagLookbackPeriods = 1;
_metricsDiscovery = metricsDiscovery;
_rollupManager = rollupManager;
_kairosDbClient = kairosDbClient;
Expand Down Expand Up @@ -157,9 +158,12 @@ private void requestMetricsFromDiscovery(final Object fetch) {
private void fetchMetricTags(final String metricName) {
_periodicMetrics.recordCounter("rollup/generator/metric_names_message/received", 1);
final long startTime = System.nanoTime();
final long now = System.currentTimeMillis();
final long beginningOfPeriod = now - (now % KAIROSDB_PERIOD_MILLIS);
final long startPeriod = beginningOfPeriod - (_tagLookbackPeriods * KAIROSDB_PERIOD_MILLIS);
Patterns.pipe(_kairosDbClient.queryMetricTags(
new TagsQuery.Builder()
.setStartTime(Instant.ofEpochMilli(0))
.setStartTime(Instant.ofEpochMilli(startPeriod))
.setMetrics(ImmutableList.of(
ThreadLocalBuilder.build(MetricTags.Builder.class, builder -> builder.setName(metricName))
))
Expand Down Expand Up @@ -510,6 +514,7 @@ private MetricsQuery buildLastDataPointQuery(
private final KairosDbClient _kairosDbClient;
private final Map<RollupPeriod, Integer> _maxBackFillByPeriod;
private final FiniteDuration _fetchBackoff;
private final int _tagLookbackPeriods;
private final Clock _clock;
private final PeriodicMetrics _periodicMetrics;
private final MetricsFactory _metricsFactory;
Expand All @@ -518,4 +523,5 @@ private MetricsQuery buildLastDataPointQuery(

static final Object FETCH_METRIC = new Object();
private static final Logger LOGGER = LoggerFactory.getLogger(RollupGenerator.class);
private static final long KAIROSDB_PERIOD_MILLIS = 1000L * 60 * 60 * 24 * 21;
}
3 changes: 2 additions & 1 deletion test/java/com/arpnetworking/rollups/RollupGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.any;
Expand Down Expand Up @@ -184,7 +185,7 @@ public void testFetchesTagNames() {
verify(_kairosDbClient, times(1)).queryMetricTags(captor.capture());
final TagsQuery tagQuery = captor.getValue();
assertEquals("metric", tagQuery.getMetrics().get(0).getName());
assertEquals(Optional.of(Instant.ofEpochSecond(0)), tagQuery.getStartTime());
assertNotEquals(Optional.of(Instant.ofEpochSecond(0)), tagQuery.getStartTime());
}

@Test
Expand Down

0 comments on commit 58fb8d4

Please sign in to comment.