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

Telemetry Rework #3701

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open

Telemetry Rework #3701

wants to merge 33 commits into from

Conversation

timwoj
Copy link
Contributor

@timwoj timwoj commented Apr 24, 2024

This PR represents all of the work to pull the telemetry code out of broker and into a module inside of Zeek itself. The major change here is usage of the prometheus-cpp library for all of the storage and coordination of families and instruments. It also moves to a setup where we provide a Prometheus Service Discovery endpoint for automatic configuration of all of the nodes in Prometheus, removing the internal aggregation of data onto the manager node for Prometheus to scrape.

@timwoj
Copy link
Contributor Author

timwoj commented Apr 25, 2024

The docs around telemetry need some rewriting to go with this PR.

Comment on lines +6 to +7
##! again. Specifically, to disable listening on port 9911, set
##! :zeek:see:`Telemetry::metrics_port` to `0/unknown` again.
Copy link
Contributor

@bbannier bbannier May 10, 2024

Choose a reason for hiding this comment

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

I am not a fan of coupling a specific port value 0/unknown to disabling metrics functionality.

With this patch users are able to query an endpoint for the actually used port which opens up the door to let the OS assign ports which could simplify configuration; typically port 0 is used for that, mirroring the behavior of bind.

It seems that the underlying endpoint impl can both parse addresses with port 0 as well as pass that through to the OS for automatic port assignment so IMO it would be unfortunate to completely close the door on even allowing that by this API choice.

Would you be open to instead introducing a dedicated flag for to toggle metrics functionality, e.g., --enable-metrics or --disable-metrics?

Copy link
Contributor

@bbannier bbannier May 10, 2024

Choose a reason for hiding this comment

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

An intermediate solution could be to sharpen the interpretation of "port 0" when parsing the config to only interpret 0/unknown (or maybe any port on an unknown protocol) as disabling,

if ( metrics_port->Port() != 0 )

With that it would be impossible to disable metrics via the ZEEK_METRICS_PORT env var though since it never contains a protocol, only a port number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that the underlying endpoint impl can both parse addresses with port 0 as well as pass that through to the OS for automatic port assignment so IMO it would be unfortunate to completely close the door on even allowing that by this API choice.

We don't notify the user in any way what port number is being used by the telemetry manager, since we expect them to set it themselves as part of the configuration. If CivetWeb picks its own port, the user won't know what that port is, nor will the services.json endpoint know what any of the ports are. I'm inclined to not allow it to be configured like that.

Would you be open to instead introducing a dedicated flag for to toggle metrics functionality, e.g., --enable-metrics or --disable-metrics?

How about a script-level setting that overrides any other ports you set? That would cover cluster mode.

With that it would be impossible to disable metrics via the ZEEK_METRICS_PORT env var though since it never contains a protocol, only a port number.

In standalone mode, not setting ZEEK_METRICS_PORT and not setting Telemetry::metrics_port already disables creating the Prometheus server.

Copy link
Member

Choose a reason for hiding this comment

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

Much of this is just moving things over from how they worked in Broker-land ... but I agree that we should revisit some of it. See my comment above in options.zeek about whether we even need the ZEEK_METRICS_PORT environment variable?

In terms of enabling, I agree that we shouldn't tie lots of functionality to the value of a port. But here it's really just whether there's a listening port for scraping or not — not the greater telemetry machinery. It makes sense to keep telemetry itself functional regardless of this value since there's also a telemetry log, plus the functionality is worthwhile just for the script layer too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ended up removing all of the environment variables, in favor of controlling everything from script-land instead.

Copy link
Member

@ckreibich ckreibich left a comment

Choose a reason for hiding this comment

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

Good stuff Tim! I really like how this shifts the code — it actually hasn't grown anywhere near as much as I suspected. I'm still not through all of this though, sigh — I have not yet reviewed the test cases, so I'll follow up on these.

My comments mainly flag things where I see an opportunity in this rework to simplify some things from the Broker era that may not hold any more.

I'll review the docs separately, but I noticed that it still mentions Broker stuff in a few places. We'll need to make a broader edit pass on those. It would also be helpful to put a brief recap of the basic concepts (families, instruments, etc) somewhere in the code, or perhaps the development section of the docs, since things like families or instruments are all mysterious if one doesn't know Prometheus.

NEWS Outdated Show resolved Hide resolved
ci/alpine/Dockerfile Show resolved Hide resolved
scripts/base/frameworks/cluster/main.zeek Show resolved Hide resolved
scripts/base/frameworks/telemetry/main.zeek Show resolved Hide resolved
src/telemetry/Manager.cc Outdated Show resolved Hide resolved
src/telemetry/Manager.cc Outdated Show resolved Hide resolved
src/telemetry/Manager.cc Outdated Show resolved Hide resolved
scripts/base/frameworks/telemetry/main.zeek Show resolved Hide resolved
src/telemetry/Manager.cc Show resolved Hide resolved
@timwoj timwoj requested a review from ckreibich May 13, 2024 22:24
@timwoj timwoj force-pushed the topic/timw/prometheus-cpp-3 branch 2 times, most recently from 516a228 to 43ac602 Compare May 16, 2024 19:54
Copy link
Member

@ckreibich ckreibich left a comment

Choose a reason for hiding this comment

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

I'm now all the way through Tim, great stuff — I like that we're removing more things now.

I will tinker with this some more — I'm tempted to add a test case for it over in zeek-testing-cluster since it would nicely complement the approach here in the btests. I have a PR coming up to simplify a few things in the supervisor where we'd otherwise need to reflect the metrics port in a few data structures. (This was this comment on Slack a while back.)

scripts/base/frameworks/cluster/main.zeek Show resolved Hide resolved
scripts/base/frameworks/telemetry/main.zeek Show resolved Hide resolved
labels: vector of string &default=vector();

## Whether the metric represents something that is accumulating.
## Defaults to ``T`` for counters and ``F`` for gauges and
Copy link
Member

Choose a reason for hiding this comment

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

Yeah. I just followed the code path for is_total and it now really is only used to add the suffix _total to the Prometheus metrics name, right? Since we have the metric_type below, and we generally know whether we're operating on a counter, gauge, or histogram elsewhere in the code, it seems we can always just use _total automatically for counters. (This is a Prometheus requirement, right?) It seems safe to me to deprecate this field (or just remove it outright, given the next point...).

As to double vs count ... even in the prior code we only supported doubles in various instrument-adjusting script-level APIs, right? It seems to me the difference is really a detail. It could matter for example for meaningfully plotting the metrics based on that typing info, for small values (it doesn't make sense to say "3.5 packets" or some such). But that looks pretty irrelevant: for large values the visual difference is negligible, and if one knows which metrics one is dealing with, one already knows whether they deal in doubles or counts.

Long story short: it looks safe to me to reduce this to just having all instruments operating on doubles. If we do that, it brings up the question of how much we let it affect the C++ design around BaseType etc. I could see keeping that as-is, in case we make other customizations in the future?

src/telemetry/Counter.h Outdated Show resolved Hide resolved
src/telemetry/Manager.h Show resolved Hide resolved
src/telemetry/Manager.h Outdated Show resolved Hide resolved
src/telemetry/ProcessStats.cc Show resolved Hide resolved
src/telemetry/Utils.cc Show resolved Hide resolved
@timwoj timwoj force-pushed the topic/timw/prometheus-cpp-3 branch from 047d330 to 21e61e9 Compare May 23, 2024 01:27
@timwoj timwoj force-pushed the topic/timw/prometheus-cpp-3 branch from 21e61e9 to 23b997c Compare May 23, 2024 01:30
@timwoj timwoj marked this pull request as ready for review May 23, 2024 01:31
@timwoj
Copy link
Contributor Author

timwoj commented May 24, 2024

@ckreibich I just added two commits that change everything to doubles and removes the is_sum argument everywhere.

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.

Telemetry rework: Moving towards a Prometheus-first model
3 participants