Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.hypertrace.core.grpcutils.context;

import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

public class FastUUIDGenerator {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be public? Doesn't need a new release, but next time you're in here can you move this to package private since it's an internal impl detail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially thought of it to our own lib so it can be used. But, I think, we can make it private, anywhere else we can use the third-party library that is already there in most of the projects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**
* This function generates UUIDs using ThreadLocalRandom, which is faster and doesn't block like
* the default randomUUID method that relies on /dev/random. It's suitable for most random UUID
* needs.
*/
public static UUID randomUUID() {
long mostSigBits = ThreadLocalRandom.current().nextLong();
long leastSigBits = ThreadLocalRandom.current().nextLong();

// Set the version (4) For random UUID
mostSigBits &= 0xFFFFFFFFFFFF0FFFL;
mostSigBits |= 0x0000000000004000L;
// Set variant to RFC 4122
leastSigBits &= 0x3FFFFFFFFFFFFFFFL;
leastSigBits |= 0x8000000000000000L;

return new UUID(mostSigBits, leastSigBits);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
Expand All @@ -34,7 +33,9 @@ public class RequestContext {
public static RequestContext forTenantId(String tenantId) {
return new RequestContext()
.put(RequestContextConstants.TENANT_ID_HEADER_KEY, tenantId)
.put(RequestContextConstants.REQUEST_ID_HEADER_KEY, UUID.randomUUID().toString());
.put(
RequestContextConstants.REQUEST_ID_HEADER_KEY,
FastUUIDGenerator.randomUUID().toString());
}

public static RequestContext fromMetadata(Metadata metadata) {
Expand Down
2 changes: 1 addition & 1 deletion owasp-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<packageUrl regex="true">^pkg:maven/org\.hypertrace\..*@.*$</packageUrl>
<cpe>cpe:/a:grpc:grpc</cpe>
</suppress>
<suppress until="2023-08-31Z">
<suppress until="2023-09-30Z">
<notes><![CDATA[
file name: jackson-databind-2.14.2.jar
This is currently disputed.
Expand Down