mirror of
https://github.com/prometheus-community/postgres_exporter
synced 2025-04-08 02:01:23 +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)
|
||||
}
|
||||
|
||||
// TODO: fix linter override
|
||||
// nolint: nakedret
|
||||
func (s *pgSetting) normaliseUnit() (val float64, unit string, err error) {
|
||||
val, err = strconv.ParseFloat(s.setting, 64)
|
||||
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.")
|
||||
thisMap[columnName] = MetricMap{
|
||||
discard: true,
|
||||
conversion: func(in interface{}) (float64, bool) {
|
||||
conversion: func(_ interface{}) (float64, bool) {
|
||||
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.
|
||||
// nolint: dupl
|
||||
switch columnMapping.usage {
|
||||
case DISCARD, LABEL:
|
||||
thisMap[columnName] = MetricMap{
|
||||
discard: true,
|
||||
conversion: func(in interface{}) (float64, bool) {
|
||||
conversion: func(_ interface{}) (float64, bool) {
|
||||
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
|
||||
func stringToColumnUsage(s string) (u ColumnUsage, err error) {
|
||||
func stringToColumnUsage(s string) (ColumnUsage, error) {
|
||||
var u ColumnUsage
|
||||
var err error
|
||||
switch s {
|
||||
case "DISCARD":
|
||||
u = DISCARD
|
||||
@ -602,7 +605,7 @@ func stringToColumnUsage(s string) (u ColumnUsage, err error) {
|
||||
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
|
||||
@ -794,10 +797,9 @@ func queryNamespaceMapping(ch chan<- prometheus.Metric, db *sql.DB, namespace st
|
||||
if !found {
|
||||
// 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?
|
||||
// nolint: gas
|
||||
rows, err = db.Query(fmt.Sprintf("SELECT * FROM %s;", namespace))
|
||||
rows, err = db.Query(fmt.Sprintf("SELECT * FROM %s;", namespace)) // nolint: gas, safesql
|
||||
} else {
|
||||
rows, err = db.Query(query)
|
||||
rows, err = db.Query(query) // nolint: safesql
|
||||
}
|
||||
if err != nil {
|
||||
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 {
|
||||
log.Debugln("Querying namespace: ", namespace)
|
||||
nonFatalErrors, err := queryNamespaceMapping(ch, db, namespace, mapping, queryOverrides)
|
||||
// Serious error - a namespace disappeard
|
||||
// Serious error - a namespace disappeared
|
||||
if err != nil {
|
||||
namespaceErrors[namespace] = 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
|
||||
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
|
||||
discardableMetric := testMetricMap["test_namespace"]["metric_which_discards"]
|
||||
|
Loading…
Reference in New Issue
Block a user