-
Notifications
You must be signed in to change notification settings - Fork 293
Fix sai api loglevel #365
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
Fix sai api loglevel #365
Conversation
Add support for attribute capability query in lua script (sonic-net#362)
…added to m_settingChangeObservers
@gechiang Could you help test this PR? #Closed |
common/logger.cpp
Outdated
{ | ||
for (const auto& i : m_settingChangeObservers) | ||
{ | ||
if(selectableKeys.find(i.first) == selectableKeys.end()) |
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.first [](start = 39, length = 7)
i.first
is used multiple times. Could you give it a name to improve readability? #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/logger.cpp
Outdated
{ | ||
if(selectableKeys.find(i.first) == selectableKeys.end()) | ||
{ | ||
std::shared_ptr<ConsumerStateTable> table = std::make_shared<ConsumerStateTable>(&db, i.first); |
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.
std::shared_ptr [](start = 20, length = 35)
auto #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.
@shi-su, can you provide more detail description of the pr? what is the bug, how the bug is fixed. |
common/logger.cpp
Outdated
{ | ||
for (const auto& i : m_settingChangeObservers) | ||
{ | ||
if(selectableKeys.find(i.first) == selectableKeys.end()) |
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.
selectableKeys [](start = 19, length = 14)
You can insert
and check return value. No need to find beforehand. #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.
Since the vector selectables and the set selectableKeys in now combined as a map, inserting into the map requires a pointer to a consumerStateTable. In such a case, I think it might be better to find before creating the consumerStateTable.
common/logger.cpp
Outdated
{ | ||
std::shared_ptr<ConsumerStateTable> table = std::make_shared<ConsumerStateTable>(&db, i.first); | ||
selectableKeys.insert(i.first); | ||
selectables.push_back(table); |
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.
push_back [](start = 32, length = 9)
emplace_back? #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 now becomes inserting into a 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.
https://en.cppreference.com/w/cpp/container/map/emplace
In reply to: 456727155 [](ancestors = 456727155)
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.
Changed to emplace.
common/logger.cpp
Outdated
select.addSelectable(table.get()); | ||
} | ||
std::vector<std::shared_ptr<ConsumerStateTable>> selectables; | ||
std::set<std::string> selectableKeys; | ||
|
||
while(true) |
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.
while(true) [](start = 4, length = 11)
Add one blank after while
#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.
Blank added.
sure I will help test this out |
common/logger.cpp
Outdated
select.addSelectable(table.get()); | ||
} | ||
std::vector<std::shared_ptr<ConsumerStateTable>> selectables; | ||
std::set<std::string> selectableKeys; |
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.
Seems selectables
is only used to manage memory. You may use a map instead of vector + set. #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.
Fixed as prescribed.
common/logger.cpp
Outdated
Selectable *selectable = nullptr; | ||
|
||
int ret = select.select(&selectable); | ||
int ret = select.select(&selectable, 1000); |
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.
1000 [](start = 45, length = 4)
Add comment about constant unit. #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/logger.cpp
Outdated
Selectable *selectable = nullptr; | ||
|
||
int ret = select.select(&selectable); | ||
int ret = select.select(&selectable, 1000); |
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.
select [](start = 25, length = 6)
Add a unit test case to simulate the fixed bug. #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.
A unit test is added.
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 comments
|
||
if (ret == Select::ERROR) | ||
{ | ||
SWSS_LOG_NOTICE("%s select error %s", __PRETTY_FUNCTION__, strerror(errno)); | ||
continue; | ||
} | ||
|
||
if (ret == Select::TIMEOUT) | ||
{ | ||
continue; |
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 this is not intended to happen, please add log line
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.
Since a timeout is added to select selectables, the timeout is actually intended. I added an info level log to the timeout.
I have tested this change and find it resolved the issue I raised. I was able to set the levels of all the SAI component via the "-a" option as well as individual SAI component via the "-c" option. Fix looks good. |
common/logger.cpp
Outdated
{ | ||
for (const auto& i : m_settingChangeObservers) | ||
{ | ||
std::string dbName = i.first; |
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.
std::string [](start = 16, length = 11)
const std::string&
or const auto&
#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.
@shi-su, can you updat the submodule pointer on sonic-buildimage? |
Signed-off-by: Mihir Patel <[email protected]>
Why I did it
This PR contains the code changes to fix the SAI API log level issue "swssloglevel -l SAI_LOG_LEVEL_ERROR -s -c switch" or any SAI API component no longer works in Master branch #366
Why this issue happens
In the initialization of syncd, the main function first calls linkToDbNative function to initialize the log level for syncd. Then the log levels for SAI APIs are initialized using linkToDb. Since the settingThread of logger is set up by linkToDbNative function and the ConsumerStateTables are set up only in the initialization of the thread, the SAI API log levels in only added to m_settingChangeObservers, whereas the corresponding ConsumerStateTables are not created. Therefore, the SAI API log levels are not successfully initialized.
How I did it
Instead of creating ConsumerStateTables at the initialization of settingThread, I create ConsumerStateTables in the execution loop of the thread. Such a change fixes the issue by allowing to create the corresponding ConsumerStateTables when there are new items added to m_settingChangeObservers.
How to verify it
Verify all SAI API log levels are correctly initialized and can be modified in vs tests. A unit test is also added to simulate the scenario and verify the log levels can be properly handled.