|
| 1 | +// Copyright 2021 Datafuse Labs |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +use std::sync::LazyLock; |
| 16 | +use std::time::Duration; |
| 17 | + |
| 18 | +use databend_common_base::runtime::metrics::register_counter_family; |
| 19 | +use databend_common_base::runtime::metrics::register_histogram_family_in_milliseconds; |
| 20 | +use databend_common_base::runtime::metrics::FamilyCounter; |
| 21 | +use databend_common_base::runtime::metrics::FamilyHistogram; |
| 22 | + |
| 23 | +use crate::VecLabels; |
| 24 | + |
| 25 | +static AUTH_JWKS_REQUESTS_COUNT: LazyLock<FamilyCounter<VecLabels>> = |
| 26 | + LazyLock::new(|| register_counter_family("auth_jwks_requests_count")); |
| 27 | +static AUTH_JWKS_REFRESH_DURATION: LazyLock<FamilyHistogram<VecLabels>> = |
| 28 | + LazyLock::new(|| register_histogram_family_in_milliseconds("auth_jwks_refresh_duration_ms")); |
| 29 | + |
| 30 | +pub fn metrics_incr_auth_jwks_requests_count(url: String, reason: String, status: u16) { |
| 31 | + let labels = vec![ |
| 32 | + ("url", url), |
| 33 | + ("reason", reason), |
| 34 | + ("status", status.to_string()), |
| 35 | + ]; |
| 36 | + AUTH_JWKS_REQUESTS_COUNT.get_or_create(&labels).inc(); |
| 37 | +} |
| 38 | + |
| 39 | +pub fn metrics_observe_auth_jwks_refresh_duration(url: String, duration: Duration) { |
| 40 | + let labels = vec![("url", url)]; |
| 41 | + AUTH_JWKS_REFRESH_DURATION |
| 42 | + .get_or_create(&labels) |
| 43 | + .observe(duration.as_millis() as f64); |
| 44 | +} |
0 commit comments