Skip to content

A github action that comments on PR to describe impact on metrics

Notifications You must be signed in to change notification settings

autometrics-dev/diff-metrics

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Autometrics Report

This GitHub action will comment on Pull Requests to tell you how metrics are going to be affected.

The report tells you immediately if your new feature is well instrumented, and shows a useful summary of the metrics that will be reported without needing to go through the diff.

An example of generated report on Github

Inputs

  • gh-token: a github token that gives access to

    • the PR
    • the repo
    • read/write access to comments on issues/PR

    The built-in ${{ secrets.GITHUB_TOKEN }} will work, you do not need to create a new one. To make the built-in token work, the job must be given a specific set of permissions. The permissions added in the "Example Usage" section show the minimal set of permissions needed.

  • rs-roots: a list of project roots for rust projects, one root per line. The values are given relative to the root of the repository, and should point to the directory containing the Cargo.toml file.

  • ts-roots: a list of project roots for typescript projects, one root per line. The values are given relative to the root of the repository, and should point to the directory containing the package.json file.

  • go-roots: a list of project roots for golang projects, one root per line. The values are given relative to the root of the repository, and should point to the directory containing the go.mod file.

  • py-roots: a list of project roots for python projects, one root per line. The values are given relative to the root of the repository, and should point to the directory containing the actual module source code. If you have a monorepo, you need to specify the root of each submodule.

  • retention-days: the number of days to keep the list of functions as workflow artifacts. By default it will use the same retention settings as the settings in the repository (by setting retention-days to 0)

  • am-version: a string that allows to choose the version of am_list to download/use. You can skip the patch (e.g. 0.2) or the minor (e.g. 0) to tell the action to download the latest version that falls within the bound. Defaults to an empty string (""), which means "download the latest version, semver-wise"

Argument Mandatory
gh-token yes
rs-roots no
ts-roots no
go-roots no
py-roots no
retention-days no
am-version no

Outputs

The action does 2 things:

  • it writes comments to pull request giving the monitoring impact of the Pull Request.
  • it saves the data used to compute this report as workflow artifacts. Workflow artifacts stay private to the repository that created them, but this allows for further processing if need be.

Example Usage

The job must only contain the checkout step and the diff-metrics step, the steps that follow within the job would act on an older version of the repository.

name: Metrics report

on: [pull_request]

jobs:
  build:
    # The task only runs on linux x64 machines.
    runs-on: ubuntu-latest

    # Permissions are necessary to be able to edit and write comments on the PR
    permissions:
      issues: write
      pull-requests: write
      repository-projects: read
      contents: read

    steps:
      - uses: actions/checkout@v3
      - uses: autometrics-dev/diff-metrics@v1
        with:
          gh-token: ${{ secrets.GITHUB_TOKEN }}
          rs-roots: |
            .

Mono repo example

In the case of a mono repo that would look like

.
├── project-a
│  ├── README.md
│  │ ...
│  └── Cargo.toml
├── project-b
│  ├── README.md
│  │ ...
│  └── Cargo.toml
├── project-c
│  ├── README.md
│  │ ...
│  └── Cargo.toml
├── project-d
│  ├── README.md
│  │ ...
│  └── go.mod
├── project-ts
│  ├── README.md
│  │ ...
│  └── package.json
└── README.md

The step using diff-metrics would look like this:

uses: autometrics-dev/diff-metrics@v1
with:
  gh-token: ${{ secrets.GITHUB_TOKEN }}
  rs-roots: |
    project-a
    project-b
    project-c
  go-roots: |
    project-d
  ts-roots: |
    project-ts
Language support

Look at the issues in the repository to see the advancement of language support. All languages in the table will be eventually supported.

Language Support
Rust
Typescript
Go ⚠️1
Python
C#

Footnotes

  1. Golang's version detects functions decorated with //autometrics directives, but does not deal with net/http middleware wrapper yet.