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

Use strings.ReplaceAll() rather than strings.Replace() with -1 #376

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
repos:
- repo: https://github.com/jessp01/pre-commit-golang.git
rev: v0.5.9
hooks:
- id: go-fmt
- id: go-imports
- id: go-vet
- id: go-lint
- id: go-critic
- id: go-ineffassign
- id: shellcheck
10 changes: 5 additions & 5 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
wg.Wait()
}

func (e *Exporter) scrape(ch chan<- prometheus.Metric) {

Check failure on line 239 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

cognitive complexity 34 of func `(*Exporter).scrape` is high (> 30) (gocognit)

Check failure on line 239 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

cognitive complexity 34 of func `(*Exporter).scrape` is high (> 30) (gocognit)
e.totalScrapes.Inc()
var err error
defer func(begun time.Time) {
Expand All @@ -250,16 +250,16 @@

if err = e.db.Ping(); err != nil {
if strings.Contains(err.Error(), "sql: database is closed") {
level.Info(e.logger).Log("Reconnecting to DB")

Check failure on line 253 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `(github.com/go-kit/log.Logger).Log` is not checked (errcheck)

Check failure on line 253 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `(github.com/go-kit/log.Logger).Log` is not checked (errcheck)
err = e.connect()
if err != nil {
level.Error(e.logger).Log("Error reconnecting to DB", err)

Check failure on line 256 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `(github.com/go-kit/log.Logger).Log` is not checked (errcheck)

Check failure on line 256 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `(github.com/go-kit/log.Logger).Log` is not checked (errcheck)
}
}
}

if err = e.db.Ping(); err != nil {
level.Error(e.logger).Log("Error pinging oracle:", err)

Check failure on line 262 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `(github.com/go-kit/log.Logger).Log` is not checked (errcheck)

Check failure on line 262 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `(github.com/go-kit/log.Logger).Log` is not checked (errcheck)
e.up.Set(0)
return
}
Expand All @@ -275,7 +275,7 @@

for _, metric := range e.metricsToScrape.Metric {
wg.Add(1)
metric := metric //https://golang.org/doc/faq#closures_and_goroutines

Check failure on line 278 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

File is not `gofumpt`-ed with `-extra` (gofumpt)

Check failure on line 278 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

File is not `gofumpt`-ed with `-extra` (gofumpt)

go func() {
defer wg.Done()
Expand All @@ -301,7 +301,7 @@
}

for column, metricType := range metric.MetricsType {
if metricType == "histogram" {

Check failure on line 304 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

string `histogram` has 3 occurrences, make it a constant (goconst)

Check failure on line 304 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

string `histogram` has 3 occurrences, make it a constant (goconst)
_, ok := metric.MetricsBuckets[column]
if !ok {
level.Error(e.logger).Log("Unable to find MetricsBuckets configuration key for metric. (metric=" + column + ")")
Expand Down Expand Up @@ -405,8 +405,8 @@
}

// generic method for retrieving metrics.
func (e *Exporter) scrapeGenericValues(db *sql.DB, ch chan<- prometheus.Metric, context string, labels []string,

Check failure on line 408 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

cognitive complexity 63 of func `(*Exporter).scrapeGenericValues` is high (> 30) (gocognit)

Check failure on line 408 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

cognitive complexity 63 of func `(*Exporter).scrapeGenericValues` is high (> 30) (gocognit)
metricsDesc map[string]string, metricsType map[string]string, metricsBuckets map[string]map[string]string, fieldToAppend string, ignoreZeroResult bool, request string) error {

Check failure on line 409 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

File is not `gofumpt`-ed with `-extra` (gofumpt)

Check failure on line 409 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

File is not `gofumpt`-ed with `-extra` (gofumpt)
metricsCount := 0
genericParser := func(row map[string]string) error {
// Construct labels value
Expand All @@ -420,7 +420,7 @@
// If not a float, skip current metric
if err != nil {
level.Error(e.logger).Log("Unable to convert current value to float (metric=" + metric +
",metricHelp=" + metricHelp + ",value=<" + row[metric] + ">)")

Check failure on line 423 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

string `,value=<` has 5 occurrences, make it a constant (goconst)

Check failure on line 423 in collector/collector.go

View workflow job for this annotation

GitHub Actions / build

string `,metricHelp=` has 7 occurrences, make it a constant (goconst)
continue
}
level.Debug(e.logger).Log("Query result looks like: ", value)
Expand Down Expand Up @@ -574,11 +574,11 @@
}

func cleanName(s string) string {
s = strings.Replace(s, " ", "_", -1) // Remove spaces
s = strings.Replace(s, "(", "", -1) // Remove open parenthesis
s = strings.Replace(s, ")", "", -1) // Remove close parenthesis
s = strings.Replace(s, "/", "", -1) // Remove forward slashes
s = strings.Replace(s, "*", "", -1) // Remove asterisks
s = strings.ReplaceAll(s, " ", "_") // Remove spaces
s = strings.ReplaceAll(s, "(", "") // Remove open parenthesis
s = strings.ReplaceAll(s, ")", "") // Remove close parenthesis
s = strings.ReplaceAll(s, "/", "") // Remove forward slashes
s = strings.ReplaceAll(s, "*", "") // Remove asterisks
s = strings.ToLower(s)
return s
}
Expand Down
Loading