Skip to content

Commit 3efc671

Browse files
authored
Merge pull request #537 from salesforce/W-13497368-final
W-13497368
2 parents 2e6f982 + e8a686b commit 3efc671

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

timbermill-java/timbermill-local/src/main/java/com/datorama/oss/timbermill/common/cache/CacheConfig.java

+17
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,23 @@
55
public class CacheConfig {
66
private RedisService redisService;
77
private int cacheRedisTtlInSeconds;
8+
private int orphansCacheRedisTtlInSeconds;
9+
private int eventsCacheRedisTtlInSeconds;
810
private long maximumTasksCacheWeight;
911
private long maximumOrphansCacheWeight;
1012

1113
public CacheConfig(RedisService redisService, int cacheRedisTtlInSeconds, long maximumTasksCacheWeight, long maximumOrphansCacheWeight) {
14+
this(redisService, cacheRedisTtlInSeconds, maximumTasksCacheWeight, maximumOrphansCacheWeight, cacheRedisTtlInSeconds, cacheRedisTtlInSeconds);
15+
}
16+
public CacheConfig(RedisService redisService, int cacheRedisTtlInSeconds, long maximumTasksCacheWeight, long maximumOrphansCacheWeight, int orphansCacheRedisTtlInSeconds,
17+
int eventsCacheRedisTtlInSeconds) {
1218
this.redisService = redisService;
1319
this.cacheRedisTtlInSeconds = cacheRedisTtlInSeconds;
1420
this.maximumTasksCacheWeight = maximumTasksCacheWeight;
1521
this.maximumOrphansCacheWeight = maximumOrphansCacheWeight;
22+
this.eventsCacheRedisTtlInSeconds = eventsCacheRedisTtlInSeconds;
23+
this.orphansCacheRedisTtlInSeconds = orphansCacheRedisTtlInSeconds;
24+
1625
}
1726

1827
RedisService getRedisService() {
@@ -31,4 +40,12 @@ long getMaximumOrphansCacheWeight() {
3140
return maximumOrphansCacheWeight;
3241
}
3342

43+
public int getOrphansCacheRedisTtlInSeconds() {
44+
return orphansCacheRedisTtlInSeconds;
45+
}
46+
47+
public int getEventsCacheRedisTtlInSeconds() {
48+
return eventsCacheRedisTtlInSeconds;
49+
}
50+
3451
}

timbermill-java/timbermill-local/src/main/java/com/datorama/oss/timbermill/common/cache/CacheHandlerUtil.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public class CacheHandlerUtil {
44
public static AbstractCacheHandler getCacheHandler(String strategy, CacheConfig cacheParams) {
55
if (strategy.compareToIgnoreCase("redis") == 0){
6-
return new RedisCacheHandler(cacheParams.getRedisService(), cacheParams.getCacheRedisTtlInSeconds());
6+
return new RedisCacheHandler(cacheParams.getRedisService(), cacheParams.getCacheRedisTtlInSeconds(), cacheParams.getOrphansCacheRedisTtlInSeconds(), cacheParams.getEventsCacheRedisTtlInSeconds());
77
}
88
else {
99
return new LocalCacheHandler(cacheParams.getMaximumTasksCacheWeight(), cacheParams.getMaximumOrphansCacheWeight());

timbermill-java/timbermill-local/src/main/java/com/datorama/oss/timbermill/common/cache/RedisCacheHandler.java

+12-9
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,24 @@ public class RedisCacheHandler extends AbstractCacheHandler {
2323
private JedisLock lock;
2424
private final RedisService redisService;
2525
private final int redisTtlInSeconds;
26-
27-
private int orphanRedisTTLRedisTTLInSeconds;
28-
private int cacheRedisTTLRedisTTLInSeconds;
2926

27+
private int cacheOrphansRedisTtlInSeconds;
28+
private int cacheEventsRedisTtlInSeconds;
3029

3130
RedisCacheHandler(RedisService redisService, int cacheRedisTtlInSeconds) {
31+
this(redisService, cacheRedisTtlInSeconds, cacheRedisTtlInSeconds, cacheRedisTtlInSeconds);
32+
}
33+
34+
RedisCacheHandler(RedisService redisService, int cacheRedisTtlInSeconds, int cacheOrphansRedisTtlInSeconds, int cacheEventsRedisTtlInSeconds) {
3235
if (redisService == null){
3336
throw new RuntimeException("Redis cache used but no redis host defined");
3437
}
3538
this.redisService = redisService;
3639
this.redisTtlInSeconds = cacheRedisTtlInSeconds;
37-
orphanRedisTTLRedisTTLInSeconds = System.getenv("ORPHANS_REDIS_TTL_SECONDS") != null ? Integer.parseInt(System.getenv("ORPHANS_REDIS_TTL_SECONDS")) : cacheRedisTtlInSeconds;
38-
cacheRedisTTLRedisTTLInSeconds = System.getenv("CACHE_REDIS_TTL_SECONDS") != null ? Integer.parseInt(System.getenv("CACHE_REDIS_TTL_SECONDS")) : cacheRedisTtlInSeconds;
39-
LOG.info("Initializing Timbermill Redis Cache with orphanRedisTTLRedisTTLInSeconds {} seconds and cacheRedisTTLRedisTTLInSeconds {}", orphanRedisTTLRedisTTLInSeconds, cacheRedisTTLRedisTTLInSeconds);
40+
this.cacheEventsRedisTtlInSeconds = cacheEventsRedisTtlInSeconds;
41+
this.cacheOrphansRedisTtlInSeconds = cacheOrphansRedisTtlInSeconds;
42+
LOG.info("Initializing Timbermill Redis Cache with cacheEventsRedisTtlInSeconds: {}, cacheOrphansRedisTtlInSeconds: {}, cacheRedisTtlInSeconds:{} ", cacheEventsRedisTtlInSeconds,
43+
cacheOrphansRedisTtlInSeconds, cacheRedisTtlInSeconds);
4044
}
4145

4246
@Override
@@ -59,8 +63,7 @@ public void pushToOrphanCache(Map<String, List<String>> orphansMap) {
5963
String orphanCacheKey = ORPHAN_PREFIX + entry.getKey();
6064
newOrphansMap.put(orphanCacheKey, entry.getValue());
6165
}
62-
63-
if (!redisService.pushToRedis(newOrphansMap, orphanRedisTTLRedisTTLInSeconds)){
66+
if (!redisService.pushToRedis(newOrphansMap, cacheOrphansRedisTtlInSeconds)){
6467
LOG.error("Failed to push some ids to Redis orphans cache.");
6568
KamonConstants.ORPHAN_CACHE_FAILED_COUNTER.withoutTags().increment();
6669
}
@@ -73,7 +76,7 @@ public Map<String, LocalTask> getFromTasksCache(Collection<String> idsList) {
7376

7477
@Override
7578
public void pushToTasksCache(Map<String, LocalTask> idsToMap) {
76-
boolean allPushed = redisService.pushToRedis(idsToMap, cacheRedisTTLRedisTTLInSeconds);
79+
boolean allPushed = redisService.pushToRedis(idsToMap, cacheEventsRedisTtlInSeconds);
7780
if (!allPushed){
7881
LOG.error("Failed to push some ids to Redis tasks cache.");
7982
}

timbermill-java/timbermill-server/src/main/java/com/datorama/timbermill/server/service/TimbermillService.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ public TimbermillService(@Value("${INDEX_BULK_SIZE:200000}") Integer indexBulkSi
9696
@Value("${MAXIMUM_ORPHANS_CACHE_WEIGHT:1000000000}") long maximumOrphansCacheWeight,
9797
@Value("${CACHE_STRATEGY:}") String cacheStrategy,
9898
@Value("${CACHE_TTL_IN_SECONDS:604800}") int cacheRedisTtlInSeconds,
99+
@Value("${ORPHAN_CACHE_TTL_IN_SECONDS:86400}") int orphansCacheRedisTtlInSeconds, //One day
100+
@Value("${EVENTS_CACHE_TTL_IN_SECONDS:86400}") int eventsCacheRedisTtlInSeconds, //One day
99101
@Value("${REDIS_MAX_MEMORY:}") String redisMaxMemory,
100102
@Value("${REDIS_MAX_MEMORY_POLICY:}") String redisMaxMemoryPolicy,
101103
@Value("${REDIS_HOST:}") String redisHost,
@@ -137,7 +139,7 @@ public TimbermillService(@Value("${INDEX_BULK_SIZE:200000}") Integer indexBulkSi
137139
elasticPassword, maxIndexAge, maxIndexSizeInGB, maxIndexDocs, numOfElasticSearchActionsTries, maxBulkIndexFetches, searchMaxSize, persistenceHandler, numberOfShards, numberOfReplicas,
138140
maxTotalFields, null, scrollLimitation, scrollTimeoutSeconds, fetchByIdsPartitions, expiredMaxIndicesToDeleteInParallel);
139141

140-
CacheConfig cacheParams = new CacheConfig(redisService, cacheRedisTtlInSeconds, maximumTasksCacheWeight, maximumOrphansCacheWeight);
142+
CacheConfig cacheParams = new CacheConfig(redisService, cacheRedisTtlInSeconds, maximumTasksCacheWeight, maximumOrphansCacheWeight, orphansCacheRedisTtlInSeconds, eventsCacheRedisTtlInSeconds);
141143
AbstractCacheHandler cacheHandler = CacheHandlerUtil.getCacheHandler(cacheStrategy, cacheParams);
142144
this.eventsMaxElement = eventsMaxElement;
143145
taskIndexer = new TaskIndexer(pluginsJson, daysRotation, es, timbermillVersion, cacheHandler);

0 commit comments

Comments
 (0)