Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added feature_toggle_usage_total counter #532

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion server/src/metrics/client_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use chrono::{DateTime, Utc};
use dashmap::DashMap;
use iter_tools::Itertools;
use lazy_static::lazy_static;
use prometheus::{register_histogram, Histogram};
use prometheus::{register_histogram, register_int_counter_vec, Histogram, IntCounterVec};
use serde::{Deserialize, Serialize};
use std::{
collections::HashMap,
Expand All @@ -25,6 +25,12 @@ lazy_static! {
vec![1000.0, 10000.0, 20000.0, 50000.0, 75000.0, 100000.0, 250000.0, 500000.0, 1000000.0]
)
.unwrap();
pub static ref FEATURE_TOGGLE_USAGE_TOTAL: IntCounterVec = register_int_counter_vec!(
"feature_toggle_usage_total",
"Number of times a feature flag has been used",
&["appName", "toggle", "active"]
)
.unwrap();
}

#[derive(Debug, PartialEq, Eq, Hash, Clone)]
Expand Down Expand Up @@ -329,6 +335,12 @@ impl MetricsCache {
pub fn sink_metrics(&self, metrics: &[ClientMetricsEnv]) {
debug!("Sinking {} metrics", metrics.len());
for metric in metrics.iter() {
FEATURE_TOGGLE_USAGE_TOTAL
.with_label_values(&[&metric.app_name, &metric.feature_name, "true"])
.inc_by(metric.yes as u64);
FEATURE_TOGGLE_USAGE_TOTAL
.with_label_values(&[&metric.app_name, &metric.feature_name, "false"])
.inc_by(metric.no as u64);
self.metrics
.entry(MetricsKey {
app_name: metric.app_name.clone(),
Expand Down
5 changes: 5 additions & 0 deletions server/src/prom_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ fn register_custom_metrics(registry: &prometheus::Registry) {
crate::http::unleash_client::UPSTREAM_VERSION.clone(),
))
.unwrap();
registry
.register(Box::new(
crate::metrics::client_metrics::FEATURE_TOGGLE_USAGE_TOTAL.clone(),
))
.unwrap();
}

#[cfg(test)]
Expand Down
Loading