-
Notifications
You must be signed in to change notification settings - Fork 273
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
Error Handling Framework : sonic-swss-common library support #309
base: master
Are you sure you want to change the base?
Conversation
54ab228
to
c717a13
Compare
c717a13
to
d07b893
Compare
@@ -26,7 +26,8 @@ const TableNameSeparatorMap TableBase::tableNameSeparatorMap = { | |||
{ CONFIG_DB, TABLE_NAME_SEPARATOR_VBAR }, | |||
{ PFC_WD_DB, TABLE_NAME_SEPARATOR_COLON }, | |||
{ FLEX_COUNTER_DB, TABLE_NAME_SEPARATOR_COLON }, | |||
{ STATE_DB, TABLE_NAME_SEPARATOR_VBAR } | |||
{ STATE_DB, TABLE_NAME_SEPARATOR_VBAR }, | |||
{ ERROR_DB, TABLE_NAME_SEPARATOR_COLON } |
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.
TABLE_NAME_SEPARATOR_COLON [](start = 22, length = 26)
prefer TABLE_NAME_SEPARATOR_VBAR for new comer #Closed
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 key format in ERROR_DB is same as in APP_DB. This is the reason why COLON was chosen instead of VBAR. As you said, ERROR_DB delimiter will be moved to VBAR when APP_DB delimiter changes to VBAR in future.
common/errormap.cpp
Outdated
{ "SAI_STATUS_FAILURE", "SWSS_RC_FAILURE" } | ||
}; | ||
|
||
ErrorMap &ErrorMap::getInstance() |
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.
getInstance [](start = 24, length = 11)
everything in ErrorMap is static, why we need an instance? #Closed
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.
Removed getIntance() in ErrorMap
common/errorlistener.h
Outdated
#include "notificationconsumer.h" | ||
#include "selectable.h" | ||
#include "table.h" | ||
#include <dbconnector.h> |
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.
#include <dbconnector.h> | |
#include "dbconnector.h" | |
``` #Closed |
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.
Done
common/errorlistener.h
Outdated
|
||
static std::string getErrorChannelName(std::string& appTableName) | ||
{ | ||
std::string errorChnl = "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.
errorChnl [](start = 28, length = 9)
errorChannel #Closed
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.
Done
common/errorlistener.cpp
Outdated
|
||
// Filter the error notifications that the caller is not interested in. | ||
if (!(((m_errorFlags & ERR_NOTIFY_POSITIVE_ACK) && (j["rc"] == "SWSS_RC_SUCCESS")) || | ||
((m_errorFlags & ERR_NOTIFY_FAIL) && (j["rc"] != "SWSS_RC_SUCCESS")))) |
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.
)))) [](start = 86, length = 4)
Too complex in single expression. Consider split to multiple statements. #Closed
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.
Simplified by splitting into two statements.
common/errorlistener.cpp
Outdated
m_errorNotificationConsumer->pop(op, data, values); | ||
SWSS_LOG_DEBUG("ErrorListener op: %s data: %s", op.c_str(), data.c_str()); | ||
|
||
json j = json::parse(data); |
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.
parse [](start = 23, length = 5)
parse [](start = 23, length = 5)
possible to throw? should we return -1? #Closed
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.
We need to return -1 here. This return code is ignored by applications processing the error (Ex: BGP). But the error can still be fetched from the error database.
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 mean json::parse() will throw if it met some invalid input. I guess you need to catch it and return -1.
In reply to: 340924415 [](ancestors = 340924415)
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.
Done
return -1; | ||
} | ||
|
||
key = j["key"]; |
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.
j["key"]; [](start = 14, length = 9)
possible to throw? should we return -1?
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.
We need to return -1 here. This return code is ignored by applications processing the error (Ex: BGP). But the error can still be fetched from the error database.
warm_restart.cpp | ||
warm_restart.cpp \ | ||
errormap.cpp \ | ||
errorlistener.cpp |
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.
If they are only used in swss, how about move code to that repo? #Closed
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's placed in swss-common folder as the error listener could be in any docker. The docker that is interested in receiving the error needs to link swss-common package.
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.
Commented
common/errorlistener.h
Outdated
|
||
return errorChnl; | ||
return errorChannel; |
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.
please don't put code to header files
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.
Moved to corresponding .cpp files
|
||
return errorChnl; | ||
return errorChannel; | ||
} | ||
|
||
int getFd() { return m_errorNotificationConsumer->getFd(); } |
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.
dont put code in headers, move to cpp file
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.
Moved to corresponding .cpp file
common/errorlistener.cpp
Outdated
delete m_errorNotificationsDb; | ||
} | ||
|
||
/* Returns the Error notification corresponding to an entry in the APP_DB. |
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.
make function comments in doxygen format with brief line and then main explanation
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.
Done
common/errorlistener.h
Outdated
#include "dbconnector.h" | ||
|
||
// Error notifications of interest to the error listener | ||
typedef enum |
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.
typedef enum _error_notify_flags_t
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.
Done
|
||
ErrorMap::SwssRC ErrorMap::getSwssRC(const std::string &swssRCStr) | ||
{ | ||
for (auto &elem : m_swssStrToRC) |
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.
use find ?
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.
Used array of pairs for m_swssStrToRC instead of map, as we need functions to convert from SWSS RC string to SWSS RC code and vice versa. This is the reason why for loop is used to find the given input in the array.
/* Error mapping is not found */ | ||
SWSS_LOG_ERROR("Invalid SWSS error code %d is received", rc); | ||
|
||
return "SWSS_RC_UNKNOWN"; |
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.
used multiple times, actually you can introduce this error code and return it from map
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 codes mentioned in m_swssStrToRC and m_saiToSwssRC are the codes generated by SAI and supported in error handling framework. In the case where SAI return code is not supported in error handling framework, we return UNKNOWN error code.
common/errormap.h
Outdated
|
||
private: | ||
ErrorMap() = default; | ||
~ErrorMap(); |
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.
also = default,
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.
Done. Removed the default constructor.
}; | ||
|
||
typedef std::map<std::string, std::string> SaiToSwssRCMap; | ||
typedef std::vector<std::pair<std::string, SwssRC>> SwssStrToRCMap; |
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.
whyt this is vector and not actual map ?
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.
Used array of pairs for m_swssStrToRC instead of map, as we need functions to convert from SWSS RC string to SWSS RC code and vice versa. This is the reason why for loop is used to find the given input in the array.
If we want to use map here, then we need to have two maps one taking SWSS RC code as key and another taking SWSS RC string as key. To avoid two maps, I have used array of pairs.
{ std::make_pair("SWSS_RC_INVALID_OBJECT_ID", SWSS_RC_INVALID_OBJECT_ID)} | ||
}; | ||
|
||
const ErrorMap::SaiToSwssRCMap ErrorMap::m_saiToSwssRC = { |
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.
convert to std::map
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.
Used array of pairs for m_swssStrToRC instead of map, as we need functions to convert from SWSS RC string to SWSS RC code and vice versa. This is the reason why for loop is used to find the given input in the array.
If we want to use map here, then we need to have two maps one taking SWSS RC code as key and another taking SWSS RC string as key. To avoid two maps, I have used array of pairs.
4a9d987
to
6cf7dfd
Compare
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.
Looks good to me. Please check with other reviewers.
common/errorlistener.h
Outdated
// Error notifications of interest to the error listener | ||
typedef enum _error_notify_flags_t | ||
{ | ||
ERR_NOTIFY_FAIL = 1, |
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.
just curious why not have enum start from zero?
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.
Added ERR_NOTIFY_NONE with value of zero to indicate that application is not interested in any notifications
Defined ERR_NOTIFY_NONE
Error handling framework is responsible for notifying ASIC/SAI programming failures to the applications.
Error handling framework is responsible for notifying ASIC/SAI programming failures to the applications.
This repo defines the following classes as part of error handling feature.
Related PRs:
sonic-net/sonic-utilities#666
sonic-net/sonic-swss#1100
sonic-net/sonic-sairedis#523
Signed-off-by: Siva Mukka ([email protected])