Skip to content

Conversation

@Dilhasha
Copy link

This PR supports the ICP 2.0.

@Dilhasha Dilhasha requested a review from rosensilva as a code owner November 25, 2025 10:02
@coderabbitai
Copy link

coderabbitai bot commented Nov 25, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Dilhasha Dilhasha marked this pull request as draft November 25, 2025 10:02
Comment on lines +18 to +23
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;
}
Copy link
Contributor

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

Suggested change
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");
}

Comment on lines +51 to +53

signedJWT.sign(signer);
return signedJWT.serialize();
Copy link
Contributor

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

Suggested change
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;

Comment on lines +74 to +79
// Check if new ICP is configured
if (ICPHeartBeatComponent.isICPConfigured()) {
log.info("New ICP configuration detected. Starting ICP heartbeat service.");
ICPHeartBeatComponent.invokeICPHeartbeatExecutorService();
return;
}
Copy link
Contributor

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

Suggested change
// 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));

Comment on lines 189 to 195
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);
}
Copy link
Contributor

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

Suggested change
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());
}

Comment on lines +158 to +190
*/
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
Copy link
Contributor

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

Suggested change
*/
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");

Comment on lines 117 to 142
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() {
Copy link
Contributor

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

Suggested change
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);

Copy link
Contributor

@wso2-engineering wso2-engineering bot left a 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

⚠️ Warning: AI-Generated Review Comments

  • 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.
Comment Accepted (Y/N) Reason
#### Log Improvement Suggestion No: 1
#### Log Improvement Suggestion No: 2
#### Log Improvement Suggestion No: 3
#### Log Improvement Suggestion No: 4
#### Log Improvement Suggestion No: 5
#### Log Improvement Suggestion No: 6

@Dilhasha Dilhasha changed the base branch from icp2-support to master December 10, 2025 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant