Skip to content

Commit 66c3df0

Browse files
authored
Merge branch 'main' into patch-1
2 parents cc77180 + 7fbf7ee commit 66c3df0

File tree

9 files changed

+73
-62
lines changed

9 files changed

+73
-62
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@192325c86100d080feab897ff886c34abd4c83a3 # 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/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
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ 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.14.1
1616
github.com/stretchr/testify v1.11.1
1717
go.mongodb.org/mongo-driver v1.17.4
1818
)
@@ -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

go.sum

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
106106
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
107107
github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A=
108108
github.com/containerd/platforms v0.2.1/go.mod h1:XHCb+2/hzowdiut9rkudds9bE5yJ7npe7dG/wG+uFPw=
109-
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
110-
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
109+
github.com/coreos/go-systemd/v22 v22.6.0 h1:aGVa/v8B7hpb0TKl0MWoAavPDmHvobFe5R5zn0bCJWo=
110+
github.com/coreos/go-systemd/v22 v22.6.0/go.mod h1:iG+pp635Fo7ZmV/j14KUcmEyWF+0X7Lua8rrTWzYgWU=
111111
github.com/cpuguy83/dockercfg v0.3.2 h1:DlJTyZGBDlXqUZ2Dk2Q3xHs/FtnooJJVaad2S9GKorA=
112112
github.com/cpuguy83/dockercfg v0.3.2/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc=
113113
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
@@ -150,7 +150,6 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
150150
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
151151
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
152152
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
153-
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
154153
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
155154
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
156155
github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw=
@@ -269,8 +268,8 @@ github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNw
269268
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
270269
github.com/prometheus/common v0.66.1 h1:h5E0h5/Y8niHc5DlaLlWLArTQI7tMrsfQjHV+d9ZoGs=
271270
github.com/prometheus/common v0.66.1/go.mod h1:gcaUsgf3KfRSwHY4dIMXLPV0K/Wg1oZ8+SbZk/HH/dA=
272-
github.com/prometheus/exporter-toolkit v0.14.0 h1:NMlswfibpcZZ+H0sZBiTjrA3/aBFHkNZqE+iCj5EmRg=
273-
github.com/prometheus/exporter-toolkit v0.14.0/go.mod h1:Gu5LnVvt7Nr/oqTBUC23WILZepW0nffNo10XdhQcwWA=
271+
github.com/prometheus/exporter-toolkit v0.14.1 h1:uKPE4ewweVRWFainwvAcHs3uw15pjw2dk3I7b+aNo9o=
272+
github.com/prometheus/exporter-toolkit v0.14.1/go.mod h1:di7yaAJiaMkcjcz48f/u4yRPwtyuxTU5Jr4EnM2mhtQ=
274273
github.com/prometheus/procfs v0.16.1 h1:hZ15bTNuirocR6u0JZ6BAHHmwS1p8B4P6MRqxtzMyRg=
275274
github.com/prometheus/procfs v0.16.1/go.mod h1:teAbpZRB1iIAJYREa1LsoWUXykVXA1KlTmWl8x/U+Is=
276275
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=

0 commit comments

Comments
 (0)