gnmic icon indicating copy to clipboard operation
gnmic copied to clipboard

Add option to convert enum to numerical when possible

Open XioNoX opened this issue 8 months ago • 3 comments

Hi,

We use gNMIc in subscribe mode to expose network devices metrics to Prometheus. You can see our config in https://github.com/wikimedia/operations-puppet/blob/production/hieradata/common/profile/gnmi_telemetry.yaml

However as we're exposing that data for a timeseries DB, we need to do some transformations, especially some enums that we need to have as digits instead of strings. A good example is BGP session states :

  rename-bgp-session-state:
    event-strings:
      value-names: ["/network-instances/network-instance/protocols/protocol/bgp/neighbors/neighbor/state/session-state"]
      transforms:
        - replace: {apply-on: "value", old: "IDLE", new: "1"}
        - replace: {apply-on: "value", old: "CONNECT", new: "2"}
        - replace: {apply-on: "value", old: "ACTIVE", new: "3"}
        - replace: {apply-on: "value", old: "OPENSENT", new: "4"}
        - replace: {apply-on: "value", old: "OPENCONFIRM", new: "5"}
        - replace: {apply-on: "value", old: "ESTABLISHED", new: "6"}

The issue is that the YANG model doesn't seem to have a mapping from string to value. https://github.com/openconfig/public/blob/master/release/models/bgp/openconfig-bgp-neighbor.yang#L302

However some other models seems to have them, for example bfd-diagnostic-code does have value X https://github.com/openconfig/public/blob/master/release/models/bfd/openconfig-bfd.yang#L157

As we're using gNMIc for more and more metrics (BGP, BFD, OSPF, etc), I was wondering if it was possible to add a way to use the numerical values when present it YANG. For example a processor dedicated to it.

And I'm wondering what it would take to define them in YANG for all the missing enums.

Thanks

XioNoX avatar Mar 31 '25 12:03 XioNoX

Hi,

If the value statement is missing under an enum is it automatically assigned (sequentially) https://datatracker.ietf.org/doc/html/rfc7950#section-9.6.4.2

If a value is not specified, then one will be automatically assigned.
   If the "enum" substatement is the first one defined, the assigned
   value is zero (0); otherwise, the assigned value is one greater than
   the current highest enum value (i.e., the highest enum value,
   implicit or explicit, prior to the current "enum" substatement in the
   parent "type" statement).

Explicit value statements are really only needed if custom values are required by the author.

As for creating mappings based on YANG, this would require parsing YANG models at startup and generate mappings based on all the enums in the models. That means all YANG files should be available for gNMIc to read, proper file paths should be configured. Isn't easier to create the mappings manually ? It is cumbersome, but it's done once and the same mapping has to be done on the visualization side (value back to string).

karimra avatar Apr 01 '25 15:04 karimra

Thanks for your reply !

Isn't easier to create the mappings manually ? It is cumbersome, but it's done once and the same mapping has to be done on the visualization side (value back to string).

No strong feelings,my goal here was to raise a pain-point for discussion. Thanks for the clarification. If the "fix" is more of a problem than the initial problem then it's not worth doing :)

XioNoX avatar Apr 09 '25 11:04 XioNoX

@XioNoX I have exact same setup, I've written a template in grafana to define what each values mean.

lazyb0nes avatar Apr 13 '25 10:04 lazyb0nes