Skip to content

testing/fake/gnmi: use Path.Elem instead of deprecated Path.Element#244

Open
timehacker wants to merge 2 commits into
openconfig:masterfrom
timehacker:fix/fake-server-path-elem
Open

testing/fake/gnmi: use Path.Elem instead of deprecated Path.Element#244
timehacker wants to merge 2 commits into
openconfig:masterfrom
timehacker:fix/fake-server-path-elem

Conversation

@timehacker

Copy link
Copy Markdown

Problem

valToResp() in the fake gNMI server builds subscription responses with &gpb.Path{Element: val.Path} — the deprecated []string field that was superseded by Path.Elem ([]*PathElem) in gNMI v0.4 (2018).

Modern consumers that call only p.GetElem() receive an empty path for every update. In practice this means every metric value from a fake-server subscription arrives under the key "/" rather than its real OpenConfig path (e.g. /interfaces/interface/state/counters/in-octets).

Fix

Add stringsToPathElems() which converts the []string path representation from the fake proto config into []*PathElem, correctly extracting key–value pairs from bracketed decorators:

"interface[name=swp1]" → PathElem{Name:"interface", Key:{"name":"swp1"}}

Both the Delete and Update branches of valToResp() are updated to use Path.Elem via this helper.

Also included

  • TestStringsToPathElems: unit tests for the new helper covering simple elements, single-key elements, multi-key elements, and empty-string filtering.
  • TestValToRespPathEncoding: asserts that responses from valToResp() populate Path.Elem and leave the deprecated Path.Element empty.
  • cumulus-linux.pb.txt: a Cumulus Linux 5.x simulation config for the fake_server command (interfaces swp1–swp4, temperature sensors, fans, PSU, QoS buffers) that serves as a realistic test fixture and demonstrates the fix with real-world OpenConfig paths.

Tested

Verified end-to-end: gnmic v0.44.1 subscribing to the patched fake server now sees full OpenConfig paths in subscription responses, enabling downstream consumers to produce correctly named metrics.

valToResp() was building gNMI SubscribeResponse messages with
&gpb.Path{Element: val.Path}, where Element is the []string field that
was deprecated in gNMI v0.4 (2018) in favour of Path.Elem
([]*PathElem).  Modern consumers — gnmic v0.44+, openconfig/gnmi
libraries, and VictoriaMetrics exporters — call p.GetElem() only and
silently ignore Element.  The result is that every subscription response
from the fake server carries an empty path, causing all metric values to
land under "/" rather than their real OpenConfig paths.

Add stringsToPathElems() which converts the []string path representation
from the fake proto config into []*PathElem, correctly extracting
key-value pairs from bracketed decorators such as
"interface[name=swp1]" → PathElem{Name:"interface", Key:{"name":"swp1"}}.
Both the Delete and Update branches of valToResp() are updated to use
Path.Elem via this helper.

Also add:
- TestStringsToPathElems: unit tests for the new helper covering simple
  elements, single-key elements, multi-key elements, and empty-string
  filtering.
- TestValToRespPathEncoding: integration-style test asserting that
  responses from valToResp() populate Path.Elem and leave the deprecated
  Path.Element empty.
- cumulus-linux.pb.txt: a Cumulus Linux 5.x simulation config for the
  fake_server command (interfaces swp1-swp4, temperature sensors, fans,
  PSU, QoS buffers) that serves as a realistic test fixture and
  demonstrates the fix with real-world OpenConfig paths.
@google-cla

google-cla Bot commented Jun 8, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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.

1 participant