pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches...

34
Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa

Transcript of pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches...

Page 1: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

Continuous Integration f o r Commi t fes ts Testing all the patches all the time

Thomas Munro, PGCon 2018, Ottawa

Page 2: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

$ whoami• PostgreSQL hacker at EnterpriseDB (~3 years)

• Some things I’ve worked on: Parallel Hash Join, various parallel query infrastructure, transition tables for triggers (sous-chef), remote_apply, replay_lag, SKIP LOCKED, various portability stuff

Page 3: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

cfbot.cputube.org• List of current

proposed patches

• Does the patch apply, do the tests pass on Windows, do the tests pass on Linux?

• Recent changes highlighted

Page 4: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

Per author view

Page 5: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at
Page 6: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

• core file backtraces

• regression tests output diffs

Page 7: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

Motivation

Page 8: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

[email protected]

• ~140 people contributing code

• ~500 people contributing to discussions

• Up to ~250 proposed patches in consideration at a time

Page 9: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

commitfest.postgresql.org• 4 times a year patches are reviewed and committed in a month-long

‘commitfest’

• Patch submission and review is done entirely through the pgsql-hackers, pgsql-bugs, pgsql-committers mailing lists

• Patches are tracked through the commitfest.postgresql.org web app; registering a thread in the CF app is approximately like making a ‘pull request’ in many other projects

Page 10: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

Patch inflation

0

75

150

225

300

2014

-12

2015

-02

2015

-07

2015

-09

2015

-11

2016

-01

2016

-03

2016

-09

2016

-11

2017

-01

2017

-03

2017

-09

2017

-11

2018

-01

2018

-03

Moved Committed Returned Rejected

Page 11: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

Welcome, new contributors

0

30

60

90

120

2014

-12

2015

-02

2015

-07

2015

-09

2015

-11

2016

-01

2016

-03

2016

-09

2016

-11

2017

-01

2017

-03

2017

-09

2017

-11

2018

-01

2018

-03

Distinct patch authors

Page 12: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

How long do patches live?

0

25

50

75

100

1 2 3 4 5 6Age (no. commitfests) of patches that reached final state in CF 2018-03

Page 13: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

Reviewer & committer bandwidth is precious

Page 14: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

Automatically discoverable problems

• Bitrot: please rebase!

• Other compilers are pickier than yours

• Tests fail (maybe with obscure build options or full TAP tests)

• Portability bugs (endianness, word size, OS, libraries)

• Uninitialised data, race conditions, …

• Documentation is broken

Page 15: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

Build farm

• The build farm will find some of these problems automatically

• … but that happens after commit, and consumes committer time and energy

• People will shout at you — ask me how I know

• Let’s apply some of that sort of automation to proposals, during the review phase

Page 16: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

Implementation

Page 17: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

-1 from me

This time last year

• Daily cronjob to check for bitrot in time for morning coffee

• Various experiments with executing tests, but … how safe is that?

From: Cron Daemon <munro@asterix> Subject: Cron <munro@asterix> /home/munro/patches/patchmon.sh

7 out of 8 hunks failed while patching src/backend/libpq/auth.c Failed to apply /home/munro/patches/ldap-diagnostic-message-v3.patch 1 out of 2 hunks failed while patching configure 1 out of 2 hunks failed while patching configure.in Failed to apply /home/munro/patches/kqueue-v7.patch

Page 18: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

Let’s execute random code from the internet…

What could possibly go wrong?

Page 19: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

patch -p1 < foo.patch

• CVE-2018-1000156CVE-2016-10713CVE-2015-1418CVE-2015-1416CVE-2015-1395CVE-2015-1196CVE-2014-9637CVE-2010-4651

• patch: runs arbitrary shell commands

• patch: writes to files outside the target source tree

• patch: denial of service

Page 20: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

pristine source tree,

patch tools

cloned ZFS filesystem1

2

3 Apply patches in jail

4 Push branch to GitHub as commitfest/18/1234

5

patches

Destroy jail, filesystem

Step 1: Quarantine and apply

github.com/postgresql-cfbot/postgresql

Page 21: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at
Page 22: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at
Page 23: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

• Many wonderful, generous, free-for-open-source build-bot providers

• Running untrusted code in throw-away virtual machine images is their core business

• travis-ci.org for Ubuntu, macOSappveyor.com for Windows… there are many more

• Friendly result pages and APIs

Step 2: Build and test

Page 24: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

How to• Tell travis-ci.org, appveyor.com, … to watch your github.com,

bitbucket.com, … public source repository and build any branch with a control file in it

• Add the control file to your branch (.travis.yml, appveyor.yml etc as appropriate):script: ./configure … && make -j4 && make check

• This is a nice way to test your branches before you submit patches, and can send you emails, provide ‘badges’ for your web page, tell your IRC channel, release homing pigeons etc

• This talk is about plugging an old school mailing list workflow into this technology!

Page 25: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

cfbot information flow

git.postgresql.org

cfbot.cputube.org

commitfest.postgresql.org

GitHub

Travis CI

archives.postgresql.org

AppVeyor CI

Page 26: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at
Page 27: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

Step 3: Collect results

• CI providers have APIs where you can collect the results

• Collecting them in a small database allows consolidated reporting in one place

• You can also browse results directly at CI websites

Page 28: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

Active battles

Page 29: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

Windows• Currently able to run make check on appveyor.com CI, but the tablespace test fails so I just exclude it

• Not yet attempting to run check-world

• If you know how to fix this, please see me after, I will pay you in beer

Page 30: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

Rare transient false negatives

• —coverage .gdca files getting trampled on by multiple backends (later GCC will fix that)

• Failure to fetch “winflexbison” from sf.net

• Failure to fetch XSL files from oasis-open.org, sf.net

• Timeout of crash-restart TAP test —undiagnosed!

Page 31: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

Plans for the future

Page 32: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

Terriblemock-up

Page 33: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

• Run Coverity and other static analysis tools?

• Run Valgrind, Clang asan etc to look for bugs?

• Add a big endian 32 bit non-Linux system for maximum portability bug detection with one stone?

• Display built documentation for review?

• Make Travis/AppVeyor fetch and apply patches themselves?

• Put .travis.yml, .appveyor.yml files in the tree?

• Andreas Seltenreich’s SQL Smith?

• Code coverage report? (that is, reinstate)

• Automated performance testing…?

Page 34: pgcon 2018 - continuous integration...Continuous Integration for Commitfests Testing all the patches all the time Thomas Munro, PGCon 2018, Ottawa $ whoami • PostgreSQL hacker at

• Thanks to Andres Freund, Dagfinn Ilmari Mannsåker, Andrew Dunstan, Peter van Hardenberg, Oli Bridgman for ideas and scripting improvements

• Thanks to Travis CI and AppVeyor CI for supporting open source

• Thanks to pgsql-hackers for all the patches

Questions, ideas?