Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
postgres: configurable table/index limits (#1200)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyam8 authored Jun 9, 2023
1 parent 627d28e commit 82039e8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
13 changes: 13 additions & 0 deletions config/go.d/postgres.conf
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@
# Syntax:
# dsn: postgres://postgres:[email protected]:5432/postgres
#
# - max_db_tables
# Maximum number of tables in the database.
# Table metrics will not be collected for databases that have more tables than max_db_tables.
# Default is 50. 0 means no limit.
# Syntax:
# max_db_tables: 50
#
# - max_db_indexes
# Maximum number of indexes in the database.
# Index metrics will not be collected for databases that have more indexes than max_db_indexes. 0 means no limit.
# Default is 250. 0 means no limit.
# Syntax:
# max_db_indexes: 250
#
# [ JOB defaults ]:
# No parameters
Expand Down
7 changes: 3 additions & 4 deletions modules/postgres/do_query_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,9 @@ func (p *Postgres) doQueryQueryableDatabases() error {
continue
}

// charts: 20 x table, 4 x index.
// https://discord.com/channels/847502280503590932/1022693928874549368
if tables > 50 || indexes > 250 {
p.Warningf("database '%s' has too many user tables(%d)/indexes(%d), skipping it", dbname, tables, indexes)
if (p.MaxDBTables != 0 && tables > p.MaxDBTables) || (p.MaxDBIndexes != 0 && indexes > p.MaxDBIndexes) {
p.Warningf("database '%s' has too many user tables(%d/%d)/indexes(%d/%d), skipping it",
dbname, tables, p.MaxDBTables, indexes, p.MaxDBIndexes)
conn.connErrors = connErrMax
_ = db.Close()
stdlib.UnregisterConnConfig(connStr)
Expand Down
6 changes: 6 additions & 0 deletions modules/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func New() *Postgres {
DSN: "postgres://postgres:[email protected]:5432/postgres",
XactTimeHistogram: []float64{.1, .5, 1, 2.5, 5, 10},
QueryTimeHistogram: []float64{.1, .5, 1, 2.5, 5, 10},
// charts: 20 x table, 4 x index.
// https://discord.com/channels/847502280503590932/1022693928874549368
MaxDBTables: 50,
MaxDBIndexes: 250,
},
charts: baseCharts.Copy(),
dbConns: make(map[string]*dbConn),
Expand All @@ -52,6 +56,8 @@ type Config struct {
DBSelector string `yaml:"collect_databases_matching"`
XactTimeHistogram []float64 `yaml:"transaction_time_histogram"`
QueryTimeHistogram []float64 `yaml:"query_time_histogram"`
MaxDBTables int64 `yaml:"max_db_tables"`
MaxDBIndexes int64 `yaml:"max_db_indexes"`
}

type (
Expand Down

0 comments on commit 82039e8

Please sign in to comment.