From 82039e82a16ff941fa134e525f7893be045668e1 Mon Sep 17 00:00:00 2001 From: Ilya Mashchenko Date: Fri, 9 Jun 2023 21:24:55 +0300 Subject: [PATCH] postgres: configurable table/index limits (#1200) --- config/go.d/postgres.conf | 13 +++++++++++++ modules/postgres/do_query_misc.go | 7 +++---- modules/postgres/postgres.go | 6 ++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/config/go.d/postgres.conf b/config/go.d/postgres.conf index c8722adf6..a716776de 100644 --- a/config/go.d/postgres.conf +++ b/config/go.d/postgres.conf @@ -62,6 +62,19 @@ # Syntax: # dsn: postgres://postgres:postgres@127.0.0.1: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 diff --git a/modules/postgres/do_query_misc.go b/modules/postgres/do_query_misc.go index 13cb644fb..a2299c8b4 100644 --- a/modules/postgres/do_query_misc.go +++ b/modules/postgres/do_query_misc.go @@ -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) diff --git a/modules/postgres/postgres.go b/modules/postgres/postgres.go index 9479ba107..db63929e2 100644 --- a/modules/postgres/postgres.go +++ b/modules/postgres/postgres.go @@ -29,6 +29,10 @@ func New() *Postgres { DSN: "postgres://postgres:postgres@127.0.0.1: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), @@ -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 (