Restore label_names field in MetricOpts record

This commit is contained in:
Tim Wojtulewicz 2024-06-04 08:49:42 -07:00 committed by Tim Wojtulewicz
parent 1cdca7c1d0
commit 99e64aa113
6 changed files with 55 additions and 46 deletions

View file

@ -36,8 +36,7 @@ export {
}; };
## Register a counter family. ## Register a counter family.
global register_counter_family: function(opts: MetricOpts, global register_counter_family: function(opts: MetricOpts): CounterFamily;
label_names: labels_vector &default=vector()): CounterFamily;
## Get a :zeek:see:`Telemetry::Counter` instance given family and label values. ## Get a :zeek:see:`Telemetry::Counter` instance given family and label values.
global counter_with: function(cf: CounterFamily, global counter_with: function(cf: CounterFamily,
@ -120,8 +119,7 @@ export {
}; };
## Register a gauge family. ## Register a gauge family.
global register_gauge_family: function(opts: MetricOpts, global register_gauge_family: function(opts: MetricOpts): GaugeFamily;
label_names: labels_vector &default=vector()): GaugeFamily;
## Get a :zeek:see:`Telemetry::Gauge` instance given family and label values. ## Get a :zeek:see:`Telemetry::Gauge` instance given family and label values.
@ -217,8 +215,7 @@ export {
}; };
## Register a histogram family. ## Register a histogram family.
global register_histogram_family: function(opts: MetricOpts, global register_histogram_family: function(opts: MetricOpts): HistogramFamily;
label_names: labels_vector &default=vector()): HistogramFamily;
## Get a :zeek:see:`Telemetry::Histogram` instance given family and label values. ## Get a :zeek:see:`Telemetry::Histogram` instance given family and label values.
global histogram_with: function(hf: HistogramFamily, global histogram_with: function(hf: HistogramFamily,
@ -293,16 +290,16 @@ function make_labels(keys: vector of string, values: labels_vector): table[strin
return labels; return labels;
} }
function register_counter_family(opts: MetricOpts, label_names: labels_vector): CounterFamily function register_counter_family(opts: MetricOpts): CounterFamily
{ {
local f = Telemetry::__counter_family( local f = Telemetry::__counter_family(
opts$prefix, opts$prefix,
opts$name, opts$name,
label_names, opts$label_names,
opts$help_text, opts$help_text,
opts$unit opts$unit
); );
return CounterFamily($__family=f, $__labels=label_names); return CounterFamily($__family=f, $__labels=opts$label_names);
} }
# Fallback Counter returned when there are issues with the labels. # Fallback Counter returned when there are issues with the labels.
@ -352,16 +349,16 @@ function counter_family_set(cf: CounterFamily, label_values: labels_vector, valu
return counter_set(counter_with(cf, label_values), value); return counter_set(counter_with(cf, label_values), value);
} }
function register_gauge_family(opts: MetricOpts, label_names: labels_vector): GaugeFamily function register_gauge_family(opts: MetricOpts): GaugeFamily
{ {
local f = Telemetry::__gauge_family( local f = Telemetry::__gauge_family(
opts$prefix, opts$prefix,
opts$name, opts$name,
label_names, opts$label_names,
opts$help_text, opts$help_text,
opts$unit opts$unit
); );
return GaugeFamily($__family=f, $__labels=label_names); return GaugeFamily($__family=f, $__labels=opts$label_names);
} }
# Fallback Gauge returned when there are issues with the label usage. # Fallback Gauge returned when there are issues with the label usage.
@ -420,17 +417,17 @@ function gauge_family_set(gf: GaugeFamily, label_values: labels_vector, value: d
return gauge_set(gauge_with(gf, label_values), value); return gauge_set(gauge_with(gf, label_values), value);
} }
function register_histogram_family(opts: MetricOpts, label_names: labels_vector): HistogramFamily function register_histogram_family(opts: MetricOpts): HistogramFamily
{ {
local f = Telemetry::__histogram_family( local f = Telemetry::__histogram_family(
opts$prefix, opts$prefix,
opts$name, opts$name,
label_names, opts$label_names,
opts$bounds, opts$bounds,
opts$help_text, opts$help_text,
opts$unit opts$unit
); );
return HistogramFamily($__family=f, $__labels=label_names); return HistogramFamily($__family=f, $__labels=opts$label_names);
} }
# Fallback Histogram when there are issues with the labels. # Fallback Histogram when there are issues with the labels.
@ -486,10 +483,10 @@ global version_gauge_family = Telemetry::register_gauge_family([
$prefix="zeek", $prefix="zeek",
$name="version_info", $name="version_info",
$unit="", $unit="",
$help_text="The Zeek version"], $help_text="The Zeek version",
vector("version_number", "major", "minor", "patch", "commit", $label_names=vector("version_number", "major", "minor", "patch", "commit",
"beta", "debug","version_string") "beta", "debug","version_string")
); ]);
event zeek_init() event zeek_init()
{ {

View file

@ -5802,6 +5802,18 @@ export {
## Documentation for this metric. ## Documentation for this metric.
help_text: string &optional; help_text: string &optional;
## The label names (also called dimensions) of the metric. When
## instantiating or working with concrete metrics, corresponding
## label values have to be provided. Examples of a label might
## be the protocol a general observation applies to, the
## directionality in a traffic flow, or protocol-specific
## context like a particular message type. This field is only
## used in the construction of new metrics and will not be
## filled in when returned from
## :zeek:see:`Telemetry::collect_metrics` or
## :zeek:see:`Telemetry::collect_histogram_metrics`,
label_names: vector of string &default=vector();
## Whether the metric represents something that is accumulating. ## Whether the metric represents something that is accumulating.
## Defaults to ``T`` for counters and ``F`` for gauges and ## Defaults to ``T`` for counters and ``F`` for gauges and
## histograms. ## histograms.

View file

@ -14,42 +14,42 @@ global btest_a_cf = Telemetry::register_counter_family([
$prefix="btest", $prefix="btest",
$name="a_test", $name="a_test",
$unit="", $unit="",
$help_text="A btest metric"], $help_text="A btest metric",
vector("x", "y") $label_names=vector("x", "y")
); ]);
global btest_b_cf = Telemetry::register_counter_family([ global btest_b_cf = Telemetry::register_counter_family([
$prefix="btest", $prefix="btest",
$name="b_test", $name="b_test",
$unit="", $unit="",
$help_text="Another btest metric"], $help_text="Another btest metric",
vector("x", "y") $label_names=vector("x", "y")
); ]);
global btest_c_cf = Telemetry::register_counter_family([ global btest_c_cf = Telemetry::register_counter_family([
$prefix="btest", $prefix="btest",
$name="c_test", $name="c_test",
$unit="", $unit="",
$help_text="The last btest metric"], $help_text="The last btest metric",
vector("x", "y") $label_names=vector("x", "y")
); ]);
global system_sensor_temp_gf = Telemetry::register_gauge_family([ global system_sensor_temp_gf = Telemetry::register_gauge_family([
$prefix="system", $prefix="system",
$name="sensor_temperature", $name="sensor_temperature",
$unit="celsius", $unit="celsius",
$help_text="Temperatures reported by sensors in the system"], $help_text="Temperatures reported by sensors in the system",
vector("name") $label_names=vector("name")
); ]);
global btest_sample_histogram_hf = Telemetry::register_histogram_family([ global btest_sample_histogram_hf = Telemetry::register_histogram_family([
$prefix="btest", $prefix="btest",
$name="sample_histogram", $name="sample_histogram",
$unit="", $unit="",
$help_text="A sample histogram that is not returned by Telemetry::collect_metrics", $help_text="A sample histogram that is not returned by Telemetry::collect_metrics",
$bounds=vector(1.0, 2.0, 3.0, 4.0, 5.0)], $bounds=vector(1.0, 2.0, 3.0, 4.0, 5.0),
vector("dim") $label_names=vector("dim")
); ]);
function print_metrics(what: string, metrics: vector of Telemetry::Metric) function print_metrics(what: string, metrics: vector of Telemetry::Metric)
{ {

View file

@ -18,11 +18,11 @@ global connection_duration_hf = Telemetry::register_histogram_family([
global realistic_connection_duration_hf = Telemetry::register_histogram_family([ global realistic_connection_duration_hf = Telemetry::register_histogram_family([
$prefix="zeek", $prefix="zeek",
$name="realistic_connection_duration", $name="realistic_connection_duration",
$label_names=vector("proto"),
$unit="seconds", $unit="seconds",
$help_text="Monitored connection durations by protocol", $help_text="Monitored connection durations by protocol",
$bounds=vector(0.1, 1.0, 10.0, 30.0, 60.0, 120.0, 300, 900.0, 1800.0)], $bounds=vector(0.1, 1.0, 10.0, 30.0, 60.0, 120.0, 300, 900.0, 1800.0),
vector("proto"), ]);
);
global connection_duration_h = Telemetry::histogram_with(connection_duration_hf); global connection_duration_h = Telemetry::histogram_with(connection_duration_hf);

View file

@ -140,9 +140,9 @@ event zeek_init()
$prefix="btest", $prefix="btest",
$name="btest_testing_gauge", $name="btest_testing_gauge",
$unit="", $unit="",
$help_text="Btest testing"], $help_text="Btest testing",
vector("dim_1"), $label_names=vector("dim_1"),
); ]);
local gauge = Telemetry::gauge_with(gauge_family, vector("dim_1_value")); local gauge = Telemetry::gauge_with(gauge_family, vector("dim_1_value"));
print to_json(gauge); print to_json(gauge);
print to_json(gauge_family); print to_json(gauge_family);
@ -151,9 +151,9 @@ event zeek_init()
$prefix="btest", $prefix="btest",
$name="btest_testing_counter", $name="btest_testing_counter",
$unit="", $unit="",
$help_text="Btest testing"], $help_text="Btest testing",
vector("dim_1"), $label_names=vector("dim_1"),
); ]);
local counter = Telemetry::counter_with(counter_family, vector("dim_1_value")); local counter = Telemetry::counter_with(counter_family, vector("dim_1_value"));
print to_json(counter); print to_json(counter);
print to_json(counter_family); print to_json(counter_family);

View file

@ -12,9 +12,9 @@ global connections_by_proto_cf = Telemetry::register_counter_family([
$prefix="btest", $prefix="btest",
$name="connections", $name="connections",
$unit="", $unit="",
$help_text="Total number of monitored connections"], $help_text="Total number of monitored connections",
$labels=vector("proto") $label_names=vector("proto")
); ]);
global connection_duration_hf = Telemetry::register_histogram_family([ global connection_duration_hf = Telemetry::register_histogram_family([
$prefix="btest", $prefix="btest",