Call `::Triage` instead of `Triage` in the context of gitlab-triage
Context
- Some scheduled pipelines are failing:
- MR causing issues: !2387 (merged)
What does this MR do and why?
In triage-ops, the Triage
class refers to the class
defined in triage/triage.rb
.
However, In gitlab-triage, the Triage
class refers to the
class defined in lib/gitlab/triage.rb
, which doesn't have
the api_token
method defined.
This MR ensures we call the Triage class from triage-ops.
Steps to reproduce locally
Quick checks with debugger
# Before this MR
(byebug) Triage.api_token(:com)
*** NoMethodError Exception: undefined method `api_token' for Gitlab::Triage:Module
# After this MR
(byebug) ::Triage.api_token(:com)
*** KeyError Exception: key not found: "GITLAB_COM_API_TOKEN"
Env variables
export TRIAGE_SOURCE_PATH=9970
export TRIAGE_POLICY_FILE=policies/stages/hygiene/close-stale-bugs.yml
export TRIAGE_SOURCE_TYPE=groups
export GITLAB_TRIAGE_BRANCH=master
export EXTRA_FLAGS="--dry-run"
export GITLAB_COM_API_TOKEN=<redacted>
Before the fix
$ bin/run_with_sentry gitlab-triage -r ./plugins/all --debug -f $TRIAGE_POLICY_FILE --token $GITLAB_COM_API_TOKEN --source $TRIAGE_SOURCE_TYPE --source-id $TRIAGE_SOURCE_PATH $EXTRA_FLAGS
I, [2023-08-28T15:20:55.132558 #26088] INFO -- sentry: ** [Raven] Raven 3.1.1 configured not to capture errors: DSN not set
*********************************************************************
Executing policies from policies/stages/hygiene/close-stale-bugs.yml.
*********************************************************************
Performing a dry run.
=========================
Triaging the `9970` group
=========================
---------------------------------------
Processing summaries & rules for issues
---------------------------------------
----------------------------------------------------------------------------
Gathering resources for rule: **Remove stale label from active vintage bug**
----------------------------------------------------------------------------
.[DEBUG] query_api: https://gitlab.com/api/v4/groups/9970/issues?per_page=100&labels=type%3A%3Abug%2Cvintage%2Cstale&state=opened
[DEBUG] rate_limit_infos: Rate limit remaining: 1970 (reset at 2023-08-28 15:21:57 +0200)
* Found 35 resources...
* Filtering resources.../Users/gitlab/src/gitlab-triage/lib/gitlab/triage/resource/context.rb:27:in `eval': undefined method `api_token' for Gitlab::Triage:Module (NoMethodError)
from /Users/gitlab/src/gitlab-triage/lib/gitlab/triage/resource/context.rb:25:in `instance_eval'
from /Users/gitlab/src/gitlab-triage/lib/gitlab/triage/resource/context.rb:25:in `eval'
from /Users/gitlab/src/gitlab-triage/lib/gitlab/triage/filters/ruby_conditions_filter.rb:22:in `calculate'
from /Users/gitlab/src/gitlab-triage/lib/gitlab/triage/engine.rb:468:in `block in filter_resources'
from /Users/gitlab/src/gitlab-triage/lib/gitlab/triage/engine.rb:420:in `select'
from /Users/gitlab/src/gitlab-triage/lib/gitlab/triage/engine.rb:420:in `filter_resources'
from /Users/gitlab/src/gitlab-triage/lib/gitlab/triage/engine.rb:357:in `block in resources_for_rule'
from /Users/gitlab/src/gitlab-triage/lib/gitlab/triage/expand_condition.rb:13:in `each'
from /Users/gitlab/src/gitlab-triage/lib/gitlab/triage/expand_condition.rb:13:in `perform'
After the fix
$ bin/run_with_sentry gitlab-triage -r ./plugins/all --debug -f $TRIAGE_POLICY_FILE --token $GITLAB_COM_API_TOKEN --source $TRIAGE_SOURCE_TYPE --source-id $TRIAGE_SOURCE_PATH $EXTRA_FLAGS
I, [2023-08-28T15:20:42.207523 #25919] INFO -- sentry: ** [Raven] Raven 3.1.1 configured not to capture errors: DSN not set
*********************************************************************
Executing policies from policies/stages/hygiene/close-stale-bugs.yml.
*********************************************************************
Performing a dry run.
=========================
Triaging the `9970` group
=========================
---------------------------------------
Processing summaries & rules for issues
---------------------------------------
----------------------------------------------------------------------------
Gathering resources for rule: **Remove stale label from active vintage bug**
----------------------------------------------------------------------------
.[DEBUG] query_api: https://gitlab.com/api/v4/groups/9970/issues?per_page=100&labels=type%3A%3Abug%2Cvintage%2Cstale&state=opened
[DEBUG] rate_limit_infos: Rate limit remaining: 1974 (reset at 2023-08-28 15:21:44 +0200)
* Found 35 resources...
* Filtering resources.../Users/gitlab/src/triage-ops/triage/triage.rb:97:in `fetch': key not found: "GITLAB_COM_API_TOKEN" (KeyError)
Did you mean? "GITLAB_API_PRIVATE_TOKEN"
from /Users/gitlab/src/triage-ops/triage/triage.rb:97:in `block in api_token'
from /Users/gitlab/.asdf/installs/ruby/3.0.5/lib/ruby/gems/3.0.0/gems/mini_cache-1.1.0/lib/mini_cache/store.rb:113:in `get_or_set'
from /Users/gitlab/src/triage-ops/triage/triage.rb:96:in `api_token'
from /Users/gitlab/src/gitlab-triage/lib/gitlab/triage/resource/context.rb:27:in `eval'
from /Users/gitlab/src/gitlab-triage/lib/gitlab/triage/resource/context.rb:25:in `instance_eval'
from /Users/gitlab/src/gitlab-triage/lib/gitlab/triage/resource/context.rb:25:in `eval'
from /Users/gitlab/src/gitlab-triage/lib/gitlab/triage/filters/ruby_conditions_filter.rb:22:in `calculate'
from /Users/gitlab/src/gitlab-triage/lib/gitlab/triage/engine.rb:468:in `block in filter_resources'
from /Users/gitlab/src/gitlab-triage/lib/gitlab/triage/engine.rb:420:in `select'
from /Users/gitlab/src/gitlab-triage/lib/gitlab/triage/engine.rb:420:in `filter_resources'
from /Users/gitlab/src/gitlab-triage/lib/gitlab/triage/engine.rb:357:in `block in resources_for_rule'
from /Users/gitlab/src/gitlab-triage/lib/gitlab/triage/expand_condition.rb:13:in `each'
from /Users/gitlab/src/gitlab-triage/lib/gitlab/triage/expand_condition.rb:13:in `perform'
Expected impact & dry-runs
These are strongly recommended to assist reviewers and reduce the time to merge your change.
See https://gitlab.com/gitlab-org/quality/triage-ops/-/tree/master/doc/scheduled#testing-policies-with-a-dry-run on how to perform dry-runs for new policies.
See https://gitlab.com/gitlab-org/quality/triage-ops/-/blob/master/doc/reactive/best_practices.md#use-the-sandbox-to-test-new-processors on how to make sure a new processor can be tested.
Action items
-
If adding environment variables for reactive processors, update config/triage-web.yaml
and.gitlab/ci/triage-web.yml
-
(If applicable) Add documentation to the handbook pages for Triage Operations => - (If applicable) Identify the affected groups and how to communicate to them:
-
/cc @ person_or_group
=> -
Relevant Slack channels => -
Engineering week-in-review
-
Edited by David Dieulivol