Setting up PerfCompare and Treeherder

When I started my internship at Mozilla, one of the biggest challenges I faced was setting up my environment and getting my tests to pass. Treeherder setup, in particular, required multiple steps, and while the documentation was helpful, I had to piece together some additional details to get everything running smoothly. Eventually, I figured it out and created a system that worked for me. I'm documenting it here to help new interns or programmers navigate and overcome these setup hurdles.


PerfCompare Setup

PerfCompare is pretty straightforward to set up since the setup process is well outlined in the repository README. Here’s what worked for me:

  1. Fork the repository: Mozilla PerfCompare

  2. Clone your forked repo:

     git clone https://github.com/YOUR_GITHUB_USERNAME/perfcompare.git
    
  3. Install dependencies and run the app:

     npm install
     npm run dev
    
  4. Create a new branch:

     git checkout -b new-branch-name
    
  5. Make changes and fix linting issues:

     npm run fix-all  # Runs linting, test coverage, updates snapshots, and fixes lint errors
    
  6. Stage and commit your changes:

     git add .
     git commit -m "Describe your changes"
    
  7. Rebase with the upstream branch:

     git fetch upstream
     git rebase upstream/main
    
    • If there are conflicts, resolve them and commit.
  8. Push changes to your branch:

     git push --force origin new-branch-name
    
  9. Create a pull request on GitHub:

    • Be descriptive.

    • Attach relevant screenshots.

    • Add deployment and Bugzilla links where necessary.

PerfCompare Documentation: User Guide | How to use PerfCompare

Treeherder Setup

Treeherder was trickier to set up, especially on Windows. Here’s what worked for me:

  1. Fork the repository: Mozilla Treeherder

  2. Clone your forked repo:

     git clone https://github.com/YOUR_GITHUB_USERNAME/treeherder.git
    
  3. Ensure Docker and Docker Compose are installed:

    • On Windows, make sure WSL is properly configured.

    • Install Docker Desktop.

    • Sometimes, docker-compose up fails unless Docker Desktop is open. Keep this in mind when starting services.

  4. Set up the test database:

    • Move the provided test database file (decompressed SQL file) to the root folder.

    • Run:

        psql -h localhost -U postgres -W < treeherder.sql
      
  5. Start services:

     docker-compose up --build
    
    • After creating services, you don’t need to use the --build flag every time. Just run:

        docker-compose up
      
  6. Access the database:

     psql -h localhost -U postgres -d treeherder
    
    • Login with password: mozilla1234
  7. Access the backend service:

     docker-compose exec backend bash
    
  8. Run Python scripts:

     docker-compose exec backend python manage.py shell
    
  9. Set up pre-commit hooks (optional but helpful):

     pre-commit install
     pre-commit run --all-files
    

Running Tests

  1. Before running tests:

    • Ensure you're inside the backend service:

        docker-compose exec backend bash
      
  2. Run all tests:

     pytest tests
    
    • This takes time but ensures everything is working.
  3. Run specific test files:

     pytest tests/webapp/api/test_push_api.py
    
  4. Run a specific test within a test file:

     pytest tests/webapp/api/test_push_api.py::test_push_search
    

Handling Migrations

  1. Create a new migration:

     python manage.py makemigrations
    
  2. Apply migrations:

     python manage.py migrate
    
  3. Rollback to a previous migration:

     python manage.py migrate yourappname previous_migration_name
    

Pushing Changes

  1. Stage changes:

     git add .
    
  2. Commit changes:

     git commit -m "Describe your changes"
    
  3. Rebase with the upstream branch:

     git fetch upstream
     git rebase upstream/master
    
    • If there are conflicts, resolve them and commit.
  4. Push changes:

     git push --force origin new-branch-name
    

Treeherder Documentation: Installation Guide | User Guide

These are some of the commands that helped me implement Full-text Search in PerfCompare. I hope this helps future interns or contributors overcome the setup hurdles!