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

Remove prometheus/client_golang replace #682

Merged
merged 5 commits into from
Jul 6, 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
2 changes: 1 addition & 1 deletion exporter/collstats_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (d *collstatsCollector) Collect(ch chan<- prometheus.Metric) {
}

func (d *collstatsCollector) collect(ch chan<- prometheus.Metric) {
defer prometheus.MeasureCollectTime(ch, "mongodb", "collstats")()
defer measureCollectTime(ch, "mongodb", "collstats")()

collections := d.collections

Expand Down
2 changes: 1 addition & 1 deletion exporter/dbstats_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (d *dbstatsCollector) Collect(ch chan<- prometheus.Metric) {
}

func (d *dbstatsCollector) collect(ch chan<- prometheus.Metric) {
defer prometheus.MeasureCollectTime(ch, "mongodb", "dbstats")()
defer measureCollectTime(ch, "mongodb", "dbstats")()

logger := d.base.logger
client := d.base.client
Expand Down
2 changes: 1 addition & 1 deletion exporter/diagnostic_data_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (d *diagnosticDataCollector) Collect(ch chan<- prometheus.Metric) {
}

func (d *diagnosticDataCollector) collect(ch chan<- prometheus.Metric) {
defer prometheus.MeasureCollectTime(ch, "mongodb", "diagnostic_data")()
defer measureCollectTime(ch, "mongodb", "diagnostic_data")()

var m bson.M

Expand Down
8 changes: 5 additions & 3 deletions exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,13 @@
})

server := &http.Server{
Addr: e.webListenAddress,
Handler: mux,
}

if err := web.ListenAndServe(server, e.opts.TLSConfigPath, promlog.New(&promlog.Config{})); err != nil {
flags := &web.FlagConfig{

Check failure on line 362 in exporter/exporter.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, mongo:4.2, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 WebSystemdSocket is missing in FlagConfig (exhaustruct) Raw Output: exporter/exporter.go:362:12: WebSystemdSocket is missing in FlagConfig (exhaustruct) flags := &web.FlagConfig{ ^

Check failure on line 362 in exporter/exporter.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, mongo:4.4, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 WebSystemdSocket is missing in FlagConfig (exhaustruct) Raw Output: exporter/exporter.go:362:12: WebSystemdSocket is missing in FlagConfig (exhaustruct) flags := &web.FlagConfig{ ^

Check failure on line 362 in exporter/exporter.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, mongo:5.0, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 WebSystemdSocket is missing in FlagConfig (exhaustruct) Raw Output: exporter/exporter.go:362:12: WebSystemdSocket is missing in FlagConfig (exhaustruct) flags := &web.FlagConfig{ ^

Check failure on line 362 in exporter/exporter.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, percona/percona-server-mongodb:4.2, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 WebSystemdSocket is missing in FlagConfig (exhaustruct) Raw Output: exporter/exporter.go:362:12: WebSystemdSocket is missing in FlagConfig (exhaustruct) flags := &web.FlagConfig{ ^

Check failure on line 362 in exporter/exporter.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, percona/percona-server-mongodb:4.4, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 WebSystemdSocket is missing in FlagConfig (exhaustruct) Raw Output: exporter/exporter.go:362:12: WebSystemdSocket is missing in FlagConfig (exhaustruct) flags := &web.FlagConfig{ ^

Check failure on line 362 in exporter/exporter.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, percona/percona-server-mongodb:5.0, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 WebSystemdSocket is missing in FlagConfig (exhaustruct) Raw Output: exporter/exporter.go:362:12: WebSystemdSocket is missing in FlagConfig (exhaustruct) flags := &web.FlagConfig{ ^

Check failure on line 362 in exporter/exporter.go

View workflow job for this annotation

GitHub Actions / Build (tip, mongo:4.4, ubuntu-latest, true)

[golangci-lint] reported by reviewdog 🐶 WebSystemdSocket is missing in FlagConfig (exhaustruct) Raw Output: exporter/exporter.go:362:12: WebSystemdSocket is missing in FlagConfig (exhaustruct) flags := &web.FlagConfig{ ^
WebListenAddresses: &[]string{e.webListenAddress},
WebConfigFile: &e.opts.TLSConfigPath,
}
if err := web.ListenAndServe(server, flags, promlog.New(&promlog.Config{})); err != nil {

Check failure on line 366 in exporter/exporter.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, mongo:4.2, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 Level, Format are missing in Config (exhaustruct) Raw Output: exporter/exporter.go:366:59: Level, Format are missing in Config (exhaustruct) if err := web.ListenAndServe(server, flags, promlog.New(&promlog.Config{})); err != nil { ^

Check failure on line 366 in exporter/exporter.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, mongo:4.4, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 Level, Format are missing in Config (exhaustruct) Raw Output: exporter/exporter.go:366:59: Level, Format are missing in Config (exhaustruct) if err := web.ListenAndServe(server, flags, promlog.New(&promlog.Config{})); err != nil { ^

Check failure on line 366 in exporter/exporter.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, mongo:5.0, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 Level, Format are missing in Config (exhaustruct) Raw Output: exporter/exporter.go:366:59: Level, Format are missing in Config (exhaustruct) if err := web.ListenAndServe(server, flags, promlog.New(&promlog.Config{})); err != nil { ^

Check failure on line 366 in exporter/exporter.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, percona/percona-server-mongodb:4.2, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 Level, Format are missing in Config (exhaustruct) Raw Output: exporter/exporter.go:366:59: Level, Format are missing in Config (exhaustruct) if err := web.ListenAndServe(server, flags, promlog.New(&promlog.Config{})); err != nil { ^

Check failure on line 366 in exporter/exporter.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, percona/percona-server-mongodb:4.4, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 Level, Format are missing in Config (exhaustruct) Raw Output: exporter/exporter.go:366:59: Level, Format are missing in Config (exhaustruct) if err := web.ListenAndServe(server, flags, promlog.New(&promlog.Config{})); err != nil { ^

Check failure on line 366 in exporter/exporter.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, percona/percona-server-mongodb:5.0, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 Level, Format are missing in Config (exhaustruct) Raw Output: exporter/exporter.go:366:59: Level, Format are missing in Config (exhaustruct) if err := web.ListenAndServe(server, flags, promlog.New(&promlog.Config{})); err != nil { ^

Check failure on line 366 in exporter/exporter.go

View workflow job for this annotation

GitHub Actions / Build (tip, mongo:4.4, ubuntu-latest, true)

[golangci-lint] reported by reviewdog 🐶 Level, Format are missing in Config (exhaustruct) Raw Output: exporter/exporter.go:366:59: Level, Format are missing in Config (exhaustruct) if err := web.ListenAndServe(server, flags, promlog.New(&promlog.Config{})); err != nil { ^
e.logger.Errorf("error starting server: %v", err)
os.Exit(1)
}
Expand Down
43 changes: 43 additions & 0 deletions exporter/exporter_metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// mongodb_exporter
// Copyright (C) 2022 Percona LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package exporter

import (
"time"

"github.com/prometheus/client_golang/prometheus"
)

// measureCollectTime measures time taken for scrape by collector

Check failure on line 24 in exporter/exporter_metrics.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, mongo:4.2, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 Comment should end in a period (godot) Raw Output: exporter/exporter_metrics.go:24:66: Comment should end in a period (godot) // measureCollectTime measures time taken for scrape by collector ^

Check failure on line 24 in exporter/exporter_metrics.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, mongo:4.4, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 Comment should end in a period (godot) Raw Output: exporter/exporter_metrics.go:24:66: Comment should end in a period (godot) // measureCollectTime measures time taken for scrape by collector ^

Check failure on line 24 in exporter/exporter_metrics.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, mongo:5.0, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 Comment should end in a period (godot) Raw Output: exporter/exporter_metrics.go:24:66: Comment should end in a period (godot) // measureCollectTime measures time taken for scrape by collector ^

Check failure on line 24 in exporter/exporter_metrics.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, percona/percona-server-mongodb:4.2, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 Comment should end in a period (godot) Raw Output: exporter/exporter_metrics.go:24:66: Comment should end in a period (godot) // measureCollectTime measures time taken for scrape by collector ^

Check failure on line 24 in exporter/exporter_metrics.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, percona/percona-server-mongodb:4.4, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 Comment should end in a period (godot) Raw Output: exporter/exporter_metrics.go:24:66: Comment should end in a period (godot) // measureCollectTime measures time taken for scrape by collector ^

Check failure on line 24 in exporter/exporter_metrics.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, percona/percona-server-mongodb:5.0, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 Comment should end in a period (godot) Raw Output: exporter/exporter_metrics.go:24:66: Comment should end in a period (godot) // measureCollectTime measures time taken for scrape by collector ^

Check failure on line 24 in exporter/exporter_metrics.go

View workflow job for this annotation

GitHub Actions / Build (tip, mongo:4.4, ubuntu-latest, true)

[golangci-lint] reported by reviewdog 🐶 Comment should end in a period (godot) Raw Output: exporter/exporter_metrics.go:24:66: Comment should end in a period (godot) // measureCollectTime measures time taken for scrape by collector ^
func measureCollectTime(ch chan<- prometheus.Metric, exporter, collector string) func() {

Check failure on line 25 in exporter/exporter_metrics.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, mongo:4.2, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 `measureCollectTime` - `exporter` always receives `"mongodb"` (unparam) Raw Output: exporter/exporter_metrics.go:25:54: `measureCollectTime` - `exporter` always receives `"mongodb"` (unparam) func measureCollectTime(ch chan<- prometheus.Metric, exporter, collector string) func() { ^

Check failure on line 25 in exporter/exporter_metrics.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, mongo:4.4, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 `measureCollectTime` - `exporter` always receives `"mongodb"` (unparam) Raw Output: exporter/exporter_metrics.go:25:54: `measureCollectTime` - `exporter` always receives `"mongodb"` (unparam) func measureCollectTime(ch chan<- prometheus.Metric, exporter, collector string) func() { ^

Check failure on line 25 in exporter/exporter_metrics.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, mongo:5.0, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 `measureCollectTime` - `exporter` always receives `"mongodb"` (unparam) Raw Output: exporter/exporter_metrics.go:25:54: `measureCollectTime` - `exporter` always receives `"mongodb"` (unparam) func measureCollectTime(ch chan<- prometheus.Metric, exporter, collector string) func() { ^

Check failure on line 25 in exporter/exporter_metrics.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, percona/percona-server-mongodb:4.2, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 `measureCollectTime` - `exporter` always receives `"mongodb"` (unparam) Raw Output: exporter/exporter_metrics.go:25:54: `measureCollectTime` - `exporter` always receives `"mongodb"` (unparam) func measureCollectTime(ch chan<- prometheus.Metric, exporter, collector string) func() { ^

Check failure on line 25 in exporter/exporter_metrics.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, percona/percona-server-mongodb:4.4, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 `measureCollectTime` - `exporter` always receives `"mongodb"` (unparam) Raw Output: exporter/exporter_metrics.go:25:54: `measureCollectTime` - `exporter` always receives `"mongodb"` (unparam) func measureCollectTime(ch chan<- prometheus.Metric, exporter, collector string) func() { ^

Check failure on line 25 in exporter/exporter_metrics.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x, percona/percona-server-mongodb:5.0, ubuntu-latest, false)

[golangci-lint] reported by reviewdog 🐶 `measureCollectTime` - `exporter` always receives `"mongodb"` (unparam) Raw Output: exporter/exporter_metrics.go:25:54: `measureCollectTime` - `exporter` always receives `"mongodb"` (unparam) func measureCollectTime(ch chan<- prometheus.Metric, exporter, collector string) func() { ^

Check failure on line 25 in exporter/exporter_metrics.go

View workflow job for this annotation

GitHub Actions / Build (tip, mongo:4.4, ubuntu-latest, true)

[golangci-lint] reported by reviewdog 🐶 `measureCollectTime` - `exporter` always receives `"mongodb"` (unparam) Raw Output: exporter/exporter_metrics.go:25:54: `measureCollectTime` - `exporter` always receives `"mongodb"` (unparam) func measureCollectTime(ch chan<- prometheus.Metric, exporter, collector string) func() { ^
startTime := time.Now()
timeToCollectDesc := prometheus.NewDesc(
"collector_scrape_time_ms",
"Time taken for scrape by collector",
[]string{"exporter"},
prometheus.Labels{"collector": collector}, // to have ID calculated correctly
)

return func() {
scrapeTime := time.Since(startTime)
scrapeMetric := prometheus.MustNewConstMetric(
timeToCollectDesc,
prometheus.GaugeValue,
float64(scrapeTime.Milliseconds()),
exporter)
ch <- scrapeMetric
}
}
2 changes: 1 addition & 1 deletion exporter/general_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (d *generalCollector) Collect(ch chan<- prometheus.Metric) {
}

func (d *generalCollector) collect(ch chan<- prometheus.Metric) {
defer prometheus.MeasureCollectTime(ch, "mongodb", "general")()
defer measureCollectTime(ch, "mongodb", "general")()
ch <- mongodbUpMetric(d.ctx, d.base.client, d.base.logger)
}

Expand Down
2 changes: 1 addition & 1 deletion exporter/indexstats_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (d *indexstatsCollector) Collect(ch chan<- prometheus.Metric) {
}

func (d *indexstatsCollector) collect(ch chan<- prometheus.Metric) {
defer prometheus.MeasureCollectTime(ch, "mongodb", "indexstats")()
defer measureCollectTime(ch, "mongodb", "indexstats")()

collections := d.collections

Expand Down
2 changes: 1 addition & 1 deletion exporter/replset_status_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (d *replSetGetStatusCollector) Collect(ch chan<- prometheus.Metric) {
}

func (d *replSetGetStatusCollector) collect(ch chan<- prometheus.Metric) {
defer prometheus.MeasureCollectTime(ch, "mongodb", "replset_status")()
defer measureCollectTime(ch, "mongodb", "replset_status")()

logger := d.base.logger
client := d.base.client
Expand Down
2 changes: 1 addition & 1 deletion exporter/top_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (d *topCollector) Collect(ch chan<- prometheus.Metric) {
}

func (d *topCollector) collect(ch chan<- prometheus.Metric) {
defer prometheus.MeasureCollectTime(ch, "mongodb", "top")()
defer measureCollectTime(ch, "mongodb", "top")()

logger := d.base.logger
client := d.base.client
Expand Down
40 changes: 17 additions & 23 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,50 @@ module github.com/percona/mongodb_exporter

go 1.19

// Update percona-toolkit with `go get -v github.com/percona/percona-toolkit@3.0; go mod tidy` (without `-u`)
// until we have everything we need in a tagged release.

replace github.com/prometheus/client_golang v1.12.2 => github.com/Percona-Lab/client_golang v1.12.2-0.20220701073455-ee06569fd6a5

require (
github.com/AlekSi/pointer v1.1.0
github.com/alecthomas/kong v0.8.0
github.com/golang/snappy v0.0.3 // indirect
github.com/percona/exporter_shared v0.7.4-0.20211108113423-8555cdbac68b
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.2
github.com/prometheus/client_golang v1.14.0
github.com/prometheus/client_model v0.4.0
github.com/prometheus/common v0.37.0
github.com/prometheus/exporter-toolkit v0.7.2
github.com/prometheus/common v0.42.0
github.com/prometheus/exporter-toolkit v0.10.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.8.2
go.mongodb.org/mongo-driver v1.11.7
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-kit/log v0.2.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.1 // indirect
github.com/xdg-go/stringprep v1.0.3 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/crypto v0.8.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/oauth2 v0.6.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading