-
Notifications
You must be signed in to change notification settings - Fork 268
Support ICP 2.0 for MI #4510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Support ICP 2.0 for MI #4510
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| public HMACJWTTokenGenerator(String hmacSecret) { | ||
| if (hmacSecret == null || hmacSecret.getBytes(StandardCharsets.UTF_8).length < 32) { | ||
| throw new IllegalArgumentException("HMAC secret must be at least 256 bits (32 bytes)"); | ||
| } | ||
| this.hmacSecret = hmacSecret; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 1
| public HMACJWTTokenGenerator(String hmacSecret) { | |
| if (hmacSecret == null || hmacSecret.getBytes(StandardCharsets.UTF_8).length < 32) { | |
| throw new IllegalArgumentException("HMAC secret must be at least 256 bits (32 bytes)"); | |
| } | |
| this.hmacSecret = hmacSecret; | |
| } | |
| public HMACJWTTokenGenerator(String hmacSecret) { | |
| if (hmacSecret == null || hmacSecret.getBytes(StandardCharsets.UTF_8).length < 32) { | |
| throw new IllegalArgumentException("HMAC secret must be at least 256 bits (32 bytes)"); | |
| } | |
| this.hmacSecret = hmacSecret; | |
| log.info("HMACJWTTokenGenerator initialized successfully"); | |
| } |
|
|
||
| signedJWT.sign(signer); | ||
| return signedJWT.serialize(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 2
| signedJWT.sign(signer); | |
| return signedJWT.serialize(); | |
| signedJWT.sign(signer); | |
| String token = signedJWT.serialize(); | |
| if (log.isDebugEnabled()) { | |
| log.debug("JWT token generated successfully for issuer: " + issuer + ", audience: " + audience); | |
| } | |
| return token; |
| // Check if new ICP is configured | ||
| if (ICPHeartBeatComponent.isICPConfigured()) { | ||
| log.info("New ICP configuration detected. Starting ICP heartbeat service."); | ||
| ICPHeartBeatComponent.invokeICPHeartbeatExecutorService(); | ||
| return; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 3
| // Check if new ICP is configured | |
| if (ICPHeartBeatComponent.isICPConfigured()) { | |
| log.info("New ICP configuration detected. Starting ICP heartbeat service."); | |
| ICPHeartBeatComponent.invokeICPHeartbeatExecutorService(); | |
| return; | |
| } | |
| // Check if new ICP is configured | |
| if (ICPHeartBeatComponent.isICPConfigured()) { | |
| log.info("New ICP configuration detected. Starting ICP heartbeat service."); | |
| ICPHeartBeatComponent.invokeICPHeartbeatExecutorService(); | |
| return; | |
| } | |
| log.debug("Starting dashboard heartbeat service with URL: " + configs.get(DASHBOARD_CONFIG_URL)); |
| JsonObject responseObject = null; | ||
| try { | ||
| responseObject = new JsonParser().parse(stringResponse).getAsJsonObject(); | ||
| Gson gson = new Gson(); | ||
| responseObject = gson.fromJson(stringResponse, JsonObject.class); | ||
| } catch (JsonParseException e) { | ||
| log.debug("Error occurred while parsing the heartbeat response.", e); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 4
| JsonObject responseObject = null; | |
| try { | |
| responseObject = new JsonParser().parse(stringResponse).getAsJsonObject(); | |
| Gson gson = new Gson(); | |
| responseObject = gson.fromJson(stringResponse, JsonObject.class); | |
| } catch (JsonParseException e) { | |
| log.debug("Error occurred while parsing the heartbeat response.", e); | |
| } | |
| try { | |
| Gson gson = new Gson(); | |
| responseObject = gson.fromJson(stringResponse, JsonObject.class); | |
| log.debug("Successfully parsed heartbeat response."); | |
| } catch (JsonParseException e) { | |
| log.error("Error occurred while parsing the heartbeat response: " + e.getMessage()); | |
| } |
| */ | ||
| private static void sendDeltaHeartbeat(String icpUrl) { | ||
| try { | ||
| // Build full payload to calculate hash | ||
| JsonObject fullPayload = buildFullHeartbeatPayload(false); | ||
| String currentHash = fullPayload.get("runtimeHash").getAsString(); | ||
|
|
||
| // Build delta payload |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 5
| */ | |
| private static void sendDeltaHeartbeat(String icpUrl) { | |
| try { | |
| // Build full payload to calculate hash | |
| JsonObject fullPayload = buildFullHeartbeatPayload(false); | |
| String currentHash = fullPayload.get("runtimeHash").getAsString(); | |
| // Build delta payload | |
| public static void invokeICPHeartbeatExecutorService() { | |
| String icpUrl = getConfigValue(ICP_CONFIG_URL, DEFAULT_ICP_URL); | |
| if (icpUrl == null) { | |
| log.warn("ICP URL not configured. ICP heartbeat will not be started."); | |
| return; | |
| } | |
| long interval = getInterval(); | |
| log.info("Starting ICP heartbeat service. Interval: " + interval + "s"); | |
| log.info("Starting ICP heartbeat service with URL: " + icpUrl + ", Interval: " + interval + "s"); |
| String trimmedId = existingId.trim(); | ||
| if (!trimmedId.isEmpty()) { | ||
| return trimmedId; | ||
| } | ||
| } | ||
|
|
||
| // Generate new UUID if file doesn't exist or is empty | ||
| String newRuntimeId = UUID.randomUUID().toString(); | ||
| Files.writeString(runtimeIdPath, newRuntimeId); | ||
| return newRuntimeId; | ||
| } | ||
|
|
||
| /** | ||
| * Starts the ICP heartbeat executor service that sends periodic delta heartbeats | ||
| * and full heartbeats when requested by the ICP. | ||
| */ | ||
| public static void invokeICPHeartbeatExecutorService() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 6
| String trimmedId = existingId.trim(); | |
| if (!trimmedId.isEmpty()) { | |
| return trimmedId; | |
| } | |
| } | |
| // Generate new UUID if file doesn't exist or is empty | |
| String newRuntimeId = UUID.randomUUID().toString(); | |
| Files.writeString(runtimeIdPath, newRuntimeId); | |
| return newRuntimeId; | |
| } | |
| /** | |
| * Starts the ICP heartbeat executor service that sends periodic delta heartbeats | |
| * and full heartbeats when requested by the ICP. | |
| */ | |
| public static void invokeICPHeartbeatExecutorService() { | |
| private static String initRuntimeId() throws IOException { | |
| // Use current working directory for the runtime ID file | |
| Path runtimeIdPath = Paths.get(runtimeIdFile); | |
| log.debug("Initializing runtime ID from path: " + runtimeIdPath.toAbsolutePath()); | |
| // Check if file exists and read the UUID | |
| if (Files.exists(runtimeIdPath)) { | |
| String existingId = Files.readString(runtimeIdPath); | |
| // Validate it's not empty and trim whitespace | |
| String trimmedId = existingId.trim(); | |
| if (!trimmedId.isEmpty()) { | |
| log.info("Using existing runtime ID: " + trimmedId); | |
| return trimmedId; | |
| } | |
| } | |
| // Generate new UUID if file doesn't exist or is empty | |
| String newRuntimeId = UUID.randomUUID().toString(); | |
| Files.writeString(runtimeIdPath, newRuntimeId); | |
| log.info("Generated new runtime ID: " + newRuntimeId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI Agent Log Improvement Checklist
- The log-related comments and suggestions in this review were generated by an AI tool to assist with identifying potential improvements. Purpose of reviewing the code for log improvements is to improve the troubleshooting capabilities of our products.
- Please make sure to manually review and validate all suggestions before applying any changes. Not every code suggestion would make sense or add value to our purpose. Therefore, you have the freedom to decide which of the suggestions are helpful.
✅ Before merging this pull request:
- Review all AI-generated comments for accuracy and relevance.
- Complete and verify the table below. We need your feedback to measure the accuracy of these suggestions and the value they add. If you are rejecting a certain code suggestion, please mention the reason briefly in the suggestion for us to capture it.
eb3b020 to
c3d9038
Compare
c3d9038 to
6b3faca
Compare
663a7e1 to
ffa90df
Compare
This PR supports the ICP 2.0.