use mz_ore::cast::CastFrom;
use mz_ore::metric;
use mz_ore::metrics::raw::IntCounterVec;
use mz_ore::metrics::MetricsRegistry;
use crate::decode::{DataDecoderInner, PreDelimitedFormat};
#[derive(Clone, Debug)]
pub struct DecodeMetricDefs {
events_read: IntCounterVec,
}
impl DecodeMetricDefs {
pub(crate) fn register_with(registry: &MetricsRegistry) -> Self {
Self {
events_read: registry.register(metric!(
name: "mz_dataflow_events_read_total",
help: "Count of events we have read from the wire",
var_labels: ["format", "status"],
)),
}
}
fn counter_inc(&self, decoder: &DataDecoderInner, success: bool, n: usize) {
let format_label = match decoder {
DataDecoderInner::Avro(_) => "avro",
DataDecoderInner::Csv(_) => "csv",
DataDecoderInner::DelimitedBytes { format, .. }
| DataDecoderInner::PreDelimited(format) => match format {
PreDelimitedFormat::Bytes => "raw",
PreDelimitedFormat::Json => "json",
PreDelimitedFormat::Text => "text",
PreDelimitedFormat::Regex(..) => "regex",
PreDelimitedFormat::Protobuf(..) => "protobuf",
},
};
let success_label = if success { "success" } else { "error" };
self.events_read
.with_label_values(&[format_label, success_label])
.inc_by(u64::cast_from(n));
}
pub(crate) fn count_successes(&self, decoder: &DataDecoderInner, n: usize) {
self.counter_inc(decoder, true, n);
}
pub(crate) fn count_errors(&self, decoder: &DataDecoderInner, n: usize) {
self.counter_inc(decoder, true, n);
}
}