Skip to content

Commit 08ee76b

Browse files
authored
Merge branch 'main' into PMM-7-use-image-from-env-for-encrypted
2 parents 8030c40 + fe0bb1c commit 08ee76b

27 files changed

+730
-218
lines changed

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
uses: actions/checkout@v4
3333

3434
- name: Set up Go
35-
uses: actions/setup-go@v4
35+
uses: actions/setup-go@v5
3636
with:
3737
go-version-file: ${{ github.workspace }}/go.mod
3838

.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@v4
2424

2525
- name: Set up Go
26-
uses: actions/setup-go@v4
26+
uses: actions/setup-go@v5
2727
with:
2828
go-version-file: ${{ github.workspace }}/go.mod
2929

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
fetch-depth: 0
1919

2020
- name: Set up Go
21-
uses: actions/setup-go@v4
21+
uses: actions/setup-go@v5
2222
with:
2323
go-version-file: ${{ github.workspace }}/go.mod
2424

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ test-race: env ## Run all tests with race flag.
104104
go test -race -v -timeout 30s ./...
105105

106106
test-cluster: env ## Starts MongoDB test cluster. Use env var TEST_MONGODB_IMAGE to set flavor and version. Example: TEST_MONGODB_IMAGE=mongo:3.6 make test-cluster
107-
docker compose up -d --wait
107+
docker compose up -d
108108

109109
test-cluster-clean: env ## Stops MongoDB test cluster.
110110
docker compose down --remove-orphans

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ Usage example: `db.setProfilingLevel(2)`
128128
|1| The profiler collects data for operations that take longer than the value of `slowms` or that match a filter.<br> When a filter is set: <ul><li> The `slowms` and `sampleRate` options are not used for profiling.</li><li>The profiler only captures operations that match the filter.</li></ul>
129129
|2|The profiler collects data for all operations.|
130130

131+
#### Enabling shards metrics gathering
132+
When shard metrics collection is enabled by `--collector.shards`, the exporter will expose metrics related to sharded Mongo.
133+
Example, if shards collector is enabled:
134+
```
135+
# HELP mongodb_shards_collection_chunks_count sharded collection chunks.
136+
# TYPE mongodb_shards_collection_chunks_count counter
137+
mongodb_shards_collection_chunks_count{collection="system.sessions",database="config",shard="rs1"} 250
138+
mongodb_shards_collection_chunks_count{collection="system.sessions",database="config",shard="rs2"} 250
139+
```
140+
You can see shard name, it's collection, database and count.
141+
131142
#### Cluster role labels
132143
The exporter sets some topology labels in all metrics.
133144
The labels are:

REFERENCE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@
2727
|--collector.collstats-limit=0|Disable collstats, dbstats, topmetrics and indexstats collector if there are more than \<n\> collections. 0=No limit|
2828
|--collector.profile-time-ts=30|Set time for scrape slow queries| This interval must be synchronized with the Prometheus scrape interval|
2929
|--collector.profile|Enable collecting metrics from profile|
30+
|--collector.shards|Enable collecting metrics related to Mongo shards|
3031
|--metrics.overridedescendingindex| Enable descending index name override to replace -1 with _DESC ||
3132
|--version|Show version and exit|

docker-compose.yml

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,39 @@ services:
66
ports:
77
- "${TEST_MONGODB_S1_PRIMARY_PORT:-17001}:27017"
88
command: mongod --replSet rs1 --shardsvr --port 27017 --oplogSize 16
9-
links:
10-
- mongo-1-2:mongo-1-2
11-
- mongo-1-3:mongo-1-3
9+
networks:
10+
- rs1
11+
depends_on:
12+
- "mongo-1-2"
13+
- "mongo-1-3"
14+
- "mongo-1-arbiter"
1215

1316
mongo-1-2:
1417
container_name: "mongo-1-2"
1518
image: ${TEST_MONGODB_IMAGE:-mongo:4.4}
1619
ports:
1720
- "${TEST_MONGODB_S1_SECONDARY1_PORT:-17002}:27017"
1821
command: mongod --replSet rs1 --shardsvr --port 27017 --oplogSize 16
22+
networks:
23+
- rs1
1924

2025
mongo-1-3:
2126
container_name: "mongo-1-3"
2227
image: ${TEST_MONGODB_IMAGE:-mongo:4.4}
2328
ports:
2429
- "${TEST_MONGODB_S1_SECONDARY2_PORT:-17003}:27017"
2530
command: mongod --replSet rs1 --shardsvr --port 27017 --oplogSize 16
31+
networks:
32+
- rs1
2633

2734
mongo-1-arbiter:
2835
container_name: "mongo-1-arbiter"
2936
image: ${TEST_MONGODB_IMAGE:-mongo:4.4}
3037
ports:
3138
- "${TEST_MONGODB_S1_ARBITER:-17011}:27017"
3239
command: mongod --replSet rs1 --shardsvr --port 27017 --oplogSize 16
40+
networks:
41+
- rs1
3342

3443
mongo-rs1-setup:
3544
container_name: "mongo-rs1-setup"
@@ -39,11 +48,6 @@ services:
3948
- "mongo-1-2"
4049
- "mongo-1-3"
4150
- "mongo-1-arbiter"
42-
links:
43-
- mongo-1-1:mongo-1-1
44-
- mongo-1-2:mongo-1-2
45-
- mongo-1-3:mongo-1-3
46-
- mongo-1-arbiter:mongo-1-arbiter
4751
volumes:
4852
- ./docker/scripts:/scripts
4953
environment:
@@ -52,38 +56,46 @@ services:
5256
- MONGO3=mongo-1-3
5357
- ARBITER=mongo-1-arbiter
5458
- RS=rs1
59+
- VERSION=${TEST_MONGODB_IMAGE}
5560
entrypoint: [ "/scripts/setup.sh" ]
61+
networks:
62+
- rs1
5663

5764
mongo-2-2:
5865
container_name: "mongo-2-2"
5966
image: ${TEST_MONGODB_IMAGE:-mongo:4.4}
6067
ports:
6168
- "${TEST_MONGODB_S2_PRIMARY_PORT:-17004}:27017"
6269
command: mongod --replSet rs2 --shardsvr --port 27017 --oplogSize 16
70+
networks:
71+
- rs2
6372

6473
mongo-2-3:
6574
container_name: "mongo-2-3"
6675
image: ${TEST_MONGODB_IMAGE:-mongo:4.4}
6776
ports:
6877
- "${TEST_MONGODB_S2_SECONDARY1_PORT:-17005}:27017"
6978
command: mongod --replSet rs2 --shardsvr --port 27017 --oplogSize 16
79+
networks:
80+
- rs2
7081

7182
mongo-2-1:
7283
container_name: "mongo-2-1"
7384
image: ${TEST_MONGODB_IMAGE:-mongo:4.4}
7485
ports:
7586
- "${TEST_MONGODB_S2_SECONDARY2_PORT:-17006}:27017"
7687
command: mongod --replSet rs2 --shardsvr --port 27017 --oplogSize 16
77-
links:
78-
- mongo-2-2:mongo-2-2
79-
- mongo-2-3:mongo-2-3
88+
networks:
89+
- rs2
8090

8191
mongo-2-arbiter:
8292
container_name: "mongo-2-arbiter"
8393
image: ${TEST_MONGODB_IMAGE:-mongo:4.4}
8494
ports:
8595
- "${TEST_MONGODB_S2_ARBITER:-17012}:27017"
8696
command: mongod --replSet rs1 --shardsvr --port 27017 --oplogSize 16
97+
networks:
98+
- rs2
8799

88100
mongo-rs2-setup:
89101
container_name: "mongo-rs2-setup"
@@ -93,19 +105,18 @@ services:
93105
- "mongo-2-2"
94106
- "mongo-2-3"
95107
- "mongo-2-arbiter"
96-
links:
97-
- mongo-2-1:mongo-2-1
98-
- mongo-2-2:mongo-2-2
99-
- mongo-2-3:mongo-2-3
100108
volumes:
101109
- ./docker/scripts:/scripts
102110
environment:
103-
- MONGO1=mongo-2-1
104-
- MONGO2=mongo-2-2
111+
- MONGO1=mongo-2-2
112+
- MONGO2=mongo-2-1
105113
- MONGO3=mongo-2-3
106114
- ARBITER=mongo-2-arbiter
107115
- RS=rs2
116+
- VERSION=${TEST_MONGODB_IMAGE}
108117
entrypoint: [ "/scripts/setup.sh" ]
118+
networks:
119+
- rs2
109120

110121
# Config servers
111122
mongo-cnf-2:
@@ -114,23 +125,29 @@ services:
114125
ports:
115126
- "${TEST_MONGODB_CONFIGSVR1_PORT:-17007}:27017"
116127
command: mongod --dbpath /data/db --replSet cnf-serv --configsvr --port 27017 --oplogSize 16
128+
networks:
129+
- cnf-serv
117130

118131
mongo-cnf-3:
119132
container_name: "mongo-cnf-3"
120133
image: ${TEST_MONGODB_IMAGE:-mongo:4.4}
121134
ports:
122135
- "${TEST_MONGODB_CONFIGSVR2_PORT:-17008}:27017"
123136
command: mongod --dbpath /data/db --replSet cnf-serv --configsvr --port 27017 --oplogSize 16
137+
networks:
138+
- cnf-serv
124139

125140
mongo-cnf-1:
126141
container_name: "mongo-cnf-1"
127142
image: ${TEST_MONGODB_IMAGE:-mongo:4.4}
128143
ports:
129144
- "${TEST_MONGODB_CONFIGSVR3_PORT:-17009}:27017"
130145
command: mongod --dbpath /data/db --replSet cnf-serv --configsvr --port 27017 --oplogSize 16
131-
links:
132-
- mongo-cnf-2:mongo-cnf-2
133-
- mongo-cnf-3:mongo-cnf-3
146+
networks:
147+
- cnf-serv
148+
depends_on:
149+
- mongo-cnf-2
150+
- mongo-cnf-3
134151

135152
mongo-cnf-setup:
136153
container_name: "mongo-cnf-setup"
@@ -139,10 +156,6 @@ services:
139156
- "mongo-cnf-1"
140157
- "mongo-cnf-2"
141158
- "mongo-cnf-3"
142-
links:
143-
- mongo-cnf-1:mongo-cnf-1
144-
- mongo-cnf-2:mongo-cnf-2
145-
- mongo-cnf-3:mongo-cnf-3
146159
volumes:
147160
- ./docker/scripts:/scripts
148161
environment:
@@ -151,36 +164,34 @@ services:
151164
- MONGO3=mongo-cnf-3
152165
- RS=cnf-serv
153166
- PORT=27017
167+
- VERSION=${TEST_MONGODB_IMAGE}
154168
entrypoint: [ "/scripts/setup.sh","cnf_servers" ]
169+
networks:
170+
- cnf-serv
155171

156172
mongos:
157173
container_name: "mongos"
158174
image: ${TEST_MONGODB_IMAGE:-mongo:4.4}
159175
ports:
160176
- "${TEST_MONGODB_MONGOS_PORT:-17000}:27017"
177+
networks:
178+
- mongo-shard
179+
- rs1
180+
- rs2
181+
- cnf-serv
161182
depends_on:
162183
- "mongo-rs1-setup"
163184
- "mongo-rs2-setup"
164185
- "mongo-cnf-setup"
165-
external_links:
166-
- mongo-cnf-1:mongo-cnf-1
167-
- mongo-cnf-2:mongo-cnf-2
168-
- mongo-cnf-3:mongo-cnf-3
169-
- mongo-1-1:mongo-1-1
170-
- mongo-1-2:mongo-1-2
171-
- mongo-1-3:mongo-1-3
172-
- mongo-2-1:mongo-2-1
173-
- mongo-2-2:mongo-2-2
174-
- mongo-2-3:mongo-2-3
175186
command: mongos --configdb cnf-serv/mongo-cnf-1:27017,mongo-cnf-2:27017,mongo-cnf-3:27017 --port 27017 --bind_ip 0.0.0.0
176187

177188
mongo-shard-setup:
178189
container_name: "mongo-shard-setup"
179190
image: ${TEST_MONGODB_IMAGE:-mongo:4.4}
180191
depends_on:
181192
- "mongos"
182-
links:
183-
- mongos:mongos
193+
networks:
194+
- mongo-shard
184195
volumes:
185196
- ./docker/scripts:/scripts
186197
environment:
@@ -197,6 +208,7 @@ services:
197208
- PORT1=27017
198209
- PORT2=27017
199210
- PORT3=27017
211+
- VERSION=${TEST_MONGODB_IMAGE}
200212
entrypoint: [ "/scripts/init-shard.sh" ]
201213
restart: on-failure:20
202214

@@ -208,6 +220,7 @@ services:
208220
command: mongod --port 27017 --oplogSize 16
209221

210222
standalone-encrypted:
223+
user: root
211224
container_name: "standalone-encrypted"
212225
image: ${TEST_MONGODB_IMAGE:-mongo:4.4}
213226
ports:
@@ -216,3 +229,9 @@ services:
216229
- ./docker/secret/mongodb_secrets.txt:/secret/mongodb_secrets.txt
217230
- ./docker/scripts:/scripts
218231
command: /scripts/run-mongodb-encrypted.sh
232+
233+
networks:
234+
rs1:
235+
rs2:
236+
cnf-serv:
237+
mongo-shard:

docker/scripts/init-shard.sh

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
#!/bin/bash
2+
# `mongosh` is used starting from MongoDB 5.x
3+
MONGODB_CLIENT="mongosh --quiet"
4+
PARSED=(${VERSION//:/ })
5+
MONGODB_VERSION=${PARSED[1]}
6+
MONGODB_VENDOR=${PARSED[0]}
7+
if [ "`echo ${MONGODB_VERSION} | cut -c 1`" = "4" ]; then
8+
MONGODB_CLIENT="mongo"
9+
fi
10+
if [ "`echo ${MONGODB_VERSION} | cut -c 1`" = "5" ] && [ ${MONGODB_VENDOR} == "percona/percona-server-mongodb" ]; then
11+
MONGODB_CLIENT="mongo"
12+
fi
13+
echo "MongoDB vendor, client and version: ${MONGODB_VENDOR} ${MONGODB_CLIENT} ${MONGODB_VERSION}"
214

315
mongodb1=`getent hosts ${MONGOS} | awk '{ print $1 }'`
416

@@ -17,16 +29,20 @@ mongodb33=`getent hosts ${MONGO33} | awk '{ print $1 }'`
1729
port=${PORT:-27017}
1830

1931
echo "Waiting for startup.."
20-
until mongo --host ${mongodb1}:${port} --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)' &>/dev/null; do
32+
until ${MONGODB_CLIENT} --host ${mongodb1}:${port} --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)' &>/dev/null; do
2133
printf '.'
2234
sleep 1
2335
done
2436

2537
echo "Started.."
2638

2739
echo init-shard.sh time now: `date +"%T" `
28-
mongo --host ${mongodb1}:${port} <<EOF
40+
${MONGODB_CLIENT} --host ${mongodb1}:${port} <<EOF
2941
sh.addShard( "${RS1}/${mongodb11}:${PORT1},${mongodb12}:${PORT2},${mongodb13}:${PORT3}" );
3042
sh.addShard( "${RS2}/${mongodb21}:${PORT1},${mongodb22}:${PORT2},${mongodb23}:${PORT3}" );
43+
use test;
44+
db.createCollection("shard");
45+
sh.enableSharding("test");
46+
sh.shardCollection( "test.shard", { id: "hashed" }, false, { numInitialChunks: 500, collation: { locale: "simple" }} );
3147
sh.status();
3248
EOF

0 commit comments

Comments
 (0)