-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #921 from IABTechLab/llp-UID2-937-log-sdk-version-…
…metrics Start collecting per-site stats of client versions.
- Loading branch information
Showing
12 changed files
with
248 additions
and
212 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
52 changes: 52 additions & 0 deletions
52
src/main/java/com/uid2/operator/monitoring/ClientVersionStatRecorder.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,52 @@ | ||
package com.uid2.operator.monitoring; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.stream.Stream; | ||
|
||
public class ClientVersionStatRecorder { | ||
private static final String NOT_RECORDED = "<Not recorded>"; | ||
private final int siteClientBucketLimit; | ||
private final Map<Integer, Map<String, Integer>> siteIdToVersionCounts = new HashMap<>(); | ||
|
||
public ClientVersionStatRecorder(int maxVersionBucketsPerSite) { | ||
this.siteClientBucketLimit = maxVersionBucketsPerSite; | ||
} | ||
|
||
public Stream<ILoggedStat> getStatsView() { | ||
return siteIdToVersionCounts.entrySet().stream().map(entry -> new SiteClientVersionStat(entry.getKey(), entry.getValue())); | ||
} | ||
|
||
private void removeLowVersionCounts(int siteId) { | ||
var versionCounts = siteIdToVersionCounts.get(siteId); | ||
if (versionCounts == null) { | ||
return; | ||
} | ||
|
||
// Remove 3 items to avoid a couple of new version values from continuously evicting each other | ||
var lowestEntries = versionCounts.entrySet().stream() | ||
.sorted(Map.Entry.comparingByValue()) | ||
.filter(entry -> !entry.getKey().equals(NOT_RECORDED)) | ||
.limit(3) | ||
.toList(); | ||
for (var entry : lowestEntries) { | ||
var notRecordedCount = versionCounts.getOrDefault(NOT_RECORDED, 0); | ||
versionCounts.put(NOT_RECORDED, notRecordedCount + entry.getValue()); | ||
versionCounts.remove(entry.getKey()); | ||
} | ||
} | ||
|
||
public void add(Integer siteId, String clientVersion) { | ||
if (siteId == null || clientVersion == null || clientVersion.isBlank()) { | ||
return; | ||
} | ||
|
||
var clientVersionCounts = siteIdToVersionCounts.computeIfAbsent(siteId, k -> new HashMap<>()); | ||
|
||
var count = clientVersionCounts.getOrDefault(clientVersion, 0); | ||
if (count == 0 && clientVersionCounts.size() >= siteClientBucketLimit) { | ||
removeLowVersionCounts(siteId); | ||
} | ||
clientVersionCounts.put(clientVersion, count + 1); | ||
} | ||
} |
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,6 @@ | ||
package com.uid2.operator.monitoring; | ||
|
||
public interface ILoggedStat { | ||
public String GetLogPrefix(); | ||
public Object GetValueToLog(); | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/uid2/operator/monitoring/SiteClientVersionStat.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,24 @@ | ||
package com.uid2.operator.monitoring; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public final class SiteClientVersionStat implements ILoggedStat { | ||
private final Integer siteId; | ||
private final Map<String, Integer> versionCounts; | ||
|
||
public SiteClientVersionStat(Integer siteId, Map<String, Integer> versionCounts) { | ||
this.siteId = siteId; | ||
this.versionCounts = versionCounts; | ||
} | ||
|
||
@Override | ||
public String GetLogPrefix() { | ||
return "version log; siteId=%d versions=".formatted(siteId); | ||
} | ||
|
||
@Override | ||
public Object GetValueToLog() { | ||
return versionCounts; | ||
} | ||
} |
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
52 changes: 0 additions & 52 deletions
52
src/main/java/com/uid2/operator/vertx/ClientVersionCapturingHandler.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.