Populate CHASSIS_APP_DB when flex counters are read#1378
Populate CHASSIS_APP_DB when flex counters are read#1378viveksrao-arista wants to merge 6 commits intosonic-net:masterfrom
Conversation
When flex counters are read, if the counter is for a VOQ, populate chassis app db.
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.
please remove all global variables, all connectsion for db should come from parametrs to the class not had coded
syncd/FlexCounter.cpp
Outdated
| 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.
no api should be uses, VendorCalss shoud be used
There was a problem hiding this comment.
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?
syncd/FlexCounter.cpp
Outdated
| } | ||
| } | ||
|
|
||
| void addVoqEntryToChassisAppDb(_In_ const sai_object_id_t rid, |
There was a problem hiding this comment.
first parameter should be also in separate line
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.
{ to new line, plese forllow code quality
| 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.
add empty line before each if and after each }
| template <typename StatType> | ||
| class CounterContext : public BaseCounterContext |
There was a problem hiding this comment.
this should be in separate file 1 class per one file cpp
There was a problem hiding this comment.
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.
why there is space after ( ? remove
There was a problem hiding this comment.
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.
please keep same style as rest of the file
syncd/FlexCounter.cpp
Outdated
|
|
||
| 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.
do not use gloal apis ! Vendor class should be used!
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.
Why? I need a pointer and not a reference to an object here.
…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.
you are changing output variable, yo ushould use _ Out _, or better make function as return std::string instead of modyfying input parameter
| 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.
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.
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.
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.
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.
all databases names are hardcoded, they should be obrained from defines or config header
…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.