-
Notifications
You must be signed in to change notification settings - Fork 115
feat(scorecard): Custom threshold keys and colors #2378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dzemanov
merged 23 commits into
redhat-developer:main
from
dzemanov:scorecard-threshold-keys-colors
Mar 4, 2026
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
5ff6bb0
Enable custom threshold keys
dzemanov 2ea9c40
Introduce custom colors
dzemanov 981c3cc
Introduce SCORECARD_THRESHOLD_RULE_COLOR_VALUES
dzemanov b288c47
Unify scorecard error colors
dzemanov e0efe3a
Simplify resolveStatusColor
dzemanov 2687201
Use constant for error state color
dzemanov ad09ead
Unify scorecard error state handling for color
dzemanov ff782a0
Custom threshold keys must specify color
dzemanov e85e0e5
Update docs
dzemanov 8cf1585
Update reports
dzemanov 8dbfdce
Fix issues
dzemanov 2073904
Fix e2e
dzemanov 1535377
Rename to fix case
dzemanov b6580a1
Update docs
dzemanov 7e41434
Merge branch 'main' into scorecard-threshold-keys-colors
Eswaraiahsapram 82be613
Split utils
dzemanov cc80a4e
Use statusCounts as record
dzemanov 72603ca
Use error state color
dzemanov 3620a63
Update to include also PG config
dzemanov 11b52a5
Prefer Number.parseInt
dzemanov 833a7ae
Fix rgba colors
dzemanov d9219f0
Simplify DbAggregatedMetric computation
dzemanov 021ba67
Fix overriding custom keys by entity annotations
dzemanov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| '@red-hat-developer-hub/backstage-plugin-scorecard-backend': minor | ||
| '@red-hat-developer-hub/backstage-plugin-scorecard-common': minor | ||
| '@red-hat-developer-hub/backstage-plugin-scorecard-node': minor | ||
| '@red-hat-developer-hub/backstage-plugin-scorecard': minor | ||
| --- | ||
|
|
||
| Introduces custom threshold rule keys and colors that can be configured in `app-config.yaml`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
workspaces/scorecard/plugins/scorecard-backend/knexfile.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * Copyright Red Hat, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| // To create new migration file use: "yarn knex migrate:make migrations", | ||
| // open generated new migration file and edit it to complete code. | ||
| // | ||
| // This `knexfile.js` exports multiple named environments, so you must specify | ||
| // which one to use with `--env` when running migrations. | ||
| // | ||
| // Examples: | ||
| // - sqlite3: "yarn knex --env sqlite3 migrate:latest" | ||
| // - pg: "yarn knex --env pg migrate:latest" | ||
| // | ||
| // To run new migration use: "yarn knex --env sqlite3 migrate:up some_file_name" | ||
| // To run latest migration use: "yarn knex --env sqlite3 migrate:latest" | ||
| // To rollback concrete migration use: "yarn knex --env sqlite3 migrate:down some_file_name" | ||
| // To rollback latest migration batch use: "yarn knex --env sqlite3 migrate:rollback" | ||
|
|
||
| module.exports = { | ||
| sqlite3: { | ||
| client: 'better-sqlite3', | ||
| connection: ':memory:', | ||
| useNullAsDefault: true, | ||
| migrations: { | ||
| directory: './migrations', | ||
| }, | ||
| }, | ||
| pg: { | ||
| client: 'pg', | ||
| connection: { | ||
| host: process.env.POSTGRES_HOST, | ||
| port: Number.parseInt(process.env.POSTGRES_PORT, 10), | ||
| user: process.env.POSTGRES_USER, | ||
| password: process.env.POSTGRES_PASSWORD, | ||
| database: process.env.POSTGRES_DB, | ||
| }, | ||
| migrations: { | ||
| directory: './migrations', | ||
| }, | ||
| }, | ||
| }; | ||
92 changes: 92 additions & 0 deletions
92
...ard/plugins/scorecard-backend/migrations/20260206115752_remove_status_check_constraint.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /* | ||
| * Copyright Red Hat, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| exports.up = async function up(knex) { | ||
| // Remove the status_check constraint that limits status values to 'success', 'warning', 'error' | ||
| const client = knex.client.config.client; | ||
|
|
||
| if (client === 'sqlite3' || client === 'better-sqlite3') { | ||
| await knex.raw(` | ||
| ALTER TABLE metric_values | ||
| RENAME COLUMN status TO status_old; | ||
| `); | ||
|
|
||
| await knex.raw(` | ||
| ALTER TABLE metric_values | ||
| ADD COLUMN status VARCHAR(255) NULL; | ||
| `); | ||
|
|
||
| await knex.raw(` | ||
| UPDATE metric_values | ||
| SET status = status_old; | ||
| `); | ||
|
|
||
| await knex.raw(` | ||
| ALTER TABLE metric_values | ||
| DROP COLUMN status_old; | ||
| `); | ||
| } else { | ||
| await knex.schema.alterTable('metric_values', table => { | ||
| table.dropChecks(['status_check']); | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| exports.down = async function down(knex) { | ||
| // Re-add the status_check constraint | ||
|
|
||
| // Fail if any incompatible rows with status values that don't match the constraint | ||
| const incompatibleRows = await knex('metric_values') | ||
| .whereNotIn('status', ['success', 'warning', 'error']) | ||
| .whereNotNull('status') | ||
| .count('* as count') | ||
| .first(); | ||
| if (incompatibleRows && incompatibleRows.count > 0) { | ||
| throw new Error( | ||
| `Cannot rollback migration: Found ${incompatibleRows.count} rows with status values ` + | ||
| `outside of ['success', 'warning', 'error']. Please migrate or remove these rows before rolling back.`, | ||
| ); | ||
| } | ||
|
|
||
| const client = knex.client.config.client; | ||
|
|
||
| if (client === 'sqlite3' || client === 'better-sqlite3') { | ||
| await knex.raw(` | ||
| ALTER TABLE metric_values | ||
| RENAME COLUMN status TO status_old; | ||
| `); | ||
|
|
||
| await knex.raw(` | ||
| ALTER TABLE metric_values | ||
| ADD COLUMN status VARCHAR(255) NULL | ||
| CHECK (status IN ('success', 'warning', 'error')); | ||
| `); | ||
|
|
||
| await knex.raw(` | ||
| UPDATE metric_values | ||
| SET status = status_old; | ||
| `); | ||
|
|
||
| await knex.raw(` | ||
| ALTER TABLE metric_values | ||
| DROP COLUMN status_old; | ||
| `); | ||
| } else { | ||
| await knex.raw( | ||
| "ALTER TABLE metric_values ADD CONSTRAINT status_check CHECK (status IN ('success', 'warning', 'error'))", | ||
| ); | ||
| } | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.