mirror of https://github.com/buster-so/buster.git
ok metrics are working again
This commit is contained in:
parent
3f3b9233f3
commit
d11c62446a
|
@ -193,8 +193,8 @@ async function processDashboardFile(file: { id: string; yml_content: string }):
|
|||
}
|
||||
|
||||
// Collect all metric IDs from rows if they exist
|
||||
const metricIds: string[] = dashboard.config.rows
|
||||
? dashboard.config.rows.flatMap((row) => row.items).map((item) => item.id)
|
||||
const metricIds: string[] = dashboard.rows
|
||||
? dashboard.rows.flatMap((row) => row.items).map((item) => item.id)
|
||||
: [];
|
||||
|
||||
// Validate metric IDs if any exist
|
||||
|
@ -226,7 +226,7 @@ async function processDashboardFile(file: { id: string; yml_content: string }):
|
|||
created_at: existingFile.createdAt,
|
||||
updated_at: new Date().toISOString(),
|
||||
version_number: latestVersion,
|
||||
content: dashboard.config, // Store the DashboardConfig directly
|
||||
content: { rows: dashboard.rows }, // Extract the config properties
|
||||
};
|
||||
|
||||
return {
|
||||
|
@ -346,7 +346,7 @@ const modifyDashboardFiles = wrapTraced(
|
|||
await tx
|
||||
.update(dashboardFiles)
|
||||
.set({
|
||||
content: sp.dashboard.config as DashboardConfig,
|
||||
content: { rows: sp.dashboard.rows } as DashboardConfig,
|
||||
updatedAt: sp.dashboardFile.updated_at,
|
||||
versionHistory: updatedVersionHistory,
|
||||
name: sp.dashboard.name,
|
||||
|
@ -355,8 +355,8 @@ const modifyDashboardFiles = wrapTraced(
|
|||
.execute();
|
||||
|
||||
// Update metric associations
|
||||
const newMetricIds = sp.dashboard.config.rows
|
||||
? sp.dashboard.config.rows.flatMap((row) => row.items).map((item) => item.id)
|
||||
const newMetricIds = sp.dashboard.rows
|
||||
? sp.dashboard.rows.flatMap((row) => row.items).map((item) => item.id)
|
||||
: [];
|
||||
|
||||
const existingAssociations = await tx
|
||||
|
|
|
@ -3,9 +3,10 @@ import type { DataSource } from '@buster/data-source';
|
|||
import { assetPermissions, db, metricFiles, updateMessageEntries } from '@buster/database';
|
||||
import {
|
||||
type ChartConfigProps,
|
||||
ChartConfigPropsSchema,
|
||||
type ColumnMetaData,
|
||||
type DataMetadata,
|
||||
type MetricYml,
|
||||
MetricYmlSchema,
|
||||
} from '@buster/server-shared/metrics';
|
||||
import { wrapTraced } from 'braintrust';
|
||||
import * as yaml from 'yaml';
|
||||
|
@ -51,7 +52,7 @@ interface MetricFileResult {
|
|||
success: boolean;
|
||||
error?: string;
|
||||
metricFile?: FileWithId;
|
||||
metricYml?: ChartConfigProps;
|
||||
metricYml?: MetricYml;
|
||||
message?: string;
|
||||
results?: Record<string, unknown>[];
|
||||
}
|
||||
|
@ -59,13 +60,10 @@ interface MetricFileResult {
|
|||
type VersionHistory = (typeof metricFiles.$inferSelect)['versionHistory'];
|
||||
|
||||
// Helper function to create initial version history
|
||||
function createInitialMetricVersionHistory(
|
||||
metric: ChartConfigProps,
|
||||
createdAt: string
|
||||
): VersionHistory {
|
||||
function createInitialMetricVersionHistory(metric: MetricYml, createdAt: string): VersionHistory {
|
||||
return {
|
||||
'1': {
|
||||
content: JSON.stringify(metric),
|
||||
content: metric,
|
||||
updated_at: createdAt,
|
||||
version_number: 1,
|
||||
},
|
||||
|
@ -219,12 +217,12 @@ async function processMetricFile(
|
|||
// Parse and validate YAML
|
||||
const metricYml = yaml.parse(fixedYmlContent);
|
||||
|
||||
const validatedMetricYml = ChartConfigPropsSchema.parse(metricYml);
|
||||
const validatedMetricYml = MetricYmlSchema.parse(metricYml);
|
||||
|
||||
// Validate and adjust bar/line chart axes
|
||||
let finalMetricYml: ChartConfigProps;
|
||||
let finalChartConfig: ChartConfigProps;
|
||||
try {
|
||||
finalMetricYml = validateAndAdjustBarLineAxes(validatedMetricYml);
|
||||
finalChartConfig = validateAndAdjustBarLineAxes(validatedMetricYml.chartConfig);
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
|
@ -232,12 +230,18 @@ async function processMetricFile(
|
|||
};
|
||||
}
|
||||
|
||||
// Create the final metric YML with the adjusted chart config
|
||||
const finalMetricYml: MetricYml = {
|
||||
...validatedMetricYml,
|
||||
chartConfig: finalChartConfig,
|
||||
};
|
||||
|
||||
// Use provided metric ID from state or generate new one
|
||||
const id = metricId || randomUUID();
|
||||
|
||||
// Validate SQL by running it
|
||||
const sqlValidationResult = await validateSql(
|
||||
metricYml.sql,
|
||||
finalMetricYml.sql,
|
||||
dataSourceId,
|
||||
userId,
|
||||
dataSourceDialect
|
||||
|
@ -254,7 +258,7 @@ async function processMetricFile(
|
|||
const now = new Date().toISOString();
|
||||
const metricFile: FileWithId = {
|
||||
id,
|
||||
name: metricYml.name,
|
||||
name: finalMetricYml.name,
|
||||
file_type: 'metric',
|
||||
result_message: sqlValidationResult.message || '',
|
||||
results: sqlValidationResult.results || [],
|
||||
|
@ -552,7 +556,7 @@ const createMetricFiles = wrapTraced(
|
|||
const successfulProcessing: Array<{
|
||||
fileName: string;
|
||||
metricFile: FileWithId;
|
||||
metricYml: ChartConfigProps;
|
||||
metricYml: MetricYml;
|
||||
message: string;
|
||||
results: Record<string, unknown>[];
|
||||
}> = [];
|
||||
|
|
|
@ -74,7 +74,7 @@ function addMetricVersionToHistory(
|
|||
return {
|
||||
...history,
|
||||
[nextVersion.toString()]: {
|
||||
content: JSON.stringify(metric),
|
||||
content: metric,
|
||||
updated_at: updatedAt,
|
||||
version_number: nextVersion,
|
||||
},
|
||||
|
|
|
@ -1285,7 +1285,13 @@ export const metricFiles = pgTable(
|
|||
Record<
|
||||
string, //version number as a string
|
||||
{
|
||||
content: string;
|
||||
content: string | {
|
||||
name: string;
|
||||
description: string;
|
||||
timeFrame: string;
|
||||
sql: string;
|
||||
chartConfig: Record<string, unknown>;
|
||||
};
|
||||
updated_at: string;
|
||||
version_number: number;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue