-
Notifications
You must be signed in to change notification settings - Fork 45
Add functionality to graph DHCP stats on each VLAN page and Prefix page in NAV #3633
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
base: master
Are you sure you want to change the base?
Conversation
This way, we can pass wildcard strings such as "*" and "{foo,bar}" to graphite
metric template functions and be assured that they won't be escaped to "_" and
"_foo_bar_".
Before, we only needed to translate from runtime data to Graphite paths, so we
only needed the metric_path_for_dhcp() function. But now we'll need to start
translating from Graphite paths back to runtime data because the Graphite paths
contains the <first_ip> and <last_ip> segments used to decide which
VLANs/Prefixes a stat belongs to. Further, the Graphite paths also contains the
<server_name>, <allocation_type>, <ip_version>, <group_name>, and
<group_name_source> segments used to decide which graph on that specific
VLAN/Prefix page a stat should be displayed in.
Thus this commit adds a new class, DhcpPath, which basically has the purpose of
containing runtime path data and translating between path data sourced from
external sources (DHCP server APIs), runtime data, and Graphite paths, like so:
external path data ---> runtime path data <---> Graphite path
(DHCP server) (DhcpPath) (Graphite)
More specifically, use the class to do the following translations:
external path data ---> runtime path data ---> Graphite path
(Kea API) (DhcpPath) (Graphite)
Thus delegating validity checks and transformations.
Also, this commit renames some variables and comments to stay consistent
with the variables and comments used in DhcpPath.
Because we didn't previously test for the case when a Kea DHCP configuration file *does* contains a pool with a user-context object but that *does not* contain the "group" key wanted by the kea_dhcp.py client.
3439a9d to
90682bc
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3633 +/- ##
==========================================
+ Coverage 62.67% 62.74% +0.06%
==========================================
Files 611 612 +1
Lines 45102 45290 +188
Branches 43 43
==========================================
+ Hits 28268 28416 +148
- Misses 16824 16864 +40
Partials 10 10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This is part of simplifying the terminology used in the up-and-coming documentation and configuration files for dhcpstats and its frontend; terminology in the implementation and terminology used in the (user) interface termonology should diverge as little as possible. The documentation has more or less used the terms 'endpoint' and '(DHCP) server' interchangeably. We fix this so that only the term '(DHCP) server' is used. Where the user-facing interfaces are affected, backwards compability is added to avoid the most dramatical errors.
We really never need get-config-hash to work; it's just used to spare one round-trip. Catching dhcpstats.errors.CommunicationError means we now should be gracefully handling any API errors and any HTTP errors; a superset of what we did earlier.
This type represents a graphite metric; a type which is useful in other modules than just dhcpstats/kea_dhcp.py.
This fix allows HTTPS schemes with one or more uppercased letters to also be detected.
This is mostly so that we're able to support HTTP Basic Authentication in the kea_dhcp.py client where the password is the empty string.
These can be used instead of string interpolations sprinkled among other business code, which quickly becomes unwieldy when you want a little bit more advanced Graphite renders.
The function fetch_graph_urls_for_prefixes takes a set of prefixes (e.g. obtained from a models.manage.Prefix or from a models.manage.Vlan) and returns one url per DHCP graph from Graphite related to one or more of the prefixes. Each url returns a JSON with graph data.
..a VLAN/Prefix page has DHCP graphs displayed if NAV has collected some recent enough DHCP stats for IP addresses that intersect that VLAN/Prefix.
90682bc to
db85e5a
Compare
db85e5a to
50cb13a
Compare
|




Scope and purpose
Fixes #2373. Another PR intends to add documentation and release notes.
This pull request
Adds DHCP stats graphs to VLAN and Prefix pages in NAV where recent-enough stats for that VLAN/Prefix are found in the Carbon/Graphite database:

Changes how paths are stored under "nav.dhcp" in the Carbon/Graphite database:
<pool-name>to<group-name>in all pieces of documentation.range, apool, and asubnet, because different DHCP servers have different semantics and data-coarseness. Arangeis the set of all IPs between afirst-ipand alast-ip, whereas apoolis an arbitrary set of IPs greater thanfirst-ipand less thanlast-ip. Further, all IPs in arangeand apoolare available for lease, whereas this is not necessarily the case for asubnet.{special_groups,custom_groups}to differentiate between group-names that NAV must create and manage itself and group-names that NAV is able to infer from some piece of externally sourced information such as DHCP server config files.Expects
[server_<server-name>]sections indhcpstats.confinstead of[endpoint_<server-name>]for consistencyChanges the name of the
user_context_poolname_keyoption indhcpstats.conftouser_context_groupname_key.Contributor Checklist
Every pull request should have this checklist filled out, no matter how small it is.
More information about contributing to NAV can be found in the
Hacker's guide to NAV.
Added/changed documentationSee independent PR<major>.<minor>.x). For a new feature or other additions, it should be based onmaster.Testing It For Yourself
You can run this script to fill the prefixes
192.0.2.0/24and198.51.100.0/24with DHCP stats (you might need to installsocatandgawk, and you might need to change127.0.0.1to the address of your Carbon/Graphite database):Here's a screencast:
screencast.mp4
At
2:00in the video, notice that the graph labelledDHCP ranges in 'guest' on server 'kea-trd'has stats from ranges in both192.0.2.0/24and198.51.100.0/24despite vlan 20 only containing192.0.2.0/24. This is because whenever a group (here:'guest' on server 'kea-trd') has at least one range/pool/subnet overlapping with the VLAN/Prefix, the whole group will be displayed on that VLAN/Prefix's page.