Skip to content

Commit a6cb3a0

Browse files
committed
Switch db value to json
Signed-off-by: Dominika Zemanovicova <[email protected]>
1 parent 36ce785 commit a6cb3a0

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

workspaces/scorecard/plugins/scorecard-backend/migrations/20250915113801_init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ exports.up = async function up(knex) {
2727
.notNullable()
2828
.comment('The entity ref for which this metric value was calculated');
2929
table
30-
.decimal('value', 15, 6)
30+
.json('value')
3131
.nullable()
3232
.comment('Metric value when calculation succeeds');
3333
table

workspaces/scorecard/plugins/scorecard-backend/src/database/MetricValuesStore.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { MetricValue } from '@red-hat-developer-hub/backstage-plugin-scorecard-common';
18+
1719
export type DbMetricValue = {
1820
id: number;
1921
catalog_entity_ref: string;
2022
metric_id: string;
21-
value?: number;
23+
value?: MetricValue;
2224
timestamp: Date;
2325
error_message?: string;
2426
};

workspaces/scorecard/plugins/scorecard-backend/src/service/CatalogMetricService.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ export class CatalogMetricService {
102102
return rawResults.map(({ metric_id, value, error_message, timestamp }) => {
103103
const provider = this.registry.getProvider(metric_id);
104104
const metric = provider.getMetric();
105-
const convertedValue =
106-
metric.type === 'boolean' && value !== undefined
107-
? Boolean(value)
108-
: value;
109105

110106
let thresholds: ThresholdConfig | undefined;
111107
let evaluation: string | undefined;
@@ -116,12 +112,12 @@ export class CatalogMetricService {
116112
provider,
117113
metric.type,
118114
);
119-
if (convertedValue === undefined) {
115+
if (value === undefined) {
120116
thresholdError =
121117
'Unable to evaluate thresholds, metric value is missing';
122118
} else {
123119
evaluation = this.thresholdEvaluator.getFirstMatchingThreshold(
124-
convertedValue,
120+
value,
125121
metric.type,
126122
thresholds,
127123
);
@@ -146,7 +142,7 @@ export class CatalogMetricService {
146142
stringifyError(new Error(`Metric value is 'undefined'`)),
147143
}),
148144
result: {
149-
value: convertedValue,
145+
value,
150146
timestamp: new Date(timestamp).toISOString(),
151147
thresholdResult: {
152148
definition: thresholds,

workspaces/scorecard/plugins/scorecard-node/src/api/MetricProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
export type MetricProviderInsertion = {
2929
catalog_entity_ref: string;
3030
metric_id: string;
31-
value?: number;
31+
value?: MetricValue;
3232
timestamp: Date;
3333
error_message?: string;
3434
};

0 commit comments

Comments
 (0)