Skip to content

Commit 2843270

Browse files
authored
Remove prometheus/client_golang replace (#682)
* Remove prometheus/client_golang replace * Apply formater * Downgrade client_golang to previous version * Upgrade exporter-toolkit to v0.10.0
1 parent 1503b1c commit 2843270

11 files changed

+108
-83
lines changed

exporter/collstats_collector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (d *collstatsCollector) Collect(ch chan<- prometheus.Metric) {
5959
}
6060

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

6464
collections := d.collections
6565

exporter/dbstats_collector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (d *dbstatsCollector) Collect(ch chan<- prometheus.Metric) {
5656
}
5757

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

6161
logger := d.base.logger
6262
client := d.base.client

exporter/diagnostic_data_collector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (d *diagnosticDataCollector) Collect(ch chan<- prometheus.Metric) {
5959
}
6060

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

6464
var m bson.M
6565

exporter/exporter.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,13 @@ func (e *Exporter) Run() {
357357
})
358358

359359
server := &http.Server{
360-
Addr: e.webListenAddress,
361360
Handler: mux,
362361
}
363-
364-
if err := web.ListenAndServe(server, e.opts.TLSConfigPath, promlog.New(&promlog.Config{})); err != nil {
362+
flags := &web.FlagConfig{
363+
WebListenAddresses: &[]string{e.webListenAddress},
364+
WebConfigFile: &e.opts.TLSConfigPath,
365+
}
366+
if err := web.ListenAndServe(server, flags, promlog.New(&promlog.Config{})); err != nil {
365367
e.logger.Errorf("error starting server: %v", err)
366368
os.Exit(1)
367369
}

exporter/exporter_metrics.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// mongodb_exporter
2+
// Copyright (C) 2022 Percona LLC
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
package exporter
17+
18+
import (
19+
"time"
20+
21+
"github.com/prometheus/client_golang/prometheus"
22+
)
23+
24+
// measureCollectTime measures time taken for scrape by collector
25+
func measureCollectTime(ch chan<- prometheus.Metric, exporter, collector string) func() {
26+
startTime := time.Now()
27+
timeToCollectDesc := prometheus.NewDesc(
28+
"collector_scrape_time_ms",
29+
"Time taken for scrape by collector",
30+
[]string{"exporter"},
31+
prometheus.Labels{"collector": collector}, // to have ID calculated correctly
32+
)
33+
34+
return func() {
35+
scrapeTime := time.Since(startTime)
36+
scrapeMetric := prometheus.MustNewConstMetric(
37+
timeToCollectDesc,
38+
prometheus.GaugeValue,
39+
float64(scrapeTime.Milliseconds()),
40+
exporter)
41+
ch <- scrapeMetric
42+
}
43+
}

exporter/general_collector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (d *generalCollector) Collect(ch chan<- prometheus.Metric) {
4848
}
4949

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

exporter/indexstats_collector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (d *indexstatsCollector) Collect(ch chan<- prometheus.Metric) {
6060
}
6161

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

6565
collections := d.collections
6666

exporter/replset_status_collector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (d *replSetGetStatusCollector) Collect(ch chan<- prometheus.Metric) {
5757
}
5858

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

6262
logger := d.base.logger
6363
client := d.base.client

exporter/top_collector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (d *topCollector) Collect(ch chan<- prometheus.Metric) {
5656
}
5757

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

6161
logger := d.base.logger
6262
client := d.base.client

go.mod

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,50 @@ module github.com/percona/mongodb_exporter
22

33
go 1.19
44

5-
// Update percona-toolkit with `go get -v github.com/percona/[email protected]; go mod tidy` (without `-u`)
6-
// until we have everything we need in a tagged release.
7-
8-
replace github.com/prometheus/client_golang v1.12.2 => github.com/Percona-Lab/client_golang v1.12.2-0.20220701073455-ee06569fd6a5
9-
105
require (
116
github.com/AlekSi/pointer v1.1.0
127
github.com/alecthomas/kong v0.8.0
138
github.com/golang/snappy v0.0.3 // indirect
149
github.com/percona/exporter_shared v0.7.4-0.20211108113423-8555cdbac68b
1510
github.com/pkg/errors v0.9.1
16-
github.com/prometheus/client_golang v1.12.2
11+
github.com/prometheus/client_golang v1.14.0
1712
github.com/prometheus/client_model v0.4.0
18-
github.com/prometheus/common v0.37.0
19-
github.com/prometheus/exporter-toolkit v0.7.2
13+
github.com/prometheus/common v0.42.0
14+
github.com/prometheus/exporter-toolkit v0.10.0
2015
github.com/sirupsen/logrus v1.9.3
2116
github.com/stretchr/testify v1.8.2
2217
go.mongodb.org/mongo-driver v1.11.7
2318
)
2419

2520
require (
2621
github.com/beorn7/perks v1.0.1 // indirect
27-
github.com/cespare/xxhash/v2 v2.1.2 // indirect
22+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
23+
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
2824
github.com/davecgh/go-spew v1.1.1 // indirect
29-
github.com/go-kit/log v0.2.0 // indirect
25+
github.com/go-kit/log v0.2.1 // indirect
3026
github.com/go-logfmt/logfmt v0.5.1 // indirect
31-
github.com/golang/protobuf v1.5.2 // indirect
32-
github.com/google/go-cmp v0.5.8 // indirect
27+
github.com/golang/protobuf v1.5.3 // indirect
3328
github.com/jpillora/backoff v1.0.0 // indirect
3429
github.com/klauspost/compress v1.13.6 // indirect
35-
github.com/kr/pretty v0.3.0 // indirect
36-
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
30+
github.com/kr/text v0.2.0 // indirect
31+
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
3732
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
3833
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
39-
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
4034
github.com/pmezard/go-difflib v1.0.0 // indirect
41-
github.com/prometheus/procfs v0.7.3 // indirect
35+
github.com/prometheus/procfs v0.10.1 // indirect
36+
github.com/rogpeppe/go-internal v1.11.0 // indirect
4237
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
4338
github.com/xdg-go/scram v1.1.1 // indirect
4439
github.com/xdg-go/stringprep v1.0.3 // indirect
4540
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
46-
golang.org/x/crypto v0.1.0 // indirect
47-
golang.org/x/net v0.8.0 // indirect
48-
golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2 // indirect
49-
golang.org/x/sync v0.1.0 // indirect
50-
golang.org/x/sys v0.6.0 // indirect
51-
golang.org/x/text v0.8.0 // indirect
41+
golang.org/x/crypto v0.8.0 // indirect
42+
golang.org/x/net v0.9.0 // indirect
43+
golang.org/x/oauth2 v0.6.0 // indirect
44+
golang.org/x/sync v0.2.0 // indirect
45+
golang.org/x/sys v0.8.0 // indirect
46+
golang.org/x/text v0.9.0 // indirect
5247
google.golang.org/appengine v1.6.7 // indirect
5348
google.golang.org/protobuf v1.30.0 // indirect
54-
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
5549
gopkg.in/yaml.v2 v2.4.0 // indirect
5650
gopkg.in/yaml.v3 v3.0.1 // indirect
5751
)

0 commit comments

Comments
 (0)