@@ -12,9 +12,6 @@ package schematelemetrycontroller
1212
1313import (
1414 "context"
15- "fmt"
16- "hash/fnv"
17- "math/rand"
1815 "time"
1916
2017 "github.com/cockroachdb/cockroach/pkg/jobs"
@@ -39,19 +36,13 @@ import (
3936// SchemaTelemetryScheduleName is the name of the schema telemetry schedule.
4037const SchemaTelemetryScheduleName = "sql-schema-telemetry"
4138
42- const (
43- cronWeekly = "@weekly"
44- cronDaily = "@daily"
45- cronHourly = "@hourly"
46- )
47-
4839// SchemaTelemetryRecurrence is the cron-tab string specifying the recurrence
4940// for schema telemetry job.
5041var SchemaTelemetryRecurrence = settings .RegisterValidatedStringSetting (
5142 settings .TenantReadOnly ,
5243 "sql.schema.telemetry.recurrence" ,
5344 "cron-tab recurrence for SQL schema telemetry job" ,
54- cronWeekly , /* defaultValue */
45+ "@weekly" , /* defaultValue */
5546 func (_ * settings.Values , s string ) error {
5647 if _ , err := cron .ParseStandard (s ); err != nil {
5748 return errors .Wrap (err , "invalid cron expression" )
@@ -166,7 +157,7 @@ func updateSchedule(ctx context.Context, db isql.DB, st *cluster.Settings, clust
166157 }
167158 }
168159 // Update schedule with new recurrence, if different.
169- cronExpr := MaybeRewriteCronExpr (
160+ cronExpr := scheduledjobs . MaybeRewriteCronExpr (
170161 clusterID , SchemaTelemetryRecurrence .Get (& st .SV ),
171162 )
172163 if sj .ScheduleExpr () == cronExpr {
@@ -185,34 +176,6 @@ func updateSchedule(ctx context.Context, db isql.DB, st *cluster.Settings, clust
185176 }
186177}
187178
188- // MaybeRewriteCronExpr is used to rewrite the interval-oriented cron exprs
189- // into an equivalent frequency interval but with an offset derived from the
190- // uuid. For a given pair of inputs, the output of this function will always
191- // be the same. If the input cronExpr is not a special form as denoted by
192- // the keys of cronExprRewrites, it will be returned unmodified. This rewrite
193- // occurs in order to uniformly distribute the production of telemetry logs
194- // over the intended time interval to avoid bursts.
195- func MaybeRewriteCronExpr (id uuid.UUID , cronExpr string ) string {
196- if f , ok := cronExprRewrites [cronExpr ]; ok {
197- hash := fnv .New64a () // arbitrary hash function
198- _ , _ = hash .Write (id .GetBytes ())
199- return f (rand .New (rand .NewSource (int64 (hash .Sum64 ()))))
200- }
201- return cronExpr
202- }
203-
204- var cronExprRewrites = map [string ]func (r * rand.Rand ) string {
205- cronWeekly : func (r * rand.Rand ) string {
206- return fmt .Sprintf ("%d %d * * %d" , r .Intn (60 ), r .Intn (23 ), r .Intn (7 ))
207- },
208- cronDaily : func (r * rand.Rand ) string {
209- return fmt .Sprintf ("%d %d * * *" , r .Intn (60 ), r .Intn (23 ))
210- },
211- cronHourly : func (r * rand.Rand ) string {
212- return fmt .Sprintf ("%d * * * *" , r .Intn (60 ))
213- },
214- }
215-
216179// CreateSchemaTelemetryJob is part of the eval.SchemaTelemetryController
217180// interface.
218181func (c * Controller ) CreateSchemaTelemetryJob (
0 commit comments