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

adjust enrollment status telemetry to only send for active experiments #5889

Merged
merged 1 commit into from
Oct 27, 2023
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
6 changes: 6 additions & 0 deletions components/nimbus/src/stateful/dbcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use std::sync::RwLock;
// This struct is the cached data. This is never mutated, but instead
// recreated every time the cache is updated.
struct CachedData {
pub experiments: Vec<Experiment>,
pub enrollments: Vec<ExperimentEnrollment>,
pub experiments_by_slug: HashMap<String, EnrolledExperiment>,
pub features_by_feature_id: HashMap<String, EnrolledFeatureConfig>,
Expand Down Expand Up @@ -81,6 +82,7 @@ impl DatabaseCache {
// This is where rollouts (promoted experiments on a given feature) will be merged in to the feature variables.

let data = CachedData {
experiments,
enrollments,
experiments_by_slug,
features_by_feature_id,
Expand Down Expand Up @@ -154,6 +156,10 @@ impl DatabaseCache {
})
}

pub fn get_experiments(&self) -> Result<Vec<Experiment>> {
self.get_data(|data| data.experiments.to_vec())
}

pub fn get_enrollments(&self) -> Result<Vec<ExperimentEnrollment>> {
self.get_data(|data| data.enrollments.to_owned())
}
Expand Down
11 changes: 10 additions & 1 deletion components/nimbus/src/stateful/nimbus_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,11 +692,20 @@ impl NimbusClient {
}

fn record_enrollment_status_telemetry(&self) -> Result<()> {
let experiments = self
.database_cache
.get_experiments()?
.iter()
.map(|exp| exp.slug.clone())
.collect::<HashSet<String>>();
self.metrics_handler.record_enrollment_statuses(
self.database_cache
.get_enrollments()?
.into_iter()
.map(|e| e.into())
.filter_map(|e| match experiments.contains(&e.slug) {
true => Some(e.into()),
false => None,
})
.collect(),
);
Ok(())
Expand Down
28 changes: 12 additions & 16 deletions components/nimbus/src/tests/stateful/test_nimbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1402,28 +1402,24 @@ fn test_enrollment_status_metrics_recorded() -> Result<()> {

let metric_records: Vec<EnrollmentStatusExtraDef> =
serde_json::from_value(metrics.assert_get_vec_value("enrollment_status"))?;
assert_eq!(metric_records.len(), 7);
assert_eq!(metric_records.len(), 6);

assert_eq!(metric_records[3].slug(), slug_1);
assert_eq!(metric_records[3].status(), "WasEnrolled");
assert_eq!(metric_records[3].branch(), "treatment");
assert_eq!(metric_records[3].slug(), slug_2);
assert_eq!(metric_records[3].status(), "Disqualified");
assert_eq!(metric_records[3].reason(), "NotTargeted");
assert_eq!(metric_records[3].branch(), "control");

assert_eq!(metric_records[4].slug(), slug_2);
assert_eq!(metric_records[4].status(), "Disqualified");
assert_eq!(metric_records[4].reason(), "NotTargeted");
assert_eq!(metric_records[4].branch(), "control");

assert_eq!(metric_records[5].slug(), slug_4);
assert_eq!(metric_records[5].status(), "Error");
assert_eq!(metric_records[4].slug(), slug_4);
assert_eq!(metric_records[4].status(), "Error");
assert_eq!(
metric_records[5].error_string(),
metric_records[4].error_string(),
"EvaluationError: Identifier 'blah' is undefined"
);

assert_eq!(metric_records[6].slug(), slug_3);
assert_eq!(metric_records[6].status(), "Disqualified");
assert_eq!(metric_records[6].reason(), "NotSelected");
assert_eq!(metric_records[6].branch(), "control");
assert_eq!(metric_records[5].slug(), slug_3);
assert_eq!(metric_records[5].status(), "Disqualified");
assert_eq!(metric_records[5].reason(), "NotSelected");
assert_eq!(metric_records[5].branch(), "control");

Ok(())
}