Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMM-8646 postgres_exporter on stalled after intermittent connection latency. #48

Closed
wants to merge 97 commits into from

Conversation

JiriCtvrtka
Copy link

@JiriCtvrtka JiriCtvrtka commented Sep 9, 2021

Our exporter merged with upstream one. Remains fix many lint errors to pass build and then test new functionality.

arvenil and others added 30 commits July 30, 2018 21:48
PMM-2705: Add security code. Rebrand exporter.
Test with all PostgreSQL versions README claims are supported.
…ds-for-PostgreSQL

PMM-3436 investigate some dashboards for PostgreSQL
# Conflicts:
#	.travis.yml
#	Makefile
#	README.md
#	cmd/postgres_exporter/pg_setting.go
#	cmd/postgres_exporter/postgres_exporter.go
#	cmd/postgres_exporter/postgres_exporter_integration_test.go
- Added Go 1.13.x
- Made it skip non-trunk PMM-XXXX branch builds, but still build pull requests.
* PMM-5723 Reviewdog checks.

* PMM-5723 Add golangci config.

* PMM-5723 Reviewdog required rules.

* PMM-5723 Github token for reviewdog.

* PMM-5723 Fix tests.

Co-authored-by: Andrii Skomorokhov <andrii.skomorokhov@percona.com>
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

golangci-lint

cmd/postgres_exporter/main.go|62| line is 196 characters (lll)
cmd/postgres_exporter/main.go|63| line is 194 characters (lll)
cmd/postgres_exporter/namespace.go|106| line is 149 characters (lll)
cmd/postgres_exporter/namespace.go|112| line is 142 characters (lll)
cmd/postgres_exporter/namespace.go|117| line is 155 characters (lll)
cmd/postgres_exporter/namespace.go|135| line is 173 characters (lll)
cmd/postgres_exporter/namespace.go|141| line is 141 characters (lll)
cmd/postgres_exporter/namespace.go|146| line is 175 characters (lll)
cmd/postgres_exporter/namespace.go|158| line is 166 characters (lll)
cmd/postgres_exporter/namespace.go|173| line is 155 characters (lll)
cmd/postgres_exporter/namespace.go|96 col 4| if ok is deeply nested (complexity: 23) (nestif)
cmd/postgres_exporter/datasource.go|98 col 2| if len(dsn) == 0 is deeply nested (complexity: 12) (nestif)
cmd/postgres_exporter/queries.go|255 col 75| addQueries - result 0 (error) is always nil (unparam)
cmd/postgres_exporter/datasource.go|38 col 3| only one cuddle assignment allowed before if statement (wsl)
cmd/postgres_exporter/datasource.go|49 col 3| if statements should only be cuddled with assignments (wsl)
cmd/postgres_exporter/datasource.go|57 col 4| assignments should only be cuddled with other assignments (wsl)
cmd/postgres_exporter/datasource.go|53 col 3| only one cuddle assignment allowed before range statement (wsl)
cmd/postgres_exporter/datasource.go|29 col 2| ranges should only be cuddled with assignments used in the iteration (wsl)
cmd/postgres_exporter/datasource.go|64 col 2| only one cuddle assignment allowed before range statement (wsl)
cmd/postgres_exporter/datasource.go|100 col 3| declarations should never be cuddled (wsl)
cmd/postgres_exporter/datasource.go|101 col 3| declarations should never be cuddled (wsl)
cmd/postgres_exporter/datasource.go|108 col 4| assignments should only be cuddled with other assignments (wsl)
cmd/postgres_exporter/datasource.go|118 col 4| assignments should only be cuddled with other assignments (wsl)
cmd/postgres_exporter/datasource.go|139 col 2| return statements should not be cuddled if block has more than two lines (wsl)
cmd/postgres_exporter/namespace.go|43 col 2| declarations should never be cuddled (wsl)
cmd/postgres_exporter/namespace.go|52 col 2| if statements should only be cuddled with assignments (wsl)
cmd/postgres_exporter/namespace.go|59 col 2| only one cuddle assignment allowed before if statement (wsl)
cmd/postgres_exporter/namespace.go|71 col 2| only one cuddle assignment allowed before range statement (wsl)
cmd/postgres_exporter/namespace.go|105 col 6| only one cuddle assignment allowed before if statement (wsl)
cmd/postgres_exporter/namespace.go|121 col 6| ranges should only be cuddled with assignments used in the iteration (wsl)
cmd/postgres_exporter/namespace.go|178 col 4| append only allowed to cuddle with appended value (wsl)
cmd/postgres_exporter/namespace.go|181 col 2| return statements should not be cuddled if block has more than two lines (wsl)
cmd/postgres_exporter/queries.go|190 col 5| branch statements should not be cuddled if block has more than two lines (wsl)
cmd/postgres_exporter/queries.go|304 col 3| append only allowed to cuddle with appended value (wsl)
cmd/postgres_exporter/server.go|174 col 4| branch statements should not be cuddled if block has more than two lines (wsl)
cmd/postgres_exporter/server.go|158 col 2| for statement without condition should never be cuddled (wsl)
cmd/postgres_exporter/util.go|41 col 2| only one cuddle assignment allowed before switch statement (wsl)
cmd/postgres_exporter/util.go|72 col 1| calculated cyclomatic complexity for function dbToFloat64 is 12, max is 10 (cyclop)
cmd/postgres_exporter/util.go|110 col 1| calculated cyclomatic complexity for function dbToUint64 is 13, max is 10 (cyclop)
cmd/postgres_exporter/namespace.go|53 col 119| non-wrapping format verb for fmt.Errorf. Use %w to format errors (errorlint)
cmd/postgres_exporter/main.go|140 col 48| PidFn, Namespace, ReportErrors are missing in ProcessCollectorOpts (exhaustivestruct)
cmd/postgres_exporter/server.go|76 col 8| runonserver, lastMapVersion, metricMap, queryOverrides, mappingMtx, cacheMtx are missing in Server (exhaustivestruct)
cmd/postgres_exporter/server.go|143 col 10| m is missing in Servers (exhaustivestruct)
cmd/postgres_exporter/main.go|29 col 5| Branch is a global variable (gochecknoglobals)
cmd/postgres_exporter/main.go|32 col 5| BuildDate is a global variable (gochecknoglobals)
cmd/postgres_exporter/main.go|35 col 5| Revision is a global variable (gochecknoglobals)
cmd/postgres_exporter/main.go|39 col 5| Version is a global variable (gochecknoglobals)
cmd/postgres_exporter/main.go|42 col 5| VersionShort is a global variable (gochecknoglobals)
cmd/postgres_exporter/main.go|52 col 2| onlyDumpMaps is a global variable (gochecknoglobals)
cmd/postgres_exporter/queries.go|50 col 5| queryOverrides is a global variable (gochecknoglobals)
cmd/postgres_exporter/namespace.go|60 col 44| err113: do not define dynamic errors, use wrapped static errors instead: "errors.New(fmt.Sprintln("Error retrieving column list for: ", namespace, err))" (goerr113)
cmd/postgres_exporter/namespace.go|82 col 45| err113: do not define dynamic errors, use wrapped static errors instead: "errors.New(fmt.Sprintln("Error retrieving rows:", namespace, err))" (goerr113)
cmd/postgres_exporter/namespace.go|130 col 47| err113: do not define dynamic errors, use wrapped static errors instead: "errors.New(fmt.Sprintln("Missing column: ", namespace, columnName+"_sum"))" (goerr113)
cmd/postgres_exporter/queries.go|302 col 16| err113: do not define dynamic errors, use wrapped static errors instead: "errors.New(fmt.Sprintln("Error retrieving rows:", err))" (goerr113)
cmd/postgres_exporter/queries.go|308 col 15| err113: do not define dynamic errors, use wrapped static errors instead: "errors.New(fmt.Sprintln("error retrieving rows:", err))" (goerr113)
cmd/postgres_exporter/server.go|128 col 9| err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf("queryNamespaceMappings returned %d errors", len(errMap))" (goerr113)
cmd/postgres_exporter/util.go|64 col 9| err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf("wrong ColumnUsage given : %s", s)" (goerr113)
cmd/postgres_exporter/util.go|183 col 15| err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf("malformed dsn %q", dsn)" (goerr113)
cmd/postgres_exporter/util.go|182 col 23| mnd: Magic number: 2, in detected (gomnd)
cmd/postgres_exporter/queries.go|258 col 3| error is not nil (line 256) but it returns nil (nilerr)
cmd/postgres_exporter/datasource.go|33 col 4| continue with no blank line before (nlreturn)
cmd/postgres_exporter/datasource.go|40 col 4| continue with no blank line before (nlreturn)
cmd/postgres_exporter/datasource.go|51 col 4| continue with no blank line before (nlreturn)
cmd/postgres_exporter/main.go|99 col 3| return with no blank line before (nlreturn)
cmd/postgres_exporter/namespace.go|48 col 30| rows.Err must be checked (rowserrcheck)
cmd/postgres_exporter/namespace.go|50 col 30| rows.Err must be checked (rowserrcheck)
cmd/postgres_exporter/queries.go|31 col 25| yaml(camel): got 'cache_seconds' want 'cacheSeconds' (tagliatelle)
cmd/postgres_exporter/queries.go|207 col 20| error returned from external package is unwrapped: sig: func gopkg.in/yaml.v2.Unmarshal(in []byte, out interface{}) (err error) (wrapcheck)
cmd/postgres_exporter/server.go|69 col 15| error returned from external package is unwrapped: sig: func database/sql.Open(driverName string, dataSourceName string) (*database/sql.DB, error) (wrapcheck)
cmd/postgres_exporter/server.go|94 col 9| error returned from external package is unwrapped: sig: func (*database/sql.DB).Close() error (wrapcheck)
cmd/postgres_exporter/queries.go|26 col 1| directive // nolint: golint is unused for linter "golint" (nolintlint)
cmd/postgres_exporter/queries.go|36 col 1| directive // nolint: golint is unused for linter "golint" (nolintlint)

cmd/postgres_exporter/main.go Outdated Show resolved Hide resolved
disableDefaultMetrics = kingpin.Flag("disable-default-metrics", "Do not include default metrics.").Default("false").Envar("PG_EXPORTER_DISABLE_DEFAULT_METRICS").Bool()
disableSettingsMetrics = kingpin.Flag("disable-settings-metrics", "Do not include pg_settings metrics.").Default("false").Envar("PG_EXPORTER_DISABLE_SETTINGS_METRICS").Bool()
autoDiscoverDatabases = kingpin.Flag("auto-discover-databases", "Whether to discover the databases on a server dynamically.").Default("false").Envar("PG_EXPORTER_AUTO_DISCOVER_DATABASES").Bool()
queriesPath = kingpin.Flag("extend.query-path", "Path to custom queries to run.").Default("").Envar("PG_EXPORTER_EXTEND_QUERY_PATH").String()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
queriesPath is unused (deadcode)

cmd/postgres_exporter/main.go Outdated Show resolved Hide resolved
constantLabelsList = kingpin.Flag("constantLabels", "A list of label=value separated by comma(,).").Default("").Envar("PG_EXPORTER_CONSTANT_LABELS").String()
excludeDatabases = kingpin.Flag("exclude-databases", "A list of databases to remove when autoDiscoverDatabases is enabled").Default("").Envar("PG_EXPORTER_EXCLUDE_DATABASES").String()
includeDatabases = kingpin.Flag("include-databases", "A list of databases to include when autoDiscoverDatabases is enabled").Default("").Envar("PG_EXPORTER_INCLUDE_DATABASES").String()
metricPrefix = kingpin.Flag("metric-prefix", "A metric prefix can be used to have non-default (not \"pg\") prefixes for each of the metrics").Default("pg").Envar("PG_EXPORTER_METRIC_PREFIX").String()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
metricPrefix is unused (deadcode)

cmd/postgres_exporter/main.go Outdated Show resolved Hide resolved
cmd/postgres_exporter/main.go Outdated Show resolved Hide resolved
includeDatabases = kingpin.Flag("include-databases", "A list of databases to include when autoDiscoverDatabases is enabled").Default("").Envar("PG_EXPORTER_INCLUDE_DATABASES").String()
metricPrefix = kingpin.Flag("metric-prefix", "A metric prefix can be used to have non-default (not \"pg\") prefixes for each of the metrics").Default("pg").Envar("PG_EXPORTER_METRIC_PREFIX").String()
logger = log.NewNopLogger()
collectCustomQueryLr = kingpin.Flag("collect.custom_query.lr", "Enable custom queries with low resolution directory.").Default("false").Envar("PG_EXPORTER_EXTEND_QUERY_LR").Bool()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
line is 192 characters (lll)

metricPrefix = kingpin.Flag("metric-prefix", "A metric prefix can be used to have non-default (not \"pg\") prefixes for each of the metrics").Default("pg").Envar("PG_EXPORTER_METRIC_PREFIX").String()
logger = log.NewNopLogger()
collectCustomQueryLr = kingpin.Flag("collect.custom_query.lr", "Enable custom queries with low resolution directory.").Default("false").Envar("PG_EXPORTER_EXTEND_QUERY_LR").Bool()
collectCustomQueryMr = kingpin.Flag("collect.custom_query.mr", "Enable custom queries with medium resolution directory.").Default("false").Envar("PG_EXPORTER_EXTEND_QUERY_MR").Bool()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
line is 195 characters (lll)

logger = log.NewNopLogger()
collectCustomQueryLr = kingpin.Flag("collect.custom_query.lr", "Enable custom queries with low resolution directory.").Default("false").Envar("PG_EXPORTER_EXTEND_QUERY_LR").Bool()
collectCustomQueryMr = kingpin.Flag("collect.custom_query.mr", "Enable custom queries with medium resolution directory.").Default("false").Envar("PG_EXPORTER_EXTEND_QUERY_MR").Bool()
collectCustomQueryHr = kingpin.Flag("collect.custom_query.hr", "Enable custom queries with high resolution directory.").Default("false").Envar("PG_EXPORTER_EXTEND_QUERY_HR").Bool()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
line is 193 characters (lll)

collectCustomQueryLr = kingpin.Flag("collect.custom_query.lr", "Enable custom queries with low resolution directory.").Default("false").Envar("PG_EXPORTER_EXTEND_QUERY_LR").Bool()
collectCustomQueryMr = kingpin.Flag("collect.custom_query.mr", "Enable custom queries with medium resolution directory.").Default("false").Envar("PG_EXPORTER_EXTEND_QUERY_MR").Bool()
collectCustomQueryHr = kingpin.Flag("collect.custom_query.hr", "Enable custom queries with high resolution directory.").Default("false").Envar("PG_EXPORTER_EXTEND_QUERY_HR").Bool()
collectCustomQueryLrDirectory = kingpin.Flag("collect.custom_query.lr.directory", "Path to custom queries with low resolution directory.").Envar("PG_EXPORTER_EXTEND_QUERY_LR_PATH").String()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
line is 193 characters (lll)

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

golangci-lint

cmd/postgres_exporter/namespace.go|178 col 4| append only allowed to cuddle with appended value (wsl)
cmd/postgres_exporter/namespace.go|181 col 2| return statements should not be cuddled if block has more than two lines (wsl)
cmd/postgres_exporter/queries.go|190 col 5| branch statements should not be cuddled if block has more than two lines (wsl)
cmd/postgres_exporter/queries.go|304 col 3| append only allowed to cuddle with appended value (wsl)
cmd/postgres_exporter/server.go|174 col 4| branch statements should not be cuddled if block has more than two lines (wsl)
cmd/postgres_exporter/server.go|158 col 2| for statement without condition should never be cuddled (wsl)
cmd/postgres_exporter/util.go|41 col 2| only one cuddle assignment allowed before switch statement (wsl)
cmd/postgres_exporter/util.go|72 col 1| calculated cyclomatic complexity for function dbToFloat64 is 12, max is 10 (cyclop)
cmd/postgres_exporter/util.go|110 col 1| calculated cyclomatic complexity for function dbToUint64 is 13, max is 10 (cyclop)
cmd/postgres_exporter/namespace.go|53 col 119| non-wrapping format verb for fmt.Errorf. Use %w to format errors (errorlint)
cmd/postgres_exporter/main.go|140 col 48| PidFn, Namespace, ReportErrors are missing in ProcessCollectorOpts (exhaustivestruct)
cmd/postgres_exporter/server.go|76 col 8| runonserver, lastMapVersion, metricMap, queryOverrides, mappingMtx, cacheMtx are missing in Server (exhaustivestruct)
cmd/postgres_exporter/server.go|143 col 10| m is missing in Servers (exhaustivestruct)
cmd/postgres_exporter/main.go|29 col 5| Branch is a global variable (gochecknoglobals)
cmd/postgres_exporter/main.go|32 col 5| BuildDate is a global variable (gochecknoglobals)
cmd/postgres_exporter/main.go|35 col 5| Revision is a global variable (gochecknoglobals)
cmd/postgres_exporter/main.go|39 col 5| Version is a global variable (gochecknoglobals)
cmd/postgres_exporter/main.go|42 col 5| VersionShort is a global variable (gochecknoglobals)
cmd/postgres_exporter/main.go|52 col 2| onlyDumpMaps is a global variable (gochecknoglobals)
cmd/postgres_exporter/queries.go|50 col 5| queryOverrides is a global variable (gochecknoglobals)
cmd/postgres_exporter/namespace.go|60 col 44| err113: do not define dynamic errors, use wrapped static errors instead: "errors.New(fmt.Sprintln("Error retrieving column list for: ", namespace, err))" (goerr113)
cmd/postgres_exporter/namespace.go|82 col 45| err113: do not define dynamic errors, use wrapped static errors instead: "errors.New(fmt.Sprintln("Error retrieving rows:", namespace, err))" (goerr113)
cmd/postgres_exporter/namespace.go|130 col 47| err113: do not define dynamic errors, use wrapped static errors instead: "errors.New(fmt.Sprintln("Missing column: ", namespace, columnName+"_sum"))" (goerr113)
cmd/postgres_exporter/queries.go|302 col 16| err113: do not define dynamic errors, use wrapped static errors instead: "errors.New(fmt.Sprintln("Error retrieving rows:", err))" (goerr113)
cmd/postgres_exporter/queries.go|308 col 15| err113: do not define dynamic errors, use wrapped static errors instead: "errors.New(fmt.Sprintln("error retrieving rows:", err))" (goerr113)
cmd/postgres_exporter/server.go|128 col 9| err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf("queryNamespaceMappings returned %d errors", len(errMap))" (goerr113)
cmd/postgres_exporter/util.go|64 col 9| err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf("wrong ColumnUsage given : %s", s)" (goerr113)
cmd/postgres_exporter/util.go|183 col 15| err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf("malformed dsn %q", dsn)" (goerr113)
cmd/postgres_exporter/util.go|182 col 23| mnd: Magic number: 2, in detected (gomnd)
cmd/postgres_exporter/queries.go|258 col 3| error is not nil (line 256) but it returns nil (nilerr)
cmd/postgres_exporter/datasource.go|33 col 4| continue with no blank line before (nlreturn)
cmd/postgres_exporter/datasource.go|40 col 4| continue with no blank line before (nlreturn)
cmd/postgres_exporter/datasource.go|51 col 4| continue with no blank line before (nlreturn)
cmd/postgres_exporter/main.go|99 col 3| return with no blank line before (nlreturn)
cmd/postgres_exporter/namespace.go|48 col 30| rows.Err must be checked (rowserrcheck)
cmd/postgres_exporter/namespace.go|50 col 30| rows.Err must be checked (rowserrcheck)
cmd/postgres_exporter/queries.go|31 col 25| yaml(camel): got 'cache_seconds' want 'cacheSeconds' (tagliatelle)
cmd/postgres_exporter/queries.go|207 col 20| error returned from external package is unwrapped: sig: func gopkg.in/yaml.v2.Unmarshal(in []byte, out interface{}) (err error) (wrapcheck)
cmd/postgres_exporter/server.go|69 col 15| error returned from external package is unwrapped: sig: func database/sql.Open(driverName string, dataSourceName string) (*database/sql.DB, error) (wrapcheck)
cmd/postgres_exporter/server.go|94 col 9| error returned from external package is unwrapped: sig: func (*database/sql.DB).Close() error (wrapcheck)
cmd/postgres_exporter/queries.go|26 col 1| directive // nolint: golint is unused for linter "golint" (nolintlint)
cmd/postgres_exporter/queries.go|36 col 1| directive // nolint: golint is unused for linter "golint" (nolintlint)

collectCustomQueryMr = kingpin.Flag("collect.custom_query.mr", "Enable custom queries with medium resolution directory.").Default("false").Envar("PG_EXPORTER_EXTEND_QUERY_MR").Bool()
collectCustomQueryHr = kingpin.Flag("collect.custom_query.hr", "Enable custom queries with high resolution directory.").Default("false").Envar("PG_EXPORTER_EXTEND_QUERY_HR").Bool()
collectCustomQueryLrDirectory = kingpin.Flag("collect.custom_query.lr.directory", "Path to custom queries with low resolution directory.").Envar("PG_EXPORTER_EXTEND_QUERY_LR_PATH").String()
collectCustomQueryMrDirectory = kingpin.Flag("collect.custom_query.mr.directory", "Path to custom queries with medium resolution directory.").Envar("PG_EXPORTER_EXTEND_QUERY_MR_PATH").String()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
line is 196 characters (lll)

collectCustomQueryHr = kingpin.Flag("collect.custom_query.hr", "Enable custom queries with high resolution directory.").Default("false").Envar("PG_EXPORTER_EXTEND_QUERY_HR").Bool()
collectCustomQueryLrDirectory = kingpin.Flag("collect.custom_query.lr.directory", "Path to custom queries with low resolution directory.").Envar("PG_EXPORTER_EXTEND_QUERY_LR_PATH").String()
collectCustomQueryMrDirectory = kingpin.Flag("collect.custom_query.mr.directory", "Path to custom queries with medium resolution directory.").Envar("PG_EXPORTER_EXTEND_QUERY_MR_PATH").String()
collectCustomQueryHrDirectory = kingpin.Flag("collect.custom_query.hr.directory", "Path to custom queries with high resolution directory.").Envar("PG_EXPORTER_EXTEND_QUERY_HR_PATH").String()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
line is 194 characters (lll)

var keys []float64
err = pq.Array(&keys).Scan(columnData[idx])
if err != nil {
return []prometheus.Metric{}, []error{}, errors.New(fmt.Sprintln("Error retrieving", columnName, "buckets:", namespace, err))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
line is 149 characters (lll)

var values []int64
valuesIdx, ok := columnIdx[columnName+"_bucket"]
if !ok {
nonfatalErrors = append(nonfatalErrors, errors.New(fmt.Sprintln("Missing column: ", namespace, columnName+"_bucket")))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
line is 142 characters (lll)

}
err = pq.Array(&values).Scan(columnData[valuesIdx])
if err != nil {
return []prometheus.Metric{}, []error{}, errors.New(fmt.Sprintln("Error retrieving", columnName, "bucket values:", namespace, err))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
line is 155 characters (lll)

} else {
rows, err = server.db.Query(query)
}
if err != nil {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
if statements should only be cuddled with assignments (wsl)


var columnNames []string
columnNames, err = rows.Columns()
if err != nil {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
only one cuddle assignment allowed before if statement (wsl)


var columnData = make([]interface{}, len(columnNames))
var scanArgs = make([]interface{}, len(columnNames))
for i := range columnData {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
only one cuddle assignment allowed before range statement (wsl)

if metricMapping.histogram {
var keys []float64
err = pq.Array(&keys).Scan(columnData[idx])
if err != nil {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
only one cuddle assignment allowed before if statement (wsl)

}

buckets := make(map[float64]uint64, len(keys))
for i, key := range keys {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
ranges should only be cuddled with assignments used in the iteration (wsl)

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

golangci-lint

cmd/postgres_exporter/datasource.go|33 col 4| continue with no blank line before (nlreturn)
cmd/postgres_exporter/datasource.go|40 col 4| continue with no blank line before (nlreturn)
cmd/postgres_exporter/datasource.go|51 col 4| continue with no blank line before (nlreturn)
cmd/postgres_exporter/main.go|99 col 3| return with no blank line before (nlreturn)
cmd/postgres_exporter/namespace.go|48 col 30| rows.Err must be checked (rowserrcheck)
cmd/postgres_exporter/namespace.go|50 col 30| rows.Err must be checked (rowserrcheck)
cmd/postgres_exporter/queries.go|31 col 25| yaml(camel): got 'cache_seconds' want 'cacheSeconds' (tagliatelle)
cmd/postgres_exporter/queries.go|207 col 20| error returned from external package is unwrapped: sig: func gopkg.in/yaml.v2.Unmarshal(in []byte, out interface{}) (err error) (wrapcheck)
cmd/postgres_exporter/server.go|69 col 15| error returned from external package is unwrapped: sig: func database/sql.Open(driverName string, dataSourceName string) (*database/sql.DB, error) (wrapcheck)
cmd/postgres_exporter/server.go|94 col 9| error returned from external package is unwrapped: sig: func (*database/sql.DB).Close() error (wrapcheck)
cmd/postgres_exporter/queries.go|26 col 1| directive // nolint: golint is unused for linter "golint" (nolintlint)
cmd/postgres_exporter/queries.go|36 col 1| directive // nolint: golint is unused for linter "golint" (nolintlint)

}
metric = prometheus.MustNewConstMetric(desc, prometheus.UntypedValue, value, labels...)
}
metrics = append(metrics, metric)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
append only allowed to cuddle with appended value (wsl)

metrics = append(metrics, metric)
}
}
return metrics, nonfatalErrors, nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
return statements should not be cuddled if block has more than two lines (wsl)

if queryDef.versionRange(pgVersion) {
resultMap[name] = queryDef.query
matched = true
break

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
branch statements should not be cuddled if block has more than two lines (wsl)

if err != nil {
return nil, errors.New(fmt.Sprintln("Error retrieving rows:", err))
}
result = append(result, databaseName)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
append only allowed to cuddle with appended value (wsl)

if err = server.Ping(); err != nil {
delete(s.servers, dsn)
time.Sleep(time.Duration(errCount) * time.Second)
continue

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
branch statements should not be cuddled if block has more than two lines (wsl)


errMap := queryNamespaceMappings(ch, s)
if len(errMap) > 0 {
err = fmt.Errorf("queryNamespaceMappings returned %d errors", len(errMap))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf("queryNamespaceMappings returned %d errors", len(errMap))" (goerr113)

u = DURATION

default:
err = fmt.Errorf("wrong ColumnUsage given : %s", s)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf("wrong ColumnUsage given : %s", s)" (goerr113)

for _, pair := range pairs {
splitted := strings.SplitN(pair, "=", 2)
if len(splitted) != 2 {
return "", fmt.Errorf("malformed dsn %q", dsn)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf("malformed dsn %q", dsn)" (goerr113)

kv := make(map[string]string, len(pairs))
for _, pair := range pairs {
splitted := strings.SplitN(pair, "=", 2)
if len(splitted) != 2 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
mnd: Magic number: 2, in detected (gomnd)

func addQueries(content []byte, pgVersion semver.Version, server *Server) error {
metricMaps, newQueryOverrides, err := parseUserQueries(content)
if err != nil {
return nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
error is not nil (line 256) but it returns nil (nilerr)

parsedDSN, err := url.Parse(dsn)
if err != nil {
log.Errorf("Unable to parse DSN (%s): %v", loggableDSN(dsn), err)
continue

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
continue with no blank line before (nlreturn)

server, err := e.servers.GetServer(dsn)
if err != nil {
log.Errorf("Error opening connection to database (%s): %v", loggableDSN(dsn), err)
continue

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
continue with no blank line before (nlreturn)

server.mappingMtx.Unlock()
if err != nil {
log.Errorf("Error querying databases (%s): %v", loggableDSN(dsn), err)
continue

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
continue with no blank line before (nlreturn)


if *onlyDumpMaps {
dumpMaps()
return

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
return with no blank line before (nlreturn)

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?
rows, err = server.db.Query(fmt.Sprintf("SELECT * FROM %s;", namespace)) // nolint: gas

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
rows.Err must be checked (rowserrcheck)


err := yaml.Unmarshal(content, &userQueries)
if err != nil {
return nil, nil, err

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
error returned from external package is unwrapped: sig: func gopkg.in/yaml.v2.Unmarshal(in []byte, out interface{}) (err error) (wrapcheck)


db, err := sql.Open("postgres", dsn)
if err != nil {
return nil, err

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
error returned from external package is unwrapped: sig: func database/sql.Open(driverName string, dataSourceName string) (*database/sql.DB, error) (wrapcheck)


// Close disconnects from Postgres.
func (s *Server) Close() error {
return s.db.Close()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
error returned from external package is unwrapped: sig: func (*database/sql.DB).Close() error (wrapcheck)

)

// UserQuery represents a user defined query
// nolint: golint

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
directive // nolint: golint is unused for linter "golint" (nolintlint)

}

// UserQueries represents a set of UserQuery objects
// nolint: golint

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
directive // nolint: golint is unused for linter "golint" (nolintlint)


var (
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9187").Envar("PG_EXPORTER_WEB_LISTEN_ADDRESS").String()
//webConfig = webflag.AddFlags(kingpin.CommandLine)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
commentFormatting: put a space between // and comment text (gocritic)

disableDefaultMetrics = kingpin.Flag("disable-default-metrics", "Do not include default metrics.").Default("false").Envar("PG_EXPORTER_DISABLE_DEFAULT_METRICS").Bool()
disableSettingsMetrics = kingpin.Flag("disable-settings-metrics", "Do not include pg_settings metrics.").Default("false").Envar("PG_EXPORTER_DISABLE_SETTINGS_METRICS").Bool()
autoDiscoverDatabases = kingpin.Flag("auto-discover-databases", "Whether to discover the databases on a server dynamically.").Default("false").Envar("PG_EXPORTER_AUTO_DISCOVER_DATABASES").Bool()
//queriesPath = kingpin.Flag("extend.query-path", "Path to custom queries to run.").Default("").Envar("PG_EXPORTER_EXTEND_QUERY_PATH").String()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
commentFormatting: put a space between // and comment text (gocritic)

onlyDumpMaps = kingpin.Flag("dumpmaps", "Do not run, simply dump the maps.").Bool()
constantLabelsList = kingpin.Flag("constantLabels", "A list of label=value separated by comma(,).").Default("").Envar("PG_EXPORTER_CONSTANT_LABELS").String()
excludeDatabases = kingpin.Flag("exclude-databases", "A list of databases to remove when autoDiscoverDatabases is enabled").Default("").Envar("PG_EXPORTER_EXCLUDE_DATABASES").String()
//includeDatabases = kingpin.Flag("include-databases", "A list of databases to include when autoDiscoverDatabases is enabled").Default("").Envar("PG_EXPORTER_INCLUDE_DATABASES").String()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
commentFormatting: put a space between // and comment text (gocritic)

excludeDatabases = kingpin.Flag("exclude-databases", "A list of databases to remove when autoDiscoverDatabases is enabled").Default("").Envar("PG_EXPORTER_EXCLUDE_DATABASES").String()
//includeDatabases = kingpin.Flag("include-databases", "A list of databases to include when autoDiscoverDatabases is enabled").Default("").Envar("PG_EXPORTER_INCLUDE_DATABASES").String()
//metricPrefix = kingpin.Flag("metric-prefix", "A metric prefix can be used to have non-default (not \"pg\") prefixes for each of the metrics").Default("pg").Envar("PG_EXPORTER_METRIC_PREFIX").String()
//logger = log.NewNopLogger()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
Comment should end in a period (godot)

var VersionShort = "0.0.1"

var (
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9187").Envar("PG_EXPORTER_WEB_LISTEN_ADDRESS").String()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
line is 177 characters (lll)

disableSettingsMetrics = kingpin.Flag("disable-settings-metrics", "Do not include pg_settings metrics.").Default("false").Envar("PG_EXPORTER_DISABLE_SETTINGS_METRICS").Bool()
autoDiscoverDatabases = kingpin.Flag("auto-discover-databases", "Whether to discover the databases on a server dynamically.").Default("false").Envar("PG_EXPORTER_AUTO_DISCOVER_DATABASES").Bool()
//queriesPath = kingpin.Flag("extend.query-path", "Path to custom queries to run.").Default("").Envar("PG_EXPORTER_EXTEND_QUERY_PATH").String()
onlyDumpMaps = kingpin.Flag("dumpmaps", "Do not run, simply dump the maps.").Bool()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
onlyDumpMaps is a global variable (gochecknoglobals)

case []byte:
// Try and convert to string and then parse to a float64
strV := string(v)
result, err := strconv.ParseFloat(strV, 64)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
mnd: Magic number: 64, in detected (gomnd)

}
return result, true
case string:
result, err := strconv.ParseFloat(v, 64)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
mnd: Magic number: 64, in detected (gomnd)

case []byte:
// Try and convert to string and then parse to a uint64
strV := string(v)
result, err := strconv.ParseUint(strV, 10, 64)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
mnd: Magic number: 10, in detected (gomnd)

}
return result, true
case string:
result, err := strconv.ParseUint(v, 10, 64)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
mnd: Magic number: 10, in detected (gomnd)


var (
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9187").Envar("PG_EXPORTER_WEB_LISTEN_ADDRESS").String()
//webConfig = webflag.AddFlags(kingpin.CommandLine)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
commentFormatting: put a space between // and comment text (gocritic)

disableDefaultMetrics = kingpin.Flag("disable-default-metrics", "Do not include default metrics.").Default("false").Envar("PG_EXPORTER_DISABLE_DEFAULT_METRICS").Bool()
disableSettingsMetrics = kingpin.Flag("disable-settings-metrics", "Do not include pg_settings metrics.").Default("false").Envar("PG_EXPORTER_DISABLE_SETTINGS_METRICS").Bool()
autoDiscoverDatabases = kingpin.Flag("auto-discover-databases", "Whether to discover the databases on a server dynamically.").Default("false").Envar("PG_EXPORTER_AUTO_DISCOVER_DATABASES").Bool()
//queriesPath = kingpin.Flag("extend.query-path", "Path to custom queries to run.").Default("").Envar("PG_EXPORTER_EXTEND_QUERY_PATH").String()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
commentFormatting: put a space between // and comment text (gocritic)

onlyDumpMaps = kingpin.Flag("dumpmaps", "Do not run, simply dump the maps.").Bool()
constantLabelsList = kingpin.Flag("constantLabels", "A list of label=value separated by comma(,).").Default("").Envar("PG_EXPORTER_CONSTANT_LABELS").String()
excludeDatabases = kingpin.Flag("exclude-databases", "A list of databases to remove when autoDiscoverDatabases is enabled").Default("").Envar("PG_EXPORTER_EXCLUDE_DATABASES").String()
//includeDatabases = kingpin.Flag("include-databases", "A list of databases to include when autoDiscoverDatabases is enabled").Default("").Envar("PG_EXPORTER_INCLUDE_DATABASES").String()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
commentFormatting: put a space between // and comment text (gocritic)

excludeDatabases = kingpin.Flag("exclude-databases", "A list of databases to remove when autoDiscoverDatabases is enabled").Default("").Envar("PG_EXPORTER_EXCLUDE_DATABASES").String()
//includeDatabases = kingpin.Flag("include-databases", "A list of databases to include when autoDiscoverDatabases is enabled").Default("").Envar("PG_EXPORTER_INCLUDE_DATABASES").String()
//metricPrefix = kingpin.Flag("metric-prefix", "A metric prefix can be used to have non-default (not \"pg\") prefixes for each of the metrics").Default("pg").Envar("PG_EXPORTER_METRIC_PREFIX").String()
//logger = log.NewNopLogger()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
Comment should end in a period (godot)

var VersionShort = "0.0.1"

var (
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9187").Envar("PG_EXPORTER_WEB_LISTEN_ADDRESS").String()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
line is 177 characters (lll)

disableSettingsMetrics = kingpin.Flag("disable-settings-metrics", "Do not include pg_settings metrics.").Default("false").Envar("PG_EXPORTER_DISABLE_SETTINGS_METRICS").Bool()
autoDiscoverDatabases = kingpin.Flag("auto-discover-databases", "Whether to discover the databases on a server dynamically.").Default("false").Envar("PG_EXPORTER_AUTO_DISCOVER_DATABASES").Bool()
//queriesPath = kingpin.Flag("extend.query-path", "Path to custom queries to run.").Default("").Envar("PG_EXPORTER_EXTEND_QUERY_PATH").String()
onlyDumpMaps = kingpin.Flag("dumpmaps", "Do not run, simply dump the maps.").Bool()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
onlyDumpMaps is a global variable (gochecknoglobals)

case []byte:
// Try and convert to string and then parse to a float64
strV := string(v)
result, err := strconv.ParseFloat(strV, 64)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
mnd: Magic number: 64, in detected (gomnd)

}
return result, true
case string:
result, err := strconv.ParseFloat(v, 64)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
mnd: Magic number: 64, in detected (gomnd)

case []byte:
// Try and convert to string and then parse to a uint64
strV := string(v)
result, err := strconv.ParseUint(strV, 10, 64)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
mnd: Magic number: 10, in detected (gomnd)

}
return result, true
case string:
result, err := strconv.ParseUint(v, 10, 64)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
mnd: Magic number: 10, in detected (gomnd)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet