Error Handling Framework : sonic-swss-common library support#309
Error Handling Framework : sonic-swss-common library support#309sivamukka wants to merge 4 commits intosonic-net:masterfrom
Conversation
54ab228 to
c717a13
Compare
c717a13 to
d07b893
Compare
| { 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.
TABLE_NAME_SEPARATOR_COLON [](start = 22, length = 26)
prefer TABLE_NAME_SEPARATOR_VBAR for new comer #Closed
There was a problem hiding this comment.
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.
getInstance [](start = 24, length = 11)
everything in ErrorMap is static, why we need an instance? #Closed
There was a problem hiding this comment.
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.
| #include <dbconnector.h> | |
| #include "dbconnector.h" | |
| ``` #Closed |
common/errorlistener.h
Outdated
|
|
||
| static std::string getErrorChannelName(std::string& appTableName) | ||
| { | ||
| std::string errorChnl = "ERROR_"; |
There was a problem hiding this comment.
errorChnl [](start = 28, length = 9)
errorChannel #Closed
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.
)))) [](start = 86, length = 4)
Too complex in single expression. Consider split to multiple statements. #Closed
There was a problem hiding this comment.
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.
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.
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.
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)
| return -1; | ||
| } | ||
|
|
||
| key = j["key"]; |
There was a problem hiding this comment.
j["key"]; [](start = 14, length = 9)
possible to throw? should we return -1?
There was a problem hiding this comment.
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.
If they are only used in swss, how about move code to that repo? #Closed
There was a problem hiding this comment.
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.
common/errorlistener.h
Outdated
| errorChannel += appTableName + "_CHANNEL"; | ||
|
|
||
| return errorChnl; | ||
| return errorChannel; |
There was a problem hiding this comment.
please don't put code to header files
There was a problem hiding this comment.
Moved to corresponding .cpp files
| return errorChannel; | ||
| } | ||
|
|
||
| int getFd() { return m_errorNotificationConsumer->getFd(); } |
There was a problem hiding this comment.
dont put code in headers, move to cpp file
There was a problem hiding this comment.
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.
make function comments in doxygen format with brief line and then main explanation
common/errorlistener.h
Outdated
| #include "dbconnector.h" | ||
|
|
||
| // Error notifications of interest to the error listener | ||
| typedef enum |
There was a problem hiding this comment.
typedef enum _error_notify_flags_t
|
|
||
| ErrorMap::SwssRC ErrorMap::getSwssRC(const std::string &swssRCStr) | ||
| { | ||
| for (auto &elem : m_swssStrToRC) |
There was a problem hiding this comment.
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.
used multiple times, actually you can introduce this error code and return it from map
There was a problem hiding this comment.
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.
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.
whyt this is vector and not actual map ?
There was a problem hiding this comment.
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.
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
qiluo-msft
left a comment
There was a problem hiding this comment.
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.
just curious why not have enum start from zero?
There was a problem hiding this comment.
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])