Skip to content

Commit

Permalink
add shadow read and content nodes comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
aubin-tchoi committed Jan 17, 2025
1 parent 99d7604 commit 77dc6f3
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
53 changes: 53 additions & 0 deletions front/lib/api/content_nodes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {
ContentNodeType,
CoreAPIContentNode,
DataSourceViewContentNode,
DataSourceViewType,
} from "@dust-tt/types";
import {
Expand All @@ -12,6 +13,7 @@ import {
} from "@dust-tt/types";

import type { DataSourceViewResource } from "@app/lib/resources/data_source_view_resource";
import type logger from "@app/logger/logger";

export function getContentNodeInternalIdFromTableId(
dataSourceView: DataSourceViewResource | DataSourceViewType,
Expand Down Expand Up @@ -49,6 +51,57 @@ export function getContentNodeInternalIdFromTableId(
}
}

export function compareNodes({
connectorsContentNodes,
coreContentNodes,
localLogger,
}: {
connectorsContentNodes: DataSourceViewContentNode[];
coreContentNodes: DataSourceViewContentNode[];
localLogger: typeof logger;
}) {
connectorsContentNodes.forEach((connectorsNode) => {
const coreNodes = coreContentNodes.filter(
(coreNode) => coreNode.internalId === connectorsNode.internalId
);
if (coreNodes.length !== 1) {
localLogger.info(
{
internalId: connectorsNode.internalId,
coreNodesId: coreNodes.map((n) => n.internalId),
},
"[CoreNodes] Invalid match"
);
} else {
const coreNode = coreNodes[0];
const diff = Object.fromEntries(
Object.entries(connectorsNode)
.filter(
([key, value]) =>
value !== coreNode[key as keyof DataSourceViewContentNode]
)
.map(([key, value]) => [
key,
{
connectors: value,
core: coreNode[key as keyof DataSourceViewContentNode],
},
])
);

if (Object.keys(diff).length > 0) {
localLogger.info(
{
internalId: connectorsNode.internalId,
diff,
},
"[CoreNodes] Node mismatch"
);
}
}
});
}

export function getContentNodeMetadata(
node: CoreAPIContentNode,
viewType: "tables" | "documents"
Expand Down
36 changes: 36 additions & 0 deletions front/lib/api/data_source_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import assert from "assert";

import config from "@app/lib/api/config";
import {
compareNodes,
getContentNodeInternalIdFromTableId,
getContentNodeMetadata,
} from "@app/lib/api/content_nodes";
Expand Down Expand Up @@ -343,6 +344,41 @@ export async function getContentNodesForDataSourceView(
}

contentNodesResult = contentNodesRes.value;

const localLogger = logger.child({
dataSourceId: dataSourceView.dataSource.sId,
dataSourceViewId: dataSourceView.sId,
provider: dataSourceView.dataSource.connectorProvider,
});

// shadow read from core
const coreContentNodesRes =
await getContentNodesForManagedDataSourceViewFromCore(
dataSourceView,
params
);

if (contentNodesRes.isErr()) {
localLogger.info(
{ error: contentNodesRes.error },
"[CoreNodes] Could not fetch content nodes from core"
);
} else if (coreContentNodesRes.isOk()) {
if (coreContentNodesRes.value.total !== contentNodesResult.total) {
localLogger.info(
{
coreNodesCount: coreContentNodesRes.value.total,
connectorsNodesCount: contentNodesResult.total,
},
"[CoreNodes] Content nodes count mismatch"
);
}
compareNodes({
connectorsContentNodes: contentNodesResult.nodes,
coreContentNodes: coreContentNodesRes.value.nodes,
localLogger,
});
}
} else {
const contentNodesRes = await getContentNodesForStaticDataSourceView(
dataSourceView,
Expand Down

0 comments on commit 77dc6f3

Please sign in to comment.