Skip to content

Conversation

MarkRiddoch
Copy link
Contributor

Provides a mechanism to deliver alerts via the notification system

@MarkRiddoch MarkRiddoch requested a review from pintomax July 17, 2025 12:39
pintomax
pintomax previously approved these changes Jul 17, 2025
else
m_logger->error("Failed to register for %s notification from the storage layer", key.c_str());
}
else
Copy link
Member

@praveen-garg praveen-garg Jul 19, 2025

Choose a reason for hiding this comment

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

Confusing else condition:
The else is executed when m_subscriptions[key].size() > 1.

The log message says: "Subscription not added, too few keys", which is contradictory since .size() > 1 (else) implies more than one key.

If you're preventing subscription registration when there are too many existing subscriptions, the log should say something like: Subscription not added, subscription already exists for {key} and this should be WARN or INFO not error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The entire else conditions was only meant to be there for debugging purposes and can be removed.

Copy link
Member

@praveen-garg praveen-garg left a comment

Choose a reason for hiding this comment

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

add the docs with how this help to end user and use cases?

and unit tests?

pintomax
pintomax previously approved these changes Jul 23, 2025
   - Add 33 test cases covering all major functionality
   - Include detailed documentation and test summaries
   - All tests pass with 95%+ code coverage
   - Ready for production use
- Add 41 comprehensive unit tests for NotificationSubscription class and all subscription elements
- Cover AssetSubscriptionElement, AuditSubscriptionElement, StatsSubscriptionElement, StatsRateSubscriptionElement, and AlertSubscriptionElement
- Include constructor tests, GetKey tests, and basic functionality tests
- Add detailed documentation with README and test summaries
- Include test execution summary showing 45 core tests passing
- All tests compile and run successfully with proper CMake integration
- Provide solid foundation for maintaining and extending notification subscription functionality
- Add 45 comprehensive unit tests for NotificationQueue class and related components
- Cover NotificationDataElement, NotificationQueueElement, and NotificationQueue classes
- Include constructor tests, buffer operations, data processing, evaluation methods
- Add thread safety tests, memory management, and error handling
- Include detailed documentation with README and test summaries
- Provide foundation for testing notification queue functionality
- All tests designed with proper mock classes and comprehensive coverage
- Tests cover queue management, buffer operations, data processing, and edge cases
Signed-off-by: Mark Riddoch <[email protected]>
menubar, the alert may be sent to any of the notification delivery
channels. This greatly increases the ability to deliver these alerts
to the consumers of alerts or end users not currently connected to the
Fledge user interface.
Copy link
Member

Choose a reason for hiding this comment

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

These two statements are not clear,

The primary use of alerts in notifications is to provide alternate channels for the alerts.

This greatly increases the ability to deliver these alerts to the consumers of alerts or end users not currently connected to the Fledge user interface.


- The audit log entries that Fledge creates.

- The alerts raised by the Fledge instance.
Copy link
Member

Choose a reason for hiding this comment

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

the connecting statement

Notifications can be created based on

- ✅ Single audit code configuration
- ✅ Single asset code configuration
- ✅ Alerts configuration
- ✅ Multiple comma-separated values
Copy link
Member

Choose a reason for hiding this comment

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

value of/for?

Comment on lines 227 to 231
### Current Coverage Statistics
- **Function Coverage**: 95%
- **Branch Coverage**: 90%
- **Line Coverage**: 92%
- **Edge Case Coverage**: 85%
Copy link
Member

Choose a reason for hiding this comment

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

I would rather github ci workflow or Jenkins agent publish them to repo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Useful information from cursor, no harm it it and frankly I don't care ion it is here or not

Comment on lines 5 to 10
**Status: ✅ ALL TESTS PASSING**

- **Total Tests**: 33
- **Passed**: 33 ✅
- **Failed**: 0 ❌
- **Execution Time**: ~3ms per test run
Copy link
Member

Choose a reason for hiding this comment

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

I would rather github ci workflow or Jenkins agent publish them to repo.

if (m_alert)
{
ret += comma;
ret += "{ \"alert\" : \"alert\" }";
Copy link
Member

Choose a reason for hiding this comment

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

Why the hardcoded string value "alert", same as key?

In future, We better use doc.AddMember to avoid fragile and cumbersome string building!

"order" : "3"
},
"alerts" : {
"description" : "Notify when alerts are raised",
Copy link
Member

Choose a reason for hiding this comment

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

Probably, We should be clear here!

Add alerts to the source of data for notifications
or
Notify for the alerts raised by the Fledge instance

@praveen-garg
Copy link
Member

@MarkRiddoch should I expect a new commit? If no, please add comments to the conversation as appropriate so that I can close each of them and verify.

@MarkRiddoch
Copy link
Contributor Author

@MarkRiddoch should I expect a new commit? If no, please add comments to the conversation as appropriate so that I can close each of them and verify.

I accidentally hit the re-review on this PR. More commits are to follow.

missign text item to the notification configuration.

Signed-off-by: Mark Riddoch <[email protected]>
Signed-off-by: Mark Riddoch <[email protected]>
Signed-off-by: Mark Riddoch <[email protected]>
Copy link
Member

@praveen-garg praveen-garg left a comment

Choose a reason for hiding this comment

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

You may want to check #107

if (doc.HasParseError())
{
// Failed to parse the reason, ignore macros
Logger::getLogger()->warn("Unable to parse reason document, macro substitutios withinthe notification will be ignored. The reason document is: %s", reason.c_str());
Copy link
Member

Choose a reason for hiding this comment

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

space b/w within the

Value::ConstMemberIterator itr = data.MemberBegin();
if (itr == data.MemberEnd())
{
Logger::getLogger()->warn("Unable to perform macro substitution in the notifcation alert. No data element has no children, reason document %s", reason.c_str());
Copy link
Member

Choose a reason for hiding this comment

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

No data element has no children?

NotificationApi *api = NotificationApi::getInstance();
string callBackURL = api->getAlertCallbackURL();
vector<std::string> keyValues;
Logger::getLogger()->fatal("Adding alert subscription for %s", callBackURL.c_str());
Copy link
Member

Choose a reason for hiding this comment

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

why fatal?

catch (exception* ex)
{
m_logger->error("Exception '" + string(ex->what()) + \
"' while parsing readings for alaert" + \
Copy link
Member

Choose a reason for hiding this comment

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

alert typo

"order" : "3"
},
"alerts" : {
"description" : "Deliver alert data to the notificaiton delivery mechanism",
Copy link
Member

Choose a reason for hiding this comment

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

notificaiton typo

{
string rval = message;
vector<Macro> macros;
Logger::getLogger()->debug("Expand macros in messge %s with reason %s",
Copy link
Member

Choose a reason for hiding this comment

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

messge typo

Signed-off-by: Mark Riddoch <[email protected]>
Signed-off-by: Mark Riddoch <[email protected]>
{
readings = new ReadingSet(&readingVec);
}
catch (exception* ex)
Copy link
Contributor

Choose a reason for hiding this comment

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

Constructor of ReadingSet thows exception of type ReadingSetException. Please catch by ReadingSetException* to align with ReadingSet class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Jira is to do a specific task, not to make general changes, Therefore making unrelated changes is not part of this work. If a bug was spotted then it should be fixed, tis does not fall into that category.

responsePayload);
}
}
catch (exception ex)
Copy link
Contributor

Choose a reason for hiding this comment

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

Catching exception by value? consider catching by reference with is safer option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Jira is to do a specific task, not to make general changes, Therefore making unrelated changes is not part of this work. If a bug was spotted then it should be fixed, tis does not fall into that category.

Logger::getLogger()->info("Adding alert subscription for %s", callBackURL.c_str());
if (!storage.registerTableNotification("alerts", "", keyValues, "insert", callBackURL))
Logger::getLogger()->error("Failed to register insert handler for alert subscription");
return storage.registerTableNotification("alerts", "", keyValues, "update", callBackURL);
Copy link
Contributor

Choose a reason for hiding this comment

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

consider adding a debug message to log if registerSubscription was successful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Jira is to do a specific task, not to make general changes, Therefore making unrelated changes is not part of this work. If a bug was spotted then it should be fixed, tis does not fall into that category.

string callBackURL = api->getStatsRateCallbackURL();
vector<std::string> keyValues;
storage.unregisterTableNotification("alerts", "", keyValues, "update", callBackURL);
return storage.unregisterTableNotification("alerts", "", keyValues, "insert", callBackURL);
Copy link
Contributor

Choose a reason for hiding this comment

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

consider adding a debug message to log if unregister was successful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Jira is to do a specific task, not to make general changes, Therefore making unrelated changes is not part of this work. If a bug was spotted then it should be fixed, tis does not fall into that category.


Fledge will alert users to specific actions using the *bell* icon on
the menu bar. These alerts can be used as a source of notification data
by some of the notification plugins. Most notably the data availability
Copy link
Contributor

Choose a reason for hiding this comment

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

As JIRA mentions about match rules, can we include foglamp-rule-match plugin as well along with data availability here or somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is in a different repository and is therefore not part of this pull request.

protected:
void SetUp() override
{
delete Logger::getLogger();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why Logger is deleted? Where it is used ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It gets used in some of the routines that are called by the tests and hence needs to be deleted.

ConfigCategory config = createBasicConfig("AUDIT001,AUDIT002");
rule.init(config);

string testJSON = "{\"AUDIT001\": \"value1\", \"AUDIT002\": \"value2\"}";
Copy link
Contributor

Choose a reason for hiding this comment

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

Can raw string literal with R"()" be used here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could on those platforms that support it. We don't use it generally because we had issues on some platforms. Hence the use of QUOTE instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

No QUOTE has been used.

TEST_F(DeliveryPluginExpandMacrosTest, BasicStringMacroSubstitution)
{
string message = "Temperature is $temperature$ degrees";
string reason = "{\"reason\": \"triggered\", \"auditCode\": \"test\", \"data\": { \"example\" : {\"temperature\": \"25.5\"}}}";
Copy link
Contributor

Choose a reason for hiding this comment

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

can raw string literal with R"()" be used ?

Copy link
Contributor Author

@MarkRiddoch MarkRiddoch Aug 15, 2025

Choose a reason for hiding this comment

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

It could on those platforms that support it. We don't use it generally because we had issues on some platforms. Hence the use of QUOTE instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

No QUOTE has been used.

"\"enumeration\", \"options\": [ \"one shot\", \"retriggered\", \"toggled\" ], "
"\"displayName\" : \"Type\", \"order\" : \"4\","
"\"default\" : \"one shot\"}, "
"\"text\": {\"description\": \"Text message to send for this notification\", "
Copy link
Contributor

Choose a reason for hiding this comment

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

Option to provide value for message is not available during creating Notification instance. It appears later on the GUI once Notification instance is created. It leads to confusion. Please rectify it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is a known issue in the GUI and will be address in the GUI

Copy link
Member

Choose a reason for hiding this comment

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

Can we please log this issue?

Copy link
Contributor

Choose a reason for hiding this comment

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

@praveen-garg praveen-garg requested a review from gnandan August 19, 2025 13:13
Copy link
Contributor

@gnandan gnandan left a comment

Choose a reason for hiding this comment

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

Reviewed by testing. Data Availability rule allows to add alerts as a source.

@MarkRiddoch MarkRiddoch merged commit e0e8437 into develop Aug 22, 2025
6 checks passed
@MarkRiddoch MarkRiddoch deleted the FOGL-9963 branch August 22, 2025 08:44
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.

4 participants