mirror of
https://github.com/prometheus-community/postgres_exporter
synced 2025-04-23 23:45:28 +00:00
Fix new linter issues.
This commit is contained in:
parent
9118b7c814
commit
5abe56d1fc
@ -82,6 +82,8 @@ func (s *pgSetting) metric() prometheus.Metric {
|
|||||||
return prometheus.MustNewConstMetric(desc, prometheus.GaugeValue, val)
|
return prometheus.MustNewConstMetric(desc, prometheus.GaugeValue, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: fix linter override
|
||||||
|
// nolint: nakedret
|
||||||
func (s *pgSetting) normaliseUnit() (val float64, unit string, err error) {
|
func (s *pgSetting) normaliseUnit() (val float64, unit string, err error) {
|
||||||
val, err = strconv.ParseFloat(s.setting, 64)
|
val, err = strconv.ParseFloat(s.setting, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -490,7 +490,7 @@ func makeDescMap(pgVersion semver.Version, metricMaps map[string]map[string]Colu
|
|||||||
log.Debugln(columnName, "is being forced to discard due to version incompatibility.")
|
log.Debugln(columnName, "is being forced to discard due to version incompatibility.")
|
||||||
thisMap[columnName] = MetricMap{
|
thisMap[columnName] = MetricMap{
|
||||||
discard: true,
|
discard: true,
|
||||||
conversion: func(in interface{}) (float64, bool) {
|
conversion: func(_ interface{}) (float64, bool) {
|
||||||
return math.NaN(), true
|
return math.NaN(), true
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -499,11 +499,12 @@ func makeDescMap(pgVersion semver.Version, metricMaps map[string]map[string]Colu
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Determine how to convert the column based on its usage.
|
// Determine how to convert the column based on its usage.
|
||||||
|
// nolint: dupl
|
||||||
switch columnMapping.usage {
|
switch columnMapping.usage {
|
||||||
case DISCARD, LABEL:
|
case DISCARD, LABEL:
|
||||||
thisMap[columnName] = MetricMap{
|
thisMap[columnName] = MetricMap{
|
||||||
discard: true,
|
discard: true,
|
||||||
conversion: func(in interface{}) (float64, bool) {
|
conversion: func(_ interface{}) (float64, bool) {
|
||||||
return math.NaN(), true
|
return math.NaN(), true
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -578,7 +579,9 @@ func makeDescMap(pgVersion semver.Version, metricMaps map[string]map[string]Colu
|
|||||||
}
|
}
|
||||||
|
|
||||||
// convert a string to the corresponding ColumnUsage
|
// convert a string to the corresponding ColumnUsage
|
||||||
func stringToColumnUsage(s string) (u ColumnUsage, err error) {
|
func stringToColumnUsage(s string) (ColumnUsage, error) {
|
||||||
|
var u ColumnUsage
|
||||||
|
var err error
|
||||||
switch s {
|
switch s {
|
||||||
case "DISCARD":
|
case "DISCARD":
|
||||||
u = DISCARD
|
u = DISCARD
|
||||||
@ -602,7 +605,7 @@ func stringToColumnUsage(s string) (u ColumnUsage, err error) {
|
|||||||
err = fmt.Errorf("wrong ColumnUsage given : %s", s)
|
err = fmt.Errorf("wrong ColumnUsage given : %s", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return u, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert database.sql types to float64s for Prometheus consumption. Null types are mapped to NaN. string and []byte
|
// Convert database.sql types to float64s for Prometheus consumption. Null types are mapped to NaN. string and []byte
|
||||||
@ -794,10 +797,9 @@ func queryNamespaceMapping(ch chan<- prometheus.Metric, db *sql.DB, namespace st
|
|||||||
if !found {
|
if !found {
|
||||||
// I've no idea how to avoid this properly at the moment, but this is
|
// I've no idea how to avoid this properly at the moment, but this is
|
||||||
// an admin tool so you're not injecting SQL right?
|
// an admin tool so you're not injecting SQL right?
|
||||||
// nolint: gas
|
rows, err = db.Query(fmt.Sprintf("SELECT * FROM %s;", namespace)) // nolint: gas, safesql
|
||||||
rows, err = db.Query(fmt.Sprintf("SELECT * FROM %s;", namespace))
|
|
||||||
} else {
|
} else {
|
||||||
rows, err = db.Query(query)
|
rows, err = db.Query(query) // nolint: safesql
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []error{}, errors.New(fmt.Sprintln("Error running query on database: ", namespace, err))
|
return []error{}, errors.New(fmt.Sprintln("Error running query on database: ", namespace, err))
|
||||||
@ -882,7 +884,7 @@ func queryNamespaceMappings(ch chan<- prometheus.Metric, db *sql.DB, metricMap m
|
|||||||
for namespace, mapping := range metricMap {
|
for namespace, mapping := range metricMap {
|
||||||
log.Debugln("Querying namespace: ", namespace)
|
log.Debugln("Querying namespace: ", namespace)
|
||||||
nonFatalErrors, err := queryNamespaceMapping(ch, db, namespace, mapping, queryOverrides)
|
nonFatalErrors, err := queryNamespaceMapping(ch, db, namespace, mapping, queryOverrides)
|
||||||
// Serious error - a namespace disappeard
|
// Serious error - a namespace disappeared
|
||||||
if err != nil {
|
if err != nil {
|
||||||
namespaceErrors[namespace] = err
|
namespaceErrors[namespace] = err
|
||||||
log.Infoln(err)
|
log.Infoln(err)
|
||||||
|
@ -47,6 +47,7 @@ func (s *FunctionalSuite) TestSemanticVersionColumnDiscard(c *C) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nolint: dupl
|
||||||
{
|
{
|
||||||
// Update the map so the discard metric should be eliminated
|
// Update the map so the discard metric should be eliminated
|
||||||
discardableMetric := testMetricMap["test_namespace"]["metric_which_discards"]
|
discardableMetric := testMetricMap["test_namespace"]["metric_which_discards"]
|
||||||
@ -67,6 +68,7 @@ func (s *FunctionalSuite) TestSemanticVersionColumnDiscard(c *C) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nolint: dupl
|
||||||
{
|
{
|
||||||
// Update the map so the discard metric should be kept but has a version
|
// Update the map so the discard metric should be kept but has a version
|
||||||
discardableMetric := testMetricMap["test_namespace"]["metric_which_discards"]
|
discardableMetric := testMetricMap["test_namespace"]["metric_which_discards"]
|
||||||
|
Loading…
Reference in New Issue
Block a user