You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: workspaces/scorecard/plugins/scorecard-backend-module-github/src/metricProviders/GithubOpenPRsProvider.test.ts
+38-7Lines changed: 38 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,7 @@ import { ConfigReader } from '@backstage/config';
Copy file name to clipboardExpand all lines: workspaces/scorecard/plugins/scorecard-backend/docs/thresholds.md
+28-27Lines changed: 28 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
# Thresholds Configuration
2
2
3
-
Thresholds define conditions that determine which category a metric value belongs to (`error`, `warning`, or `success`). When a metric value matches a threshold condition, it gets assigned to that threshold's category. The Scorecard plugin provides multiple ways to configure thresholds with a flexible priority system.
3
+
Thresholds define conditions that determine which category a metric value belongs to (`success`, `warning`, or `error`). When a metric value matches a threshold condition, it gets assigned to that threshold's category. The Scorecard plugin provides multiple ways to configure thresholds with a flexible priority system.
4
4
5
5
## Overview
6
6
7
7
Thresholds are evaluated in order and the **first matching** threshold rule is applied. Each threshold rule consists of:
8
8
9
-
-**`key`**: The threshold category (only allowed keys are `error`, `warning`, `success`)
9
+
-**`key`**: The threshold category (only allowed keys are `success`, `warning`, `error`)
10
10
-**`expression`**: The condition that determines if a metric value matches this threshold
11
11
12
12
## Threshold Configuration Options
@@ -24,9 +24,9 @@ export class MyMetricProvider implements MetricProvider<'number'> {
24
24
getMetricThresholds():ThresholdConfig {
25
25
return {
26
26
rules: [
27
-
{ key: 'error', expression: '>50' },
28
-
{ key: 'warning', expression: '10-50' },
29
27
{ key: 'success', expression: '<10' },
28
+
{ key: 'warning', expression: '10-50' },
29
+
{ key: 'error', expression: '>50' },
30
30
],
31
31
};
32
32
}
@@ -81,12 +81,12 @@ scorecard:
81
81
myMetric:
82
82
thresholds:
83
83
rules:
84
+
- key: success
85
+
expression: '<10'
86
+
- key: warning
87
+
expression: '<=20'
84
88
- key: error
85
89
expression: '>20'
86
-
- key: warning
87
-
expression: '>10'
88
-
- key: success
89
-
expression: '<=10'
90
90
myOtherDatasource:
91
91
myOtherMetric: ...
92
92
```
@@ -102,9 +102,9 @@ metadata:
102
102
name: my-service
103
103
annotations:
104
104
# Override specific threshold rules for this entity
{ key: 'warning', expression: '>10' }, // from app-config
167
-
{ key: 'success', expression: '<=10' } // from app-config
168
169
]
169
170
```
170
171
@@ -225,27 +226,27 @@ The `ThresholdEvaluator` service processes threshold rules and determines which
225
226
226
227
### Key Features
227
228
228
-
1. **Order-dependent evaluation**: Rules are evaluated in the order they appear
229
+
1. **Order-dependent evaluation**: Rules are evaluated in the order they appear. If provider supports overriding defaults through [app configuration](#App-Configuration-Thresholds), you can change the evaluation order by specifying threshold keys in a different order. Entity annotations cannot alter the evaluation order, which is determined by either the [app configuration](#Provider-Default-Thresholds) or, if not specified, the [default provider configuration](#Provider-Default-Thresholds).
229
230
2. **First-match wins**: Returns the first threshold rule whose condition the value satisfies
230
231
3. **Type-safe**: Validates expressions against metric types
231
-
4. **Error handling**: Graceful handling of invalid expressions. You should validate your expressions loaded from config in your custom providers using `validateThresholds` from `backstage-plugin-scorecard-node`. Invalid annotation expressions are logged and skipped (do not override)
232
+
4. **Error handling**: You should validate your expressions loaded from config in your custom providers using `validateThresholds` from `backstage-plugin-scorecard-node`. Invalid expressions will result in evaluation error.
232
233
233
234
### Best Practices
234
235
235
236
### 1. Logical Ordering
236
237
237
238
Order rules from most restrictive to least restrictive.
238
239
239
-
In this example, the `error` rule would never be triggered because any value greater than 20 would already match the `warning` rule (since it is evaluated first). As a result, all values above 50 would be classified as `warning` instead of `error`:
240
+
In this example, the `success` rule would never be triggered because any value smaller than 15 would already match the `warning` rule (since it is evaluated first). As a result, all values under 15 would be classified as `warning` instead of `success`:
0 commit comments