Skip to content

Commit 5e17916

Browse files
authored
Merge pull request #39 from solarwinds/cc/NH-125271
Use caffeine cache
2 parents 53e67a1 + c15a188 commit 5e17916

File tree

7 files changed

+103
-67
lines changed

7 files changed

+103
-67
lines changed

.github/workflows/push.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ jobs:
6666
done
6767
exit $code
6868
69+
- name: Check shading(sampling)
70+
run: |
71+
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
72+
code=0
73+
for path in $(jar tf "sampling/target/sampling-$VERSION.jar" | grep -E -v '^((com/solarwinds|META))')
74+
do
75+
PACKAGE=$(echo "$path" | awk -F/ '{print $2}')
76+
if [ -n "$PACKAGE" ]; then
77+
echo "Package ($path) is not shaded"
78+
code=1
79+
fi
80+
done
81+
exit $code
82+
6983
deploy_snapshot:
7084
runs-on: ubuntu-latest
7185
steps:

.gitignore

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
/target
1+
**/target
22
.settings/
33
.classpath
44
.project
5-
core/target
6-
dependencies/target
7-
api/target
8-
test-apps/target
9-
test-apps/*/target
10-
test-apps/*/target-eclipse
115
*.iml
126
.idea/
137
.DS_Store
14-
dependencies/dependency-reduced-pom.xml
8+
**/dependency-reduced-pom.xml
159
out/
16-
.flattened-pom.xml
10+
**/.flattened-pom.xml
11+
.spotless/

pom.xml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<name>joboe</name>
1111

1212
<properties>
13-
<revision>10.0.24-SNAPSHOT</revision>
13+
<revision>10.0.25-SNAPSHOT</revision>
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1515
<project.build.outputTimestamp>${git.commit.time}</project.build.outputTimestamp>
1616
</properties>
@@ -104,6 +104,25 @@
104104
</execution>
105105
</executions>
106106
</plugin>
107+
<plugin>
108+
<groupId>com.diffplug.spotless</groupId>
109+
<artifactId>spotless-maven-plugin</artifactId>
110+
<version>2.46.1</version>
111+
<configuration>
112+
<java>
113+
<googleJavaFormat/>
114+
<removeUnusedImports/>
115+
<trimTrailingWhitespace/>
116+
<endWithNewline/>
117+
</java>
118+
<pom>
119+
<sortPom>
120+
<encoding>UTF-8</encoding>
121+
<expandEmptyElements>false</expandEmptyElements>
122+
</sortPom>
123+
</pom>
124+
</configuration>
125+
</plugin>
107126
</plugins>
108127
</build>
109128

sampling/pom.xml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,59 @@
2323
<artifactId>logging</artifactId>
2424
<version>${revision}</version>
2525
</dependency>
26+
<dependency>
27+
<groupId>com.github.ben-manes.caffeine</groupId>
28+
<artifactId>caffeine</artifactId>
29+
<version>2.9.3</version>
30+
</dependency>
2631
</dependencies>
32+
33+
<build>
34+
<plugins>
35+
<plugin>
36+
<groupId>org.apache.maven.plugins</groupId>
37+
<artifactId>maven-shade-plugin</artifactId>
38+
<version>3.2.4</version>
39+
<executions>
40+
<execution>
41+
<phase>package</phase>
42+
<goals>
43+
<goal>shade</goal>
44+
</goals>
45+
<configuration>
46+
<relocations>
47+
<relocation>
48+
<pattern>com.github.benmanes.caffeine</pattern>
49+
<shadedPattern>com.solarwinds.joboe.shaded.caffeine</shadedPattern>
50+
</relocation>
51+
<relocation>
52+
<pattern>org.checkerframework</pattern>
53+
<shadedPattern>com.solarwinds.joboe.shaded.checkerframework</shadedPattern>
54+
</relocation>
55+
<relocation>
56+
<pattern>com.google.errorprone</pattern>
57+
<shadedPattern>com.solarwinds.joboe.shaded.errorprone</shadedPattern>
58+
</relocation>
59+
</relocations>
60+
<transformers>
61+
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
62+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"/>
63+
</transformers>
64+
<filters>
65+
<filter>
66+
<artifact>*:*</artifact>
67+
<excludes>
68+
<exclude>META-INF/*.SF</exclude>
69+
<exclude>META-INF/*.DSA</exclude>
70+
<exclude>META-INF/*.RSA</exclude>
71+
</excludes>
72+
</filter>
73+
</filters>
74+
<createDependencyReducedPom>true</createDependencyReducedPom>
75+
</configuration>
76+
</execution>
77+
</executions>
78+
</plugin>
79+
</plugins>
80+
</build>
2781
</project>

sampling/src/main/java/com/solarwinds/joboe/sampling/LruCache.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

sampling/src/main/java/com/solarwinds/joboe/sampling/TraceConfigs.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.solarwinds.joboe.sampling;
22

33

4+
import com.github.benmanes.caffeine.cache.Cache;
5+
import com.github.benmanes.caffeine.cache.Caffeine;
6+
47
import java.io.Serializable;
58
import java.util.List;
69
import java.util.Map;
@@ -16,9 +19,13 @@ public class TraceConfigs implements Serializable {
1619

1720
private final Map<ResourceMatcher, TraceConfig> traceConfigsByMatcher;
1821

19-
private final Map<String, TraceConfig> lruCache = new LruCache<>(1048);
22+
private final Cache<String, TraceConfig> lruCache = Caffeine.newBuilder()
23+
.maximumSize(1048)
24+
.build();
2025

21-
private final Map<String, String> lruCacheKey = new LruCache<>(1048);
26+
private final Cache<String, String> lruCacheKey = Caffeine.newBuilder()
27+
.maximumSize(1048)
28+
.build();
2229

2330

2431
public TraceConfigs(Map<ResourceMatcher, TraceConfig> traceConfigsByMatcher) {
@@ -30,8 +37,8 @@ public TraceConfig getTraceConfig(List<String> signals) {
3037
signals.forEach(key::append);
3138
TraceConfig result = null;
3239

33-
if (lruCacheKey.get(key.toString()) != null) {
34-
return lruCache.get(key.toString());
40+
if (lruCacheKey.getIfPresent(key.toString()) != null) {
41+
return lruCache.getIfPresent(key.toString());
3542
}
3643

3744
outer:

sampling/src/test/java/com/solarwinds/joboe/sampling/LruCacheTest.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)