-
Notifications
You must be signed in to change notification settings - Fork 274
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
Populate CHASSIS_APP_DB when flex counters are read #1378
Populate CHASSIS_APP_DB when flex counters are read #1378
Conversation
When flex counters are read, if the counter is for a VOQ, populate chassis 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.
fix coments
syncd/FlexCounter.cpp
Outdated
// --> Needed for agg voq stats | ||
static sai_queue_api_t *sai_queue_api = NULL; | ||
static swss::DBConnector configDb("CONFIG_DB", 0); | ||
static swss::Table cfgDeviceMetaDataTable(&configDb, CFG_DEVICE_METADATA_TABLE_NAME); | ||
static swss::DBConnector counterDb("COUNTERS_DB", 0); | ||
// <-- agg voq stats 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.
please remove all global variables, all connectsion for db should come from parametrs to the class not had coded
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.
syncd/FlexCounter.cpp
Outdated
@@ -31,6 +31,13 @@ static const std::string ATTR_TYPE_PG = "Priority Group Attribute"; | |||
static const std::string ATTR_TYPE_MACSEC_SA = "MACSEC SA Attribute"; | |||
static const std::string ATTR_TYPE_ACL_COUNTER = "ACL Counter Attribute"; | |||
|
|||
// --> Needed for agg voq stats | |||
static sai_queue_api_t *sai_queue_api = NULL; |
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 api should be uses, VendorCalss shoud 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.
Sorry, I do not understand. I need a handle sai_queue_api
so that I can query queue stats like this status = sai_queue_api->get_queue_attribute(rid, 1, &attr);
. I am not aware of an alternative to this. What is VendorClass? How to use it? Can you point me to an example?
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 VendorSai 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.
Done.
syncd/FlexCounter.cpp
Outdated
@@ -511,8 +519,72 @@ class CounterContext : public BaseCounterContext | |||
} | |||
} | |||
|
|||
void addVoqEntryToChassisAppDb(_In_ const sai_object_id_t rid, |
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.
first parameter should be also in separate 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.
Done.
syncd/FlexCounter.cpp
Outdated
void addVoqEntryToChassisAppDb(_In_ const sai_object_id_t rid, | ||
_In_ const sai_object_id_t vid, | ||
_In_ std::vector<swss::FieldValueTuple> &counterValues, | ||
_Out_ swss::Table *appDbCountersTable ) { |
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.
{ to new line, plese forllow code quality
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.
if (!iface) | ||
{ | ||
SWSS_LOG_ERROR("Cannot query port name for queue. rid 0x%" PRIx64 "vid 0x%" PRIx64, rid, vid); | ||
return; | ||
} |
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 empty line before each if and after each }
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
template <typename StatType> | ||
class CounterContext : public BaseCounterContext |
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.
this should be in separate file 1 class per one file 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.
This code is not added by me.
syncd/FlexCounter.cpp
Outdated
attr.id = SAI_QUEUE_ATTR_INDEX; | ||
status = sai_queue_api->get_queue_attribute(rid, 1, &attr); | ||
if (status != SAI_STATUS_SUCCESS ) { | ||
SWSS_LOG_ERROR( "sai get_queue_attribute failed for SAI_QUEUE_ATTR_INDEX." |
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 there is space after ( ? remove
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.
Well that's string concatenation and is used to keep the line within a reasonable length. Helps when editing code in terminals and editors that do not support line length of say for eg more than 85 characters or so. Good practice to make your code readable across various editors and terminals. Linux mandates a line length of 85 chars. Not sure what Sonic enforces. Good to follow none the less.
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 keep same style as rest of the 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.
Done
syncd/FlexCounter.cpp
Outdated
@@ -1014,6 +1097,14 @@ FlexCounter::FlexCounter( | |||
m_enable = false; | |||
m_isDiscarded = false; | |||
|
|||
if (!sai_queue_api) { | |||
sai_status_t status; | |||
status = sai_api_query(SAI_API_QUEUE, (void **)&sai_queue_api); |
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.
do not use gloal apis ! Vendor class should 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.
Done
syncd/FlexCounter.cpp
Outdated
{ | ||
swss::DBConnector appDb("CHASSIS_APP_DB", 0, true); | ||
swss::RedisPipeline appDbPipeline(&appDb); | ||
appDbCountersTable = new swss::Table(&appDbPipeline, "COUNTERS", 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.
don't use new operator !
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? I need a pointer and not a reference to an object 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.
use shared_ptr
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
…es. Use shared_ptr instead of using new operator. Address code formatting comments
syncd/FlexCounter.cpp
Outdated
} | ||
} | ||
}; | ||
|
||
void FlexCounter::getCfgSwitchType( | ||
_In_ std::string &switch_type) |
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 are changing output variable, yo ushould use _ Out _, or better make function as return std::string instead of modyfying input parameter
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
if (switch_type != "voq" && switch_type != "fabric" && switch_type != "chassis-packet" && switch_type != "switch" && switch_type != "dpu") | ||
{ | ||
SWSS_LOG_ERROR("Invalid switch type %s configured", switch_type.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.
this seems really fishy here, why you need to check all those variables? this should be more unified?
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.
Copying this function from https://github.com/sonic-net/sonic-swss/blob/master/orchagent/main.cpp#L160
{ | ||
try | ||
{ | ||
if (!m_cfgDeviceMetaDataTable->hget("localhost", "switch_type", switch_type)) |
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.
is this connecting for localhost database to get this ? this seems a hacky way to do that, also all variables are hard coded, those should be defined somewhere with comments
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.
Pretty much every access to database is hardcoded in FlexCounter.cpp. We probably should change all of them in a separate pull request to not mix things up.
m_configDb = std::make_shared<swss::DBConnector>("CONFIG_DB", 0); | ||
m_cfgDeviceMetaDataTable = std::make_shared<swss::Table>(m_configDb.get(), CFG_DEVICE_METADATA_TABLE_NAME); | ||
|
||
getCfgSwitchType(m_switchType); | ||
|
||
if (m_switchType == "voq") | ||
{ | ||
m_appDb = std::make_shared<swss::DBConnector>("CHASSIS_APP_DB", 0, true); | ||
m_appDbPipeline = std::make_shared<swss::RedisPipeline>(m_appDb.get()); | ||
m_appDbCountersTable = std::make_shared<swss::Table>(m_appDbPipeline.get(), "COUNTERS", 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.
all databases names are hardcoded, they should be obrained from defines or config header
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.
Same as above
…es. Use shared_ptr instead of using new operator. Address code formatting comments
We will not be changing sonic-sairedis as per the new design, therefore closing this pull request. Updated HLD: #1587 |
When flex counters are read, if the counter is for a VOQ, populate chassis app db for this VOQ so that on the supervisor it can be used to calculate aggregate stats across all VOQs for a port.