Skip to content

Commit 995f869

Browse files
pooknullhors
andauthored
K8SPSMDB-818: fix explainRole role (#1317)
* K8SPSMDB-818: fix `explainRole` role https://jira.percona.com/browse/K8SPSMDB-818 * improve monitoring test * fix roles * improve `get_qan_values` function * update privileges only for crVersion > 1.15.0 * comment qan check * small change * fix `init-deploy` test --------- Co-authored-by: Viacheslav Sarzhan <[email protected]>
1 parent 935b8d0 commit 995f869

File tree

13 files changed

+164
-93
lines changed

13 files changed

+164
-93
lines changed

e2e-tests/demand-backup-sharded/run

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,6 @@ test_dir=$(realpath "$(dirname "$0")")
77
. "${test_dir}/../functions"
88
set_debug
99

10-
insert_data() {
11-
local data=$1
12-
13-
for i in $(seq 0 2); do
14-
run_mongos \
15-
"use myApp${i/0/}\n db.test.insert({ x: ${data} })" \
16-
"myApp:myPass@$cluster-mongos.$namespace"
17-
done
18-
}
19-
2010
check_data() {
2111
local postfix=$1
2212

@@ -78,7 +68,9 @@ run_mongos \
7868
run_mongos \
7969
'sh.enableSharding("myApp2","rs2")' \
8070
"clusterAdmin:clusterAdmin123456@$cluster-mongos.$namespace"
81-
insert_data "100500"
71+
insert_data_mongos "100500" "myApp"
72+
insert_data_mongos "100500" "myApp1"
73+
insert_data_mongos "100500" "myApp2"
8274
minikube_sleep
8375
compare_mongos_cmd "find" "myApp:myPass@$cluster-mongos.$namespace"
8476

@@ -117,7 +109,9 @@ if [ -z "$SKIP_BACKUPS_TO_AWS_GCP_AZURE" ]; then
117109
curl -s "https://s3.amazonaws.com/${backup_dest_aws}/rs0/myApp.test.gz" | gunzip >/dev/null
118110
curl -s "https://s3.amazonaws.com/${backup_dest_aws}/rs1/myApp1.test.gz" | gunzip >/dev/null
119111
curl -s "https://s3.amazonaws.com/${backup_dest_aws}/rs2/myApp2.test.gz" | gunzip >/dev/null
120-
insert_data "100501"
112+
insert_data_mongos "100501" "myApp"
113+
insert_data_mongos "100501" "myApp1"
114+
insert_data_mongos "100501" "myApp2"
121115
check_data "-2nd"
122116
run_restore "$backup_name_aws"
123117
wait_restore "$backup_name_aws" "$cluster"
@@ -128,7 +122,9 @@ if [ -z "$SKIP_BACKUPS_TO_AWS_GCP_AZURE" ]; then
128122
curl -s "https://storage.googleapis.com/${backup_dest_gcp}/rs0/myApp.test.gz" | gunzip >/dev/null
129123
curl -s "https://storage.googleapis.com/${backup_dest_gcp}/rs1/myApp1.test.gz" | gunzip >/dev/null
130124
curl -s "https://storage.googleapis.com/${backup_dest_gcp}/rs2/myApp2.test.gz" | gunzip >/dev/null
131-
insert_data "100501"
125+
insert_data_mongos "100501" "myApp"
126+
insert_data_mongos "100501" "myApp1"
127+
insert_data_mongos "100501" "myApp2"
132128
check_data "-2nd"
133129
run_restore "$backup_name_gcp"
134130
wait_restore "$backup_name_gcp" "$cluster"
@@ -139,7 +135,9 @@ if [ -z "$SKIP_BACKUPS_TO_AWS_GCP_AZURE" ]; then
139135
curl -s "https://engk8soperators.blob.core.windows.net/${backup_dest_azure}/rs0/myApp.test.gz" | gunzip >/dev/null
140136
curl -s "https://engk8soperators.blob.core.windows.net/${backup_dest_azure}/rs1/myApp1.test.gz" | gunzip >/dev/null
141137
curl -s "https://engk8soperators.blob.core.windows.net/${backup_dest_azure}/rs2/myApp2.test.gz" | gunzip >/dev/null
142-
insert_data "100501"
138+
insert_data_mongos "100501" "myApp"
139+
insert_data_mongos "100501" "myApp1"
140+
insert_data_mongos "100501" "myApp2"
143141
check_data "-2nd"
144142
run_restore "$backup_name_azure"
145143
wait_restore "$backup_name_azure" "$cluster"
@@ -152,7 +150,9 @@ kubectl_bin run -i --rm aws-cli --image=perconalab/awscli --restart=Never -- \
152150
/usr/bin/env AWS_ACCESS_KEY_ID=some-access-key AWS_SECRET_ACCESS_KEY=some-secret-key AWS_DEFAULT_REGION=us-east-1 \
153151
/usr/bin/aws --endpoint-url http://minio-service:9000 s3 ls "s3://${backup_dest_minio}/rs0/" \
154152
| grep "myApp.test.gz"
155-
insert_data "100501"
153+
insert_data_mongos "100501" "myApp"
154+
insert_data_mongos "100501" "myApp1"
155+
insert_data_mongos "100501" "myApp2"
156156
check_data "-2nd"
157157
run_restore "$backup_name_minio"
158158
wait_restore "$backup_name_minio" "$cluster"

e2e-tests/functions

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -667,9 +667,9 @@ compare_kubectl() {
667667
del(.spec.ipFamilyPolicy) |
668668
(.. | select(. == "extensions/v1beta1")) = "apps/v1" |
669669
(.. | select(. == "batch/v1beta1")) = "batch/v1" ' - >${new_result}
670-
670+
671671
yq -i eval 'del(.spec.persistentVolumeClaimRetentionPolicy)' ${new_result}
672-
672+
673673
if version_gt "1.22"; then
674674
yq -i eval 'del(.spec.internalTrafficPolicy)' ${new_result}
675675
yq -i eval 'del(.spec.allocateLoadBalancerNodePorts)' ${new_result}
@@ -979,56 +979,50 @@ get_metric_values() {
979979
}
980980

981981
get_qan_values() {
982-
local instance=$1
983-
local start=$($date -u "+%Y-%m-%dT%H:%M:%S" -d "-30 minute")
984-
local end=$($date -u "+%Y-%m-%dT%H:%M:%S")
985-
local endpoint=$(get_service_endpoint monitoring-service)
986-
987-
local uuid=$(
988-
curl -s -k "https://$endpoint/qan-api/instances?deleted=no" \
989-
| jq '.[] | select(.Subsystem == "mongo" and .Name == "'$instance'") | .UUID' \
990-
| sed -e 's/^"//; s/"$//;'
991-
)
992-
993-
curl -s -k "https://$endpoint/qan-api/qan/profile/$uuid?begin=$start&end=$end&offset=0" \
994-
| jq '.Query[].Fingerprint'
995-
}
996-
997-
get_qan20_values() {
998-
local instance=$1
982+
local service_type=$1
999983
local user_pass=$2
1000-
local start=$($date -u "+%Y-%m-%dT%H:%M:%S" -d "-30 minute")
1001-
local end=$($date -u "+%Y-%m-%dT%H:%M:%S")
1002-
local endpoint=$(get_service_endpoint monitoring-service)
984+
local start
985+
local end
986+
local endpoint
987+
start=$($date -u -d '-12 hour' '+%Y-%m-%dT%H:%M:%S%:z')
988+
end=$($date -u '+%Y-%m-%dT%H:%M:%S%:z')
989+
endpoint=$(get_service_endpoint monitoring-service)
1003990

1004991
cat >payload.json <<EOF
1005992
{
1006-
"columns":[
1007-
"load",
1008-
"num_queries",
1009-
"query_time"
1010-
],
1011-
"first_seen": false,
1012-
"group_by": "queryid",
1013-
"include_only_fields": [],
1014-
"keyword": "",
1015-
"labels": [
1016-
{
1017-
"key": "cluster",
1018-
"value": ["monitoring"]
1019-
}],
1020-
"limit": 10,
1021-
"offset": 0,
1022-
"order_by": "-load",
1023-
"main_metric": "load",
1024-
"period_start_from": "$($date -u -d '-12 hour' '+%Y-%m-%dT%H:%M:%S%:z')",
1025-
"period_start_to": "$($date -u '+%Y-%m-%dT%H:%M:%S%:z')"
993+
"period_start_from": "$start",
994+
"period_start_to": "$end",
995+
"group_by": "queryid",
996+
"labels": [
997+
{
998+
"key": "service_type",
999+
"value": [
1000+
"All",
1001+
"$service_type"
1002+
]
1003+
}
1004+
],
1005+
"columns": [
1006+
"load",
1007+
"num_queries",
1008+
"query_time"
1009+
],
1010+
"order_by": "-load",
1011+
"offset": 0,
1012+
"limit": 10,
1013+
"main_metric": "load",
1014+
"search": ""
10261015
}
10271016
EOF
10281017

1029-
curl -s -k -XPOST -d @payload.json "https://${user_pass}@$endpoint/v0/qan/GetReport" \
1030-
| jq '.rows[].fingerprint'
1018+
local response
1019+
response=$(curl -s -k -XPOST -d @payload.json "https://${user_pass}@$endpoint/v0/qan/GetReport" \
1020+
| jq '.rows[].fingerprint')
10311021
rm -f payload.json
1022+
if [[ $response == "null" ]]; then
1023+
echo "No data for $service_type service type in QAN"
1024+
exit 1
1025+
fi
10321026
}
10331027

10341028
cat_config() {
@@ -1278,7 +1272,10 @@ check_passwords_leak() {
12781272
secrets=$(kubectl_bin get secrets -o json | jq -r '.items[].data | to_entries | .[] | select(.key | (contains("_PASSWORD"))) | .value')
12791273
echo secrets=$secrets
12801274

1281-
passwords="$(for i in $secrets; do base64 -d <<< $i; echo; done) $secrets"
1275+
passwords="$(for i in $secrets; do
1276+
base64 -d <<<$i
1277+
echo
1278+
done) $secrets"
12821279
echo passwords=$passwords
12831280

12841281
pods=$(kubectl_bin get pods -o name | awk -F "/" '{print $2}')
@@ -1295,7 +1292,7 @@ check_passwords_leak() {
12951292
if [[ ${c} =~ "pmm" ]]; then
12961293
continue
12971294
fi
1298-
kubectl_bin -n "$NS" logs $p -c $c > ${TEMP_DIR}/logs_output-$p-$c.txt
1295+
kubectl_bin -n "$NS" logs $p -c $c >${TEMP_DIR}/logs_output-$p-$c.txt
12991296
echo logs saved in: ${TEMP_DIR}/logs_output-$p-$c.txt
13001297
for pass in $passwords; do
13011298
count=$(grep -c --fixed-strings -- "$pass" ${TEMP_DIR}/logs_output-$p-$c.txt || :)
@@ -1315,3 +1312,14 @@ check_passwords_leak() {
13151312
collect_logs $OPERATOR_NS
13161313
fi
13171314
}
1315+
1316+
insert_data_mongos() {
1317+
local data=$1
1318+
local db_name=$2
1319+
local flags=$3
1320+
1321+
run_mongos \
1322+
"use ${db_name}\n db.test.insert({ x: ${data} })" \
1323+
"myApp:myPass@$cluster-mongos.$namespace" "" "" \
1324+
"$flags"
1325+
}

e2e-tests/init-deploy/compare/clusterMonitor-42.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@
2828
},
2929
"actions": [
3030
"collStats",
31+
"dbHash",
3132
"dbStats",
33+
"find",
3234
"getDatabaseVersion",
3335
"getShardVersion",
34-
"indexStats"
36+
"indexStats",
37+
"listCollections",
38+
"listIndexes"
3539
]
3640
},
3741
{
@@ -41,11 +45,9 @@
4145
},
4246
"actions": [
4347
"collStats",
44-
"dbHash",
4548
"dbStats",
4649
"find",
47-
"listCollections",
48-
"listIndexes"
50+
"indexStats"
4951
]
5052
},
5153
{

e2e-tests/init-deploy/compare/clusterMonitor-44.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@
2828
},
2929
"actions": [
3030
"collStats",
31+
"dbHash",
3132
"dbStats",
33+
"find",
3234
"getDatabaseVersion",
3335
"getShardVersion",
34-
"indexStats"
36+
"indexStats",
37+
"listCollections",
38+
"listIndexes"
3539
]
3640
},
3741
{
@@ -41,11 +45,9 @@
4145
},
4246
"actions": [
4347
"collStats",
44-
"dbHash",
4548
"dbStats",
4649
"find",
47-
"listCollections",
48-
"listIndexes"
50+
"indexStats"
4951
]
5052
},
5153
{

e2e-tests/init-deploy/compare/clusterMonitor-50.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@
2828
},
2929
"actions": [
3030
"collStats",
31+
"dbHash",
3132
"dbStats",
33+
"find",
3234
"getDatabaseVersion",
3335
"getShardVersion",
34-
"indexStats"
36+
"indexStats",
37+
"listCollections",
38+
"listIndexes"
3539
]
3640
},
3741
{
@@ -41,11 +45,9 @@
4145
},
4246
"actions": [
4347
"collStats",
44-
"dbHash",
4548
"dbStats",
4649
"find",
47-
"listCollections",
48-
"listIndexes"
50+
"indexStats"
4951
]
5052
},
5153
{

e2e-tests/init-deploy/compare/clusterMonitor-60.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@
2828
},
2929
"actions": [
3030
"collStats",
31+
"dbHash",
3132
"dbStats",
33+
"find",
3234
"getDatabaseVersion",
3335
"getShardVersion",
34-
"indexStats"
36+
"indexStats",
37+
"listCollections",
38+
"listIndexes"
3539
]
3640
},
3741
{
@@ -41,11 +45,9 @@
4145
},
4246
"actions": [
4347
"collStats",
44-
"dbHash",
4548
"dbStats",
4649
"find",
47-
"listCollections",
48-
"listIndexes"
50+
"indexStats"
4951
]
5052
},
5153
{

e2e-tests/monitoring-2-0/compare/statefulset_monitoring-cfg-oc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ spec:
212212
- name: PMM_AGENT_SETUP_METRICS_MODE
213213
value: push
214214
- name: PMM_ADMIN_CUSTOM_PARAMS
215-
value: --environment=dev-mongod
215+
value: --enable-all-collectors --environment=dev-mongod
216216
- name: PMM_AGENT_SERVER_USERNAME
217217
value: api_key
218218
- name: PMM_AGENT_SERVER_PASSWORD

e2e-tests/monitoring-2-0/compare/statefulset_monitoring-cfg.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ spec:
213213
- name: PMM_AGENT_SETUP_METRICS_MODE
214214
value: push
215215
- name: PMM_ADMIN_CUSTOM_PARAMS
216-
value: --environment=dev-mongod
216+
value: --enable-all-collectors --environment=dev-mongod
217217
- name: PMM_AGENT_SERVER_USERNAME
218218
value: api_key
219219
- name: PMM_AGENT_SERVER_PASSWORD

e2e-tests/monitoring-2-0/compare/statefulset_monitoring-rs0-oc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ spec:
200200
- name: PMM_AGENT_SETUP_METRICS_MODE
201201
value: push
202202
- name: PMM_ADMIN_CUSTOM_PARAMS
203-
value: --environment=dev-mongod
203+
value: --enable-all-collectors --environment=dev-mongod
204204
- name: PMM_AGENT_SERVER_USERNAME
205205
value: api_key
206206
- name: PMM_AGENT_SERVER_PASSWORD

e2e-tests/monitoring-2-0/compare/statefulset_monitoring-rs0.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ spec:
201201
- name: PMM_AGENT_SETUP_METRICS_MODE
202202
value: push
203203
- name: PMM_ADMIN_CUSTOM_PARAMS
204-
value: --environment=dev-mongod
204+
value: --enable-all-collectors --environment=dev-mongod
205205
- name: PMM_AGENT_SERVER_USERNAME
206206
value: api_key
207207
- name: PMM_AGENT_SERVER_PASSWORD

0 commit comments

Comments
 (0)