http method github GET /api/v3/repos/cloudflare/pint/pulls/1/reviews 200 []
http method github POST /api/v3/repos/cloudflare/pint/pulls/1/reviews 200 {}
http method github GET /api/v3/repos/cloudflare/pint/pulls/1/comments 200 []
http method github GET /api/v3/repos/cloudflare/pint/issues/1/comments 200 []
http method github POST /api/v3/repos/cloudflare/pint/pulls/1/comments 200 {}
http start github 127.0.0.1:6270

mkdir testrepo
cd testrepo
exec git init --initial-branch=main .

cp ../src/v1.yml rules.yml
cp ../src/.pint.hcl .
env GIT_AUTHOR_NAME=pint
env GIT_AUTHOR_EMAIL=pint@example.com
env GIT_COMMITTER_NAME=pint
env GIT_COMMITTER_EMAIL=pint@example.com
exec git add .
exec git commit -am 'import rules and config'

exec git checkout -b v2
cp ../src/v2.yml rules.yml
exec git commit -am 'modify rules'

env GITHUB_AUTH_TOKEN=12345
env GITHUB_PULL_REQUEST_NUMBER=1
! exec pint -l debug --offline --no-color ci
! stdout .
stderr 'level=INFO msg="Pull request review created" status="200 OK"'
cmp github.got ../github.expected

-- src/v1.yml --
groups:
- name: foo
  rules:
    - alert: Foo Is Down
      expr: count(build_info) by (instance, version) != ignoring(package) group_left(foo) count(package_installed) by (instance, version, package)
      annotations:
        summary: '{{ $labels.instance }} on {{ .Labels.foo }} is down'
        help: '{{ $labels.instance }}'

-- src/v2.yml --
groups:
- name: foo
  rules:
    - alert: Foo Is Down
      expr: count(build_info) by (instance, version) != ignoring(package) group_left(foo) count(package_installed) by (instance, version, package)
      annotations:
        summary: '{{ $labels.instance }} on {{ .Labels.foo }} is down'
        help: '{{ $labels.ixtance }}'

    - alert: OpenTelemetry_Collector_Failed_Logs
      # pint disable promql/series
      expr: >-
        sum by (exporter, colo_name) (rate(otelcol_exporter_send_failed_log_records{node_status="v", exporter=~"(failover|otlp)/.*", job=~"foo_.+_bar"}[5m]))
        /
        (
          sum by (exporter, colo_name) (rate(otelcol_exporter_send_failed_log_records{exporter=~"(failover|otlp)/.*"}[5m])) + sum by (exporter, colo_name) (rate(otelcol_exporter_sent_log_records{exporter=~"(failover|otlp)/.*"}[5m]))
        )
        > 0.1
        and
        sum by (exporter, colo_name) (rate(otelcol_exporter_send_failed_log_records{node_status="v", exporter=~"(failover|otlp)/.*"}[5m])) > 10
      for: 15m
      labels:
        priority: "3"
        component: opentelemetry-collector
      annotations:
        summary: "OpenTelemetry Collector is failing to send {{ $value | humanize }} of logs to exporter {{ $labels.exporter }} in {{ $labels.colo_name }}"
        dashboard: https://grafana.example.com/d/1?var-colo_name={{ $labels.colo_name }}
        link: https://alerts.example.com/OpenTelemetry_Collector_Failed_Logs

-- src/.pint.hcl --
ci {
  baseBranch = "main"
}
repository {
  github {
    baseuri   = "http://127.0.0.1:6270"
    uploaduri = "http://127.0.0.1:6270"
    owner     = "cloudflare"
    repo      = "pint"
  }
}

-- github.expected --
GET /api/v3/repos/cloudflare/pint/pulls/1/comments
  Accept: application/vnd.github.squirrel-girl-preview, application/vnd.github.comfort-fade-preview+json
  Accept-Encoding: gzip
  Authorization: Bearer 12345
  X-Github-Api-Version: 2022-11-28

GET /api/v3/repos/cloudflare/pint/issues/1/comments
  Accept: application/vnd.github.squirrel-girl-preview
  Accept-Encoding: gzip
  Authorization: Bearer 12345
  X-Github-Api-Version: 2022-11-28

POST /api/v3/repos/cloudflare/pint/pulls/1/comments
  Accept: application/vnd.github.squirrel-girl-preview, application/vnd.github.comfort-fade-preview+json
  Accept-Encoding: gzip
  Authorization: Bearer 12345
  Content-Type: application/json
  X-Github-Api-Version: 2022-11-28
--- BODY ---
body: |
    :stop_sign: **Bug** reported by [pint](https://cloudflare.github.io/pint/) **alerts/template** check.

    <details>
    <summary>template uses non-existent label</summary>

    ```yaml
    5 |       expr: count(...) by (instance, version) != ignoring(package) group_left(foo) ...
                               ^^
    ```

    Query is using aggregation with `by(instance, version)`, only labels included inside `by(...)` will be present on the results.

    ```yaml
    8 |         help: '{{ $labels.ixtance }}'
                                 ^^^^^^^^
    ```

    The template is using `ixtance` label but the query results won't have this label.

    </details>

    ------

    :information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/alerts/template.html).
path: rules.yml
line: 8
side: RIGHT
commit_id: <COMMIT ID>
--- END ---

POST /api/v3/repos/cloudflare/pint/pulls/1/comments
  Accept: application/vnd.github.squirrel-girl-preview, application/vnd.github.comfort-fade-preview+json
  Accept-Encoding: gzip
  Authorization: Bearer 12345
  Content-Type: application/json
  X-Github-Api-Version: 2022-11-28
--- BODY ---
body: |
    :warning: **Warning** reported by [pint](https://cloudflare.github.io/pint/) **promql/impossible** check.

    <details>
    <summary>impossible label</summary>

    ```yaml
    5 |       expr: ... != ignoring(package) group_left(foo) count(...) by (instance, version, package)
                                                                        ^^
    ```

    Query is using aggregation with `by(instance, version, package)`, only labels included inside `by(...)` will be present on the results.

    ```yaml
    5 |       expr: ... != ignoring(package) group_left(foo) ...
                                                        ^^^
    ```

    You can't use `foo` because this label is not possible here.

    </details>

    ------

    :information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/promql/impossible.html).
path: rules.yml
line: 8
side: RIGHT
commit_id: <COMMIT ID>
--- END ---

POST /api/v3/repos/cloudflare/pint/pulls/1/comments
  Accept: application/vnd.github.squirrel-girl-preview, application/vnd.github.comfort-fade-preview+json
  Accept-Encoding: gzip
  Authorization: Bearer 12345
  Content-Type: application/json
  X-Github-Api-Version: 2022-11-28
--- BODY ---
body: |
    :warning: **Warning** reported by [pint](https://cloudflare.github.io/pint/) **promql/regexp** check.

    <details>
    <summary>smelly regexp selector</summary>

    ```yaml
    13 |         sum by (exporter, colo_name) (rate(otelcol_exporter_send_failed_log_records{node_status="v", exporter=~"(failover|otlp)/.*", job=~"foo_.+_bar"}[5m]))
                                                                                                                                              ^^^^^^^^^^^^^^^^^
    14 |         /
    15 |         (
       |         [...]
    20 |         ... > 10
    ```

    `{job=~"foo_.+_bar"}` looks like a smelly selector that tries to extract substrings from the value, please consider breaking down the value of this label into multiple smaller labels

    See [Prometheus documentation](https://prometheus.io/docs/prometheus/latest/querying/basics/#time-series-selectors) for details on how vector selectors work.

    </details>

    ------

    :information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/promql/regexp.html).
path: rules.yml
line: 20
side: RIGHT
commit_id: <COMMIT ID>
--- END ---

GET /api/v3/repos/cloudflare/pint/pulls/1/reviews
  Accept: application/vnd.github.v3+json
  Accept-Encoding: gzip
  Authorization: Bearer 12345
  X-Github-Api-Version: 2022-11-28

POST /api/v3/repos/cloudflare/pint/pulls/1/reviews
  Accept: application/vnd.github.v3+json
  Accept-Encoding: gzip
  Authorization: Bearer 12345
  Content-Type: application/json
  X-Github-Api-Version: 2022-11-28
--- BODY ---
commit_id: <COMMIT ID>
body: |+
    ### This pull request was validated by [pint](https://github.com/cloudflare/pint).
    :heavy_exclamation_mark:	Problems found.
    | Severity | Number of problems |
    | --- | --- |
    | Bug | 1 |
    | Warning | 2 |
    <details><summary>Stats</summary>
    <p>

    | Stat | Value |
    | --- | --- |
    | Version | unknown |
    | Number of rules parsed | 2 |
    | Number of rules checked | 2 |
    | Number of problems found | 3 |
    | Number of offline checks | 20 |
    | Number of online checks | 0 |
    | Checks duration | 0 |

    </p>
    </details>

    <details><summary>Problems</summary>
    <p>

    ```
    Bug: template uses non-existent label (alerts/template)
      ---> rules.yml:4-8 -> `Foo Is Down`
    5 |       expr: count(...) by (instance, version) != ignoring(package) group_left(foo) ...
                               ^^
                               Query is using aggregation with `by(instance, version)`, only labels included
                               inside `by(...)` will be present on the results.
      |       [...]
    8 |         help: '{{ $labels.ixtance }}'
                                 ^^^^^^^^
                                 The template is using `ixtance` label but the query results won't have this
                                 label.

    Warning: impossible label (promql/impossible)
      ---> rules.yml:5 -> `Foo Is Down`
    5 |       expr: ... != ignoring(package) group_left(foo) count(...) by (instance, version, package)
                                                                        ^^
         Query is using aggregation with `by(instance, version, package)`,
         only labels included inside `by(...)` will be present on the
         results.
                                                        ^^^
                                                        You can't use `foo` because this label is not
                                                        possible here.

    Warning: smelly regexp selector (promql/regexp)
      ---> rules.yml:13-20 -> `OpenTelemetry_Collector_Failed_Logs`
    13 |         sum by (exporter, colo_name) (rate(otelcol_exporter_send_failed_log_records{node_status="v", exporter=~"(failover|otlp)/.*", job=~"foo_.+_bar"}[5m]))
                                                                                                                                              ^^^^^^^^^^^^^^^^^
            `{job=~"foo_.+_bar"}` looks like a smelly selector that tries to extract substrings from the value, please consider breaking down the value of this
            label into multiple smaller labels
    14 |         /
    15 |         (
       |         [...]
    20 |         ... > 10

    ```

    </p>
    </details>

event: COMMENT
--- END ---

