Skip to content

Commit f8ed543

Browse files
committed
Added identity map v3 benchmark
1 parent 323fb9d commit f8ed543

File tree

2 files changed

+140
-80
lines changed

2 files changed

+140
-80
lines changed

src/main/java/com/uid2/admin/vertx/service/SaltService.java

Lines changed: 89 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ public void setupRoutes(Router router) {
116116
}
117117
}, new AuditParams(List.of("fraction"), Collections.emptyList()), Role.MAINTAINER, Role.SECRET_ROTATION));
118118

119+
router.post("/api/salt/benchmark").blockingHandler(auth.handle(ctx -> {
120+
synchronized (writeLock) {
121+
this.handleSaltBenchmark(ctx);
122+
}
123+
}, new AuditParams(List.of(), Collections.emptyList()), Role.MAINTAINER, Role.SECRET_ROTATION));
124+
119125
router.post("/api/salt/compare").blockingHandler(auth.handle(ctx -> {
120126
synchronized (writeLock) {
121127
this.handleSaltCompare(ctx);
@@ -267,14 +273,49 @@ private void handleSaltFastForward(RoutingContext rc) {
267273
}
268274
}
269275

276+
private void handleSaltBenchmark(RoutingContext rc) {
277+
try {
278+
final String candidateOperatorUrl = RequestUtil.getString(rc, "candidate_operator_url").orElse("");
279+
final String candidateApiKey = RequestUtil.getString(rc, "candidate_api_key").orElse("");
280+
final String candidateApiSecret = RequestUtil.getString(rc, "candidate_api_secret").orElse("");
281+
282+
List<List<String>> emails = new ArrayList<>();
283+
284+
for (int i = 0; i < 100; i++) {
285+
emails.add(new ArrayList<>());
286+
287+
for (int j = 0; j < IDENTITY_COUNT; j++) {
288+
String email = randomEmail();
289+
emails.get(i).add(email);
290+
}
291+
}
292+
293+
long before = System.currentTimeMillis();
294+
for (int i = 0; i < emails.size(); i++) {
295+
LOGGER.info("Identity Map V3: {}/{}", i + 1, emails.size());
296+
v3IdentityMap(emails.get(i), candidateOperatorUrl, candidateApiKey, candidateApiSecret);
297+
}
298+
long after = System.currentTimeMillis();
299+
long duration = after - before;
300+
LOGGER.info("UID Benchmark: duration={}ms", duration);
301+
302+
rc.response()
303+
.putHeader(HttpHeaders.CONTENT_TYPE, "application/json")
304+
.end();
305+
} catch (Exception e) {
306+
LOGGER.error(e.getMessage(), e);
307+
rc.fail(500, e);
308+
}
309+
}
310+
270311
private void handleSaltCompare(RoutingContext rc) {
271312
try {
272-
final String testOperatorUrl = RequestUtil.getString(rc, "test_operator_url").orElse("");
273-
final String testApiKey = RequestUtil.getString(rc, "test_api_key").orElse("");
274-
final String testApiSecret = RequestUtil.getString(rc, "test_api_secret").orElse("");
275-
final String integOperatorUrl = RequestUtil.getString(rc, "integ_operator_url").orElse("");
276-
final String integApiKey = RequestUtil.getString(rc, "integ_api_key").orElse("");
277-
final String integApiSecret = RequestUtil.getString(rc, "integ_api_secret").orElse("");
313+
final String referenceOperatorUrl = RequestUtil.getString(rc, "reference_operator_url").orElse("");
314+
final String referenceApiKey = RequestUtil.getString(rc, "reference_api_key").orElse("");
315+
final String referenceApiSecret = RequestUtil.getString(rc, "reference_api_secret").orElse("");
316+
final String candidateOperatorUrl = RequestUtil.getString(rc, "candidate_operator_url").orElse("");
317+
final String candidateApiKey = RequestUtil.getString(rc, "candidate_api_key").orElse("");
318+
final String candidateApiSecret = RequestUtil.getString(rc, "candidate_api_secret").orElse("");
278319

279320
List<String> emails = new ArrayList<>();
280321
Map<String, SaltEntry> emailToSaltMap = new HashMap<>();
@@ -288,68 +329,68 @@ private void handleSaltCompare(RoutingContext rc) {
288329
}
289330

290331
// Construct identity map args
291-
JsonNode testResponse = v3IdentityMap(emails, testOperatorUrl, testApiKey, testApiSecret);
292-
JsonNode integResponse = v3IdentityMap(emails, integOperatorUrl, integApiKey, integApiSecret);
293-
294-
JsonNode testMappings = testResponse.at("/body/email");
295-
JsonNode integMappings = integResponse.at("/body/email");
296-
297-
int testV4UidCount = 0;
298-
int testV2UidCount = 0;
299-
int testInvalidV4UidCount = 0;
300-
int testInvalidV2UidCount = 0;
301-
int testNullUidCount = 0;
302-
int testIntegMatchCount = 0;
303-
int testIntegMismatchCount = 0;
332+
JsonNode referenceResponse = v3IdentityMap(emails, referenceOperatorUrl, referenceApiKey, referenceApiSecret);
333+
JsonNode candidateResponse = v3IdentityMap(emails, candidateOperatorUrl, candidateApiKey, candidateApiSecret);
334+
335+
JsonNode referenceMappings = referenceResponse.at("/body/email");
336+
JsonNode candidateMappings = candidateResponse.at("/body/email");
337+
338+
int candidateV4UidCount = 0;
339+
int candidateV2UidCount = 0;
340+
int candidateInvalidV4UidCount = 0;
341+
int candidateInvalidV2UidCount = 0;
342+
int candidateNullUidCount = 0;
343+
int matchCount = 0;
344+
int mismatchCount = 0;
304345
for (int i = 0; i < IDENTITY_COUNT; i++) {
305346
String email = emails.get(i);
306347
SaltEntry salt = emailToSaltMap.get(email);
307348
boolean isV4 = salt.currentKeySalt() != null && salt.currentKeySalt().key() != null && salt.currentKeySalt().salt() != null;
308349

309-
String testUid = testMappings.get(i).at("/u").asText();
310-
String integUid = integMappings.get(i).at("/u").asText();
350+
String referenceUid = referenceMappings.get(i).at("/u").asText();
351+
String candidateUid = candidateMappings.get(i).at("/u").asText();
311352

312-
byte[] testUidBytes = testUid == null ? null : Base64.getDecoder().decode(testUid);
313-
byte[] integUidBytes = integUid == null ? null : Base64.getDecoder().decode(integUid);
353+
byte[] referenceUidBytes = referenceUid == null ? null : Base64.getDecoder().decode(referenceUid);
354+
byte[] candidateUidBytes = candidateUid == null ? null : Base64.getDecoder().decode(candidateUid);
314355

315-
// First, check test UID is valid
316-
if (testUidBytes == null) {
317-
LOGGER.error("TEST - UID is null");
318-
testNullUidCount++;
356+
// First, check candidate UID is valid
357+
if (candidateUidBytes == null) {
358+
LOGGER.error("CANDIDATE - UID is null");
359+
candidateNullUidCount++;
319360
} else if (isV4) {
320-
if (testUidBytes.length != 33) {
321-
LOGGER.error("TEST - salt is v4 but UID length is {}", testUidBytes.length);
322-
testInvalidV4UidCount++;
323-
} else if (assertV4Uid(testUidBytes, email, salt.currentKeySalt(), snapshot)) {
324-
testV4UidCount++;
361+
if (candidateUidBytes.length != 33) {
362+
LOGGER.error("CANDIDATE - salt is v4 but UID length is {}", candidateUidBytes.length);
363+
candidateInvalidV4UidCount++;
364+
} else if (assertV4Uid(candidateUidBytes, email, salt.currentKeySalt(), snapshot)) {
365+
candidateV4UidCount++;
325366
}
326367
} else {
327-
if (testUidBytes.length != 32) {
328-
LOGGER.error("TEST - salt is v2 but UID length is {}", testUidBytes.length);
329-
testInvalidV2UidCount++;
368+
if (candidateUidBytes.length != 32) {
369+
LOGGER.error("CANDIDATE - salt is v2 but UID length is {}", candidateUidBytes.length);
370+
candidateInvalidV2UidCount++;
330371
} else {
331-
testV2UidCount++;
372+
candidateV2UidCount++;
332373
}
333374
}
334375

335-
// Then, check if test and integ match
376+
// Then, check if reference and candidate raw UIDs match
336377
if (!isV4) {
337-
if (!Arrays.equals(testUidBytes, integUidBytes)) {
338-
LOGGER.error("TEST and INTEG UIDs do not match for {} - TEST={} | INTEG={}", email, testUid, integUid);
339-
testIntegMismatchCount++;
378+
if (!Arrays.equals(referenceUidBytes, candidateUidBytes)) {
379+
LOGGER.error("Reference and candidate UIDs do not match for {} - Reference={} | Candidate={}", email, referenceUid, candidateUid);
380+
mismatchCount++;
340381
} else {
341-
testIntegMatchCount++;
382+
matchCount++;
342383
}
343384
}
344385
}
345386

346-
LOGGER.info("UID Consistency between Test and Integ: " +
347-
"test_v4_uid_count={} test_v2_uid_count={} " +
348-
"test_v4_invalid_uid_count={} test_v2_invalid_uid_count={} test_null_uid_count={} " +
349-
"test_integ_match_count={} test_integ_mismatch_count={}",
350-
testV4UidCount, testV2UidCount,
351-
testInvalidV4UidCount, testInvalidV2UidCount, testNullUidCount,
352-
testIntegMatchCount, testIntegMismatchCount);
387+
LOGGER.info("UID Consistency between Reference and Candidate operators: " +
388+
"candidate_v4_uid_count={} candidate_v2_uid_count={} " +
389+
"candidate_v4_invalid_uid_count={} candidate_v2_invalid_uid_count={} candidate_null_uid_count={} " +
390+
"match_count={} mismatch_count={}",
391+
candidateV4UidCount, candidateV2UidCount,
392+
candidateInvalidV4UidCount, candidateInvalidV2UidCount, candidateNullUidCount,
393+
matchCount, mismatchCount);
353394

354395
rc.response()
355396
.putHeader(HttpHeaders.CONTENT_TYPE, "application/json")

webroot/adm/salt.html

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -56,34 +56,34 @@ <h1>UID2 Env - Salt Management</h1>
5656
defaultValue: true
5757
}
5858

59-
const testOperatorUrlInput = {
60-
name: 'testOperatorUrl',
61-
label: 'Test Operator URL'
59+
const referenceOperatorUrlInput = {
60+
name: 'referenceOperatorUrl',
61+
label: 'Reference Operator URL'
6262
}
6363

64-
const testApiKeyInput = {
65-
name: 'testApiKey',
66-
label: 'Test API Key'
64+
const referenceApiKeyInput = {
65+
name: 'referenceApiKey',
66+
label: 'Reference API Key'
6767
}
6868

69-
const testApiSecretInput = {
70-
name: 'testApiSecret',
71-
label: 'Test API Secret'
69+
const referenceApiSecretInput = {
70+
name: 'referenceApiSecret',
71+
label: 'Reference API Secret'
7272
}
7373

74-
const integOperatorUrlInput = {
75-
name: 'integOperatorUrl',
76-
label: 'Integ Operator URL'
74+
const candidateOperatorUrlInput = {
75+
name: 'candidateOperatorUrl',
76+
label: 'Candidate Operator URL'
7777
}
7878

79-
const integApiKeyInput = {
80-
name: 'integApiKey',
81-
label: 'Integ API Key'
79+
const candidateApiKeyInput = {
80+
name: 'candidateApiKey',
81+
label: 'Candidate API Key'
8282
}
8383

84-
const integApiSecretInput = {
85-
name: 'integApiSecret',
86-
label: 'Integ API Secret'
84+
const candidateApiSecretInput = {
85+
name: 'candidateApiSecret',
86+
label: 'Candidate API Secret'
8787
}
8888

8989
const tokenIterationsInput = {
@@ -170,28 +170,47 @@ <h1>UID2 Env - Salt Management</h1>
170170
}
171171
},
172172
},
173+
{
174+
id: 'benchmark',
175+
title: 'Benchmark Identity Map V3',
176+
role: 'maintainer',
177+
inputs: [
178+
candidateOperatorUrlInput,
179+
candidateApiKeyInput,
180+
candidateApiSecretInput
181+
],
182+
apiCall: {
183+
method: 'POST',
184+
getUrl: (inputs) => {
185+
const candidateOperatorUrl = encodeURIComponent(inputs.candidateOperatorUrl);
186+
const candidateApiKey = encodeURIComponent(inputs.candidateApiKey);
187+
const candidateApiSecret = encodeURIComponent(inputs.candidateApiSecret);
188+
return `/api/salt/benchmark?candidate_operator_url=${candidateOperatorUrl}&candidate_api_key=${candidateApiKey}&candidate_api_secret=${candidateApiSecret}`;
189+
}
190+
},
191+
},
173192
{
174193
id: 'compare',
175-
title: 'Compare Test and Integ',
194+
title: 'Compare Operator Raw UIDs',
176195
role: 'maintainer',
177196
inputs: [
178-
testOperatorUrlInput,
179-
testApiKeyInput,
180-
testApiSecretInput,
181-
integOperatorUrlInput,
182-
integApiKeyInput,
183-
integApiSecretInput
197+
referenceOperatorUrlInput,
198+
referenceApiKeyInput,
199+
referenceApiSecretInput,
200+
candidateOperatorUrlInput,
201+
candidateApiKeyInput,
202+
candidateApiSecretInput
184203
],
185204
apiCall: {
186205
method: 'POST',
187206
getUrl: (inputs) => {
188-
const testOperatorUrl = encodeURIComponent(inputs.testOperatorUrl);
189-
const testApiKey = encodeURIComponent(inputs.testApiKey);
190-
const testApiSecret = encodeURIComponent(inputs.testApiSecret);
191-
const integOperatorUrl = encodeURIComponent(inputs.integOperatorUrl);
192-
const integApiKey = encodeURIComponent(inputs.integApiKey);
193-
const integApiSecret = encodeURIComponent(inputs.integApiSecret);
194-
return `/api/salt/compare?test_operator_url=${testOperatorUrl}&test_api_key=${testApiKey}&test_api_secret=${testApiSecret}&integ_operator_url=${integOperatorUrl}&integ_api_key=${integApiKey}&integ_api_secret=${integApiSecret}`;
207+
const referenceOperatorUrl = encodeURIComponent(inputs.referenceOperatorUrl);
208+
const referenceApiKey = encodeURIComponent(inputs.referenceApiKey);
209+
const referenceApiSecret = encodeURIComponent(inputs.referenceApiSecret);
210+
const candidateOperatorUrl = encodeURIComponent(inputs.candidateOperatorUrl);
211+
const candidateApiKey = encodeURIComponent(inputs.candidateApiKey);
212+
const candidateApiSecret = encodeURIComponent(inputs.candidateApiSecret);
213+
return `/api/salt/compare?reference_operator_url=${referenceOperatorUrl}&reference_api_key=${referenceApiKey}&reference_api_secret=${referenceApiSecret}&candidate_operator_url=${candidateOperatorUrl}&candidate_api_key=${candidateApiKey}&candidate_api_secret=${candidateApiSecret}`;
195214
}
196215
},
197216
},

0 commit comments

Comments
 (0)