Page MenuHomePhabricator

[wikireplicas] Automated tests for views
Open, MediumPublic

Description

Today I discussed with @joanna_borun the idea of creating some automated tests that can be run every x hours to verify that all the Wiki Replica views are returning results, something like the following pseudocode:

for view in views:
  select * from view limit 1;

This would alert us when a schema change that is applied to the production dbs breaks a wiki replica view, e.g. if a schema change drops a column that is referenced by one or more views.

Ideally, we should detect that a schema change is going to break a view before the schema change is applied to the production dbs, but this could be a cheap fallback to implement.

Cc-ing @taavi @Marostegui to get a quick feedback on whether they think this would work and whether it would be useful.

Event Timeline

fnegri triaged this task as Medium priority.Jul 1 2024, 9:17 AM

That could work for sections without many objects, but s3 has 80k views, so probably you want to use information_schema and show warnings

You don't necessarily need to query all the tables, you can just hack things from information_schema:

root@clouddb1021.eqiad.wmnet[information_schema]> select count(*) from tables where table_schema like '%wik%' and table_type='view';
+----------+
| count(*) |
+----------+
|    81788 |
+----------+
1 row in set (3.990 sec)

So something like this could work faster than querying each of them which can take hours:

root@clouddb1021.eqiad.wmnet[information_schema]> pager pager > /dev/null ; select * from tables where table_schema like '%wik%' and table_type='view' ; nopager; show warnings;
PAGER set to 'pager > /dev/null'
81788 rows in set, 77 warnings (30.287 sec)

PAGER set to stdout
+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                                              |
+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1356 | View 'ptwikinews_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them   |
| Warning | 1356 | View 'ptwikinews_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them      |
| Warning | 1356 | View 'alswiki_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them      |
| Warning | 1356 | View 'alswiki_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them         |
| Warning | 1356 | View 'bawiki_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them       |
| Warning | 1356 | View 'bewiki_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them       |
| Warning | 1356 | View 'bewiki_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them          |
| Warning | 1356 | View 'bnwiki_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them       |
| Warning | 1356 | View 'bnwiki_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them          |
| Warning | 1356 | View 'bswiki_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them       |
| Warning | 1356 | View 'bswiki_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them          |
| Warning | 1356 | View 'cawikinews_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them   |
| Warning | 1356 | View 'cawikinews_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them      |
| Warning | 1356 | View 'cewiki_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them       |
| Warning | 1356 | View 'cewiki_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them          |
| Warning | 1356 | View 'ckbwiki_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them      |
| Warning | 1356 | View 'ckbwiki_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them         |
| Warning | 1356 | View 'dewikiquote_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them  |
| Warning | 1356 | View 'dewikiquote_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them     |
| Warning | 1356 | View 'dewiktionary_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them |
| Warning | 1356 | View 'dewiktionary_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them    |
| Warning | 1356 | View 'elwikinews_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them   |
| Warning | 1356 | View 'elwikinews_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them      |
| Warning | 1356 | View 'enwikibooks_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them  |
| Warning | 1356 | View 'enwikibooks_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them     |
| Warning | 1356 | View 'enwikinews_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them   |
| Warning | 1356 | View 'enwikinews_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them      |
| Warning | 1356 | View 'eswikinews_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them   |
| Warning | 1356 | View 'eswikinews_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them      |
| Warning | 1356 | View 'fawikinews_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them   |
| Warning | 1356 | View 'fawikinews_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them      |
| Warning | 1356 | View 'frwikinews_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them   |
| Warning | 1356 | View 'frwikinews_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them      |
| Warning | 1356 | View 'hewikisource_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them |
| Warning | 1356 | View 'hewikisource_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them    |
| Warning | 1356 | View 'hiwiki_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them       |
| Warning | 1356 | View 'hiwiki_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them          |
| Warning | 1356 | View 'iawiki_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them       |
| Warning | 1356 | View 'iawiki_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them          |
| Warning | 1356 | View 'iswiktionary_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them |
| Warning | 1356 | View 'iswiktionary_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them    |
| Warning | 1356 | View 'kawiki_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them       |
| Warning | 1356 | View 'kawiki_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them          |
| Warning | 1356 | View 'lawikisource_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them |
| Warning | 1356 | View 'lawikisource_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them    |
| Warning | 1356 | View 'mkwiki_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them       |
| Warning | 1356 | View 'mkwiki_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them          |
| Warning | 1356 | View 'plwikisource_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them |
| Warning | 1356 | View 'plwikisource_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them    |
| Warning | 1356 | View 'plwiktionary_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them |
| Warning | 1356 | View 'plwiktionary_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them    |
| Warning | 1356 | View 'ptwikibooks_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them  |
| Warning | 1356 | View 'ptwikibooks_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them     |
| Warning | 1356 | View 'ruwikimedia_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them  |
| Warning | 1356 | View 'ruwikinews_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them   |
| Warning | 1356 | View 'ruwikinews_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them      |
| Warning | 1356 | View 'ruwikiquote_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them  |
| Warning | 1356 | View 'ruwikiquote_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them     |
| Warning | 1356 | View 'ruwikisource_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them |
| Warning | 1356 | View 'ruwikisource_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them    |
| Warning | 1356 | View 'ruwiktionary_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them |
| Warning | 1356 | View 'ruwiktionary_p.flaggedtemplates' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them    |
| Warning | 1356 | View 'siwiki_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them       |
| Warning | 1356 | View 'sqwiki_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them       |
+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------+
64 rows in set (0.002 sec)

All those views are supposed to be broken so you can now verify with the select * from XX limit 1:

root@clouddb1021.eqiad.wmnet[information_schema]> select * from ptwikinews_p.flaggedpage_pending limit 1;
ERROR 1356 (HY000): View 'ptwikinews_p.flaggedpage_pending' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them

Right now processes that can break a view are:

  • Dropping a column
  • Adding a column
  • Dropping a table.
fnegri removed a subscriber: taavi.

@Marostegui thanks that's very useful! I can try implementing this as a Python script called by a systemd timer on each clouddb host. Then we can publish the results of the script to prometheus, and add an alert when the number of broken views is greater than zero.

I also created T368939: [wikireplicas] Views flaggedpage_pending and flaggedtemplates are broken to fix the broken views that you found with your manual check.

@Marostegui thanks that's very useful! I can try implementing this as a Python script called by a systemd timer on each clouddb host. Then we can publish the results of the script to prometheus, and add an alert when the number of broken views is greater than zero.

Sounds good :)

I also created T368939: [wikireplicas] Views flaggedpage_pending and flaggedtemplates are broken to fix the broken views that you found with your manual check.

Those come from:

They just need to be removed from maintain-views.yaml and run the cookbook.