forked from Deuxfleurs/tricot
cargo upgrades: update opentelemetry dependency to 0.20/prometheus to 0.13
This commit is contained in:
parent
46d517b2f7
commit
4818e8cccc
5 changed files with 98 additions and 65 deletions
108
Cargo.lock
generated
108
Cargo.lock
generated
|
@ -349,16 +349,6 @@ dependencies = [
|
|||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dashmap"
|
||||
version = "4.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"num_cpus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "deranged"
|
||||
version = "0.3.8"
|
||||
|
@ -977,36 +967,72 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "opentelemetry"
|
||||
version = "0.17.0"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6105e89802af13fdf48c49d7646d3b533a70e536d818aae7e78ba0433d01acb8"
|
||||
checksum = "9591d937bc0e6d2feb6f71a559540ab300ea49955229c347a517a28d27784c54"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"crossbeam-channel",
|
||||
"dashmap",
|
||||
"fnv",
|
||||
"futures-channel",
|
||||
"futures-executor",
|
||||
"futures-util",
|
||||
"js-sys",
|
||||
"lazy_static",
|
||||
"percent-encoding",
|
||||
"pin-project",
|
||||
"rand",
|
||||
"thiserror",
|
||||
"opentelemetry_api",
|
||||
"opentelemetry_sdk",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "opentelemetry-prometheus"
|
||||
version = "0.10.0"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9328977e479cebe12ce0d3fcecdaea4721d234895a9440c5b5dfd113f0594ac6"
|
||||
checksum = "c7d81bc254e2d572120363a2b16cdb0d715d301b5789be0cfc26ad87e4e10e53"
|
||||
dependencies = [
|
||||
"opentelemetry",
|
||||
"once_cell",
|
||||
"opentelemetry_api",
|
||||
"opentelemetry_sdk",
|
||||
"prometheus",
|
||||
"protobuf",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "opentelemetry_api"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a81f725323db1b1206ca3da8bb19874bbd3f57c3bcd59471bfb04525b265b9b"
|
||||
dependencies = [
|
||||
"futures-channel",
|
||||
"futures-util",
|
||||
"indexmap",
|
||||
"js-sys",
|
||||
"once_cell",
|
||||
"pin-project-lite",
|
||||
"thiserror",
|
||||
"urlencoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "opentelemetry_sdk"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fa8e705a0612d48139799fcbaba0d4a90f06277153e43dd2bdc16c6f0edd8026"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"crossbeam-channel",
|
||||
"futures-channel",
|
||||
"futures-executor",
|
||||
"futures-util",
|
||||
"once_cell",
|
||||
"opentelemetry_api",
|
||||
"ordered-float",
|
||||
"percent-encoding",
|
||||
"rand",
|
||||
"regex",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ordered-float"
|
||||
version = "3.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2a54938017eacd63036332b4ae5c8a49fc8c0c1d6d629893057e4f13609edd06"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "overload"
|
||||
version = "0.1.1"
|
||||
|
@ -1052,26 +1078,6 @@ version = "2.3.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fda4ed1c6c173e3fc7a83629421152e01d7b1f9b7f65fb301e490e8cfc656422"
|
||||
dependencies = [
|
||||
"pin-project-internal",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-internal"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.37",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.13"
|
||||
|
@ -2103,6 +2109,12 @@ dependencies = [
|
|||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "urlencoding"
|
||||
version = "2.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "1.4.1"
|
||||
|
|
|
@ -34,8 +34,8 @@ accept-encoding-fork = "0.2.0-alpha.3"
|
|||
async-compression = { version = "0.4", features = ["tokio", "gzip", "zstd", "deflate", "brotli"] }
|
||||
tokio-util = { version = "0.7", features = ["io"] }
|
||||
uuid = { version = "1.2", features = ["v4"] }
|
||||
opentelemetry = "0.17"
|
||||
opentelemetry-prometheus = "0.10"
|
||||
opentelemetry = "0.20"
|
||||
opentelemetry-prometheus = "0.13"
|
||||
prometheus = "0.13"
|
||||
df-consul = "0.3.5"
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ pub struct HttpsConfig {
|
|||
struct HttpsMetrics {
|
||||
requests_received: metrics::Counter<u64>,
|
||||
requests_served: metrics::Counter<u64>,
|
||||
request_proxy_duration: metrics::ValueRecorder<f64>,
|
||||
request_proxy_duration: metrics::Histogram<f64>,
|
||||
}
|
||||
|
||||
pub async fn serve_https(
|
||||
|
@ -63,7 +63,7 @@ pub async fn serve_https(
|
|||
.with_description("Total number of requests served over HTTPS")
|
||||
.init(),
|
||||
request_proxy_duration: meter
|
||||
.f64_value_recorder("https_request_proxy_duration")
|
||||
.f64_histogram("https_request_proxy_duration")
|
||||
.with_description("Duration between time when request was received, and time when backend returned status code and headers")
|
||||
.init(),
|
||||
});
|
||||
|
|
|
@ -11,27 +11,29 @@ use hyper::{
|
|||
service::{make_service_fn, service_fn},
|
||||
Body, Method, Request, Response, Server,
|
||||
};
|
||||
use opentelemetry_prometheus::PrometheusExporter;
|
||||
use opentelemetry::sdk::metrics;
|
||||
use prometheus::{Encoder, TextEncoder};
|
||||
|
||||
pub struct MetricsServer {
|
||||
bind_addr: Option<SocketAddr>,
|
||||
exporter: PrometheusExporter,
|
||||
registry: prometheus::Registry,
|
||||
}
|
||||
|
||||
impl MetricsServer {
|
||||
pub fn init(bind_addr: Option<SocketAddr>) -> MetricsServer {
|
||||
let registry = prometheus::Registry::new();
|
||||
let exporter = opentelemetry_prometheus::exporter()
|
||||
.with_default_summary_quantiles(vec![0.25, 0.5, 0.75, 0.9, 0.95, 0.99])
|
||||
.with_default_histogram_boundaries(vec![
|
||||
0.001, 0.0015, 0.002, 0.003, 0.005, 0.007, 0.01, 0.015, 0.02, 0.03, 0.05, 0.07,
|
||||
0.1, 0.15, 0.2, 0.3, 0.5, 0.7, 1., 1.5, 2., 3., 5., 7., 10., 15., 20., 30., 40.,
|
||||
50., 60., 70., 100.,
|
||||
])
|
||||
.init();
|
||||
.with_registry(registry.clone())
|
||||
.with_aggregation_selector(AggregationSelector)
|
||||
.build()
|
||||
.expect("build prometheus registry");
|
||||
let mp = metrics::MeterProvider::builder()
|
||||
.with_reader(exporter)
|
||||
.build();
|
||||
opentelemetry::global::set_meter_provider(mp);
|
||||
Self {
|
||||
bind_addr,
|
||||
exporter,
|
||||
registry,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,7 +72,7 @@ impl MetricsServer {
|
|||
(&Method::GET, "/metrics") => {
|
||||
let mut buffer = vec![];
|
||||
let encoder = TextEncoder::new();
|
||||
let metric_families = self.exporter.registry().gather();
|
||||
let metric_families = self.registry.gather();
|
||||
encoder.encode(&metric_families, &mut buffer).unwrap();
|
||||
|
||||
Response::builder()
|
||||
|
@ -88,3 +90,21 @@ impl MetricsServer {
|
|||
Ok(response)
|
||||
}
|
||||
}
|
||||
|
||||
struct AggregationSelector;
|
||||
|
||||
impl metrics::reader::AggregationSelector for AggregationSelector {
|
||||
fn aggregation(&self, kind: metrics::InstrumentKind) -> metrics::Aggregation {
|
||||
match kind {
|
||||
metrics::InstrumentKind::Histogram => metrics::Aggregation::ExplicitBucketHistogram {
|
||||
boundaries: vec![
|
||||
0.001, 0.0015, 0.002, 0.003, 0.005, 0.007, 0.01, 0.015, 0.02, 0.03, 0.05, 0.07,
|
||||
0.1, 0.15, 0.2, 0.3, 0.5, 0.7, 1., 1.5, 2., 3., 5., 7., 10., 15., 20., 30.,
|
||||
40., 50., 60., 70., 100.,
|
||||
],
|
||||
record_min_max: true,
|
||||
},
|
||||
_ => metrics::reader::DefaultAggregationSelector::new().aggregation(kind),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -334,7 +334,7 @@ pub fn spawn_proxy_config_task(
|
|||
// ----
|
||||
|
||||
struct ProxyConfigMetrics {
|
||||
_proxy_config_entries: metrics::ValueObserver<u64>,
|
||||
_proxy_config_entries: metrics::ObservableGauge<u64>,
|
||||
}
|
||||
|
||||
impl ProxyConfigMetrics {
|
||||
|
@ -342,7 +342,8 @@ impl ProxyConfigMetrics {
|
|||
let meter = opentelemetry::global::meter("tricot");
|
||||
Self {
|
||||
_proxy_config_entries: meter
|
||||
.u64_value_observer("proxy_config_entries", move |observer| {
|
||||
.u64_observable_gauge("proxy_config_entries")
|
||||
.with_callback(move |observer| {
|
||||
let mut patterns = HashMap::new();
|
||||
for ent in rx.borrow().entries.iter() {
|
||||
let attrs = (
|
||||
|
|
Loading…
Reference in a new issue