@@ -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" )
0 commit comments