Skip to content

Conversation

@ayeshLK
Copy link
Contributor

@ayeshLK ayeshLK commented Sep 25, 2025

Purpose

$subject

Part of: #3

@ayeshLK ayeshLK requested review from RadCod3 and gayaldassanayake and removed request for anupama-pathirage September 25, 2025 17:13
common:SystemStateSnapshot stateSnapshot = {
topics: getTopics(),
subscriptions: getSubscriptions()
};

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
};
};
log:printInfo("State snapshot retrieved successfully", topicCount = stateSnapshot.topics.length(), subscriptionCount = stateSnapshot.subscriptions.length());

kafka:BytesConsumerRecord[] records = check conn:websubEventConsumer->poll(config:kafka.consumer.pollingInterval);
log:printDebug("Polled Kafka records for state consolidation", recordCount = records.length(), pollingInterval = config:kafka.consumer.pollingInterval);

if records.length() > 0 {

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
if records.length() > 0 {
if records.length() > 0 {
log:printInfo("Processing batch of Kafka records", batchSize = records.length());

log:printDebug("Processing event based on hub mode", hubMode = hubMode);

match hubMode {
"register" => {

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
"register" => {
match hubMode {
"register" => {
log:printInfo("Processing topic registration event");

check processTopicRegistration(payload);
log:printDebug("Topic registration event processed successfully");
}
"deregister" => {

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
"deregister" => {
"deregister" => {
log:printInfo("Processing topic deregistration event");

check processTopicDeregistration(payload);
log:printDebug("Topic deregistration event processed successfully");
}
"subscribe" => {

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
"subscribe" => {
"subscribe" => {
log:printInfo("Processing subscription event");

check processSubscription(payload);
log:printDebug("Subscription event processed successfully");
}
"unsubscribe" => {

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 7

Suggested change
"unsubscribe" => {
"unsubscribe" => {
log:printInfo("Processing unsubscription event");

}
}
log:printDebug("Completed processing persisted data", hubMode = hubMode);
}

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 8

Suggested change
}
isolated function processStateUpdate() returns error? {
log:printInfo("Processing state update - gathering current system state");

common:SystemStateSnapshot stateSnapshot = {
topics: getTopics(),
subscriptions: getSubscriptions()
};

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 9

Suggested change
};
check persist:persistWebsubEventsSnapshot(stateSnapshot);
log:printInfo("State snapshot persisted successfully", topicCount = stateSnapshot.topics.length(), subscriptionCount = stateSnapshot.subscriptions.length());

Comment on lines 23 to +24
public isolated function persistWebsubEventsSnapshot(common:SystemStateSnapshot systemStateSnapshot) returns error? {
log:printDebug("Persisting system state snapshot", topicCount = systemStateSnapshot.topics.length(), subscriptionCount = systemStateSnapshot.subscriptions.length());

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 11

Suggested change
public isolated function persistWebsubEventsSnapshot(common:SystemStateSnapshot systemStateSnapshot) returns error? {
log:printDebug("Persisting system state snapshot", topicCount = systemStateSnapshot.topics.length(), subscriptionCount = systemStateSnapshot.subscriptions.length());
public isolated function persistWebsubEventsSnapshot(common:SystemStateSnapshot systemStateSnapshot) returns error? {
log:printInfo("Persisting system state snapshot", topicCount = systemStateSnapshot.topics.length(), subscriptionCount = systemStateSnapshot.subscriptions.length());

Comment on lines 26 to +27
check produceKafkaMessage(config:state.snapshot.topic, payload);
log:printDebug("System state snapshot persisted successfully", targetTopic = config:state.snapshot.topic);

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 12

Suggested change
check produceKafkaMessage(config:state.snapshot.topic, payload);
log:printDebug("System state snapshot persisted successfully", targetTopic = config:state.snapshot.topic);
check produceKafkaMessage(config:state.snapshot.topic, payload);
log:printInfo("System state snapshot persisted successfully", targetTopic = config:state.snapshot.topic);

Comment on lines 30 to +31
isolated function produceKafkaMessage(string topicName, json payload) returns error? {
log:printDebug("Producing Kafka message", targetTopic = topicName);

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 13

Suggested change
isolated function produceKafkaMessage(string topicName, json payload) returns error? {
log:printDebug("Producing Kafka message", targetTopic = topicName);
isolated function produceKafkaMessage(string topicName, json payload) returns error? {
if (log:isDebugEnabled()) {
log:printDebug("Producing Kafka message", targetTopic = topicName, payloadSize = payload.toJsonString().length());
}

Comment on lines 24 to +25
isolated function refreshSubscribersCache(websubhub:VerifiedSubscription[] persistedSubscribers) {
log:printDebug("Refreshing subscribers cache from persisted data", persistedSubscriberCount = persistedSubscribers.length());

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 14

Suggested change
isolated function refreshSubscribersCache(websubhub:VerifiedSubscription[] persistedSubscribers) {
log:printDebug("Refreshing subscribers cache from persisted data", persistedSubscriberCount = persistedSubscribers.length());
isolated function refreshSubscribersCache(websubhub:VerifiedSubscription[] persistedSubscribers) {
log:printInfo("Starting subscribers cache refresh", persistedSubscriberCount = persistedSubscribers.length());

Comment on lines 32 to +33
}
log:printDebug("Subscribers cache refresh completed", totalCachedSubscribers = subscribersCache.length());

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 15

Suggested change
}
log:printDebug("Subscribers cache refresh completed", totalCachedSubscribers = subscribersCache.length());
}
log:printInfo("Subscribers cache refresh completed", totalCachedSubscribers = subscribersCache.length());

Comment on lines 52 to +53
check processStateUpdate();
log:printDebug("Subscription processing completed", subscriberId = subscriberId, wasAdded = subscriptionAdded);

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 16

Suggested change
check processStateUpdate();
log:printDebug("Subscription processing completed", subscriberId = subscriberId, wasAdded = subscriptionAdded);
check processStateUpdate();
log:printInfo("Subscription processed successfully", subscriberId = subscriberId, wasAdded = subscriptionAdded);

Comment on lines 67 to +68
check processStateUpdate();
log:printDebug("Unsubscription processing completed", subscriberId = subscriberId);

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 17

Suggested change
check processStateUpdate();
log:printDebug("Unsubscription processing completed", subscriberId = subscriberId);
check processStateUpdate();
log:printInfo("Unsubscription processed successfully", subscriberId = subscriberId);

Comment on lines 25 to 30
foreach var topic in persistedTopics.cloneReadOnly() {
lock {
registeredTopicsCache[topic.topic] = topic.cloneReadOnly();
}
log:printDebug("Added topic to cache during refresh", topicName = topic.topic);
}

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 18

Suggested change
foreach var topic in persistedTopics.cloneReadOnly() {
lock {
registeredTopicsCache[topic.topic] = topic.cloneReadOnly();
}
log:printDebug("Added topic to cache during refresh", topicName = topic.topic);
}
foreach var topic in persistedTopics.cloneReadOnly() {
lock {
registeredTopicsCache[topic.topic] = topic.cloneReadOnly();
}
if (log:isDebugEnabled()) {
log:printDebug("Added topic to cache during refresh", topicName = topic.topic);
}

Comment on lines 23 to +24
isolated function refreshTopicCache(websubhub:TopicRegistration[] persistedTopics) {
log:printDebug("Refreshing topic cache from persisted data", persistedTopicCount = persistedTopics.length());

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 19

Suggested change
isolated function refreshTopicCache(websubhub:TopicRegistration[] persistedTopics) {
log:printDebug("Refreshing topic cache from persisted data", persistedTopicCount = persistedTopics.length());
solated function refreshTopicCache(websubhub:TopicRegistration[] persistedTopics) {
if (log:isDebugEnabled()) {
log:printDebug("Refreshing topic cache from persisted data", persistedTopicCount = persistedTopics.length());
}

Comment on lines 30 to +31
}
log:printDebug("Topic cache refresh completed", totalCachedTopics = registeredTopicsCache.length());

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 20

Suggested change
}
log:printDebug("Topic cache refresh completed", totalCachedTopics = registeredTopicsCache.length());
}
if (log:isDebugEnabled()) {
log:printDebug("Topic cache refresh completed", totalCachedTopics = registeredTopicsCache.length());
}

Comment on lines 33 to 34

isolated function processTopicRegistration(json payload) returns error? {

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 21

Suggested change
isolated function processTopicRegistration(json payload) returns error? {
isolated function processTopicRegistration(json payload) returns error? {
if (log:isDebugEnabled()) {
log:printDebug("Processing topic registration event");
}

Comment on lines +35 to 36
log:printDebug("Processing topic registration event");
websubhub:TopicRegistration registration = check value:cloneWithType(payload);

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 22

Suggested change
log:printDebug("Processing topic registration event");
websubhub:TopicRegistration registration = check value:cloneWithType(payload);
websubhub:TopicRegistration registration = check value:cloneWithType(payload);
if (log:isDebugEnabled()) {
log:printDebug("Deserialized topic registration", topicName = registration.topic);
}

Comment on lines 40 to 41
registeredTopicsCache[registration.topic] = registration.cloneReadOnly();
}

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 23

Suggested change
registeredTopicsCache[registration.topic] = registration.cloneReadOnly();
}
}
if (log:isDebugEnabled()) {
log:printDebug("Added topic to cache", topicName = registration.topic, totalTopics = registeredTopicsCache.length());
}

Comment on lines +42 to 43
log:printDebug("Added topic to cache", topicName = registration.topic, totalTopics = registeredTopicsCache.length());
check processStateUpdate();

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 24

Suggested change
log:printDebug("Added topic to cache", topicName = registration.topic, totalTopics = registeredTopicsCache.length());
check processStateUpdate();
check processStateUpdate();
if (log:isDebugEnabled()) {
log:printDebug("Topic registration processing completed", topicName = registration.topic);
}

Comment on lines 46 to 47

isolated function processTopicDeregistration(json payload) returns error? {

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 25

Suggested change
isolated function processTopicDeregistration(json payload) returns error? {
isolated function processTopicDeregistration(json payload) returns error? {
if (log:isDebugEnabled()) {
log:printDebug("Processing topic deregistration event");
}

Comment on lines +48 to 49
log:printDebug("Processing topic deregistration event");
websubhub:TopicDeregistration deregistration = check value:cloneWithType(payload);

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 26

Suggested change
log:printDebug("Processing topic deregistration event");
websubhub:TopicDeregistration deregistration = check value:cloneWithType(payload);
websubhub:TopicDeregistration deregistration = check value:cloneWithType(payload);
if (log:isDebugEnabled()) {
log:printDebug("Deserialized topic deregistration", topicName = deregistration.topic);
}

Comment on lines +55 to 56
topicRemoved = removedTopic is websubhub:TopicRegistration;
}

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 27

Suggested change
topicRemoved = removedTopic is websubhub:TopicRegistration;
}
}
if (log:isDebugEnabled()) {
log:printDebug("Removed topic from cache", topicName = deregistration.topic, wasRemoved = topicRemoved, totalTopics = registeredTopicsCache.length());
}

Comment on lines +57 to 58
log:printDebug("Removed topic from cache", topicName = deregistration.topic, wasRemoved = topicRemoved, totalTopics = registeredTopicsCache.length());
check processStateUpdate();

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 28

Suggested change
log:printDebug("Removed topic from cache", topicName = deregistration.topic, wasRemoved = topicRemoved, totalTopics = registeredTopicsCache.length());
check processStateUpdate();
check processStateUpdate();
if (log:isDebugEnabled()) {
log:printDebug("Topic deregistration processing completed", topicName = deregistration.topic);
}

Comment on lines +65 to 66
topics = registeredTopicsCache.toArray().cloneReadOnly();
}

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 29

Suggested change
topics = registeredTopicsCache.toArray().cloneReadOnly();
}
}
if (log:isDebugEnabled()) {
log:printDebug("Retrieved topics from cache", topicCount = topics.length());
}

Comment on lines 48 to +50
isolated remote function onRegisterTopic(websubhub:TopicRegistration message, http:Headers headers)
returns websubhub:TopicRegistrationSuccess|websubhub:TopicRegistrationError|error {
log:printDebug("Topic registration request received", topic = message.topic, securityEnabled = config:securityOn);

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 30

Suggested change
isolated remote function onRegisterTopic(websubhub:TopicRegistration message, http:Headers headers)
returns websubhub:TopicRegistrationSuccess|websubhub:TopicRegistrationError|error {
log:printDebug("Topic registration request received", topic = message.topic, securityEnabled = config:securityOn);
isolated remote function onRegisterTopic(websubhub:TopicRegistration message, http:Headers headers)
returns websubhub:TopicRegistrationSuccess|websubhub:TopicRegistrationError|error {
log:printInfo("Topic registration request received", topic = message.topic);

Comment on lines 55 to +57
}
check self.registerTopic(message);
log:printDebug("Topic registration completed successfully", topic = message.topic);

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 31

Suggested change
}
check self.registerTopic(message);
log:printDebug("Topic registration completed successfully", topic = message.topic);
}
check self.registerTopic(message);
log:printInfo("Topic registered successfully", topic = message.topic);

Comment on lines +64 to +66
log:printDebug("Checking topic existence in cache", topic = message.topic, exists = topicExist);
if topicExist {
log:printDebug("Topic registration failed - already exists", topic = message.topic);

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 32

Suggested change
log:printDebug("Checking topic existence in cache", topic = message.topic, exists = topicExist);
if topicExist {
log:printDebug("Topic registration failed - already exists", topic = message.topic);
if topicExist {
log:printDebug("Topic registration failed - already exists", topic = message.topic);
log:printWarn("Attempted to register existing topic", topic = message.topic);

Comment on lines +71 to +73
error? persistingResult = persist:addRegsiteredTopic(message.cloneReadOnly());
if persistingResult is error {
common:logError("Error occurred while persisting the topic-registration", persistingResult);

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 33

Suggested change
error? persistingResult = persist:addRegsiteredTopic(message.cloneReadOnly());
if persistingResult is error {
common:logError("Error occurred while persisting the topic-registration", persistingResult);
error? persistingResult = persist:addRegsiteredTopic(message.cloneReadOnly());
if persistingResult is error {
log:printError("Error occurred while persisting topic registration", topic = message.topic, errorMsg = persistingResult.message());

Comment on lines 85 to +87
isolated remote function onDeregisterTopic(websubhub:TopicDeregistration message, http:Headers headers)
returns websubhub:TopicDeregistrationSuccess|websubhub:TopicDeregistrationError|error {
log:printDebug("Topic deregistration request received", topic = message.topic, securityEnabled = config:securityOn);

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 34

Suggested change
isolated remote function onDeregisterTopic(websubhub:TopicDeregistration message, http:Headers headers)
returns websubhub:TopicDeregistrationSuccess|websubhub:TopicDeregistrationError|error {
log:printDebug("Topic deregistration request received", topic = message.topic, securityEnabled = config:securityOn);
isolated remote function onDeregisterTopic(websubhub:TopicDeregistration message, http:Headers headers)
returns websubhub:TopicDeregistrationSuccess|websubhub:TopicDeregistrationError|error {
log:printInfo("Topic deregistration request received", topic = message.topic);

Comment on lines 92 to +94
}
check self.deregisterTopic(message);
log:printDebug("Topic deregistration completed successfully", topic = message.topic);

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 35

Suggested change
}
check self.deregisterTopic(message);
log:printDebug("Topic deregistration completed successfully", topic = message.topic);
}
check self.deregisterTopic(message);
log:printInfo("Topic deregistered successfully", topic = message.topic);

Comment on lines +101 to +103
log:printDebug("Checking topic existence in cache for deregistration", topic = message.topic, exists = topicExist);
if !topicExist {
log:printDebug("Topic deregistration failed - not found", topic = message.topic);

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 36

Suggested change
log:printDebug("Checking topic existence in cache for deregistration", topic = message.topic, exists = topicExist);
if !topicExist {
log:printDebug("Topic deregistration failed - not found", topic = message.topic);
if !topicExist {
log:printDebug("Topic deregistration failed - not found", topic = message.topic);
log:printWarn("Attempted to deregister non-existent topic", topic = message.topic);

Comment on lines +108 to +110
error? persistingResult = persist:removeRegsiteredTopic(message.cloneReadOnly());
if persistingResult is error {
common:logError("Error occurred while persisting the topic-deregistration", persistingResult);

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 37

Suggested change
error? persistingResult = persist:removeRegsiteredTopic(message.cloneReadOnly());
if persistingResult is error {
common:logError("Error occurred while persisting the topic-deregistration", persistingResult);
error? persistingResult = persist:removeRegsiteredTopic(message.cloneReadOnly());
if persistingResult is error {
log:printError("Error occurred while persisting topic deregistration", topic = message.topic, errorMsg = persistingResult.message());

Comment on lines 122 to +124
isolated remote function onSubscription(websubhub:Subscription message, http:Headers headers)
returns websubhub:SubscriptionAccepted|websubhub:BadSubscriptionError|error {
log:printDebug("Subscription request received", topic = message.hubTopic, callback = message.hubCallback, securityEnabled = config:securityOn);

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 38

Suggested change
isolated remote function onSubscription(websubhub:Subscription message, http:Headers headers)
returns websubhub:SubscriptionAccepted|websubhub:BadSubscriptionError|error {
log:printDebug("Subscription request received", topic = message.hubTopic, callback = message.hubCallback, securityEnabled = config:securityOn);
isolated remote function onSubscription(websubhub:Subscription message, http:Headers headers)
returns websubhub:SubscriptionAccepted|websubhub:BadSubscriptionError|error {
log:printInfo("Subscription request received", topic = message.hubTopic, callback = message.hubCallback);

Comment on lines +142 to +144
log:printDebug("Topic exists check for subscription", topic = message.hubTopic, exists = topicExist);
if !topicExist {
log:printDebug("Subscription validation failed - topic not registered", topic = message.hubTopic, callback = message.hubCallback);

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 39

Suggested change
log:printDebug("Topic exists check for subscription", topic = message.hubTopic, exists = topicExist);
if !topicExist {
log:printDebug("Subscription validation failed - topic not registered", topic = message.hubTopic, callback = message.hubCallback);
if !topicExist {
log:printDebug("Subscription validation failed - topic not registered", topic = message.hubTopic, callback = message.hubCallback);
log:printWarn("Subscription attempt for non-registered topic", topic = message.hubTopic);

Comment on lines 160 to +162
}
if isValidSubscription(subscriberId) {
if isSubscriptionExist(subscriberId) {
log:printDebug("Subscription validation failed - active subscription exists", subscriberId = subscriberId, topic = message.hubTopic, callback = message.hubCallback);

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 40

Suggested change
}
if isValidSubscription(subscriberId) {
if isSubscriptionExist(subscriberId) {
log:printDebug("Subscription validation failed - active subscription exists", subscriberId = subscriberId, topic = message.hubTopic, callback = message.hubCallback);
if isSubscriptionExist(subscriberId) {
log:printDebug("Subscription validation failed - active subscription exists", subscriberId = subscriberId, topic = message.hubTopic, callback = message.hubCallback);
log:printWarn("Duplicate subscription attempt", topic = message.hubTopic, callback = message.hubCallback);

Comment on lines 176 to +177
isolated remote function onSubscriptionIntentVerified(websubhub:VerifiedSubscription message) returns error? {
log:printDebug("Processing verified subscription intent", topic = message.hubTopic, callback = message.hubCallback);

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 41

Suggested change
isolated remote function onSubscriptionIntentVerified(websubhub:VerifiedSubscription message) returns error? {
log:printDebug("Processing verified subscription intent", topic = message.hubTopic, callback = message.hubCallback);
isolated remote function onSubscriptionIntentVerified(websubhub:VerifiedSubscription message) returns error? {
log:printDebug("Processing verified subscription intent", topic = message.hubTopic, callback = message.hubCallback);
log:printInfo("Subscription verified and accepted", topic = message.hubTopic, callback = message.hubCallback);

Comment on lines 180 to +182
error? persistingResult = persist:addSubscription(subscription);
if persistingResult is error {
log:printError("Error occurred while persisting the subscription ", persistingResult);
common:logError("Error occurred while persisting the subscription", persistingResult);

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 42

Suggested change
error? persistingResult = persist:addSubscription(subscription);
if persistingResult is error {
log:printError("Error occurred while persisting the subscription ", persistingResult);
common:logError("Error occurred while persisting the subscription", persistingResult);
error? persistingResult = persist:addSubscription(subscription);
if persistingResult is error {
log:printError("Error occurred while persisting the subscription", topic = subscription.hubTopic, callback = subscription.hubCallback, errorMsg = persistingResult.message());

@ayeshLK ayeshLK requested a review from daneshk September 25, 2025 17:47
do {
while true {
kafka:BytesConsumerRecord[] records = check conn:websubEventConsumer->poll(config:kafka.consumer.pollingInterval);
log:printDebug("Polled Kafka records for state consolidation", recordCount = records.length(), pollingInterval = config:kafka.consumer.pollingInterval);
Copy link

Choose a reason for hiding this comment

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

If we have any computation, it's better to use a function pointer, as it is only executed when we enable the debug level. Otherwise, it has unnecessary tasks.

log:printDebug("Polled Kafka records for state consolidation", 
                             recordCount = isolated function() returns int { return records.length();}, 
                             pollingInterval = config:kafka.consumer.pollingInterval);

Comment on lines +50 to +51
int messageSize = lastPersistedData.length();
log:printDebug("Processing Kafka record for consolidation", messageSize = messageSize, offset = currentRecord.offset);
Copy link

Choose a reason for hiding this comment

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

We can do the same as above without initializing the variable.

Comment on lines +63 to +65
websubhub:VerifiedSubscription? removedSubscription = subscribersCache.removeIfHasKey(subscriberId);
boolean subscriptionRemoved = removedSubscription is websubhub:VerifiedSubscription;
log:printDebug("Removed subscription from cache", subscriberId = subscriberId, wasRemoved = subscriptionRemoved, totalSubscriptions = subscribersCache.length());
Copy link

Choose a reason for hiding this comment

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

same as above

Comment on lines +105 to +109
log:printDebug("Processing topic deregistration event");
websubhub:TopicDeregistration topicDeregistration = check event.fromJsonWithType();
log:printDebug("Topic deregistration event deserialized", topic = topicDeregistration.topic);
check processTopicDeregistration(topicDeregistration);
log:printDebug("Topic deregistration event processed successfully", topic = topicDeregistration.topic);
Copy link

@daneshk daneshk Sep 26, 2025

Choose a reason for hiding this comment

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

Can't we have a single log line for this? There is a cost of checking whether debug is enabled in each call

Comment on lines +84 to +86
log:printDebug("Partitions assigned successfully", topic = topicName, assignedPartitions = partitions.length());

log:printDebug("Processing partition offsets", topic = topicName);
Copy link

Choose a reason for hiding this comment

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

IMO, we can have one here

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.

2 participants