Code Monkey home page Code Monkey logo

bugbug's Introduction

bugbug

Task Status codecov

Bugbug aims at leveraging machine learning techniques to help with bug and quality management, and other software engineering tasks (such as test selection and defect prediction).

Chat with us in the bugbug Matrix room.

More information on the Mozilla Hacks blog:

Data generated by BugBug to train the models can be used independently from BugBug. See the docs for details.

Classifiers

  • assignee - The aim of this classifier is to suggest an appropriate assignee for a bug.

  • backout - The aim of this classifier is to detect patches that might be more likely to be backed-out (because of build or test failures). It could be used for test prioritization/scheduling purposes.

  • bugtype - The aim of this classifier is to classify bugs according to their type. The labels are gathered automatically from bugs: right now they are "crash/memory/performance/security". The plan is to add more types after manual labeling.

  • component - The aim of this classifier is to assign product/component to (untriaged) bugs.

  • defect vs enhancement vs task - Extension of the defect classifier to detect differences also between feature requests and development tasks.

  • defect - Bugs on Bugzilla aren't always bugs. Sometimes they are feature requests, refactorings, and so on. The aim of this classifier is to distinguish between bugs that are actually bugs and bugs that aren't. The dataset currently contains 2110 bugs, the accuracy of the current classifier is ~93% (precision ~95%, recall ~94%).

  • devdocneeded - The aim of this classifier is to detect bugs which should be documented for developers.

  • needsdiagnosis - The aim of this classifier is to detect issues that are likely invalid and don't need to be diagnosed for webcompat use case.

  • qaneeded - The aim of this classifier is to detect bugs that would need QA verification.

  • regression vs non-regression - Bugzilla has a regression keyword to identify bugs that are regressions. Unfortunately it isn't used consistently. The aim of this classifier is to detect bugs that are regressions.

  • regressionrange - The aim of this classifier is to detect regression bugs that have a regression range vs those that don't.

  • regressor - The aim of this classifier is to detect patches which are more likely to cause regressions. It could be used to make riskier patches undergo more scrutiny.

  • spam - The aim of this classifier is to detect bugs which are spam.

  • stepstoreproduce - The aim of this classifier is to detect bugs that have steps to reproduce vs those that don't.

  • testfailure - The aim of this classifier is to detect patches that might be more likely to cause test failures.

  • testselect - The aim of this classifier is to select relevant tests to run for a given patch.

  • tracking - The aim of this classifier is to detect bugs to track.

  • uplift - The aim of this classifier is to detect bugs for which uplift should be approved and bugs for which uplift should not be approved.

Setup and Prerequisites

Install the Python dependencies:

pip3 install -r requirements.txt

You may also need pip install -r test-requirements.txt. Depending on the parts of bugbug you want to run, you might need to install dependencies from other requirement files (find them with find . -name "*requirements*").

Currently, Python 3.10+ is required. You can double check the version we use by looking at setup.py.

Also, libgit2 (needs v1.0.0, only in experimental on Debian), might be required (if you can't install it, skip this step).

sudo apt-get -t experimental install libgit2-dev

Auto-formatting

This project is using pre-commit. Please run pre-commit install to install the git pre-commit hooks on your clone.

Every time you will try to commit, pre-commit will run checks on your files to make sure they follow our style standards and they aren't affected by some simple issues. If the checks fail, pre-commit won't let you commit.

Usage

Training

Run the trainer.py script with the command python -m scripts.trainer (with --help to see the required and optional arguments of the command) to perform training (warning this takes 30min+).

Testing

To use a model to classify a given bug, you can run python -m scripts.bug_classifier MODEL_NAME --bug-id ID_OF_A_BUG_FROM_BUGZILLA. N.B.: If you run the classifier script without training a model first, it will automatically download an already trained model.

Example for the "defect" model

training To train the model for mode defect:

python3 -m scripts.trainer defect

testing To use the model to classify a given bug, you can run python -m scripts.bug_classifier defect --bug-id ID_OF_A_BUG_FROM_BUGZILLA.

Training on Taskcluster (Mozilla's CI platform)

You could run the model training task on the CI. To do this, simply include Train on Taskcluster: <model name> in the pull request description.

Example

To train the spambug model on Taskcluster, you need to add the following line in the pull request description, ideally at the bottom:

Train on Taskcluster: spambug

There are a few things to consider when training a model on Taskcluster:

  • This is currently only supported in GitHub pull requests.
  • The training task will be re-run every time you push to the branch linked to the pull request. Limiting the number of times you push is wise to avoid unnecessary training and resource wastage. Alternatively, you could temporarily remove the "Train on Taskcluster" keyword from the pull request description.
  • Currently, the training task extracts only the model's name and does not consider arguments.

Running the repository mining script

Note: This section is only necessary if you want to perform changes to the repository mining script. Otherwise, you can simply use the commits data we generate automatically.

  1. Clone https://hg.mozilla.org/mozilla-central/.
  2. Run ./mach vcs-setup in the directory where you have cloned mozilla-central.
  3. Enable the extensions mentioned in infra/hgrc. For example, if you are on Linux, you can add firefoxtree to the extensions section of the ~/.hgrc file as:
    firefoxtree = ~/.mozbuild/version-control-tools/hgext/firefoxtree
    
  4. Run the repository.py script, with the only argument being the path to the mozilla-central repository.

Note: If you run into problems, it's possible the version of Mercurial you are using is not supported. Check the Docker definition at infra/dockerfile.commit_retrieval to see what we are using in production.

Note: the script will take a long time to run (on my laptop more than 7 hours). If you want to test a simple change and you don't intend to actually mine the data, you can modify the repository.py script to limit the number of analyzed commits. Simply add limit=1024 to the call to the log command.

Structure of the project

  • bugbug/labels contains manually collected labels;
  • bugbug/db.py is an implementation of a really simple JSON database;
  • bugbug/bugzilla.py contains the functions to retrieve bugs from the Bugzilla tracking system;
  • bugbug/repository.py contains the functions to mine data from the mozilla-central (Firefox) repository;
  • bugbug/bug_features.py contains functions to extract features from bug/commit data;
  • bugbug/model.py contains the base class that all models derive from;
  • bugbug/models contains implementations of specific models;
  • bugbug/nn.py contains utility functions to include Keras models into a scikit-learn pipeline;
  • bugbug/utils.py contains misc utility functions;
  • bugbug/nlp contains utility functions for NLP;
  • bugbug/labels.py contains utility functions for handling labels;
  • bugbug/bug_snapshot.py contains a module to play back the history of a bug;
  • bugbug/github.py contains functions to retrieve issues from GitHub for a specified owner/repository.

Using bugbug for non-Mozilla projects

Bugbug is focussing on Mozilla use-cases for Firefox, Bugzilla and GitHub. However, we will be happy to accept pull requests adding support for other projects or bug trackers.

bugbug's People

Contributors

abhaykatheria avatar armenzg avatar ayir avatar ayush-1506 avatar ayush1999 avatar bgrins avatar calixteman avatar chidauri avatar cklyyung avatar dependabot-preview[bot] avatar dependabot[bot] avatar johngian avatar jpangas avatar jrbenny35 avatar kanurag94 avatar ksy36 avatar kushagra414 avatar la0 avatar lakshyaaagrawal avatar lothiraldan avatar marco-c avatar monperrus avatar poojan124 avatar probaku1234 avatar promisefru avatar pyup-bot avatar rhcu avatar sbeesm avatar suhaibmujahid avatar x249wang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bugbug's Issues

Clean up stack traces

Follow-up of #9.

We should replace stack traces with one or more tokens (e.g. "STACK_TRACE"). Unfortunately it's not so easy to do it (see the discussion in #9).

Only show "meaningful enough" feature importances

Right now I handpicked the number of most important features to show (the top 20).

We should use an algorithm to select what to show. The simplest two alternatives are:

  1. Show all the contributing features that are at least X% of the sum of the contributions.
  2. Show the top contributing feature, and all other contributing features that are at least X% of the top one.

Create some new features from status flags

The status flags can be particularly useful for detecting e.g. regressions.

Some features I can think of:

  • "ever-affected", true if the status has ever been set to 'affected' (while some developers use 'affected' also for features, many use it only for bugs);
  • "unaffected-then-affected", true if the status for a given version is unaffected and for a following version is affected.

Create a classifier to detect the type of bug

Needed for mozilla/bugbot#223.

To do this, we'll need to collect some labels.
We can automatically create some by using the perf and memory keywords.

There are other types that we could try to classify other than perf and memory:

  • Security - Security vulnerability.
  • Crash - Program unexpectedly stops running.
  • Hang - Program keeps running but without response.
  • Incorrect rendering - Components or video cannot be correctly rendered.
  • Wrong functionality - Incorrect functionalities besides rendering issues.
  • Web incompatibility - Program does not work correctly for a major website or many websites due to incompatible APIs or libraries, or a functionality, which was removed on purpose, but is still used in the wild.
  • Add-on or plug-in incompatibility - Program does not work correctly for a major add-on/plug-in or many add-ons/plug-ins due to incompatible APIs or libraries, or a functionality, which was removed on purpose, but is still used in the wild.
  • Compile - Compilation errors.
  • Feature - Introduce or remove features.
  • Improvement - Minor functional or aesthetical improvement.
  • Test-only problem - Errors that only break tests.
  • Other - Other types that don't belong to the previous categories, e.g., data corruption and license incompatibility.

Use the "experience" of the bug opener as a feature

Where the "experience" of the bug opener is the number of bugs opened so far by the bug opener.

This can be useful for the detection of missing STR (hopefully an experienced bug opener will know that STRs are needed).

Create a classifier to suggest a reviewer for a bug/patch

Given features from patches (e.g. which files were modified, the components of the modified files, the number of lines modified, the past reviewers of the patch, the past authors of the patch, etc.), we want to be able to identify a good reviewer for a given patch.

This will require a few changes in the project:

  1. Collecting even more features on patches;
  2. Make it possible to train on patches rather than only bugs (model.py assumes all classifiers operate on bugs, but this one will operate on patches instead);
  3. Create the classifier itself!

Try using different textual features

Right now we are using TfidfVectorizer with its default options (basically word 1-gram). We should try a few different options and see how the accuracy changes:

  • word 1-gram
  • word 2-gram
  • word 3-gram
  • char 1-gram
  • char 2-gram
  • char 3-gram
  • word2vec
  • doc2vec
  • fasttext
  • 1d-cnn (with pre-trained word embeddings)
  • 1d-cnn (without pre-trained word embeddings)
  • bert or similar

Create a classifier to suggest an assignee for a bug

A new classifier, similar to the ones already present under bugbug/models/, should be created to predict the assignee of a bug.
This will be similar to the component model, except the label will be the assignee instead of the product/component.

Create a classifier to detect bugs that need QA

Needed for mozilla/bugbot#227.

To do this, we'll need to collect some labels.
We can automatically create some positive labels by getting bugs that have the qawanted keyword or that have qe-verify flag.
We can't automatically create negative labels because we can't be sure that QA was not needed when the keyword/flag was not set.

Use basic rules before actually using the classifier

We don't use regression in the training phase to avoid skewing results. In the evaluation phase we should use it though as its presence is a clear indication of a bug/regression, and if it is not present resort to the classifier.

Detect bugs that impact MDN Web Docs aka "dev-doc-needed"

For the last decade or so, the MDN Web Docs team relies on people adding "dev-doc-needed" to Bugzilla bugs, so that we can document if Firefox implemented a new Web platform feature or if changes to Web platform features happened in Firefox.

It would be amazing if we wouldn't have to rely so much on humans adding this keyword anymore.
I don't know if this project can help with this, but filing this issue as an idea :)

Prior related bug about this https://bugzilla.mozilla.org/show_bug.cgi?id=1376393

Create a "similar bug" recommender

"similar" not in terms of duplicate bug, but in terms of features. E.g. two bugs that are completely unrelated from each other, but that are of the same type and have similarly sized patches.

'Is reporter a developer' as a feature

Similar to #30.

This feature is going to be a boolean saying whether the reporter of the bug is a developer. As a first implementation, we can check if there is any commit where they are authors.

Perform text cleanup

We are not cleaning up the text from title or comments at all, we should:

  • replace crash stats references (bp-XXXX, example in https://bugzilla.mozilla.org/show_bug.cgi?id=1376831#c0) with one or more tokens (e.g. "___CRASH_STATS_LINK___")
  • replace file references with one or more tokens (e.g. "___FILE_REFERENCE___") - #36.
  • replace URLs with one or more tokens (e.g. "___URL___") - #33.
  • maybe remove referred text in comments (starting with ">") - #52.
  • replace hexadecimal numbers with one or more tokens (e.g. "__HEX_NUMBER__") - #56.
  • replace DLL names with one or more tokens (e.g. "__DLL_NAME__"). - #65.

For URLs, we should probably have different tokens according to the type of URL (e.g. if it's a hg.mozilla.org, or searchfox.org or dxr.mozilla.org, then the meaning of the URL might be different).

Add DB versioning

When a new DB is available, it should automatically be downloaded.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.