Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gnmi) Refactor tag-only subs for complex keys (#11011) #11019

Merged
merged 1 commit into from
Jul 7, 2022

Conversation

bewing
Copy link
Contributor

@bewing bewing commented Apr 22, 2022

Required for all PRs:

resolves #11011

Re-work how to handle tag-only subscriptions to support more complex cases/lookups and improve concurrency

@bewing bewing force-pushed the tag_subscription branch 5 times, most recently from 6705723 to 1ae4057 Compare April 24, 2022 00:09
@bewing
Copy link
Contributor Author

bewing commented Apr 24, 2022

So at this point, I think I have the basic backwards compatibility done.

Will noodle on the right way to handle tag storing/application tomorrow.

@bewing bewing force-pushed the tag_subscription branch 14 times, most recently from ee96b8a to de73fe0 Compare April 25, 2022 21:39
@bewing
Copy link
Contributor Author

bewing commented Apr 25, 2022

Continuing to think on this. What I have currently works, but I'm unsure about the store

Current store behavior:

  • User specifies a subscription leaf, and one or more PathElems that MAY contain keys when sent by the gNMI server
  • While processing an Update message, if the full PathElem of an update matches one of the original requests, and there are PathElems matching the config that do contain keys, we have received a tag update, and need to store it.
  • We want to store this update so that when we receive another update that contains those path elems, IN ORDER, we apply the tag update as a tag to that update.
  • The tag store is a tree. The root node has a map[string][]*Node pointing at other nodes. As insert walks the tree:
    • if we have no keyed PathElems remaining, write our value and return
    • Otherwise, match the first PathElem name to the map to retreive a list of nodes
    • Use a simple map comparison function to compare our map[string]string elem.Key to each node in the retrieved list (please tell me a better way to handle this)
    • When found, remove that PathElem from our key list, jump to the next node and continue

To retrieve, we start at the root, and try to walk all our keys down as far as possible, picking up extra tags along the way.

I'm not great with Golang, or computer science in general, so please feel free to recommend better approaches, up to including there already being a generic solution out there we can just import.

Still need to add tests and docs. How should deprecation of tag_only be handled if we proceed with this change?

@bewing bewing force-pushed the tag_subscription branch 7 times, most recently from 5f92ecb to ab68050 Compare April 27, 2022 03:26
@bewing
Copy link
Contributor Author

bewing commented Apr 27, 2022

Tests written. Testing has found another existing bug in handling elements with multiple keys:
lab testing with the config

[[inputs.gnmi.subscription]]
  name = "bgp"
  origin = "openconfig"
  path = "/network-instances/network-instance/protocols/protocol/bgp/neighbors/neighbor/state/session-state"
  subscription_mode = "sample"
  sample_interval="10s"

returns metrics like
bgp,/network-instances/network-instance/protocols/protocol/name=BGP,host=localhost,identifier=BGP,name=default,neighbor_address=192.0.2.1,source=172.20.0.2
when testing against EOS (which uses identifier and name keys in the protocol path element.

I think the above is out of scope for this pull request, however, and wrote the new tests to reflect the current behavior

@bewing bewing marked this pull request as ready for review April 27, 2022 03:41
@bewing bewing changed the title WIP: feat(gnmi) Advanced tag subscription support feat(gnmi) Advanced tag subscription support Apr 27, 2022
@bewing bewing force-pushed the tag_subscription branch from ab68050 to 71e956c Compare April 27, 2022 03:44
@bewing bewing changed the title feat(gnmi) Advanced tag subscription support fix(gnmi) Advanced tag subscription support (#11011) Apr 27, 2022
@bewing bewing changed the title fix(gnmi) Advanced tag subscription support (#11011) fix(gnmi) Refactor tag-only subs for complex keys (#11011) Apr 27, 2022
@bewing bewing force-pushed the tag_subscription branch from 71e956c to 4fab120 Compare April 27, 2022 03:45
Copy link
Contributor

@powersj powersj left a comment

Choose a reason for hiding this comment

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

Before I dig into this a bit more, one of the guiding principles of Telegraf is ensuring we aren't breaking existing users. When I see the config format start to change it makes me wonder :) These two questions come to mind:

  1. Will existing configurations continue to work?
  2. Would this change the format of metrics that are generated?

@bewing
Copy link
Contributor Author

bewing commented Apr 27, 2022

Before I dig into this a bit more, one of the guiding principles of Telegraf is ensuring we aren't breaking existing users. When I see the config format start to change it makes me wonder :) These two questions come to mind:

  1. Will existing configurations continue to work?

Existing configurations are silently converted to the new configuration, with the caveat that old and new configuration methods cannot be used together: https://github.com/influxdata/telegraf/pull/11019/files#diff-8f015c9f22f0f8f4f8ee17b671e6d8f3ffa1871b86fc765a96e00d9d45ba0f39R507-R510

This code works for the majority use case (applying interface descriptions to other metrics). However, given the user config in #11007, I am going to have to think a bit more. An earlier attempt had a separate function to extract legacy tags -- I will may have to add it to this PR as well, but given the underlying bug we're looking to fix, I'm not sure those users were actually getting useable/correct data

I am unsure if there is a mechanism for informing the end-user of this / an existing deprecation policy for telegraf -- would appreciate any pointers here.

  1. Would this change the format of metrics that are generated?

I did not modify existing tests when adding this code, and they all still pass, so I do not believe so.

@powersj
Copy link
Contributor

powersj commented Jul 7, 2022

@bewing thanks for this - can you resolve the conflict and we can land this?

@bewing bewing force-pushed the tag_subscription branch from 4fab120 to 0e1f790 Compare July 7, 2022 18:20
@bewing
Copy link
Contributor Author

bewing commented Jul 7, 2022

Rebased and pushed. Looks like I might have some linting to do?

@powersj
Copy link
Contributor

powersj commented Jul 7, 2022

plugins/inputs/gnmi/README.md:1: missing required section 'Metrics'

I'm happy to ignore for now, but if you want to put up a PR or update this one with the metrics section filed out it would be nice at some point. That section just describes the layout of the metric collected.

@telegraf-tiger
Copy link
Contributor

telegraf-tiger bot commented Jul 7, 2022

@bewing
Copy link
Contributor Author

bewing commented Jul 7, 2022

plugins/inputs/gnmi/README.md:1: missing required section 'Metrics'

I'm happy to ignore for now, but if you want to put up a PR or update this one with the metrics section filed out it would be nice at some point. That section just describes the layout of the metric collected.

Will put in a separate PR, as it should be a separate commit anyway.

@powersj powersj merged commit f29f7b2 into influxdata:master Jul 7, 2022
@bewing bewing deleted the tag_subscription branch July 8, 2022 13:14
srebhan added a commit to srebhan/telegraf that referenced this pull request Dec 19, 2022
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.

inputs.gnmi tag_only should support arbitrary subscriptionKey
2 participants