Skip to content

Commit 4fed38d

Browse files
authored
Merge branch 'main' into PMM-14153
2 parents 2bdf263 + 7c0fc12 commit 4fed38d

File tree

7 files changed

+32
-19
lines changed

7 files changed

+32
-19
lines changed

.github/workflows/scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ jobs:
4343

4444
# Upload the results to GitHub's code scanning dashboard (optional).
4545
- name: "Upload to code-scanning"
46-
uses: github/codeql-action/upload-sarif@39edc492dbe16b1465b0cafca41432d857bdb31a # v3.29.1
46+
uses: github/codeql-action/upload-sarif@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
4747
with:
4848
sarif_file: results.sarif

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,12 @@ env:
7070
init: ## Install linters
7171
cd tools && go generate -x -tags=tools
7272

73-
build: ## Compile using plain go build
73+
build: ## Build exporter binary using plain go build.
7474
go build -ldflags="$(GO_BUILD_LDFLAGS)" -o $(PMM_RELEASE_PATH)/mongodb_exporter
7575

76+
build-gssapi: ## Build exporter binary with GSSAPI support (requires CGO enabled).
77+
CGO_ENABLED=1 go build -ldflags="$(GO_BUILD_LDFLAGS)" -tags gssapi -o $(PMM_RELEASE_PATH)/mongodb_exporter
78+
7679
release: ## Build the binaries using goreleaser
7780
docker run --rm --privileged \
7881
-v ${PWD}:/go/src/github.com/user/repo \

exporter/exporter.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,13 @@ func (e *Exporter) getClient(ctx context.Context) (*mongo.Client, error) {
273273
e.clientMu.Lock()
274274
defer e.clientMu.Unlock()
275275

276-
// If client is already initialized, return it.
276+
// If client is already initialized, and Ping is successful -- return it.
277277
if e.client != nil {
278+
err := e.client.Ping(ctx, nil)
279+
if err != nil {
280+
return nil, fmt.Errorf("cannot connect to MongoDB: %w", err)
281+
}
282+
278283
return e.client, nil
279284
}
280285

@@ -300,20 +305,25 @@ func (e *Exporter) getClient(ctx context.Context) (*mongo.Client, error) {
300305
// run for hooking up custom HTTP servers.
301306
func (e *Exporter) Handler() http.Handler {
302307
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
303-
seconds, err := strconv.Atoi(r.Header.Get("X-Prometheus-Scrape-Timeout-Seconds"))
304-
// To support older ones vmagents.
305-
if err != nil {
306-
seconds = 10
308+
scrapeTimeoutHeader := r.Header.Get("X-Prometheus-Scrape-Timeout-Seconds")
309+
seconds := 10.0
310+
311+
if scrapeTimeoutHeader != "" {
312+
if parsedSeconds, err := strconv.ParseFloat(scrapeTimeoutHeader, 64); err == nil {
313+
seconds = parsedSeconds
314+
} else {
315+
e.logger.Info("Invalid X-Prometheus-Scrape-Timeout-Seconds header", "error", err)
316+
}
307317
}
308-
seconds -= e.opts.TimeoutOffset
318+
seconds -= float64(e.opts.TimeoutOffset)
309319

310320
var client *mongo.Client
311-
ctx, cancel := context.WithTimeout(r.Context(), time.Duration(seconds)*time.Second)
321+
ctx, cancel := context.WithTimeout(r.Context(), time.Duration(seconds*float64(time.Second)))
312322
defer cancel()
313323

314324
requestOpts := GetRequestOpts(r.URL.Query()["collect[]"], e.opts)
315325

316-
client, err = e.getClient(ctx)
326+
client, err := e.getClient(ctx)
317327
if err != nil {
318328
e.logger.Error("Cannot connect to MongoDB", "error", err)
319329
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ toolchain go1.24.3
66

77
require (
88
github.com/AlekSi/pointer v1.2.0
9-
github.com/alecthomas/kong v1.12.0
9+
github.com/alecthomas/kong v1.12.1
1010
github.com/percona/exporter_shared v0.7.6
1111
github.com/pkg/errors v0.9.1
1212
github.com/prometheus/client_golang v1.22.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERo
2020
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
2121
github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
2222
github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
23-
github.com/alecthomas/kong v1.12.0 h1:oKd/0fHSdajj5PfGDd3ScvEvpVJf9mT2mb5r9xYadYM=
24-
github.com/alecthomas/kong v1.12.0/go.mod h1:p2vqieVMeTAnaC83txKtXe8FLke2X07aruPWXyMPQrU=
23+
github.com/alecthomas/kong v1.12.1 h1:iq6aMJDcFYP9uFrLdsiZQ2ZMmcshduyGv4Pek0MQPW0=
24+
github.com/alecthomas/kong v1.12.1/go.mod h1:p2vqieVMeTAnaC83txKtXe8FLke2X07aruPWXyMPQrU=
2525
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
2626
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
2727
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=

tools/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.24
55
toolchain go1.24.3
66

77
require (
8-
github.com/daixiang0/gci v0.13.6
8+
github.com/daixiang0/gci v0.13.7
99
github.com/golangci/golangci-lint v1.64.8
1010
github.com/reviewdog/reviewdog v0.20.3
1111
mvdan.cc/gofumpt v0.8.0
@@ -200,7 +200,7 @@ require (
200200
golang.org/x/crypto v0.39.0 // indirect
201201
golang.org/x/exp/typeparams v0.0.0-20250210185358-939b2ce775ac // indirect
202202
golang.org/x/mod v0.25.0 // indirect
203-
golang.org/x/oauth2 v0.26.0 // indirect
203+
golang.org/x/oauth2 v0.27.0 // indirect
204204
golang.org/x/sync v0.15.0 // indirect
205205
golang.org/x/sys v0.33.0 // indirect
206206
golang.org/x/text v0.26.0 // indirect

tools/go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
127127
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
128128
github.com/curioswitch/go-reassign v0.3.0 h1:dh3kpQHuADL3cobV/sSGETA8DOv457dwl+fbBAhrQPs=
129129
github.com/curioswitch/go-reassign v0.3.0/go.mod h1:nApPCCTtqLJN/s8HfItCcKV0jIPwluBOvZP+dsJGA88=
130-
github.com/daixiang0/gci v0.13.6 h1:RKuEOSkGpSadkGbvZ6hJ4ddItT3cVZ9Vn9Rybk6xjl8=
131-
github.com/daixiang0/gci v0.13.6/go.mod h1:12etP2OniiIdP4q+kjUGrC/rUagga7ODbqsom5Eo5Yk=
130+
github.com/daixiang0/gci v0.13.7 h1:+0bG5eK9vlI08J+J/NWGbWPTNiXPG4WhNLJOkSxWITQ=
131+
github.com/daixiang0/gci v0.13.7/go.mod h1:812WVN6JLFY9S6Tv76twqmNqevN0pa3SX3nih0brVzQ=
132132
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
133133
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
134134
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -756,8 +756,8 @@ golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ
756756
golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
757757
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
758758
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
759-
golang.org/x/oauth2 v0.26.0 h1:afQXWNNaeC4nvZ0Ed9XvCCzXM6UHJG7iCg0W4fPqSBE=
760-
golang.org/x/oauth2 v0.26.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
759+
golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M=
760+
golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
761761
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
762762
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
763763
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

0 commit comments

Comments
 (0)