Skip to content

Commit 377a6b8

Browse files
authored
Merge branch 'percona:main' into mongodb_connections_for_mongos
2 parents 5086741 + 8290ba5 commit 377a6b8

File tree

11 files changed

+120
-109
lines changed

11 files changed

+120
-109
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
fetch-depth: 0
2626

2727
- name: Set up Go
28-
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
28+
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
2929
with:
3030
go-version-file: ${{ github.workspace }}/go.mod
3131

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2424

2525
- name: Set up Go
26-
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
26+
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
2727
with:
2828
go-version-file: ${{ github.workspace }}/go.mod
2929

.github/workflows/release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ jobs:
2626
fetch-depth: 0
2727

2828
- name: Set up Go
29-
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
29+
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
3030
with:
3131
go-version-file: ${{ github.workspace }}/go.mod
3232

3333
- name: Login to Docker Hub
34-
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
34+
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
3535
with:
3636
username: ${{ secrets.DOCKERHUB_USERNAME }}
3737
password: ${{ secrets.DOCKERHUB_TOKEN }}
3838

3939
- name: Login to GitHub Container Registry
40-
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
40+
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
4141
with:
4242
registry: ghcr.io
4343
username: ${{ github.actor }}
@@ -51,7 +51,7 @@ jobs:
5151
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
5252

5353
- name: Run GoReleaser
54-
uses: goreleaser/goreleaser-action@9c156ee8a17a598857849441385a2041ef570552 # v6.3.0
54+
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
5555
with:
5656
version: "~> v2"
5757
args: release --clean

.github/workflows/scorecard.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
persist-credentials: false
2929

3030
- name: Run analysis
31-
uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # v2.4.2
31+
uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # v2.4.3
3232
with:
3333
results_file: results.sarif
3434
results_format: sarif
@@ -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@3599b3baa15b485a2e49ef411a7a4bb2452e7f93 # v3.29.5
46+
uses: github/codeql-action/upload-sarif@f443b600d91635bebf5b0d9ebc620189c0d6fba5 # v3.29.5
4747
with:
4848
sarif_file: results.sarif

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
4242

4343
- name: Set up Go
44-
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
44+
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
4545
with:
4646
go-version-file: ${{ github.workspace }}/go.mod
4747

.scripts/postinst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ set -e
44

55
echo "Creating user and group..."
66

7-
adduser --system --no-create-home --comment "Mongodb Exporter User" mongodb_exporter
7+
useradd --system \
8+
--no-create-home \
9+
--shell /sbin/nologin \
10+
--comment "MongoDB Exporter" \
11+
mongodb_exporter
812

913
systemctl daemon-reload > dev/null || exit $?
1014

exporter/feature_compatibility_version_collector_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,19 @@ func TestFCVCollector(t *testing.T) {
5050
var mversion string
5151

5252
mmv := fmt.Sprintf("%d.%d", v.Segments()[0], v.Segments()[1])
53-
switch {
54-
case mmv == "5.0":
53+
switch mmv {
54+
case "5.0":
5555
mversion = "4.4"
56-
case mmv == "4.4":
56+
case "4.4":
5757
mversion = "4.2"
58-
case mmv == "6.0":
58+
case "6.0":
5959
mversion = "5.0"
60-
case mmv == "7.0":
60+
case "7.0":
6161
mversion = "6.0"
62-
case mmv == "8.0":
62+
case "8.0":
6363
mversion = "7.0"
64+
case "8.2":
65+
mversion = "8.0"
6466
default:
6567
mversion = mmv
6668
}

exporter/pbm_collector.go

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/prometheus/client_golang/prometheus"
2727
"go.mongodb.org/mongo-driver/mongo"
2828

29+
"github.com/percona/mongodb_exporter/internal/proto"
2930
"github.com/percona/mongodb_exporter/internal/util"
3031
)
3132

@@ -113,8 +114,14 @@ func (p *pbmCollector) collect(ch chan<- prometheus.Metric) {
113114
"PBM PITR backups are enabled for the cluster",
114115
float64(pitrEnabledMetric), nil))
115116

116-
metrics = append(metrics, p.pbmBackupsMetrics(p.ctx, pbmClient, logger)...)
117-
metrics = append(metrics, p.pbmAgentMetrics(p.ctx, pbmClient, logger)...)
117+
// Get current node info once for both agent and backup metrics
118+
currentNode, err := util.MyRole(p.ctx, p.base.client)
119+
if err != nil {
120+
logger.Error("failed to get current node info", "error", err.Error())
121+
} else {
122+
metrics = append(metrics, p.pbmBackupsMetrics(p.ctx, pbmClient, logger, currentNode)...)
123+
metrics = append(metrics, p.pbmAgentMetrics(p.ctx, pbmClient, logger, currentNode)...)
124+
}
118125
}
119126

120127
metrics = append(metrics, createPBMMetric("cluster_backup_configured",
@@ -126,13 +133,7 @@ func (p *pbmCollector) collect(ch chan<- prometheus.Metric) {
126133
}
127134
}
128135

129-
func (p *pbmCollector) pbmAgentMetrics(ctx context.Context, pbmClient *sdk.Client, l *slog.Logger) []prometheus.Metric {
130-
currentNode, err := util.MyRole(ctx, p.base.client)
131-
if err != nil {
132-
l.Error("failed to get current node info", "error", err.Error())
133-
return nil
134-
}
135-
136+
func (p *pbmCollector) pbmAgentMetrics(ctx context.Context, pbmClient *sdk.Client, l *slog.Logger, currentNode *proto.HelloResponse) []prometheus.Metric {
136137
clusterStatus, err := cli.ClusterStatus(ctx, pbmClient, cli.RSConfGetter(p.mongoURI))
137138
if err != nil {
138139
l.Error("failed to get cluster status", "error", err.Error())
@@ -174,7 +175,7 @@ func (p *pbmCollector) pbmAgentMetrics(ctx context.Context, pbmClient *sdk.Clien
174175
return metrics
175176
}
176177

177-
func (p *pbmCollector) pbmBackupsMetrics(ctx context.Context, pbmClient *sdk.Client, l *slog.Logger) []prometheus.Metric {
178+
func (p *pbmCollector) pbmBackupsMetrics(ctx context.Context, pbmClient *sdk.Client, l *slog.Logger, currentNode *proto.HelloResponse) []prometheus.Metric {
178179
backupsList, err := pbmClient.GetAllBackups(ctx)
179180
if err != nil {
180181
l.Error("failed to get PBM backup list", "error", err.Error())
@@ -184,42 +185,49 @@ func (p *pbmCollector) pbmBackupsMetrics(ctx context.Context, pbmClient *sdk.Cli
184185
metrics := make([]prometheus.Metric, 0, len(backupsList))
185186

186187
for _, backup := range backupsList {
187-
metrics = append(metrics, createPBMMetric("backup_size_bytes",
188-
"Size of PBM backup",
189-
float64(backup.Size), map[string]string{
190-
"opid": backup.OPID,
191-
"status": string(backup.Status),
192-
"name": backup.Name,
193-
}),
194-
)
195-
196-
// Add backup_last_transition_ts metric
197-
metrics = append(metrics, createPBMMetric("backup_last_transition_ts",
198-
"Last transition timestamp of PBM backup (seconds since epoch)",
199-
float64(backup.LastTransitionTS), map[string]string{
200-
"opid": backup.OPID,
201-
"status": string(backup.Status),
202-
"name": backup.Name,
203-
}),
204-
)
205-
206-
var endTime int64
207-
switch pbmAgentStatus(backup.Status) {
208-
case statusDone, statusCancelled, statusError, statusDown:
209-
endTime = backup.LastTransitionTS
210-
default:
211-
endTime = time.Now().Unix()
212-
}
188+
// Iterate through replsets in the backup metadata
189+
for _, replset := range backup.Replsets {
190+
// Determine if this is the current node
191+
self := "0"
192+
if replset.Node == currentNode.Me {
193+
self = "1"
194+
}
213195

214-
duration := time.Unix(endTime-backup.StartTS, 0).Unix()
215-
metrics = append(metrics, createPBMMetric("backup_duration_seconds",
216-
"Duration of PBM backup",
217-
float64(duration), map[string]string{
218-
"opid": backup.OPID,
219-
"status": string(backup.Status),
220-
"name": backup.Name,
221-
}),
222-
)
196+
labels := map[string]string{
197+
"opid": backup.OPID,
198+
"status": string(backup.Status),
199+
"name": backup.Name,
200+
"host": replset.Node,
201+
"replica_set": replset.Name,
202+
"self": self,
203+
"type": string(backup.Type),
204+
}
205+
206+
metrics = append(metrics, createPBMMetric("backup_size_bytes",
207+
"Size of PBM backup",
208+
float64(backup.Size), labels),
209+
)
210+
211+
// Add backup_last_transition_ts metric
212+
metrics = append(metrics, createPBMMetric("backup_last_transition_ts",
213+
"Last transition timestamp of PBM backup (seconds since epoch)",
214+
float64(backup.LastTransitionTS), labels),
215+
)
216+
217+
var endTime int64
218+
switch pbmAgentStatus(backup.Status) {
219+
case statusDone, statusCancelled, statusError, statusDown:
220+
endTime = backup.LastTransitionTS
221+
default:
222+
endTime = time.Now().Unix()
223+
}
224+
225+
duration := time.Unix(endTime-backup.StartTS, 0).Unix()
226+
metrics = append(metrics, createPBMMetric("backup_duration_seconds",
227+
"Duration of PBM backup",
228+
float64(duration), labels),
229+
)
230+
}
223231
}
224232
return metrics
225233
}

exporter/v1_compatibility.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -819,20 +819,18 @@ func specialMetrics(ctx context.Context, client *mongo.Client, m bson.M, nodeTyp
819819
}
820820
}
821821

822-
if nodeType != typeArbiter {
822+
if nodeType == typeMongod {
823823
metrics = append(metrics, myState(ctx, client))
824824
if replSetGetStatus, ok := m["replSetGetStatus"].(bson.M); ok {
825825
if rm := replSetMetrics(replSetGetStatus, l); rm != nil {
826826
metrics = append(metrics, rm...)
827827
}
828828
}
829829

830-
if nodeType != typeMongos {
831-
if opLogMetrics, err := oplogStatus(ctx, client); err != nil {
832-
l.Warn("cannot create metrics for oplog", "error", err)
833-
} else {
834-
metrics = append(metrics, opLogMetrics...)
835-
}
830+
if opLogMetrics, err := oplogStatus(ctx, client); err != nil {
831+
l.Warn("cannot create metrics for oplog", "error", err)
832+
} else {
833+
metrics = append(metrics, opLogMetrics...)
836834
}
837835
}
838836

go.mod

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/percona/mongodb_exporter
22

3-
go 1.24
3+
go 1.24.0
44

55
toolchain go1.24.3
66

@@ -12,9 +12,9 @@ require (
1212
github.com/prometheus/client_golang v1.23.2
1313
github.com/prometheus/client_model v0.6.2
1414
github.com/prometheus/common v0.66.1
15-
github.com/prometheus/exporter-toolkit v0.14.0
15+
github.com/prometheus/exporter-toolkit v0.15.0
1616
github.com/stretchr/testify v1.11.1
17-
go.mongodb.org/mongo-driver v1.17.4
17+
go.mongodb.org/mongo-driver v1.17.6
1818
)
1919

2020
require github.com/foxcpp/go-mockdns v1.1.0
@@ -61,7 +61,7 @@ require (
6161
github.com/beorn7/perks v1.0.1 // indirect
6262
github.com/cespare/xxhash/v2 v2.3.0 // indirect
6363
github.com/cncf/xds/go v0.0.0-20250326154945-ae57f3c0d45f // indirect
64-
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
64+
github.com/coreos/go-systemd/v22 v22.6.0 // indirect
6565
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
6666
github.com/dustin/go-humanize v1.0.1 // indirect
6767
github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect
@@ -115,18 +115,18 @@ require (
115115
go.opentelemetry.io/otel/sdk v1.36.0 // indirect
116116
go.opentelemetry.io/otel/sdk/metric v1.36.0 // indirect
117117
go.opentelemetry.io/otel/trace v1.36.0 // indirect
118-
go.yaml.in/yaml/v2 v2.4.2 // indirect
119-
golang.org/x/crypto v0.41.0 // indirect
118+
go.yaml.in/yaml/v2 v2.4.3 // indirect
119+
golang.org/x/crypto v0.43.0 // indirect
120120
golang.org/x/exp v0.0.0-20240529005216-23cca8864a10 // indirect
121-
golang.org/x/mod v0.26.0 // indirect
122-
golang.org/x/net v0.43.0 // indirect
121+
golang.org/x/mod v0.28.0 // indirect
122+
golang.org/x/net v0.45.0 // indirect
123123
golang.org/x/oauth2 v0.30.0 // indirect
124-
golang.org/x/sync v0.16.0 // indirect
125-
golang.org/x/sys v0.35.0 // indirect
126-
golang.org/x/term v0.34.0 // indirect
127-
golang.org/x/text v0.28.0 // indirect
128-
golang.org/x/time v0.12.0 // indirect
129-
golang.org/x/tools v0.35.0 // indirect
124+
golang.org/x/sync v0.17.0 // indirect
125+
golang.org/x/sys v0.37.0 // indirect
126+
golang.org/x/term v0.36.0 // indirect
127+
golang.org/x/text v0.30.0 // indirect
128+
golang.org/x/time v0.13.0 // indirect
129+
golang.org/x/tools v0.37.0 // indirect
130130
google.golang.org/api v0.240.0 // indirect
131131
google.golang.org/genproto v0.0.0-20250505200425-f936aa4a68b2 // indirect
132132
google.golang.org/genproto/googleapis/api v0.0.0-20250505200425-f936aa4a68b2 // indirect

0 commit comments

Comments
 (0)