Change all instruments to only handle doubles

This commit is contained in:
Tim Wojtulewicz 2024-05-24 14:51:19 -07:00
parent 6eab954fd2
commit 46ff48c29a
35 changed files with 635 additions and 1148 deletions

View file

@ -19,7 +19,7 @@ export {
## :zeek:see:`Telemetry::counter_with`. To modify counters directly
## use :zeek:see:`Telemetry::counter_family_inc`.
type CounterFamily: record {
__family: opaque of dbl_counter_metric_family;
__family: opaque of counter_metric_family;
__labels: vector of string;
};
@ -32,7 +32,7 @@ export {
## per :zeek:see:`Log::Stream` or number connections broken down
## by protocol and service.
type Counter: record {
__metric: opaque of dbl_counter_metric;
__metric: opaque of counter_metric;
};
## Register a counter family.
@ -103,7 +103,7 @@ export {
## :zeek:see:`Telemetry::gauge_family_inc` or
## :zeek:see:`Telemetry::gauge_family_set` directly.
type GaugeFamily: record {
__family: opaque of dbl_gauge_metric_family;
__family: opaque of gauge_metric_family;
__labels: vector of string;
};
@ -115,7 +115,7 @@ export {
## or footprints of long-lived values as determined by
## :zeek:see:`val_footprint`.
type Gauge: record {
__metric: opaque of dbl_gauge_metric;
__metric: opaque of gauge_metric;
};
## Register a gauge family.
@ -204,14 +204,14 @@ export {
## :zeek:see:`Telemetry::histogram_with` or use
## :zeek:see:`Telemetry::histogram_family_observe` directly.
type HistogramFamily: record {
__family: opaque of dbl_histogram_metric_family;
__family: opaque of histogram_metric_family;
__labels: vector of string;
};
## Type representing a histogram metric with initialized label values.
## Use :zeek:see:`Telemetry::histogram_observe` to make observations.
type Histogram: record {
__metric: opaque of dbl_histogram_metric;
__metric: opaque of histogram_metric;
};
## Register a histogram family.
@ -292,7 +292,7 @@ function make_labels(keys: vector of string, values: labels_vector): table[strin
function register_counter_family(opts: MetricOpts): CounterFamily
{
local f = Telemetry::__dbl_counter_family(
local f = Telemetry::__counter_family(
opts$prefix,
opts$name,
opts$labels,
@ -320,24 +320,24 @@ function counter_with(cf: CounterFamily, label_values: labels_vector): Counter
}
local labels = make_labels(cf$__labels, label_values);
local m = Telemetry::__dbl_counter_metric_get_or_add(cf$__family, labels);
local m = Telemetry::__counter_metric_get_or_add(cf$__family, labels);
return Counter($__metric=m);
}
function counter_inc(c: Counter, amount: double): bool
{
return Telemetry::__dbl_counter_inc(c$__metric, amount);
return Telemetry::__counter_inc(c$__metric, amount);
}
function counter_set(c: Counter, value: double): bool
{
local cur_value: double = Telemetry::__dbl_counter_value(c$__metric);
local cur_value: double = Telemetry::__counter_value(c$__metric);
if (value < cur_value)
{
Reporter::error(fmt("Attempted to set lower counter value=%s cur_value=%s", value, cur_value));
return F;
}
return Telemetry::__dbl_counter_inc(c$__metric, value - cur_value);
return Telemetry::__counter_inc(c$__metric, value - cur_value);
}
function counter_family_inc(cf: CounterFamily, label_values: labels_vector, amount: double): bool
@ -352,7 +352,7 @@ function counter_family_set(cf: CounterFamily, label_values: labels_vector, valu
function register_gauge_family(opts: MetricOpts): GaugeFamily
{
local f = Telemetry::__dbl_gauge_family(
local f = Telemetry::__gauge_family(
opts$prefix,
opts$name,
opts$labels,
@ -379,29 +379,29 @@ function gauge_with(gf: GaugeFamily, label_values: labels_vector): Gauge
return gauge_with(error_gauge_cf);
}
local labels = make_labels(gf$__labels, label_values);
local m = Telemetry::__dbl_gauge_metric_get_or_add(gf$__family, labels);
local m = Telemetry::__gauge_metric_get_or_add(gf$__family, labels);
return Gauge($__metric=m);
}
function gauge_inc(g: Gauge, amount: double &default=1.0): bool
{
return Telemetry::__dbl_gauge_inc(g$__metric, amount);
return Telemetry::__gauge_inc(g$__metric, amount);
}
function gauge_dec(g: Gauge, amount: double &default=1.0): bool
{
return Telemetry::__dbl_gauge_dec(g$__metric, amount);
return Telemetry::__gauge_dec(g$__metric, amount);
}
function gauge_set(g: Gauge, value: double): bool
{
# Telemetry currently does not implement __dbl_gauge_set(), do
# Telemetry currently does not implement __gauge_set(), do
# it by hand here.
local cur_value: double = Telemetry::__dbl_gauge_value(g$__metric);
local cur_value: double = Telemetry::__gauge_value(g$__metric);
if (value > cur_value)
return Telemetry::__dbl_gauge_inc(g$__metric, value - cur_value);
return Telemetry::__gauge_inc(g$__metric, value - cur_value);
return Telemetry::__dbl_gauge_dec(g$__metric, cur_value - value);
return Telemetry::__gauge_dec(g$__metric, cur_value - value);
}
function gauge_family_inc(gf: GaugeFamily, label_values: labels_vector, value: double): bool
@ -421,7 +421,7 @@ function gauge_family_set(gf: GaugeFamily, label_values: labels_vector, value: d
function register_histogram_family(opts: MetricOpts): HistogramFamily
{
local f = Telemetry::__dbl_histogram_family(
local f = Telemetry::__histogram_family(
opts$prefix,
opts$name,
opts$labels,
@ -450,13 +450,13 @@ function histogram_with(hf: HistogramFamily, label_values: labels_vector): Histo
}
local labels = make_labels(hf$__labels, label_values);
local m = Telemetry::__dbl_histogram_metric_get_or_add(hf$__family, labels);
local m = Telemetry::__histogram_metric_get_or_add(hf$__family, labels);
return Histogram($__metric=m);
}
function histogram_observe(h: Histogram, measurement: double): bool
{
return Telemetry::__dbl_histogram_observe(h$__metric, measurement);
return Telemetry::__histogram_observe(h$__metric, measurement);
}
function histogram_family_observe(hf: HistogramFamily, label_values: labels_vector, measurement: double): bool

View file

@ -5775,12 +5775,9 @@ module Telemetry;
export {
type MetricType: enum {
DOUBLE_COUNTER,
INT_COUNTER,
DOUBLE_GAUGE,
INT_GAUGE,
DOUBLE_HISTOGRAM,
INT_HISTOGRAM,
COUNTER,
GAUGE,
HISTOGRAM,
};
## Type that captures options used to create metrics.
@ -5822,13 +5819,6 @@ export {
## describes the number and bounds of the individual buckets.
bounds: vector of double &optional;
## The same meaning as *bounds*, but as :zeek:type:`count`.
## Only set in the return value of
## :zeek:see:`Telemetry::collect_histogram_metrics`.
## for histograms when the underlying type is ``int64_t``,
## otherwise ignored.
count_bounds: vector of count &optional;
## Describes the underlying metric type.
## Only set in the return value of
## :zeek:see:`Telemetry::collect_metrics` or
@ -5850,11 +5840,6 @@ export {
## This value is set for all counter and gauge metrics,
## it is unset for histograms.
value: double &optional;
## The integer value of underlying instrument if the metric type
## is INT_COUNTER or INT_GAUGE. This will be unset if the type
## is DOUBLE_COUNTER or DOUBLE_GAUGE.
count_value: count &optional;
};
## Histograms returned by the :zeek:see:`Telemetry::collect_histogram_metrics` function.
@ -5869,26 +5854,11 @@ export {
## described by the *bounds* field in *opts*;
values: vector of double;
## Integer values for the individual counters for each of the
## bckets as described in the ``bounds`` field in ``opts``. This
## value will be unset if the metric type is DOUBLE_HISTOGRAM.
count_values: vector of count &optional;
## The number of observations made for this histogram.
observations: double;
## The sum of all observations for this histogram.
sum: double;
## The integer value of the number of observations made for this
## histogram. This value will be unset if the metric type is
## DOUBLE_HISTOGRAM.
count_observations: count &optional;
## The integer value of the sum of all observations for this
## histogram. This value will be unset if the metric type is
## DOUBLE_HISTOGRAM.
count_sum: count &optional;
};
type MetricVector : vector of Metric;

View file

@ -119,17 +119,17 @@ function do_log()
local m = metrics[i];
# Histograms don't have single values, skip over them.
if ( m$opts$metric_type == DOUBLE_HISTOGRAM || m$opts$metric_type == INT_HISTOGRAM )
if ( m$opts$metric_type == HISTOGRAM )
next;
# Render the metric_type as a short string. Unknown
# shouldn't really happen, but lets have a fallback.
local metric_type = "unknown";
switch ( m$opts$metric_type ) {
case DOUBLE_COUNTER, INT_COUNTER:
case COUNTER:
metric_type = "counter";
break;
case DOUBLE_GAUGE, INT_GAUGE:
case GAUGE:
metric_type = "gauge";
break;
}