Skip to content

Commit 567191f

Browse files
authored
[sairedis] Add knob to disable recording statistics API calls (sonic-net#547)
1 parent e75a4d6 commit 567191f

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

lib/inc/sai_redis.h

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ extern volatile bool g_useTempView;
6565
extern volatile bool g_asicInitViewMode;
6666
extern volatile bool g_logrotate;
6767
extern volatile bool g_syncMode;
68+
extern volatile bool g_recordStats;
6869

6970
extern sai_service_method_table_t g_services;
7071
extern std::shared_ptr<swss::ProducerTable> g_asicState;

lib/inc/sairedis.h

+14
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,20 @@ typedef enum _sai_redis_switch_attr_t
111111
*/
112112
SAI_REDIS_SWITCH_ATTR_SYNC_MODE,
113113

114+
/**
115+
* @brief Record statistics counters API calls.
116+
*
117+
* Get statistic counters can be queried periodically and can produce a lot
118+
* of logs in sairedis recording file. There are no OIDs retrieved in those
119+
* APIs, so user can disable recording statistics calls by setting this
120+
* attribute to false.
121+
*
122+
* @type bool
123+
* @flags CREATE_AND_SET
124+
* @default true
125+
*/
126+
SAI_REDIS_SWITCH_ATTR_RECORD_STATS,
127+
114128
} sai_redis_switch_attr_t;
115129

116130
#endif // __SAIREDIS__

lib/src/sai_redis_generic_stats.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "sai_redis.h"
22
#include "meta/sai_serialize.h"
33

4+
volatile bool g_recordStats = true;
5+
46
/*
57
* Max number of counters used in 1 api call
68
*/
@@ -268,7 +270,7 @@ sai_status_t internal_redis_generic_get_stats(
268270

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

271-
if (g_record)
273+
if (g_record && g_recordStats)
272274
{
273275
recordLine("m|" + key + "|" + joinFieldValues(entry));
274276
}
@@ -313,7 +315,7 @@ sai_status_t internal_redis_generic_get_stats(
313315
counter_list,
314316
kco);
315317

316-
if (g_record)
318+
if (g_record && g_recordStats)
317319
{
318320
const auto &str_status = kfvKey(kco);
319321
const auto &values = kfvFieldsValues(kco);
@@ -331,7 +333,7 @@ sai_status_t internal_redis_generic_get_stats(
331333
break;
332334
}
333335

334-
if (g_record)
336+
if (g_record && g_recordStats)
335337
{
336338
recordLine("M|SAI_STATUS_FAILURE");
337339
}
@@ -402,7 +404,7 @@ sai_status_t internal_redis_generic_clear_stats(
402404

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

405-
if (g_record)
407+
if (g_record && g_recordStats)
406408
{
407409
recordLine("m|" + key + "|" + joinFieldValues(fvTuples));
408410
}
@@ -433,7 +435,7 @@ sai_status_t internal_redis_generic_clear_stats(
433435
continue;
434436
}
435437

436-
if (g_record)
438+
if (g_record && g_recordStats)
437439
{
438440
const auto &respFvTuples = kfvFieldsValues(kco);
439441

@@ -455,7 +457,7 @@ sai_status_t internal_redis_generic_clear_stats(
455457
break;
456458
}
457459

458-
if (g_record)
460+
if (g_record && g_recordStats)
459461
{
460462
recordLine("M|SAI_STATUS_FAILURE");
461463
}

lib/src/sai_redis_switch.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ sai_status_t redis_set_switch_attribute(
268268
g_useTempView = attr->value.booldata;
269269
return SAI_STATUS_SUCCESS;
270270

271+
case SAI_REDIS_SWITCH_ATTR_RECORD_STATS:
272+
g_recordStats = attr->value.booldata;
273+
return SAI_STATUS_SUCCESS;
274+
271275
case SAI_REDIS_SWITCH_ATTR_SYNC_MODE:
272276

273277
g_syncMode = attr->value.booldata;

0 commit comments

Comments
 (0)