feat(inputs.postgresql_extensible): Introduce max_version for query (#13620)
This commit is contained in:
parent
ab99bf32b6
commit
22100d4914
|
|
@ -68,22 +68,33 @@ to use them.
|
||||||
# default, all rows inserted with current time. By setting a timestamp column,
|
# default, all rows inserted with current time. By setting a timestamp column,
|
||||||
# the row will be inserted with that column's value.
|
# the row will be inserted with that column's value.
|
||||||
#
|
#
|
||||||
|
# The min_version field specifies minimal database version this query
|
||||||
|
# will run on.
|
||||||
|
#
|
||||||
|
# The max_version field when set specifies maximal database version
|
||||||
|
# this query will NOT run on.
|
||||||
|
#
|
||||||
|
# Database version in `minversion` and `maxversion` is represented as
|
||||||
|
# a single integer without last component, for example:
|
||||||
|
# 9.6.2 -> 906
|
||||||
|
# 15.2 -> 1500
|
||||||
|
#
|
||||||
# Structure :
|
# Structure :
|
||||||
# [[inputs.postgresql_extensible.query]]
|
# [[inputs.postgresql_extensible.query]]
|
||||||
# sqlquery string
|
# sqlquery string
|
||||||
# version string
|
# min_version int
|
||||||
|
# max_version int
|
||||||
# withdbname boolean
|
# withdbname boolean
|
||||||
# tagvalue string (coma separated)
|
# tagvalue string (coma separated)
|
||||||
# timestamp string
|
# timestamp string
|
||||||
[[inputs.postgresql_extensible.query]]
|
[[inputs.postgresql_extensible.query]]
|
||||||
sqlquery="SELECT * FROM pg_stat_database where datname"
|
sqlquery="SELECT * FROM pg_stat_database where datname"
|
||||||
version=901
|
min_version=901
|
||||||
withdbname=false
|
|
||||||
tagvalue=""
|
tagvalue=""
|
||||||
[[inputs.postgresql_extensible.query]]
|
[[inputs.postgresql_extensible.query]]
|
||||||
script="your_sql-filepath.sql"
|
script="your_sql-filepath.sql"
|
||||||
version=901
|
min_version=901
|
||||||
withdbname=false
|
max_version=1300
|
||||||
tagvalue=""
|
tagvalue=""
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,9 @@ type Postgresql struct {
|
||||||
type query []struct {
|
type query []struct {
|
||||||
Sqlquery string
|
Sqlquery string
|
||||||
Script string
|
Script string
|
||||||
Version int
|
Version int `deprecated:"1.28.0;use minVersion to specify minimal DB version this query supports"`
|
||||||
|
MinVersion int `toml:"min_version"`
|
||||||
|
MaxVersion int `toml:"max_version"`
|
||||||
Withdbname bool `deprecated:"1.22.4;use the sqlquery option to specify database to use"`
|
Withdbname bool `deprecated:"1.22.4;use the sqlquery option to specify database to use"`
|
||||||
Tagvalue string
|
Tagvalue string
|
||||||
Measurement string
|
Measurement string
|
||||||
|
|
@ -59,6 +61,9 @@ func (p *Postgresql) Init() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if p.Query[i].MinVersion == 0 {
|
||||||
|
p.Query[i].MinVersion = p.Query[i].Version
|
||||||
|
}
|
||||||
}
|
}
|
||||||
p.Service.IsPgBouncer = !p.PreparedStatements
|
p.Service.IsPgBouncer = !p.PreparedStatements
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -120,7 +125,9 @@ func (p *Postgresql) Gather(acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
sqlQuery += queryAddon
|
sqlQuery += queryAddon
|
||||||
|
|
||||||
if p.Query[i].Version <= dbVersion {
|
maxVer := p.Query[i].MaxVersion
|
||||||
|
|
||||||
|
if p.Query[i].MinVersion <= dbVersion && (maxVer == 0 || maxVer > dbVersion) {
|
||||||
p.gatherMetricsFromQuery(acc, sqlQuery, p.Query[i].Tagvalue, p.Query[i].Timestamp, measName)
|
p.gatherMetricsFromQuery(acc, sqlQuery, p.Query[i].Tagvalue, p.Query[i].Timestamp, measName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ func TestPostgresqlGeneratesMetricsIntegration(t *testing.T) {
|
||||||
|
|
||||||
acc := queryRunner(t, query{{
|
acc := queryRunner(t, query{{
|
||||||
Sqlquery: "select * from pg_stat_database",
|
Sqlquery: "select * from pg_stat_database",
|
||||||
Version: 901,
|
MinVersion: 901,
|
||||||
Withdbname: false,
|
Withdbname: false,
|
||||||
Tagvalue: "",
|
Tagvalue: "",
|
||||||
}})
|
}})
|
||||||
|
|
@ -163,7 +163,7 @@ func TestPostgresqlQueryOutputTestsIntegration(t *testing.T) {
|
||||||
for q, assertions := range examples {
|
for q, assertions := range examples {
|
||||||
acc := queryRunner(t, query{{
|
acc := queryRunner(t, query{{
|
||||||
Sqlquery: q,
|
Sqlquery: q,
|
||||||
Version: 901,
|
MinVersion: 901,
|
||||||
Withdbname: false,
|
Withdbname: false,
|
||||||
Tagvalue: "",
|
Tagvalue: "",
|
||||||
Timestamp: "ts",
|
Timestamp: "ts",
|
||||||
|
|
@ -180,7 +180,7 @@ func TestPostgresqlFieldOutputIntegration(t *testing.T) {
|
||||||
|
|
||||||
acc := queryRunner(t, query{{
|
acc := queryRunner(t, query{{
|
||||||
Sqlquery: "select * from pg_stat_database",
|
Sqlquery: "select * from pg_stat_database",
|
||||||
Version: 901,
|
MinVersion: 901,
|
||||||
Withdbname: false,
|
Withdbname: false,
|
||||||
Tagvalue: "",
|
Tagvalue: "",
|
||||||
}})
|
}})
|
||||||
|
|
@ -238,7 +238,7 @@ func TestPostgresqlFieldOutputIntegration(t *testing.T) {
|
||||||
func TestPostgresqlSqlScript(t *testing.T) {
|
func TestPostgresqlSqlScript(t *testing.T) {
|
||||||
q := query{{
|
q := query{{
|
||||||
Script: "testdata/test.sql",
|
Script: "testdata/test.sql",
|
||||||
Version: 901,
|
MinVersion: 901,
|
||||||
Withdbname: false,
|
Withdbname: false,
|
||||||
Tagvalue: "",
|
Tagvalue: "",
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -35,20 +35,31 @@
|
||||||
# default, all rows inserted with current time. By setting a timestamp column,
|
# default, all rows inserted with current time. By setting a timestamp column,
|
||||||
# the row will be inserted with that column's value.
|
# the row will be inserted with that column's value.
|
||||||
#
|
#
|
||||||
|
# The min_version field specifies minimal database version this query
|
||||||
|
# will run on.
|
||||||
|
#
|
||||||
|
# The max_version field when set specifies maximal database version
|
||||||
|
# this query will NOT run on.
|
||||||
|
#
|
||||||
|
# Database version in `minversion` and `maxversion` is represented as
|
||||||
|
# a single integer without last component, for example:
|
||||||
|
# 9.6.2 -> 906
|
||||||
|
# 15.2 -> 1500
|
||||||
|
#
|
||||||
# Structure :
|
# Structure :
|
||||||
# [[inputs.postgresql_extensible.query]]
|
# [[inputs.postgresql_extensible.query]]
|
||||||
# sqlquery string
|
# sqlquery string
|
||||||
# version string
|
# min_version int
|
||||||
|
# max_version int
|
||||||
# withdbname boolean
|
# withdbname boolean
|
||||||
# tagvalue string (coma separated)
|
# tagvalue string (coma separated)
|
||||||
# timestamp string
|
# timestamp string
|
||||||
[[inputs.postgresql_extensible.query]]
|
[[inputs.postgresql_extensible.query]]
|
||||||
sqlquery="SELECT * FROM pg_stat_database where datname"
|
sqlquery="SELECT * FROM pg_stat_database where datname"
|
||||||
version=901
|
min_version=901
|
||||||
withdbname=false
|
|
||||||
tagvalue=""
|
tagvalue=""
|
||||||
[[inputs.postgresql_extensible.query]]
|
[[inputs.postgresql_extensible.query]]
|
||||||
script="your_sql-filepath.sql"
|
script="your_sql-filepath.sql"
|
||||||
version=901
|
min_version=901
|
||||||
withdbname=false
|
max_version=1300
|
||||||
tagvalue=""
|
tagvalue=""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue