Skip to content

Commit

Permalink
[sairedis] Add knob to disable recording statistics API calls (#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored Dec 16, 2019
1 parent e75a4d6 commit 567191f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/inc/sai_redis.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ extern volatile bool g_useTempView;
extern volatile bool g_asicInitViewMode;
extern volatile bool g_logrotate;
extern volatile bool g_syncMode;
extern volatile bool g_recordStats;

extern sai_service_method_table_t g_services;
extern std::shared_ptr<swss::ProducerTable> g_asicState;
Expand Down
14 changes: 14 additions & 0 deletions lib/inc/sairedis.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ typedef enum _sai_redis_switch_attr_t
*/
SAI_REDIS_SWITCH_ATTR_SYNC_MODE,

/**
* @brief Record statistics counters API calls.
*
* Get statistic counters can be queried periodically and can produce a lot
* of logs in sairedis recording file. There are no OIDs retrieved in those
* APIs, so user can disable recording statistics calls by setting this
* attribute to false.
*
* @type bool
* @flags CREATE_AND_SET
* @default true
*/
SAI_REDIS_SWITCH_ATTR_RECORD_STATS,

} sai_redis_switch_attr_t;

#endif // __SAIREDIS__
14 changes: 8 additions & 6 deletions lib/src/sai_redis_generic_stats.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "sai_redis.h"
#include "meta/sai_serialize.h"

volatile bool g_recordStats = true;

/*
* Max number of counters used in 1 api call
*/
Expand Down Expand Up @@ -268,7 +270,7 @@ sai_status_t internal_redis_generic_get_stats(

SWSS_LOG_DEBUG("generic get stats key: %s, fields: %lu", key.c_str(), entry.size());

if (g_record)
if (g_record && g_recordStats)
{
recordLine("m|" + key + "|" + joinFieldValues(entry));
}
Expand Down Expand Up @@ -313,7 +315,7 @@ sai_status_t internal_redis_generic_get_stats(
counter_list,
kco);

if (g_record)
if (g_record && g_recordStats)
{
const auto &str_status = kfvKey(kco);
const auto &values = kfvFieldsValues(kco);
Expand All @@ -331,7 +333,7 @@ sai_status_t internal_redis_generic_get_stats(
break;
}

if (g_record)
if (g_record && g_recordStats)
{
recordLine("M|SAI_STATUS_FAILURE");
}
Expand Down Expand Up @@ -402,7 +404,7 @@ sai_status_t internal_redis_generic_clear_stats(

SWSS_LOG_DEBUG("generic clear stats key: %s, fields: %lu", key.c_str(), fvTuples.size());

if (g_record)
if (g_record && g_recordStats)
{
recordLine("m|" + key + "|" + joinFieldValues(fvTuples));
}
Expand Down Expand Up @@ -433,7 +435,7 @@ sai_status_t internal_redis_generic_clear_stats(
continue;
}

if (g_record)
if (g_record && g_recordStats)
{
const auto &respFvTuples = kfvFieldsValues(kco);

Expand All @@ -455,7 +457,7 @@ sai_status_t internal_redis_generic_clear_stats(
break;
}

if (g_record)
if (g_record && g_recordStats)
{
recordLine("M|SAI_STATUS_FAILURE");
}
Expand Down
4 changes: 4 additions & 0 deletions lib/src/sai_redis_switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ sai_status_t redis_set_switch_attribute(
g_useTempView = attr->value.booldata;
return SAI_STATUS_SUCCESS;

case SAI_REDIS_SWITCH_ATTR_RECORD_STATS:
g_recordStats = attr->value.booldata;
return SAI_STATUS_SUCCESS;

case SAI_REDIS_SWITCH_ATTR_SYNC_MODE:

g_syncMode = attr->value.booldata;
Expand Down

0 comments on commit 567191f

Please sign in to comment.