-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimental changes for skipping complete trace if transitive API ca…
…ll is present in skip list
- Loading branch information
Showing
9 changed files
with
183 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...gent/src/main/java/com/newrelic/agent/security/intcodeagent/utils/IastExclusionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.newrelic.agent.security.intcodeagent.utils; | ||
|
||
import com.newrelic.agent.security.intcodeagent.filelogging.FileLoggerThreadPool; | ||
|
||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class IastExclusionUtils { | ||
|
||
private static final FileLoggerThreadPool logger = FileLoggerThreadPool.getInstance(); | ||
|
||
private final TTLMap<String, Set<String>> encounteredTraces = new TTLMap<>("encounteredTraces"); | ||
|
||
private final TTLMap<String, Boolean> skippedTraces = new TTLMap<>("skippedTraces"); | ||
|
||
private final Set<String> skippedTraceApis = ConcurrentHashMap.newKeySet(); | ||
|
||
private IastExclusionUtils() { | ||
} | ||
|
||
public boolean skippedTrace(String traceId) { | ||
return skippedTraces.containsKey(traceId); | ||
} | ||
|
||
public boolean skipTraceApi(String id) { | ||
return skippedTraceApis.contains(id); | ||
} | ||
|
||
private static final class InstanceHolder { | ||
static final IastExclusionUtils instance = new IastExclusionUtils(); | ||
} | ||
|
||
public static IastExclusionUtils getInstance() { | ||
return InstanceHolder.instance; | ||
} | ||
|
||
public void addEncounteredTrace(String traceId, String operationApiId) { | ||
Set<String> operationApiIds = encounteredTraces.get(traceId); | ||
if (operationApiIds == null) { | ||
operationApiIds = ConcurrentHashMap.newKeySet(); | ||
encounteredTraces.put(traceId, operationApiIds); | ||
} | ||
operationApiIds.add(operationApiId); | ||
updateSkippedTraceApis(traceId, operationApiId); | ||
} | ||
|
||
public void registerSkippedTrace(String traceId) { | ||
skippedTraces.put(traceId, true); | ||
updateSkippedTraceApis(traceId); | ||
} | ||
|
||
private void updateSkippedTraceApis(String traceId) { | ||
Set<String> operationApiIds = encounteredTraces.get(traceId); | ||
if (operationApiIds != null) { | ||
skippedTraceApis.addAll(operationApiIds); | ||
} | ||
} | ||
|
||
private void updateSkippedTraceApis(String traceId, String operationApiId) { | ||
if (skippedTraces.containsKey(traceId)) { | ||
skippedTraceApis.add(operationApiId); | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...c-security-agent/src/main/java/com/newrelic/agent/security/intcodeagent/utils/TTLMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.newrelic.agent.security.intcodeagent.utils; | ||
|
||
import com.newrelic.agent.security.intcodeagent.schedulers.SchedulerHelper; | ||
|
||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class TTLMap<K, V> { | ||
|
||
private final ConcurrentHashMap<K, V> map = new ConcurrentHashMap<>(); | ||
private final ConcurrentHashMap<K, Long> timestamps = new ConcurrentHashMap<>(); | ||
private final long TTL; | ||
private final String id; | ||
|
||
public TTLMap(String id) { | ||
this(id, 300_000);// 5 minutes in milliseconds | ||
} | ||
|
||
public TTLMap(String id, long ttl) { | ||
this.id = id; | ||
TTL = ttl; | ||
} | ||
|
||
public void put(K key, V value) { | ||
map.put(key, value); | ||
timestamps.put(key, System.currentTimeMillis()); | ||
} | ||
|
||
public V get(K key) { | ||
return map.get(key); | ||
} | ||
|
||
public void remove(K key) { | ||
map.remove(key); | ||
timestamps.remove(key); | ||
} | ||
|
||
private void removeExpiredEntries() { | ||
long now = System.currentTimeMillis(); | ||
for (K key : timestamps.keySet()) { | ||
if (now - timestamps.get(key) >= TTL) { | ||
map.remove(key); | ||
timestamps.remove(key); | ||
} | ||
} | ||
} | ||
|
||
public void shutdown() { | ||
SchedulerHelper.getInstance().cancelTTLMapCleanup(this.id); | ||
} | ||
|
||
public boolean containsKey(K traceId) { | ||
return map.containsKey(traceId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters