|
1 | | -# Flakeguard |
| 1 | +Flakeguard |
| 2 | +========== |
2 | 3 |
|
3 | 4 | **Flakeguard** is a tool designed to help identify flaky tests within a Go project. Flaky tests are tests that intermittently fail without changes to the code, often due to race conditions or other non-deterministic behavior. Flakeguard assists by analyzing the impact of code changes on test packages and by running tests multiple times to determine stability. |
4 | 5 |
|
5 | | -## Features |
| 6 | +In addition to detecting flaky tests, Flakeguard can also integrate with Jira to track known flaky tests. It maintains a local database of tests and their associated Jira tickets, allowing you to create and manage these tickets directly from the command line. |
6 | 7 |
|
7 | | -- **Identify Impacted Tests**: Detects test packages that may be affected by changes in your Go project files. |
8 | | -- **Run Tests for Flakiness**: Runs tests multiple times to determine their flakiness. |
9 | | -- **Output Results in JSON**: Allows easy integration with CI pipelines and custom reporting. |
10 | | -- **Supports Exclusion Lists**: Configurable to exclude specified packages or paths from the analysis. |
11 | | -- **Recursive Dependency Analysis**: Detects all impacted packages through dependency levels. |
| 8 | +Features |
| 9 | +-------- |
12 | 10 |
|
13 | | -## Installation |
| 11 | +* **Identify Impacted Tests:** Detects test packages that may be affected by changes in your Go project files. |
| 12 | +* **Run Tests for Flakiness:** Runs tests multiple times to determine their flakiness. |
| 13 | +* **Output Results in JSON:** Allows easy integration with CI pipelines and custom reporting. |
| 14 | +* **Supports Exclusion Lists:** Configurable to exclude specified packages or paths from the analysis. |
| 15 | +* **Recursive Dependency Analysis:** Detects all impacted packages through dependency levels. |
| 16 | +* **Jira Integration (Optional):** Create, review, and manage flaky test tickets in Jira. |
| 17 | +* **Local Database:** Store known flaky tests and their associated Jira tickets for easy reference. |
14 | 18 |
|
15 | | -To install `flakeguard` CLI, you need to have Go installed on your machine. With Go installed, run the following command: |
| 19 | +Prerequisites |
| 20 | +------------- |
| 21 | + |
| 22 | +1. **Go:** Version 1.21 or later recommended. |
| 23 | +2. **Jira API Access (optional):** Required only if you want to use the Jira-related commands (`create-tickets`, `review-tickets`, `sync-jira`): |
| 24 | + * `JIRA_DOMAIN`: Your Jira instance domain (e.g. _your-company.atlassian.net_). |
| 25 | + * `JIRA_EMAIL`: The email address associated with your Jira account used for API access. |
| 26 | + * `JIRA_API_KEY`: Your Jira API token (generate one in your Jira account settings). |
| 27 | + * `JIRA_PROJECT_KEY`: (Optional) The default Jira project key to use if `--jira-project` is not specified for `create-tickets`. |
| 28 | + |
| 29 | +Installation |
| 30 | +------------ |
| 31 | + |
| 32 | +To install the `flakeguard` CLI, ensure you have Go installed. Then run: |
16 | 33 |
|
17 | | -```sh |
18 | 34 | go install github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard@latest |
19 | | -``` |
20 | 35 |
|
21 | | -## Usage |
| 36 | +You can also clone the repository and build from source: |
22 | 37 |
|
23 | | -Flakeguard offers two main commands: |
| 38 | +git clone https://github.com/smartcontractkit/chainlink-testing-framework.git |
| 39 | +cd chainlink-testing-framework/tools/flakeguard |
24 | 40 |
|
25 | | -- `find` identifies test packages affected by recent changes. |
26 | | -- `run` executes tests multiple times to identify flaky tests |
27 | | -- `create-tickets` automates the creation of Jira tickets for flaky tests detected by Flakeguard |
| 41 | +go build -o flakeguard main.go |
28 | 42 |
|
29 | | -Run with `--help` to see all flags for the commands. |
30 | 43 |
|
31 | | -### JSON Output |
| 44 | +Usage (Flaky Test Detection) |
| 45 | +---------------------------------- |
32 | 46 |
|
33 | | -Both `find` and `run` commands support JSON output `--json`, making it easy to integrate Flakeguard with CI/CD pipelines and reporting tools. |
| 47 | +Flakeguard provides two primary commands for local detection of flaky tests without involving Jira: `find` and `run`. |
34 | 48 |
|
35 | | -### Creating JIRA Tickets |
36 | | -The `create-tickets` command allows you to automate the creation of JIRA tickets for flaky tests. It reads test results from a CSV file (typically exported from a Splunk view) and creates tickets in JIRA. |
| 49 | +### `flakeguard find` |
37 | 50 |
|
38 | | -``` |
39 | | -go run main.go create-tickets --jira-project=<JIRA_PROJECT_KEY> --flaky-test-json-db-path=<PATH_TO_FLAKY_TEST_DB_JSON> --assignee-mapping=<PATH_TO_JIRA_ASSIGNEE_MAPPING_JSON> --csv-path=<PATH_TO_CSV_FILE> [--skip-existing] [--dry-run] |
40 | | -``` |
| 51 | +The `find` command scans your Go project to determine which test packages may be impacted by recent file changes. It conducts a dependency analysis to see which test packages depend on the changed files, helping you focus your testing efforts on the most relevant areas. |
41 | 52 |
|
42 | | -Example: |
43 | | -``` |
44 | | -go run main.go create-tickets --jira-project=DX --flaky-test-json-db-path=.flaky_test_db.json --assignee-mapping=.jira_assignee_mapping.json --skip-existing --csv-path '1742825894_77903.csv' |
45 | | -``` |
46 | 53 |
|
47 | | -**Options:** |
| 54 | +### `flakeguard run` |
| 55 | + |
| 56 | +After identifying packages of interest (via `flakeguard find` or otherwise), use the `run` command to execute tests multiple times to detect flakiness. |
48 | 57 |
|
49 | | -- `--jira-project`: The JIRA project key where tickets should be created (e.g., `DX`). |
50 | | -- `--test-db-path`: The path to a JSON database (`.json`) that stores information about existing flaky test tickets. |
51 | | -- `--assignee-mapping`: The path to a JSON file (`.json`) that maps test packages to JIRA assignees. |
52 | | -- `--csv-path`: The path to the CSV file containing the flaky test results. |
53 | | -- `--skip-existing`: (Optional) Skips creating tickets for tests that already have corresponding JIRA tickets in the database or JIRA. |
54 | | -- `--dry-run`: (Optional) Performs a dry run without actually creating JIRA tickets. |
55 | 58 |
|
56 | | -**Environment Variables:** |
| 59 | +Configuration Files (for Jira Integration) |
| 60 | +------------------------------------------ |
57 | 61 |
|
58 | | -- `JIRA_DOMAIN`: The domain of your JIRA instance. |
59 | | -- `JIRA_EMAIL`: The email address used to authenticate with JIRA. |
60 | | -- `JIRA_API_KEY`: The API key used to authenticate with JIRA. |
| 62 | +When using Flakeguard’s Jira integration and local database features, you may need these configuration files: |
61 | 63 |
|
62 | | -### Managing Tickets |
63 | | -The new tickets command lets you interactively manage your flaky test tickets stored in your local JSON database. With this command you can: |
| 64 | +1. ### Local Database (`flaky_tests_db.json `) |
| 65 | + |
| 66 | + * **Purpose:** Stores mappings between test definitions (package + name) and their Jira tickets, along with the assignee ID. |
| 67 | + * **Location:** By default, stored as `flaky_tests_db.json ` in your user home directory (~). This path is determined by `localdb.DefaultDBPath()`. |
| 68 | + * **Override:** Use `--test-db-path` with any command to specify a different location. |
| 69 | + * **Format:** Internal JSON structure managed by the tool (_localdb/localdb.go_). |
| 70 | +2. ### User Mapping (`user_mapping.json`) |
| 71 | + |
| 72 | + * **Purpose:** Maps Jira User Account IDs to Pillar Names or team/group identifiers. Used by: |
| 73 | + * `create-tickets`: To set the Pillar Name custom field when creating a new Jira ticket if an assignee is determined. |
| 74 | + * `review-tickets`: To allow setting the Pillar Name (\[i\] action) based on the ticket's assignee stored in the local DB. |
| 75 | + * **Format:** A JSON array of objects. |
| 76 | + |
| 77 | + * **Flag:** Use `--user-mapping-path` (default: `user_mapping.json`) when needed. |
| 78 | +3. ### User Test Mapping (`user_test_mapping.json`) |
| 79 | + |
| 80 | + * **Purpose:** Defines regex patterns to match test packages (or full test paths) to suggest an assignee (Jira User Account ID) for new tickets created by `create-tickets`. The first pattern match determines the suggested assignee. |
| 81 | + * **Format:** A JSON array of objects. The `.*` pattern can be used as a fallback. |
| 82 | + |
| 83 | + * **Flag:** Use `--user-test-mapping-path` (default: `user_test_mapping.json`) when creating tickets. |
64 | 84 |
|
65 | | -- Mark tests as skipped: Post a comment to the associated JIRA ticket and update the local DB. |
66 | | -- Unskip tests: Remove the skipped status and post an unskip comment. |
67 | | -- Navigate tickets: Use a TUI to browse through tickets. |
| 85 | + |
| 86 | +Usage (Jira Integration) |
| 87 | +------------------------ |
| 88 | + |
| 89 | +If you only need to identify flaky tests locally (via `find` and `run`) and do not intend to create or manage Jira tickets, you can skip these commands. |
| 90 | + |
| 91 | +### `flakeguard create-tickets` |
| 92 | + |
| 93 | +Interactively process a CSV file of flaky tests, suggest assignees based on patterns, check for existing Jira tickets, and create new tickets if needed. |
| 94 | + |
| 95 | +* **Key Features:** |
| 96 | + * Reads test details from CSV. |
| 97 | + * Suggests assignee using `user_test_mapping.json`. |
| 98 | + * Checks local DB and Jira for existing tickets. |
| 99 | + * Sets Pillar Name from `user_mapping.json` when creating new tickets. |
| 100 | + * Provides a text-based UI for review and confirmation. |
| 101 | + * Updates the local DB with created/manually assigned ticket keys. |
| 102 | + * Outputs tests that were not confirmed for ticket creation to a _\_remaining.csv_ file. |
| 103 | +* **Flags:** |
| 104 | + * `--csv-path` (required): Path to the input CSV file of flaky tests. |
| 105 | + * `--jira-project`: Jira project key for new tickets (required if `JIRA_PROJECT_KEY` is not set). |
| 106 | + * `--jira-issue-type`: Jira issue type for new tickets (default: _Task_). |
| 107 | + * `--jira-search-label`: Label used to search for existing tickets (default: _flaky\_test_). |
| 108 | + * `--test-db-path`: Local database file path (default: `~/flaky_tests_db.json `). |
| 109 | + * `--user-mapping-path`: Path to user mapping JSON (default: `user_mapping.json`). |
| 110 | + * `--user-test-mapping-path`: Path to user-test mapping JSON (default: `user_test_mapping.json`). |
| 111 | + * `--skip-existing`: If set, automatically skips tests that already have a known Jira key. |
| 112 | + * `--dry-run`: Simulates actions without creating Jira tickets or modifying the DB. |
| 113 | + |
| 114 | +**Example:** |
68 | 115 |
|
69 | 116 | ``` |
70 | | -go run main.go tickets --test-db-path=.flaky_test_db.json --jira-comment |
| 117 | + go run main.go create-tickets \ |
| 118 | + --jira-project=DX \ |
| 119 | + --test-db-path=flaky_test_db.json \ |
| 120 | + --user-mapping-path=user_mapping.json \ |
| 121 | + --user-test-mapping-path=user_test_mapping.json \ |
| 122 | + --skip-existing \ |
| 123 | + --dry-run=false \ |
| 124 | + --csv-path '1744018947_31163.csv' |
71 | 125 | ``` |
72 | 126 |
|
73 | | -**Options:** |
| 127 | +### `flakeguard review-tickets` |
| 128 | + |
| 129 | +Interactively review tickets in the local database. Fetches current status and Pillar Name from Jira, and lets you set the Pillar Name in Jira. |
| 130 | + |
| 131 | +* **Key Features:** |
| 132 | + * Reads test data from the local DB. |
| 133 | + * Fetches current Status and Pillar Name from Jira. |
| 134 | + * Displays Test Info, Assignee, Pillar Name, and Jira Status. |
| 135 | + * Allows setting the Pillar Name in Jira using the **\[i\]** action, based on `user_mapping.json`. |
| 136 | +* **TUI Actions:** |
| 137 | + * **\[i\]** Set Pillar Name in Jira if it’s empty (and if prerequisites are met). |
| 138 | + * **\[p\]** View previous ticket. |
| 139 | + * **\[n\]** View next ticket. |
| 140 | + * **\[q\]** Quit the TUI. |
| 141 | +* **Flags:** |
| 142 | + * `--test-db-path`: Local DB path (default: `~/flaky_tests_db.json `). |
| 143 | + * `--user-mapping-path`: Path to user mapping JSON (default: `user_mapping.json`). |
| 144 | + * `--user-test-mapping-path`: Path to user-test mapping JSON (default: `user_test_mapping.json`). |
| 145 | + * `--missing-pillars`: Only show tickets missing a Pillar Name. |
| 146 | + * `--dry-run`: Prevents the **\[i\]** action from actually updating Jira. |
| 147 | + |
| 148 | +**Examples:** |
74 | 149 |
|
75 | | -- `--test-db-path`: The path to a JSON database (.json) that stores information about your flaky test tickets. |
76 | | -- `--jira-comment`: If set to true, posts a comment to the corresponding JIRA ticket when marking a test as skipped or unskipped. |
77 | | -`--dry-run`: (Optional) Runs the command in dry-run mode without posting comments to JIRA. |
78 | | -- `--hide-skipped`: (Optional) If set, tickets already marked as skipped are hidden from the interface. |
| 150 | +``` |
| 151 | +go run main.go review-tickets --test-db-path ".flaky_test_db.json" --dry-run=false --user-mapping-path "user_mapping.json" |
| 152 | +``` |
79 | 153 |
|
80 | | -**Environment Variables:** |
| 154 | +### `flakeguard sync-jira` |
81 | 155 |
|
82 | | -- `JIRA_DOMAIN`: The domain of your JIRA instance. |
83 | | -- `JIRA_EMAIL`: The email address used to authenticate with JIRA. |
84 | | -- `JIRA_API_KEY`: The API key used to authenticate with JIRA. |
| 156 | +Scans Jira for all tickets matching a specific label and ensures they exist in the local database. Updates local assignees based on Jira's current assignee. |
85 | 157 |
|
86 | | -### Example Run |
| 158 | +* **Key Features:** |
| 159 | + * Fetches all Jira tickets |
| 160 | + * Adds missing tickets to the local DB (where the test package/name might be unknown). |
| 161 | + * Updates the _AssigneeID_ in the local DB if it differs from the current Jira assignee. |
| 162 | +* **Flags:** |
| 163 | + * `--test-db-path`: Local DB file path (default: `~/flaky_tests_db.json `). |
| 164 | + * `--jira-search-label`: Label used to find relevant tickets (default: _flaky\_test_). |
| 165 | + * `--dry-run`: Shows what would be updated without modifying the DB. |
87 | 166 |
|
88 | | -You can find example usage and see outputs with: |
| 167 | +**Example:** |
89 | 168 |
|
90 | | -```sh |
91 | | -make example # Run an example flow of running tests, aggregating results, and reporting them to GitHub |
92 | | -make example_flaky_panic # Run example flow with flaky and panicking tests |
93 | | -ls example_results # See results of each run and aggregation |
94 | 169 | ``` |
| 170 | +go run main.go sync-jira --test-db-path=.flaky_test_db.json |
| 171 | +``` |
0 commit comments