-
-
Notifications
You must be signed in to change notification settings - Fork 109
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
Refactor exporter creation with clap v4 #292
Refactor exporter creation with clap v4 #292
Conversation
e9fb2d4
to
5625266
Compare
I've added a little test and fixed a bug thanks to it. This PR is ready! |
Note that using the |
5625266
to
35289b1
Compare
rebased on dev :) |
3ac4515
to
84d2cec
Compare
01b3def
to
01050fa
Compare
729afe9
to
7a4f276
Compare
The remaining failure is caused by |
It does work since recently. Compiling only a few features should work as well. Having a look at the tests now. |
Compiling works but my tests require the warpten exporter :) edit: I've modified the tests to depend on the enabled features, it should be OK |
7a4f276
to
59c84ef
Compare
Current error is this job https://github.com/hubblo-org/ansible-scaphandre/blob/master/prometheus_in_docker_test.yml --port and --suffix seems to have become mandatory now, from the scaphandre container that failed:
I guess there is something to add to the prometheus ExporterArgs struct to make them non mandatory and add a default ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this work.
That's a huge PR though, as it touches almost all the codebase.
We'll have to write some more tests for the different exporters and validate them prior merging.
all green 🎉 I guess we just have to squash the last commits with an interactive reset |
warp10 exporter code seems to suffered a bit from the refacto, working on it |
😢 all those commits 😅 |
This PR mainly removes code. It's a refactoring of how exporters are created.
Instead of using
Arg::new
and passing aVec<clap::Args>
around, one can simply define a struct with all the options and letclap
do the work for us, thanks to thederive
macro. This creates a cleaner separation between the exporters and the magagement of the CLI. This will be useful for #50 and #145.Command-line arguments handling
Before
declaration:
usage:
After
declaration:
usage:
The documentation of the ExporterArgs structs is both for clap and for us. It shows up nicely in the IDE.
It's also easier to use this way.
Exporter initialization from CLI
Before:
After:
The code is now deduplicated, and it's easier to add a new exporter or sensor to Scaphandre.
Exporter initialization without CLI (new)
The exporters can now be created without a command-line interface, by creating the
ExporterArgs
struct.The new function
get_default_sensor
allows to get the RAPL sensor on Linux, with default params, and the MSR sensor on Windows.All exporters are used in the same way (there were some disparities before):
::new(sensor, args)
.run()
This makes good progress towards #50.
Summary of the advantages
without any code in Scaphandre doing the check!
new()
instead of when it runs.Bonus:
new
). For example, we don't need to recreate a warp10Client
on every iteration I think (correct me if I'm wrong). It's now created innew
.TODO
I'd like to add more integration tests before marking this as ready.done :)