Skip to content
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

Conversation

viveksrao-arista
Copy link

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.

When flex counters are read, if the counter is for a VOQ, populate chassis app db.
Copy link
Collaborator

@kcudnik kcudnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix coments

Comment on lines 34 to 40
// --> 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

Copy link
Collaborator

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -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;
Copy link
Collaborator

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

Copy link
Author

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?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use VendorSai class

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -511,8 +519,72 @@ class CounterContext : public BaseCounterContext
}
}

void addVoqEntryToChassisAppDb(_In_ const sai_object_id_t rid,
Copy link
Collaborator

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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 ) {
Copy link
Collaborator

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines +549 to +553
if (!iface)
{
SWSS_LOG_ERROR("Cannot query port name for queue. rid 0x%" PRIx64 "vid 0x%" PRIx64, rid, vid);
return;
}
Copy link
Collaborator

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 }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 374 to 375
template <typename StatType>
class CounterContext : public BaseCounterContext
Copy link
Collaborator

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

Copy link
Author

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.

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."
Copy link
Collaborator

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

Copy link
Author

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.

Copy link
Collaborator

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -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);
Copy link
Collaborator

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!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{
swss::DBConnector appDb("CHASSIS_APP_DB", 0, true);
swss::RedisPipeline appDbPipeline(&appDb);
appDbCountersTable = new swss::Table(&appDbPipeline, "COUNTERS", true);
Copy link
Collaborator

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 !

Copy link
Author

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use shared_ptr

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

viveksrao-arista and others added 2 commits June 1, 2024 16:21
…es. Use shared_ptr instead of using new operator. Address code formatting comments
}
}
};

void FlexCounter::getCfgSwitchType(
_In_ std::string &switch_type)
Copy link
Collaborator

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines +1109 to +1111
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());
Copy link
Collaborator

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
try
{
if (!m_cfgDeviceMetaDataTable->hget("localhost", "switch_type", switch_type))
Copy link
Collaborator

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

Copy link
Author

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.

Comment on lines +1133 to +1144
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);
}

Copy link
Collaborator

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

Copy link
Author

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
@vivekverma-arista vivekverma-arista deleted the master-populate-chassis-app-db-on-flexc branch August 29, 2024 08:17
@vivekverma-arista
Copy link

We will not be changing sonic-sairedis as per the new design, therefore closing this pull request.

Updated HLD: #1587

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants