Skip to content

Commit dbedfd6

Browse files
authored
concord-server: inject ProcessKeyCache interface instead of implementation to utilize singleton scope (#1247)
1 parent 4923686 commit dbedfd6

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

server/impl/src/main/java/com/walmartlabs/concord/server/process/queue/ProcessKeyCache.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ public ProcessKey assertKey(UUID instanceId) {
7878
return processKey;
7979
}
8080

81+
@Override
82+
public long hitCount() {
83+
return cache.stats().hitCount();
84+
}
85+
86+
@Override
87+
public long missCount() {
88+
return cache.stats().missCount();
89+
}
90+
8191
private static class ProcessNotFoundException extends Exception {
8292

8393
@Serial

server/impl/src/main/java/com/walmartlabs/concord/server/process/queue/ProcessKeyCacheGaugeModule.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
*/
2222

2323
import com.codahale.metrics.Gauge;
24-
import com.google.common.cache.CacheStats;
2524
import com.google.inject.AbstractModule;
2625
import com.google.inject.Provider;
2726
import com.google.inject.multibindings.Multibinder;
2827
import com.walmartlabs.concord.server.sdk.metrics.GaugeProvider;
28+
import com.walmartlabs.concord.server.sdk.ProcessKeyCache;
2929

30-
import java.util.function.Function;
30+
31+
import java.util.function.ToLongFunction;
3132

3233
public class ProcessKeyCacheGaugeModule extends AbstractModule {
3334

@@ -36,12 +37,12 @@ protected void configure() {
3637
Provider<ProcessKeyCache> provider = getProvider(ProcessKeyCache.class);
3738

3839
Multibinder<GaugeProvider> gauges = Multibinder.newSetBinder(binder(), GaugeProvider.class);
39-
gauges.addBinding().toInstance(create("hit-count", provider, CacheStats::hitCount));
40-
gauges.addBinding().toInstance(create("miss-count", provider, CacheStats::missCount));
40+
gauges.addBinding().toInstance(create("hit-count", provider, ProcessKeyCache::hitCount));
41+
gauges.addBinding().toInstance(create("miss-count", provider, ProcessKeyCache::missCount));
4142
}
4243

43-
private static GaugeProvider<Long> create(String suffix, Provider<ProcessKeyCache> provider, Function<CacheStats, Long> value) {
44-
return new GaugeProvider<Long>() {
44+
private static GaugeProvider<Long> create(String suffix, Provider<ProcessKeyCache> provider, ToLongFunction<ProcessKeyCache> value) {
45+
return new GaugeProvider<>() {
4546
@Override
4647
public String name() {
4748
return "process-key-cache-" + suffix;
@@ -50,10 +51,7 @@ public String name() {
5051
@Override
5152
public Gauge<Long> gauge() {
5253
ProcessKeyCache cache = provider.get();
53-
return () -> {
54-
CacheStats stats = cache.stats();
55-
return value.apply(stats);
56-
};
54+
return () -> value.applyAsLong(cache);
5755
}
5856
};
5957
}

server/impl/src/main/java/com/walmartlabs/concord/server/process/queue/ProcessQueueManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.walmartlabs.concord.server.process.logs.ProcessLogManager;
3333
import com.walmartlabs.concord.server.sdk.PartialProcessKey;
3434
import com.walmartlabs.concord.server.sdk.ProcessKey;
35+
import com.walmartlabs.concord.server.sdk.ProcessKeyCache;
3536
import com.walmartlabs.concord.server.sdk.ProcessStatus;
3637
import org.jooq.DSLContext;
3738

server/sdk/src/main/java/com/walmartlabs/concord/server/sdk/ProcessKeyCache.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ public interface ProcessKeyCache {
2727
ProcessKey assertKey(UUID instanceId);
2828

2929
ProcessKey get(UUID instanceId);
30+
31+
long hitCount();
32+
33+
long missCount();
3034
}

0 commit comments

Comments
 (0)