Skip to content

Commit 9b6ad96

Browse files
updated salt bucket format log to include salt count
1 parent 8101bf1 commit 9b6ad96

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/main/java/com/uid2/admin/salt/SaltRotation.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public Result rotateSalts(
6262
logSaltAges("refreshable-salts", targetDate, refreshableSalts);
6363
logSaltAges("rotated-salts", targetDate, saltsToRotate);
6464
logSaltAges("total-salts", targetDate, Arrays.asList(postRotationSalts));
65-
logKeyBucketCount(targetDate, preRotationSalts, postRotationSalts);
65+
logBucketFormatCount(targetDate, preRotationSalts, postRotationSalts);
6666

6767
var nextSnapshot = new SaltSnapshot(
6868
nextEffective,
@@ -247,18 +247,20 @@ private void logSaltAges(String saltCountType, TargetDate targetDate, Collection
247247
}
248248
}
249249

250-
private void logKeyBucketCount(TargetDate targetDate, SaltEntry[] preRotationSalts, SaltEntry[] postRotationSalts) {
251-
int newKeyBucketCounter = 0;
252-
int totalKeyBucketCounter = 0;
250+
private void logBucketFormatCount(TargetDate targetDate, SaltEntry[] preRotationSalts, SaltEntry[] postRotationSalts) {
251+
int newKeyBucketCounter = 0, totalKeyBucketCounter = 0, totalSaltBucketCounter = 0;
252+
253253
for (int i = 0; i < preRotationSalts.length && i < postRotationSalts.length; i++) {
254254
var oldSalt = preRotationSalts[i];
255255
var updatedSalt = postRotationSalts[i];
256256

257257
if (updatedSalt.currentKey() != null) totalKeyBucketCounter++;
258+
if (updatedSalt.currentSalt() != null) totalSaltBucketCounter++;
258259
if (updatedSalt.currentKey() != null && oldSalt.currentSalt() != null) newKeyBucketCounter++;
259260
}
260-
LOGGER.info("salt_bucket_count_type={} target_date={} bucket_count={}", "new-key-buckets", targetDate, newKeyBucketCounter);
261-
LOGGER.info("salt_bucket_count_type={} target_date={} bucket_count={}", "total-key-buckets", targetDate, totalKeyBucketCounter);
261+
262+
LOGGER.info("Salt rotation bucket format: target_date={} new_key_bucket_count={} total_key_bucket_count={} total_salt_bucket_count={}",
263+
targetDate, newKeyBucketCounter, totalKeyBucketCounter, totalSaltBucketCounter);
262264
}
263265

264266
@Getter

src/test/java/com/uid2/admin/salt/SaltRotationTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -729,11 +729,12 @@ void testKeyRotationSaltToKeyRotation() throws Exception {
729729

730730
@ParameterizedTest
731731
@CsvSource({
732-
"true, 1, 3",
733-
"false, 0, 1"
732+
"true, 1, 3, 1",
733+
"false, 0, 1, 3"
734734
})
735-
void testKeyRotationLogKeyBuckets(boolean v4Enabled, int expectedNewKeyBuckets, int expectedTotalKeyBuckets) throws Exception {
735+
void testKeyRotationLogKeyBuckets(boolean v4Enabled, int expectedNewKeyBuckets, int expectedTotalKeyBuckets, int expectedTotalSaltBuckets) throws Exception {
736736
saltRotation = new SaltRotation(keyGenerator, JsonObject.of(AdminConst.ENABLE_V4_RAW_UID, v4Enabled));
737+
when(keyGenerator.generateRandomKeyString(anyInt())).thenReturn("random-key-string");
737738

738739
final Duration[] minAges = {
739740
Duration.ofDays(30)
@@ -751,10 +752,10 @@ void testKeyRotationLogKeyBuckets(boolean v4Enabled, int expectedNewKeyBuckets,
751752
saltRotation.rotateSalts(lastSnapshot, minAges, 1, targetDate());
752753

753754
var expected = Set.of(
754-
"[INFO] salt_bucket_count_type=new-key-buckets target_date=2025-01-01 bucket_count=" + expectedNewKeyBuckets,
755-
"[INFO] salt_bucket_count_type=total-key-buckets target_date=2025-01-01 bucket_count=" + expectedTotalKeyBuckets
755+
String.format("[INFO] Salt rotation bucket format: target_date=2025-01-01 new_key_bucket_count=%d total_key_bucket_count=%d total_salt_bucket_count=%d",
756+
expectedNewKeyBuckets, expectedTotalKeyBuckets, expectedTotalSaltBuckets)
756757
);
757-
var actual = appender.list.stream().map(Object::toString).filter(s -> s.contains("salt_bucket_count_type")).collect(Collectors.toSet());
758+
var actual = appender.list.stream().map(Object::toString).filter(s -> s.contains("Salt rotation bucket format")).collect(Collectors.toSet());
758759
assertThat(actual).isEqualTo(expected);
759760
}
760761
}

0 commit comments

Comments
 (0)