Skip to content

Skip Redis client init for DBs not in database_config.json#683

Open
yijingyan2 wants to merge 3 commits into
sonic-net:masterfrom
yijingyan2:eni-map
Open

Skip Redis client init for DBs not in database_config.json#683
yijingyan2 wants to merge 3 commits into
sonic-net:masterfrom
yijingyan2:eni-map

Conversation

@yijingyan2
Copy link
Copy Markdown
Contributor

Why I did it

initRedisDbClients() and useRedisTcpClient() iterate over every entry in the spb.Target_value proto enum and call sdcfg.GetDbSock / sdcfg.GetDbTcpAddr for each one. When a Target enum value corresponds to a DB that is not present in the device's database_config.json (e.g. DPU_COUNTERS_DB on a non-smartswitch / non-DPU platform), the underlying SonicDBConfig::getDbInfo call logs an ERR-level message to syslog:

ERR gnmi#telemetry: :- getDbInfo: Failed to find DPU_COUNTERS_DB database in : key
ERR gnmi#dialout_client_cli: :- getDbInfo: Failed to find DPU_COUNTERS_DB database in : key

This was introduced as a side-effect of adding DPU_COUNTERS_DB = 18 to the Target enum. Since DPU_COUNTERS_DB is only configured on smartswitch / DPU platforms, every other platform now emits these benign ERR logs every time gnmi / dialout_client_cli starts up.

How I did it

  • Added a helper configuredDbSet(dbNamespace) that returns the set of DB names actually present in database_config.json for the given namespace.
  • In both useRedisTcpClient() (TCP path) and initRedisDbClients() (UNIX socket path), look up the configured DB set before iterating spb.Target_value. If a Target enum entry isn't in the configured set, skip it with a V(2) info log instead of calling sdcfg.GetDbSock / sdcfg.GetDbTcpAddr and triggering the ERR.
  • If GetDbList itself fails or returns empty, the helper returns nil and behaviour falls back to the original "try them all" path, so this is a strictly additive guard.

How to verify it

with this change, the test passed https://elastictest.org/scheduler/testplan/6a0ff4fe5ec6b5a1f3a20c7a?searchTestCase=rota&testcase=telemetry%2Ftest_telemetry_cert_rotation.py&type=console

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111

Description for the changelog

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

Signed-off-by: Yijing Yan <yijingyan@microsoft.com>
Copilot AI review requested due to automatic review settings May 22, 2026 10:00
@mssonicbld
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces startup log noise in sonic-gnmi by avoiding Redis client initialization attempts for gNMI Target enum DBs that are not present in the platform’s database_config.json (e.g., DPU_COUNTERS_DB on non-DPU platforms). This fits into the sonic_data_client startup path by tightening how Redis clients are pre-created for DB-backed targets.

Changes:

  • Add a helper to compute the set of DB names present in database_config.json.
  • In both TCP and UNIX-socket Redis client init paths, skip targets not present in that configured set (with a V(2) log) rather than calling GetDbSock / GetDbTcpAddr and triggering ERR logs.

Comment on lines +583 to +585
// configuredDbSet returns the set of DB names defined in the device's
// SONiC database_config.json for the given namespace.
func configuredDbSet(dbNamespace string) map[string]struct{} {
Comment on lines +609 to +616
configured := configuredDbSet(dbNamespace)
for dbName, dbn := range spb.Target_value {
if dbName != "OTHERS" {
if configured != nil {
if _, ok := configured[dbName]; !ok {
log.V(2).Infof("Skipping %s in namespace %s: not configured on this platform", dbName, dbNamespace)
continue
}
Copy link
Copy Markdown
Contributor

@theasianpianist theasianpianist left a comment

Choose a reason for hiding this comment

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

lgtm, suggest adding a new test case as per the copilot comment

Signed-off-by: Yijing Yan <yijingyan@microsoft.com>
@mssonicbld
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Yijing Yan <yijingyan@microsoft.com>
@mssonicbld
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants