openconfig / gnmic

gNMIc is a gNMI CLI client and collector
https://gnmic.openconfig.net
Apache License 2.0
192 stars 57 forks source link

Add conditions to all formatters/processors #155

Open smalenfant opened 1 year ago

smalenfant commented 1 year ago

It would be really useful to have the conditions available to all formatters. We receive multiple sensors and I don't want to apply formatters to all events.

One example here is group-by.

  group-by-lane:
    event-group-by:
      debug: true
      tags:
        - source
        - interface_name
        - lane_lane_number

This works fine for all events that contains a lane number.

{
  "name": "optics",
  "timestamp": 1687445610616000000,
  "tags": {
    "interface_name": "et-1/0/7",
    "lane_lane_number": "0",
    "source": "x.y.z",
    "subscription-name": "optics"
  },
...
{
  "name": "optics",
  "timestamp": 1687445610616000000,
  "tags": {
    "interface_name": "et-1/0/7",
    "lane_lane_number": "3",
    "source": "x.y.z",
    "subscription-name": "optics"
  },
...

But I couldn't group-by when the lane number was not present. If I would, it would merge all of those documents together. merge didn't work correctly because it uses the timestamp only, and not the tags to merge documents together. That created a single JSON document with information only from the last lane. Different issue.

{
  "name": "optics",
  "timestamp": 1687445610616000000,
  "tags": {
    "interface_name": "et-1/0/7",
    "source": "x.y.z",
    "subscription-name": "optics"
  },
  "values": {
    "module_temp_high_warning": 0
  }
}
{
  "name": "optics",
  "timestamp": 1687445610616000000,
  "tags": {
    "interface_name": "et-1/0/7",
    "source": "x.y.z",
    "subscription-name": "optics"
  },
  "values": {
    "module_temp_low_warning": 0
  }
}
karimra commented 1 year ago

I'm not sure I understand what you intend to do. If you want to group messages that don't have a lane tag (but have a source and interface name) just don't include the lane in the tag list. It should produce a list of messages each with a unique combination of (source, interface_name) with their values merged.

smalenfant commented 1 year ago

I'm trying to get full output from the router although it's down this morning. This issue is really about having "condition" around processors so they don't get executed. I provided an example only, but I would need to get this applied to different device type (for example, we have Juniper, Cisco, Nokia and Arista devices). Response varies depending on vendor. Now, we usually have this in different instance of gnmi, but if we would use gnmic with nats/kafka for example, they could be mixed together.

karimra commented 1 year ago

The reason some processors don't have a condition attribute is because their execution can be controlled using other attributes (like value-names, tag-names`, etc...) with regexes. I see that adding a condition to all processors gives a uniform way to control execution accros processors, will look into it.

I still want to understand what you are trying to achieve, there might be an easier way to get it done. I'm ok with discussing via chat or on a call if you don't want to put it out here.