Skip to content

Commit

Permalink
feat: added feature_toggle_usage_total counter (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswk authored Sep 18, 2024
1 parent 10d3854 commit 00aabbe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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

0 comments on commit 00aabbe

Please sign in to comment.