collectUserSecretsSummary returns a deployment-wide aggregate of user secrets configuration. Returns nil if another replica has already collected for this period. The summary has no natural per-row UUID for the telemetry server to de-duplicate on, so we elect a single replica per snapshot period vi
(ctx context.Context)
| 972 | // de-duplicate on, so we elect a single replica per snapshot period |
| 973 | // via the telemetry_locks table. |
| 974 | func (r *remoteReporter) collectUserSecretsSummary(ctx context.Context) (*UserSecretsSummary, error) { |
| 975 | // Claim the telemetry lock for this period. Use snapshot frequency so |
| 976 | // each telemetry snapshot period gets exactly one collection across |
| 977 | // replicas. |
| 978 | periodEndingAt := dbtime.Time(r.options.Clock.Now()).UTC().Truncate(r.options.SnapshotFrequency) |
| 979 | err := r.options.Database.InsertTelemetryLock(ctx, database.InsertTelemetryLockParams{ |
| 980 | EventType: "user_secrets_summary", |
| 981 | PeriodEndingAt: periodEndingAt, |
| 982 | }) |
| 983 | if database.IsUniqueViolation(err, database.UniqueTelemetryLocksPkey) { |
| 984 | r.options.Logger.Debug(ctx, "user secrets telemetry lock already claimed by another replica, skipping", slog.F("period_ending_at", periodEndingAt)) |
| 985 | return nil, nil //nolint:nilnil // This is simple to handle when dealing with telemetry. |
| 986 | } |
| 987 | if err != nil { |
| 988 | return nil, xerrors.Errorf("insert user secrets telemetry lock (period_ending_at=%q): %w", periodEndingAt, err) |
| 989 | } |
| 990 | |
| 991 | row, err := r.options.Database.GetUserSecretsTelemetrySummary(ctx) |
| 992 | if err != nil { |
| 993 | return nil, xerrors.Errorf("get user secrets telemetry summary: %w", err) |
| 994 | } |
| 995 | return &UserSecretsSummary{ |
| 996 | UsersWithSecrets: row.UsersWithSecrets, |
| 997 | TotalSecrets: row.TotalSecrets, |
| 998 | EnvNameOnly: row.EnvNameOnly, |
| 999 | FilePathOnly: row.FilePathOnly, |
| 1000 | Both: row.Both, |
| 1001 | Neither: row.Neither, |
| 1002 | SecretsPerUserMax: row.SecretsPerUserMax, |
| 1003 | SecretsPerUserP25: row.SecretsPerUserP25, |
| 1004 | SecretsPerUserP50: row.SecretsPerUserP50, |
| 1005 | SecretsPerUserP75: row.SecretsPerUserP75, |
| 1006 | SecretsPerUserP90: row.SecretsPerUserP90, |
| 1007 | }, nil |
| 1008 | } |
| 1009 | |
| 1010 | func CollectTasks(ctx context.Context, db database.Store) ([]Task, error) { |
| 1011 | dbTasks, err := db.ListTasks(ctx, database.ListTasksParams{ |
no test coverage detected