1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
910use mz_ore::metric;
11use mz_ore::metrics::raw::IntCounterVec;
12use mz_ore::metrics::{IntCounter, MetricsRegistry};
1314#[derive(Clone, Debug)]
15pub struct MetricsConfig {
16 connection_status: IntCounterVec,
17}
1819impl MetricsConfig {
20pub fn register_into(registry: &MetricsRegistry) -> Self {
21Self {
22 connection_status: registry.register(metric! {
23 name: "mz_connection_status",
24 help: "Count of completed network connections, by status",
25 var_labels: ["source", "status"],
26 }),
27 }
28 }
29}
3031#[derive(Clone, Debug)]
32pub struct Metrics {
33 inner: MetricsConfig,
34 label: &'static str,
35}
3637impl Metrics {
38pub fn new(inner: MetricsConfig, label: &'static str) -> Self {
39let self_ = Self { inner, label };
4041// pre-initialize labels we are planning to use to ensure they are all
42 // always emitted as time series
43self_.connection_status(false);
44 self_.connection_status(true);
4546 self_
47 }
4849pub fn connection_status(&self, is_ok: bool) -> IntCounter {
50self.inner
51 .connection_status
52 .with_label_values(&[self.source_label(), Self::status_label(is_ok)])
53 }
5455fn status_label(is_ok: bool) -> &'static str {
56if is_ok { "success" } else { "error" }
57 }
5859fn source_label(&self) -> &'static str {
60self.label
61 }
62}