You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[+] support custom configs for maintenance tasks (#1018)
* Introduce `--maintenance-interval` flag
- modify `--retention` to accept PostgreSQL interval string.
* Use new flags to control deletion and maintenance tasks.
* Test `MaintainUniqueSources()` and `DeleteOldPartitions()`
* update docs reference page to mention new flag.
* run `DeleteOldPartitions()` with `retentionInterval` not `maintenanceInterval`
* Rename test
* Capitalize `set` in flag description.
* Fix typo in comment
* rename `CmdOpts.Retention` to `RetentionInterval`
* add `PostgresWriter.scheduleJob()` function
---------
Co-authored-by: Pavlo Golub <pavlo.golub@gmail.com>
Copy file name to clipboardExpand all lines: internal/sinks/cmdopts.go
+3-2Lines changed: 3 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -6,8 +6,9 @@ import "time"
6
6
typeCmdOptsstruct {
7
7
Sinks []string`long:"sink" mapstructure:"sink" description:"URI where metrics will be stored, can be used multiple times" env:"PW_SINK"`
8
8
BatchingDelay time.Duration`long:"batching-delay" mapstructure:"batching-delay" description:"Sink-specific batching flush delay; may be ignored by some sinks" default:"950ms" env:"PW_BATCHING_DELAY"`
9
-
PartitionIntervalstring`long:"partition-interval" mapstructure:"partition-interval" description:"Time range for PostgreSQL sink table partitions. Must be a valid PostgreSQL interval expression." default:"1 week" env:"PW_PARTITION_INTERVAL"`
10
-
Retentionstring`long:"retention" mapstructure:"retention" description:"If set, metrics older than that will be deleted" default:"14 days" env:"PW_RETENTION"`
9
+
PartitionIntervalstring`long:"partition-interval" mapstructure:"partition-interval" description:"Time range for PostgreSQL sink time partitions. Must be a valid PostgreSQL interval." default:"1 week" env:"PW_PARTITION_INTERVAL"`
10
+
RetentionIntervalstring`long:"retention" mapstructure:"retention" description:"Delete metrics older than this. Set to zero to disable. Must be a valid PostgreSQL interval." default:"14 days" env:"PW_RETENTION"`
11
+
MaintenanceIntervalstring`long:"maintenance-interval" mapstructure:"maintenance-interval" description:"Run pgwatch maintenance tasks on sinks with this interval; Set to zero to disable. Must be a valid PostgreSQL interval." default:"12 hours" env:"PW_MAINTENANCE_INTERVAL"`
11
12
RealDbnameFieldstring`long:"real-dbname-field" mapstructure:"real-dbname-field" description:"Tag key for real database name" env:"PW_REAL_DBNAME_FIELD" default:"real_dbname"`
12
13
SystemIdentifierFieldstring`long:"system-identifier-field" mapstructure:"system-identifier-field" description:"Tag key for system identifier value" env:"PW_SYSTEM_IDENTIFIER_FIELD" default:"sys_id"`
// due to metrics deletion the listing can go out of sync (a trigger not really wanted)
511
+
492
512
sqlGetAdvisoryLock:=`SELECT pg_try_advisory_lock(1571543679778230000) AS have_lock`// 1571543679778230000 is just a random bigint
493
513
sqlTopLevelMetrics:=`SELECT table_name FROM admin.get_top_level_metric_tables()`
494
514
sqlDistinct:=`
495
515
WITH RECURSIVE t(dbname) AS (
496
516
SELECT MIN(dbname) AS dbname FROM %s
497
517
UNION
498
-
SELECT (SELECT MIN(dbname) FROM %s WHERE dbname > t.dbname) FROM t )
518
+
SELECT (SELECT MIN(dbname) FROM %s WHERE dbname > t.dbname) FROM t
519
+
)
499
520
SELECT dbname FROM t WHERE dbname NOTNULL ORDER BY 1`
500
521
sqlDelete:=`DELETE FROM admin.all_distinct_dbname_metrics WHERE NOT dbname = ANY($1) and metric = $2`
501
522
sqlDeleteAll:=`DELETE FROM admin.all_distinct_dbname_metrics WHERE metric = $1`
502
523
sqlAdd:=`
503
-
INSERT INTO admin.all_distinct_dbname_metrics SELECT u, $2 FROM (select unnest($1::text[]) as u) x
524
+
INSERT INTO admin.all_distinct_dbname_metrics
525
+
SELECT u, $2 FROM (select unnest($1::text[]) as u) x
504
526
WHERE NOT EXISTS (select * from admin.all_distinct_dbname_metrics where dbname = u and metric = $2)
505
527
RETURNING *`
506
528
507
-
for {
508
-
select {
509
-
case<-pgw.ctx.Done():
510
-
return
511
-
case<-time.After(time.Hour*24):
512
-
}
513
-
varlockbool
514
-
logger.Infof("Trying to get metricsDb listing maintainer advisory lock...") // to only have one "maintainer" in case of a "push" setup, as can get costly
logger.Info("Skipping admin.all_distinct_dbname_metrics maintenance as another instance has the advisory lock...")
521
-
continue
522
-
}
529
+
varlockbool
530
+
logger.Infof("Trying to get admin.all_distinct_dbname_metrics maintainer advisory lock...") // to only have one "maintainer" in case of a "push" setup, as can get costly
0 commit comments