From dd3cf57ece178bd920bba7317cedbb621b5976fe Mon Sep 17 00:00:00 2001 From: Jason Hawk Harris Date: Thu, 28 Sep 2023 14:29:19 -0500 Subject: [PATCH] populate monitors_enabled_unique_users (#57163) * populate monitors_enabled_unique_users and monitors_enabled_last_run_errored code monitors so they don't return nil * remove code_monitors_last_run_errored * adds comment about unpopulated monitors_enabled_last_run_errored --- internal/types/types.go | 14 ++++++++------ internal/usagestats/code_monitoring.go | 1 + internal/usagestats/code_monitoring_test.go | 1 + .../usagestats/code_monitoring_usage_stats.sql | 6 +++++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/internal/types/types.go b/internal/types/types.go index 7140e0d05536..58cc519a4781 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -1837,12 +1837,14 @@ type CodeMonitoringUsageStatistics struct { WebhookActionsEnabledUniqueUsers *int32 MonitorsEnabled *int32 MonitorsEnabledUniqueUsers *int32 - MonitorsEnabledLastRunErrored *int32 - ReposMonitored *int32 - TriggerRuns *int32 - TriggerRunsErrored *int32 - P50TriggerRunTimeSeconds *float32 - P90TriggerRunTimeSeconds *float32 + // (TODO @jasonhawkharris ) Currently, MonitorsEnabledLastRunErrored is unpopulated + // It will require adjusting the query to select a row inside of a group + MonitorsEnabledLastRunErrored *int32 + ReposMonitored *int32 + TriggerRuns *int32 + TriggerRunsErrored *int32 + P50TriggerRunTimeSeconds *float32 + P90TriggerRunTimeSeconds *float32 } type NotebooksUsageStatistics struct { diff --git a/internal/usagestats/code_monitoring.go b/internal/usagestats/code_monitoring.go index 3bad07a4fadf..8025d48383a5 100644 --- a/internal/usagestats/code_monitoring.go +++ b/internal/usagestats/code_monitoring.go @@ -46,6 +46,7 @@ func GetCodeMonitoringUsageStatistics(ctx context.Context, db database.DB) (*typ &stats.P50TriggerRunTimeSeconds, &stats.P90TriggerRunTimeSeconds, &stats.MonitorsEnabled, + &stats.MonitorsEnabledUniqueUsers, ); err != nil { return nil, err } diff --git a/internal/usagestats/code_monitoring_test.go b/internal/usagestats/code_monitoring_test.go index b6320ad61a38..3b7700c0c516 100644 --- a/internal/usagestats/code_monitoring_test.go +++ b/internal/usagestats/code_monitoring_test.go @@ -251,6 +251,7 @@ func TestCodeMonitoringUsageStatistics(t *testing.T) { P50TriggerRunTimeSeconds: ptr(float32(3)), P90TriggerRunTimeSeconds: ptr(float32(6)), MonitorsEnabled: ptr(int32(8)), + MonitorsEnabledUniqueUsers: ptr(int32(8)), } require.Equal(t, want, have) } diff --git a/internal/usagestats/code_monitoring_usage_stats.sql b/internal/usagestats/code_monitoring_usage_stats.sql index 4b17631d073d..a6b19167c667 100644 --- a/internal/usagestats/code_monitoring_usage_stats.sql +++ b/internal/usagestats/code_monitoring_usage_stats.sql @@ -126,7 +126,11 @@ SELECT -- monitors_enabled COALESCE(slack_actions.slack_actions_enabled, 0) + COALESCE(email_actions.email_actions_enabled, 0) + - COALESCE(webhook_actions.webhook_actions_enabled, 0) AS monitors_enabled + COALESCE(webhook_actions.webhook_actions_enabled, 0) AS monitors_enabled, + -- monitors_enabled_unique_users + COALESCE(slack_actions.slack_actions_enabled_unique_users, 0) + + COALESCE(email_actions.email_actions_enabled_unique_users, 0) + + COALESCE(webhook_actions.webhook_actions_enabled_unique_users, 0) AS monitors_enabled_unique_users FROM event_log_stats, email_actions,