telemetry: Invoke Telemetry::sync() only at scrape/collection time

This stops invoking Telemetry::sync() via a scheduled event and instead
only invokes it on-demand. This makes metric collection network time
independent and lazier, too.

With Prometheus scrape requests being processed on Zeek's main thread
now, we can safely invoke the script layer Telemetry::sync() hook.

Closes #3947
This commit is contained in:
Arne Welzel 2024-10-02 16:53:11 +02:00
parent e118887771
commit 70872673a1
16 changed files with 260 additions and 17 deletions

View file

@ -5933,6 +5933,21 @@ export {
sum: double;
};
## Telemetry sync hook.
##
## This hook is invoked when metrics are requested via functions
## :zeek:see:`Telemetry::collect_metrics` and :zeek:see:`Telemetry::collect_histogram_metrics`,
## or just before Zeek collects metrics when being scraped through
## its Prometheus endpoint.
## Script writers can use it to synchronize (or mirror) metrics with the
## telemetry subsystem. For example, when tracking table or value
## footprints with gauges, the value in question can be set on an actual
## :zeek:see:`Telemetry::Gauge` instance during execution of this hook.
##
## Implementations should be lightweight, this hook may be called
## multiple times per minute.
global sync: hook();
type MetricVector : vector of Metric;
type HistogramMetricVector : vector of HistogramMetric;