Skip to content

Commit eb53a96

Browse files
deer-wmderosalieperwmdebot
authored
add mediawiki update job verification script (#2371)
* add mediawiki update job verification script * decrease caching TTL in nginx conf and add a delay before removing the read-only mode of a wiki (#2370) * Fix broken curl command (#2372) * (chore): Update api-queue CPU requests (#2342) * (chore): Update api-queue CPU requests * Update api.values.yaml.gotmpl * argo values * Staging+Local: Deploy new MediaWiki image ghcr.io/wbstack/mediawiki:sha-a72fadf (#2373) * Production: Deploy new MediaWiki image ghcr.io/wbstack/mediawiki:sha-a72fadf (#2374) * improve output * update README * clean up output * fix typo --------- Co-authored-by: Perside Rosalie <perside.rosalie@wikimedia.de> Co-authored-by: wmdebot <121924840+wmdebot@users.noreply.github.com>
1 parent 7f498a7 commit eb53a96

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

k8s/jobs/README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,21 @@ It uses the primary replica to write to.
8181
use the ENV `WBS_DOMAIN
8282

8383
This script loops through all wikis and run `addPlatformReservedUser.sh` on each wiki to put `PlatformReservedUser` to bot group.
84-
Run `list-wiki-domains` first, save it to a file (for example: `domains.txt`), then run `addPlatformReservedUserToBotGroupForAllWikis.sh`.
84+
Run `list-wiki-domains` first, save it to a file (for example: `domains.txt`), then run `addPlatformReservedUserToBotGroupForAllWikis.sh`.
85+
86+
## mediawikiUpdate.sh
87+
Example of ENV variables to set
88+
```sh
89+
WBS_DOMAIN=coffeebase.wikibase.cloud
90+
MEDIAWIKI_BACKEND_INSTANCE_LABEL=mediawiki-143
91+
MW_VERSION=mw1.43-wbs1
92+
```
93+
94+
Creates a Job that spins up it's own mediawiki pod to run the mediawiki update maintenance script (`run.php update --quick`)
95+
96+
- Before that script is ran the wiki gets set to read-only mode
97+
- After it has run the dbVersion gets updated in the API
98+
- and read-only mode gets disabled again after two minutes (nginx cache TTL)
99+
100+
## verifyMediaWikiUpdates.sh
101+
Reports status for k8s Jobs kicked off via `mediawikiUpdate.sh`. Filters for them via namespace `adhoc-jobs` and the metadata label `wikiDomain`.

k8s/jobs/mediawikiUpdate.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@ kubectl create -f mediawikiUpdate.yaml -o=json --dry-run=client | \
3636
jq --arg wbs "$WBS_DOMAIN" --arg mwver "$MW_VERSION" '.[0].spec.template.spec.containers[0].env += [{"name": "WBS_DOMAIN", "value": $wbs}, {"name": "MW_VERSION", "value": $mwver}]' | \
3737
# return just the Job spec (dropping the existing Pod one)
3838
jq '.[0]' | \
39+
# add a k8s label to the job object with the wiki domain
40+
jq --arg wbs "$WBS_DOMAIN" '.metadata.labels += {"wikiDomain": $wbs}' | \
3941
# create the now fully formed Job from the spec
4042
kubectl create -f -

k8s/jobs/mediawikiUpdate.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,12 @@ spec:
4545
curl --fail --location --silent --request PUT \
4646
"http://${PLATFORM_API_BACKEND_HOST}/backend/setWikiDbVersion?domain=${WBS_DOMAIN}&dbVersion=${MW_VERSION}"
4747
log_info "database version updated to ${MW_VERSION}"
48-
log_info "Pause for 2 minutes before disabling readOnly mood"
48+
log_info "Pause for 2 minutes before disabling readOnly mode"
4949
sleep 120
5050
curl --fail --location --silent --request PUT \
5151
"http://${PLATFORM_API_BACKEND_HOST}/backend/setWikiReadOnly?domain=${WBS_DOMAIN}&readOnly=0"
5252
log_info "readOnly mode will be disabled for ${WBS_DOMAIN}"
5353
else
54-
log_error "update.php failed to run and exit with code $status"
5554
log_error "update.php failed to run and exit with code $status"
5655
exit 1
5756
fi

k8s/jobs/verifyMediawikiUpdates.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
JOBS=$(kubectl get jobs -n adhoc-jobs -o json)
4+
5+
COMPLETED=$(echo $JOBS | jq -r '.items[] | select((.status.succeeded // 0) >= 1 and (.metadata.labels | has("wikiDomain"))) | "\(.metadata.name)\t\(.metadata.labels.wikiDomain)"')
6+
7+
INCOMPLETE=$(echo $JOBS | jq -r '.items[] | select((.status.succeeded // 0) < 1 and (.metadata.labels | has("wikiDomain"))) | "\(.metadata.name)\t\(.metadata.labels.wikiDomain)"')
8+
# alternative query for incomplete jobs without wikiDomain label
9+
#INCOMPLETE=$(echo $JOBS | jq -r '.items[] | select((.status.succeeded // 0) < 1) | "\(.metadata.name)"')
10+
11+
COMPLETED_COUNT=$(printf "%s" "$COMPLETED" | wc -l)
12+
INCOMPLETE_COUNT=$(printf "%s" "$INCOMPLETE" | wc -l)
13+
14+
echo "Completed jobs:"
15+
echo "$COMPLETED"
16+
echo
17+
echo "Number of completed jobs: $COMPLETED_COUNT"
18+
echo
19+
echo '---'
20+
echo
21+
echo "Incomplete jobs:"
22+
echo "$INCOMPLETE"
23+
echo
24+
echo "Number of completed jobs: $INCOMPLETE_COUNT"

0 commit comments

Comments
 (0)