Skip to content

Add an example script to push isc-dhcp stats to graphite#2383

Merged
hmpf merged 12 commits intoUninett:masterfrom
hmpf:dhcp-metrics
Apr 8, 2022
Merged

Add an example script to push isc-dhcp stats to graphite#2383
hmpf merged 12 commits intoUninett:masterfrom
hmpf:dhcp-metrics

Conversation

@hmpf
Copy link
Copy Markdown
Contributor

@hmpf hmpf commented Mar 30, 2022

Closes #2371

- Include a todo for a script to push dhcpd-metrics to graphite
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2022

Codecov Report

Merging #2383 (3f89988) into master (7363b53) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #2383   +/-   ##
=======================================
  Coverage   52.55%   52.55%           
=======================================
  Files         552      552           
  Lines       40152    40152           
=======================================
  Hits        21100    21100           
  Misses      19052    19052           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7363b53...3f89988. Read the comment docs.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 30, 2022

Test results

     12 files       12 suites   12m 11s ⏱️
3 075 tests 2 979 ✔️   96 💤 0
8 700 runs  8 412 ✔️ 288 💤 0

Results for commit 3f89988.

♻️ This comment has been updated with latest results.

@hmpf hmpf marked this pull request as ready for review April 4, 2022 09:18
@hmpf hmpf requested a review from lunkwill42 April 4, 2022 10:52
Copy link
Copy Markdown
Member

@lunkwill42 lunkwill42 left a comment

Choose a reason for hiding this comment

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

Looks really nice and clean, though I can't get it to work.

And of course, I love to harp on about the Stepdown rule:

We want the code to read like a top-down narrative. We want every function to
be followed by those at the next level of abstraction so that we can read the
program, descending one level of abstraction at a time as we read down the list
of functions. I call this The Stepdown Rule.

To say this differently, we want to be able to read the program as though it
were a set of TO paragraphs, each of which is describing the current level of
abstraction and referencing subsequent TO paragraphs at the next level down.

To include the setups and teardowns, we include setups, then we include the
test page content, and then we include the teardowns.

To include the setups, we include the suite setup if this is a suite, then we
include the regular setup.

To include the suite setup, we search the parent hierarchy for the
"SuiteSetUp" page and add an include statement with the path of that page.

To search the parent...

It turns out to be very difficult for programmers to learn to follow this rule
and write functions that stay at a single level of abstraction. But learning
this trick is also very important. It is the key to keeping functions short and
making sure they do "one thing." Making the code read like a top-down set of
TO paragraphs is an effective technique for keeping the abstraction level
consistent.

I know it's not easy to use it consistently in a non-compiled language like Python, but I like to follow it whenever I can.

@hmpf
Copy link
Copy Markdown
Contributor Author

hmpf commented Apr 8, 2022

I'd squash these on merge.

@hmpf hmpf requested a review from lunkwill42 April 8, 2022 10:21
@hmpf
Copy link
Copy Markdown
Contributor Author

hmpf commented Apr 8, 2022

I'd like to unit-test the easily unit-testable bits (skipping exec_dhcpd_pools and send_to_graphite) but don't know where to put the tests.

@lunkwill42
Copy link
Copy Markdown
Member

I'd like to unit-test the easily unit-testable bits (skipping exec_dhcpd_pools and send_to_graphite) but don't know where to put the tests.

Yeah, the test suite isn't really rigged to test contrib scripts. But you could probably jig a test to have the contrib/scripts directory in its sys.path...

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 8, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Copy Markdown
Member

@lunkwill42 lunkwill42 left a comment

Choose a reason for hiding this comment

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

Still not 100% happy about the stepdown order, but it does the trick :-D

If you come up with a feasible testing strategy, a PR for that would be welcome, of course!

DEFAULT_CMD_PATH = pathlib.Path("/usr/bin/dhcpd-pools")
DEFAULT_PROTOCOL = 2 # Python 3: 3, Python 3.8+: 4
DEFAULT_PORT = "2004"
DEFAULT_PROTOCOL = 'text' # MB doesn't trust pickle so we go with text
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

😆

@hmpf hmpf merged commit 83a7835 into Uninett:master Apr 8, 2022
@hmpf hmpf deleted the dhcp-metrics branch April 8, 2022 11:03
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.

Write a contrib script that serves as a proof-of-concept of such an integration with the ISC DHCP server.

2 participants