testing/fake/gnmi: use Path.Elem instead of deprecated Path.Element#244
Open
timehacker wants to merge 2 commits into
Open
testing/fake/gnmi: use Path.Elem instead of deprecated Path.Element#244timehacker wants to merge 2 commits into
timehacker wants to merge 2 commits into
Conversation
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.
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
valToResp()in the fake gNMI server builds subscription responses with&gpb.Path{Element: val.Path}— the deprecated[]stringfield that was superseded byPath.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[]stringpath representation from the fake proto config into[]*PathElem, correctly extracting key–value pairs from bracketed decorators:Both the
DeleteandUpdatebranches ofvalToResp()are updated to usePath.Elemvia 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 fromvalToResp()populatePath.Elemand leave the deprecatedPath.Elementempty.cumulus-linux.pb.txt: a Cumulus Linux 5.x simulation config for thefake_servercommand (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.