Integrating a bug fix into Moodle core: the mechanics

Having seen Tim’s post about fixing a bug in Moodle core I thought I should take the opportunity to follow up with the next part of the process – integrating the changes into the Moodle core. Once a developer has produced a fix which is ready for integration and requests a integration review then the bug is ‘handed over’ to the integration team.

The integration team

The integration team is staffed by a group of developers at Moodle HQ. We are a geographically disparate team, spread across the world in order to prevent natural disasters and political unrest from affecting the Moodle weekly release cycle.1 Aparup and I are located in Perth, Australia; Eloy in Lardero, Spain and Sam in Nelson, New Zealand.

Together we have 20 years of Moodle development experience and this collective experience is an important part of how we work together as a team – knowing the idiosyncrasies of Moodle – how parts of the system have come to being and understanding how changes can potentially affect different areas which might otherwise be missed. I should say that since i’m the newest member of this team (and still learning the ropes) I hope that my comments are accurate!

The integration review

The integration team is responsible for ‘pulling’ code from all developers around the world, reviewing and bringing it together (integrating it!) to make up the Moodle core release. This process is the same for all developers no matter whether they work for Moodle HQ, a University, Moodle Partner or none of the above.

The purpose of the integration review could be misconceived simply as as a final technical code review before code gets into core. That is certainly a large part of it – we are striving to continually increase the quality of Moodle releases through technical reviews, increased testing and other processes. But the integration review is also about examining the impact of each change from our users point of view – ensuring that we don’t loose focus of Moodle as supporting education! Other aspects of the integration review include ensuring that discussion has taken place with interested parties before a change lands and facilitating that if it hasn’t as well as providing guidance and feedback to contributors – helping developers learn why we might want changes or if there is something that could be useful for next time.

Anyway enough preamble, the title promised mechanics so..

Down to mechanics

At the start of each week we being a new integration cycle and on average there are 30-40 issues waiting for integration into Moodle core. The process begins with an integrator moving issues waiting for integration into the ‘current integration’. Issues marked as in the ‘current integration’ are those which we will work on for this cycle. We make this distinction simply to avoid the bucket of issues we are working to integrate for the weekly release from constantly refilling.

The integrators work through the queue of issues waiting for integration one by one – in this case I cheated a bit and allocated myself MDL-32039 early, as I thought it’d be a good opportunity to do a follow up post to Tim.

Reviewing the History

The first step is to mark an issue as ‘in integration review’ in the tracker workflow (pictured) and starting to read back the comments in the issue – learning about the history of this change. In this case the change is fairly obvious and straight forward so there is not too much to consider. But sometimes there might be debate about a particular approach or how to solve an issue and comments from peer reviewers or watchers of the issue. Or indeed there might be no discussion at all when someone is proposing do something particularly radical which is equally important to note.

As a brief side note – I personally encourage all developers to ‘vocalise’ even their internal though process through bug comments and commit messages. Its an often forgoten about communication method but comments on a bug like this can help reviewers now understand the decisions without too much back and forth. And perhaps more importantly months and years down the line it can be used by other developers to understand why a change was introduced even if you are no longer working on Moodle or if you’ve forgotten.

Reviewing the code

At the point of integration review, we review changes ‘in situation’ to see how the fit with other integrated issues. So the first step is to pull the change into the master integration branch.

danp@marge ~/git/integration> git checkout master
Switched to branch 'master'
danp@marge ~/git/integration> git fetch origin
danp@marge ~/git/integration> git reset --hard origin/master
HEAD is now at abd2899 MDL-31768 - it is not possible to add a picture to the thanks page in feedback

Some notes about this first step. On git.moodle.org we have two repositories, the production moodle.git (which almost everyone should be using) is the result of what the integration process produces. We also have integration.git which is our ‘staging’ repository where we pull changes, integrate and test – this is where integration work happens before deploying to moodle.git. integration.git is intentionally separate and volatile, this is where we iron out the kinks before pushing to the production moodle.git. I have a separate integration checkout which I am using here for reviewing changes and pushing to the integration repository.

To explain what I did – I first checked out the master branch of the integration repository and brutally reset this to the current state of the integration repository to accept new changes. In most git workflows this is not an advisable strategy but the way I use my integration repository I always want it to be completely clean and blow away any changes (in fact I have a script which does this on all branches) so I am happy to do this.

Now to pull Tim’s changes:

danp@marge ~/git/integration> git pull git://github.com/timhunt/moodle.git MDL-32039
From git://github.com/timhunt/moodle
 * branch            MDL-32039  -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 .../lang/en/tool_qeupgradehelper.php               |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

I now have Tim’s changes in the master integration branch and it merged successfully without issue. This was straight forward – which is not surprising as its a fairly self contained issue and nobody else has been working on that language file this week. But simple merges are not always the case. We ask developers to rebase their changes against the latest weekly release to reduce the frequency of conflicts, but sometimes the integrator will have two changes integrated during the same week and there will be conflicts. Common examples of merge conflicts are multiple changes to the major version number in one week. This is where integrators need to examine the differences and either resolve the conflict manually or delay an issue as it might be affected by another issue which is conflicting.

Since that was straight forward I can move straight onto reviewing the change:

danp@marge ~/git/integration> git diff origin/master..master --stat
 .../lang/en/tool_qeupgradehelper.php               |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
danp@marge ~/git/integration> git diff origin/master..master

First I look at a quick summary of lines changed – this is useful to find if there are any unexpected places where lines are changed. Then I look at a diff in unified format – which when reviewing open source code you get very used to. But since this is a language change I actually decide to review it in a more readable format by using the –word-diff option of git diff.

danp@marge ~/git/integration> git diff origin/master..master --word-diff

In –word-diff format we are much more easily able to see this change and it looks good. In other circumstances the –ignore-space-change option can also be useful to find just the changes that have happened ignoring space changes such as indentations (when introducing a conditional and so forth). We will also look around the files in full form and history of file changes around the area in question. I tend to use the command line and vim, others will use IDEs such as netbeans and eclipse.

Commence pre-flight checks

At this stage I have reviewed the change, tested it and understood the impact and i’m confident in the code change that i’m ready to integrate the change. However, we have another tool up our sleeves for checking changes before integrating – our loyal servant Jenkins. Jenkins is a continuous integration server which we are in the early stages of integrating into the Moodle workflow thanks to some great work by Eloy.

I am able to run a pre-check on Tims branch before integrating. This pre-check will run the various code checkers against Tim’s change to spot problems and then produce a report on this. In the future its planned that this will happen without an integrators involvement automatically when an issue is submitted for integration.

Luckily (and as expected) the checks ran successfully and no issues were found so I am now ready to push to integration.

Rinse and repeat

Since the change in question affects multiple branches and not just master I need to repeat the review process for all other branches required (2.1 and 2.2 in this case). In the interests of keeping you awake, i’ve spared you this process. :)

Pushing.. done2

The time has come to push to the integration repository:

danp@marge ~/git/integration> git push integration-push master MOODLE_22_STABLE MOODLE_21_STABLE
Compressing objects: 100% (24/24), done.
Writing objects: 100% (26/26), 3.14 KiB, done
   21cadef..7d7331b  MOODLE_21_STABLE -> MOODLE_21_STABLE
   18ca35b..41b4bb0  MOODLE_22_STABLE -> MOODLE_22_STABLE
   abd2899..6461e14  master -> master

Done? Well not quite.. at this point the previously mentioned continuous integration server notices the change in the integration repository which has been pushed and starts running a series of tests on the changed branches. There are too many checks to go into here and they continually being evolved, but for example we will run all unit tests and ensure ‘the build is not broken’ as well as conduct fresh installs and upgrades and compare that upgraded data is exactly matching newly installed data. This automated testing stage can prevent serious and difficult to spot regressions before they make their way into production and indeed in last weeks integration cycle it caught two such bugs.

Mark as Integrated

Once the change has been pushed, we will then mark the change as integrated in the tracker and the worflow will change to mark the issue as ready for testing.

Unresolved

Since this blog post has grown to much longer than I expected, I will stop my description of the integration process as this point. I hope some of you made it to the end :)

  1. That might not be the reason.. ;-) []
  2. The title is a little in-joke as we integrators have a simple semaphore system to help avoid unnecessary conflicts by first calling out ‘pushing’ (on a chat channel) when starting the process of pushing branches and releasing ‘our lock’ completing with another shout of ‘done’. []

The beer is about to get a lot colder..

When Tim first returned to the UK from his time at Moodle HQ, the first thing he did1 was to invite me to come to The Great British Beer Festival with him. Apparently i’d taunted him with reports of Real Ale whilst he was in Perth. Well.. it’s time for Tim to get his own back!

The view out of my office window today in LancasterAfter seven years working at LUNS and nine years living in Lancaster, I’ve decided to have a change of scenery and i’m going to be leaving many great friends and colleagues behind to move to Moodle HQ in Perth, Australia. Needless to say, this was not an easy decision to make. (Although the weather like Lancaster demonstrated today could convince me otherwise!)

My involvement with Moodle started with LUNS and it has been a great journey. We were newcomers to the Moodle community with a small project to move a few keen high-schools onto supported hosting platform in 2005. My first post to moodle.org was asking the theme forums for advice on how to do multiple themes on a single codebase and the first patch I remember getting accepted was to help us solve that problem six months later: MDL-6784.2 Today LUNS is one of the largest non-HQ code contributors to recent Moodle releases and have provided hundreds of thousands of people with access to Moodle through our various clients – primary school students3, university lecturers4, high school teachers, company employees and charity workers. I’ve thoroughly enjoyed that journey and the great people who have made it what it is.

I’m really looking forward to working for Moodle HQ! Despite being so close to Moodle as a developer, I continue to be amazed and motivated by how many people I can touch by working on Moodle. Friends from my days at school and university use Moodle as part of their job on a daily basis, my youngest sister is currently studying and supported with Moodle (unfortunately only at stage 1 of Martin’s pedagogical stages) and I meet more and more moodlers ever day! I’m hoping that my time working as external developer working on the other side of the world to Perth will be a great new perspective to add to the team.

I’ll be working for LUNS for a while yet, but it feels like a good opporunity to thank everyone i’ve worked with over the years at LUNS, clients and community members who accepted my patches. :) I’m touched by the kind post about my leaving. I expect to continue working with you if more indirectly at Moodle HQ. :)

Happy Moodling!

  1. Well, the first thing I knew about, anyway []
  2. Although the git history suggests my first fix was actually a horrible JS change which surprises me more than anyone! []
  3. Making their initial steps to learning how to use a computer []
  4. No comment []

Siri Interface to the Moodle Tracker

Earlier today I came across an interesting project which provides a ‘proxy interface’ to Siri on the iPhone 4S allowing custom plugins to be created to respond to requests from Siri.

Eager to try this I hacked together a Moodle plugin for the siri proxy which would do lookups to the Moodle tracker. So, welcome Siri – the newest aid to the Moodle 2.2 QA testing effort :-)

(The plugin I wrote is available on github. It is my first ruby script and its not particularly elegant as it was just for fun :-) )

 

Software Metrics and Moodle

This weekend I attended the phpnw11 conference in Manchester, a good conference with a lot of interesting talks which i’d highly recommend to any php programmer.

Not entirely accidentally, I went to a number of talks focused on testing and continuous integration and came home with quite a lots of bits and pieces I wanted to play with. Sebastian Marek gave an excellent talk on Software Metrics (slides available) as the first track talk of the day. Obviously I can’t summarise his talk, but he introduced us to the concept of the cyclomatic complexity, NPATH, C.R.A.P. as well as WTFs/min as well as tools which can be used to measure them and other assessments of code quality. Sebastian made the point quite strongly that you can’t just use these metrics on their own, but that they could be good indicators combined with analysis of the code.

This got me wondering if the modern parts of Moodle would be analysed more favourably that older parts of Moodle which developers tend to long to refactor away?

Testing 1.9 vs 2.2

So I conducted a test using php mess detector and its code size rules on the question engine in Moodle 1.9 and compared that with master (which includes the rewritten question engine that Tim spent a good portion of the last year working on1 ).

~/git/moodle$ git checkout MOODLE_19_STABLE
~/git/moodle$ phpmd question/ html codesize > question19.html
~/git/moodle$ git checkout master
~/git/moodle$ phpmd question/ html codesize > question22.html

Results

Moodle 1.9: 315 Problems Found
Moodle 2.2: 233 Problems Found

Moodle 2.2 has better metrics than 1.9!

Well, not quite – in order to get those results I had to remove all the unit tests, which weren’t present in Moodle 1.9 and also tend to be ‘long, dumb’ methods2 which trigger just this sort of metric and made the result larger. I don’t really know the code well enough but there may be other factors such as question/ including more code…

The results matched Sebastians point that these metrics can’t be used on their own, but some of the metrics which can be generated might be very interesting datapoints to look at with time. Sonar was a tool demonstrated which could be used in combination with a continuous integration system and tools which generate these metrics to evaluate and report over time – some of which looks really cool and I hope to play with soon.

  1. and I hope he doesn’t mind me using as an example! []
  2. Incidentally Laura Beth Denker also did a great talk at phpnw11 emphasising how you should write good test code avoiding things like conditionals- slides available []

Multi-tenant Moodle without the 2.2 feature

At LUNS, we designed, built and supported what I still believe to be one of the largest multi-moodle installations in the world. The installation ran from a single codebase and comes with many tough challenges, scaling supporting and upgrading 1000 Moodle installations and 270,000 users can be quite difficult! (I think I have guestimated doing about 8000 Moodle upgrades in my time so far ;-) ).

But the question I most frequently get asked is how we achieved a 1000 Moodle install on a single codebase without modifying core Moodle code. This is the simplest part of the operation really and very straight forward to setup. I’ve promised a few people i’d blog about it so:

  1. Configure your webserver to server all hosts from a single codebase directory
  2. Create a config.php file which includes the individual site config depending on the host which is being served. e.g.
    <?php
    
    $moodle_host = $_SERVER['HTTP_HOST'];
    
    require_once('/etc/moodles/'.$moodle_host.'_config.php');
  3. Populate individual Moodle config files with site specific config as you would any other Moodle site

Thats it!

Moodle HQ are currently working on a new core Multitenancy feature, which might provide a different approach for some institutions (although i’m still not entirely clear on its use case over an approach like this).

Moved to WordPress

Three and a half years ago I decided to start writing a few blog posts about technical bits and pieces I was undertaking. At that time I had a VPS running a few PostgreSQL databases and very little knowledge of the different blogging systems available. I considered a few different options for publishing the blog including Drupal, WordPress and Serendipity. I ended up going with serendipity primarily because it supported PostgreSQL, was a dedicated blogging engine and came recommended by Penny.

On reflection I don’t really think Serendipity was the right choice for me – it doesn’t seem particularly active compared to the alternatives and thus needs some vigilance to keep an eye out for the latest security fixes. The version I was using seemed particularly plagued with php deprecated warnings after upgrading my server to squeeze.

So having recently blogged a few times recently I became a bit more motivated to do something with the blog hosting.. My requirements were relatively simple:

  • Permalinks *must* be retained (else i’d just start again..)
  • I don’t care about comments (there haven’t been enough of value to retain and recently a lot of spam..)
  • I’d like to reduce the maintenance required (if I can get rid of the virtual server that’d be cheaper too)

Blogger

I use a lot of Google services and a couple of my friends use blogger – it seemed functional enough for my needs. Unfortunately, whilst blogger supports import and a custom domains it did not seem to allow for changes to the format of permalinks so I wouldn’t be able to migrate here.

WordPress.com

WordPress itself seems to have all the elements to allow a migration from serendipity. The wordpress.com hosted solution talks of support ‘domain mapping’ but didn’t seem to mention permalink changes. When I signed up for a free blog I couldn’t see a way to change the URL format despite tantalising articles suggesting it was possible.

I contacted the wordpress.com support team asking if changing the permalink url was a service I could pay for (giving an example of my current blog and the wordpress.com post i’d to follow the same format). Two weeks after my request I got a response telling me the difference between the open source project and the wordpress.com hosted solution and that I was confused. I tried to clarify but the support response pointed me to wordpress.org support. I gave up.

Self Hosted WordPress

Having played with WordPress on wordpress.com I quite liked the look of it – clean and simple plus I know it is incredibly popular and an active project. Its frustrating that it doesn’t support PostgreSQL, but I am running another MySQL-only website1 so I got over my religious views quite quickly.

I completed the migration from serendipity by:

  • Using the RSS Importer from the full feed. I wasn’t that bothered by much of the metadata, mainly just the post content and dates and this plugin carried out the job admirably.
  • Changing the permalink structure to match the existing serendipity structure: ‘/archives/%year%-%monthnum%-%postname%.html’
  • Adding a few redirect rules to keep existing links I cared about working2:
    RewriteRule ^feeds/categories/([0-9]+)\-(.*)\.rss$ archives/category/$2/feed [R=301,L]
    RewriteRule ^categories/([0-9]+)\-(.*)$ archives/category/$2 [R=301,L]
    RewriteRule ^feeds/atom*$ feed/atom [R=301,L]
    RewriteRule ^feeds/index.rss2$ feed/rss2 [R=301,L]
    RewriteRule ^feeds/index.rss1$ feed/rdf [R=301,L]
    RewriteRule ^feeds/index.rss$ feed/rss [R=301,L]
  • Transferring the images hosted from the blog and altering the links to their new location
  • Examined the 404 logs to look for things I missed and care about.

All in all this was a fairly straightforward process made quite simple by the fact I have so few blog posts that I could easily verify the results.

The time consuming part

The default wordpress theme allowed me to upload custom header images to display randomly on the top of this blog, its made super easy by having a web based cropping interface and I thoroughly enjoyed spending 3/4 hours last night selecting images from my travels which are displayed above!3

  1. My own archived website from days of my youth when I didn’t know better :-P []
  2. I did not optimise or consider these for more than about 10 seconds, so i’m sure they could be written better []
  3. HINT HINT, RSS readers []

Why i’m moving back to the iPhone

Over the past eight months I have been using Google Nexus S with Android as my main mobile device, having previously owned an original iPhone & iPhone 3GS. I purchased a Google Nexus S out of gadget love/ tech interest on how Android compares to iOS and then was forced to ‘switch’ fulltime after my own botched ‘repair job’ on my iPhone 3GS.

There are a number of things which attract me to Android:

  1. Open Source: As an open-source developer and user I am ideologically aligned to an open source solution.
  2. Its Cheaper: In the UK at least there tend to be more competitively priced deals on Android devices.
  3. Open App Platform: Another idealogocial point – an open ecosystem sits better with me (though is distinct from an open source OS)
  4. Google Integration: I am a heavy google user and tight integration is appreciated
  5. Apps have much more flexible plugin points – hooks to the Phone/SMS features for example

But after eight months living with Android I can say:

  1. Despite the rhetoric, Google are behaving pretty poorly with their open source platform. iOS 4.3 almost seems more open than Android Honeycomb.
  2. Android continues to be cheaper, although the difference is reasonably small on similar speced hardware. But at the time I switched to iPhone I made the conscious decision to spend more for the luxury item (I moved from paying £10pm to £35pm…) and it turns out i’m still happy to pay extra for the iPhone
  3. The Android marketplace is quite frankly terrible and demonstrates all of what is wrong with a completely open platform. From a consumer point of view the closed Apple App Store is fabulous. My non-technically inclined friends and family can now install and use apps without worrying about the implications. This is quite liberating – and how computing should be!
  4. The only thing I use which the iPhone doesn’t do as well is Google Talk and searching Gmail.
  5. I don’t actually use any apps which use this functionality, despite the attraction

Android: out of sharespace
The main reason I will be moving back to iOS though is slightly intangible, the extra 10% of polish and attention to detail which iOS has in abundance and android misses and frustrates me.

I have two examples of the ‘lack of polish’ to try and make it slightly more tangible:

  • Yesterday I took a photo with the phone and wanted to send the photo to a friend using MMS. To do this, I usually use the Android ‘share menu’ and select the messaging app. Unfortunately it turned out that yesterday I had installed one too many apps and the messaging app had disappeared off the screen with no apparent way to scroll to it (see screenshot to the right). This is an example of a great feature which Android has over iOS (the share menu) yet made useless for me in practice and is very representive of the kind of things which frustrate me about android.
  • In my search for a decent music player for Android I installed multiple apps (Winamp, doubletwist, Android MP3) to test out their capabilities. The nexus s comes with earphone with inline remote which can be used to play/pause/skip music (similar to the iPhone). However when I used the remote to skip a tune I had enough of I ended up starting music on one of the other apps – so i’d have two different pieces of music playing at me at the same time, completely ruining the experience. This problem got so annoying that I gave up and bought an mp3 player. Apples approach to background audio playing in apps was, firstly not allow it until iOS 4, then allow a single app to play background audio at a time, the app playing audio is controlled by the system wide controls and can also be streamed using airplay.

Android is much better than anything that was before the iPhone and a worthy competitor, but it turns out that I prefer the more restricted system with attention to detail over the ‘open enough to cripple itself’ android platform – and I haven’t even been subjected to manufacturer hindered OS Updates.

ps. there is a great blog from an iOS user trying out Android in a similar fashion to me: Dinner with Android

A moodle bug a day keeps the doctor away…

Hi Moodlers..

Apologies – the last entry in this blog was regarding the Moodle Developers Hackfest in the Czech Republic, nearly two years ago!

Moodle Developers in Snow, December 2009

It was a great occasion, we had some big arguments on git, Moodle 2.0 wasn’t released and we didn’t manage to go skiing!

Since then:

  • Moodle 2.0 has been released (and 2.1)
  • git has been introduced into Moodle Development workflow
  • i’ve been skiing (not sure about the Australians..).
  • we drank the entire czech mint/lime provision in mojitos ;-)

Sadly since then i’ve also spent far less time doing Moodle bug fixing than before – instead i’ve been doing a lot of Moodle advocacy to various organisations.

I’ve been missing the bug fixing and decided to start to scheduling myself time to ensure at least one bug fix a week (at the minimum). Fixing bugs and pleasing Moodlers is addictive – so I hope this spirals into many more :-) Wish me luck with keeping the doctor away!

See you on the tracker!

Czech Moodle Hackfest!

Its less than a week till 16 of us (moodle developers) meet up in the Czech Republic for the first Moodle Hackfest!

I’m really excited, the opportunity to to hack and plan together is a unique opportunity and something we tend to miss at moots as we chat to fellow Moodlers and find out what our users are interested in, drink Mojitos and don’t get so much coding done!

I had hoped to spend a few weeks bug squashing, but sadly my life got in the way. :-(

In any case i’m very interested to hear what you love and hate about Moodle at the moment so the developer community can come up with ways to resolve your problems. If you hate moodle, please tell me why, how can we improve it?

ps. please keep your fingers crossed, I’ve spent months negotiating a new house which I am hoping to own the day I fly to prague!

Ubiquitous Moodle

Its not difficult for me to realise that Moodle is a popular global project – I work alongside the evidence every day; reading Moodle.org, fearing the volume of bugs which come into the tracker and in CLEO, we recently surpassed 200,000 Moodle users. Buts its actually the small events in life which help me quantify this.

When i’m fortunate enough to go to Moodlemoots the international community of Moodlers is very evident and the passion is incredible.

Often, i meet teachers at completely non-moodle related social events and discover they use Moodle.

While i’m cycling to work and pass children walking to school, I stop and realise these children are likely to be using Moodle now or some time in their future (such is the dominance of Moodle in our region).

This week I discovered my old Sixth Form College is starting to use Moodle. During my time at the college I got a passion for computer programming and also benefited enormously from my first exposure to online learning. I don’t teach people (at least in the formal sense) and so this exposure certainly helps me understand the Moodle philosophy more than I would’ve been able to without.

One of the greatest things about working on this open source project is that my contributions hopefully go some way to benefiting all these users: The moodlers I meet at moots, the teacher I met one time at a party, the schoolchildren passing me on the way to work and the college which gave me many of the fundamentals which have helped me contribute to the project.