-
Notifications
You must be signed in to change notification settings - Fork 0
FOGL-9963 Add Alerts as a source for notifications #104
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
Conversation
Signed-off-by: Mark Riddoch <[email protected]>
else | ||
m_logger->error("Failed to register for %s notification from the storage layer", key.c_str()); | ||
} | ||
else |
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.
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?
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.
The entire else conditions was only meant to be there for debugging purposes and can be removed.
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.
add the docs with how this help to end user and use cases?
and unit tests?
Signed-off-by: Mark Riddoch <[email protected]>
Signed-off-by: Mark Riddoch <[email protected]>
- 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]>
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. |
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.
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. |
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.
the connecting statement
Notifications can be created based on
- ✅ Single audit code configuration | ||
- ✅ Single asset code configuration | ||
- ✅ Alerts configuration | ||
- ✅ Multiple comma-separated values |
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.
value of/for?
### Current Coverage Statistics | ||
- **Function Coverage**: 95% | ||
- **Branch Coverage**: 90% | ||
- **Line Coverage**: 92% | ||
- **Edge Case Coverage**: 85% |
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.
I would rather github ci workflow or Jenkins agent publish them to repo
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.
Useful information from cursor, no harm it it and frankly I don't care ion it is here or not
**Status: ✅ ALL TESTS PASSING** | ||
|
||
- **Total Tests**: 33 | ||
- **Passed**: 33 ✅ | ||
- **Failed**: 0 ❌ | ||
- **Execution Time**: ~3ms per test run |
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.
I would rather github ci workflow or Jenkins agent publish them to repo.
if (m_alert) | ||
{ | ||
ret += comma; | ||
ret += "{ \"alert\" : \"alert\" }"; |
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.
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", |
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.
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
Signed-off-by: Mark Riddoch <[email protected]>
@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]>
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.
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()); |
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.
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()); |
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.
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()); |
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.
why fatal?
catch (exception* ex) | ||
{ | ||
m_logger->error("Exception '" + string(ex->what()) + \ | ||
"' while parsing readings for alaert" + \ |
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.
alert typo
"order" : "3" | ||
}, | ||
"alerts" : { | ||
"description" : "Deliver alert data to the notificaiton delivery mechanism", |
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.
notificaiton typo
{ | ||
string rval = message; | ||
vector<Macro> macros; | ||
Logger::getLogger()->debug("Expand macros in messge %s with reason %s", |
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.
messge typo
Signed-off-by: Mark Riddoch <[email protected]>
Signed-off-by: Mark Riddoch <[email protected]>
Signed-off-by: Mark Riddoch <[email protected]>
{ | ||
readings = new ReadingSet(&readingVec); | ||
} | ||
catch (exception* ex) |
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.
Constructor of ReadingSet thows exception of type ReadingSetException. Please catch by ReadingSetException* to align with ReadingSet class
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.
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) |
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.
Catching exception by value? consider catching by reference with is safer option.
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.
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); |
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.
consider adding a debug message to log if registerSubscription was successful.
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.
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); |
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.
consider adding a debug message to log if unregister was successful.
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.
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 |
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.
As JIRA mentions about match rules, can we include foglamp-rule-match plugin as well along with data availability here or somewhere else?
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.
That is in a different repository and is therefore not part of this pull request.
protected: | ||
void SetUp() override | ||
{ | ||
delete Logger::getLogger(); |
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.
Why Logger is deleted? Where it is used ?
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.
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\"}"; |
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.
Can raw string literal with R"()" be used here?
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.
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.
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.
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\"}}}"; |
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.
can raw string literal with R"()" be used ?
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.
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.
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.
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\", " |
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.
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.
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.
Yes, this is a known issue in the GUI and will be address in the GUI
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.
Can we please log this issue?
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.
@praveen-garg following JIRA has been logged https://scaledb.atlassian.net/browse/FOGL-10239
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.
Reviewed by testing. Data Availability rule allows to add alerts as a source.
Provides a mechanism to deliver alerts via the notification system