Skip to content

Commit 80ef724

Browse files
authored
enh: poke's data source view (#2601)
* enh: poke's data source view * nit
1 parent 07ccde5 commit 80ef724

File tree

5 files changed

+107
-8
lines changed

5 files changed

+107
-8
lines changed

core/bin/dust_api.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,48 @@ async fn data_sources_register(
10281028
"data_source": {
10291029
"created": ds.created(),
10301030
"data_source_id": ds.data_source_id(),
1031+
"qdrant_collection": ds.qdrant_collection(),
1032+
"config": ds.config(),
1033+
},
1034+
})),
1035+
}),
1036+
),
1037+
},
1038+
}
1039+
}
1040+
1041+
async fn data_sources_retrieve(
1042+
extract::Path((project_id, data_source_id)): extract::Path<(i64, String)>,
1043+
extract::Extension(state): extract::Extension<Arc<APIState>>,
1044+
) -> (StatusCode, Json<APIResponse>) {
1045+
let project = project::Project::new_from_id(project_id);
1046+
match state
1047+
.store
1048+
.load_data_source(&project, &data_source_id)
1049+
.await
1050+
{
1051+
Err(e) => error_response(
1052+
StatusCode::INTERNAL_SERVER_ERROR,
1053+
"internal_server_error",
1054+
"Failed to retrieve data source",
1055+
Some(e),
1056+
),
1057+
Ok(ds) => match ds {
1058+
None => error_response(
1059+
StatusCode::NOT_FOUND,
1060+
"data_source_not_found",
1061+
&format!("No data source found for id `{}`", data_source_id),
1062+
None,
1063+
),
1064+
Some(ds) => (
1065+
StatusCode::OK,
1066+
Json(APIResponse {
1067+
error: None,
1068+
response: Some(json!({
1069+
"data_source": {
1070+
"created": ds.created(),
1071+
"data_source_id": ds.data_source_id(),
1072+
"qdrant_collection": ds.qdrant_collection(),
10311073
"config": ds.config(),
10321074
},
10331075
})),
@@ -2233,6 +2275,10 @@ fn main() {
22332275
"/projects/:project_id/data_sources",
22342276
post(data_sources_register),
22352277
)
2278+
.route(
2279+
"/projects/:project_id/data_sources/:data_source_id",
2280+
get(data_sources_retrieve),
2281+
)
22362282
.route(
22372283
"/projects/:project_id/data_sources/:data_source_id/documents/:document_id/versions",
22382284
get(data_sources_documents_versions_list),

front/lib/core_api.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export type CoreAPIDataSourceConfig = {
5353
export type CoreAPIDataSource = {
5454
created: number;
5555
data_source_id: string;
56+
qdrant_collection: string;
5657
config: CoreAPIDataSourceConfig;
5758
};
5859

@@ -482,6 +483,25 @@ export const CoreAPI = {
482483
return _resultFromResponse(response);
483484
},
484485

486+
async getDataSource({
487+
projectId,
488+
dataSourceId,
489+
}: {
490+
projectId: string;
491+
dataSourceId: string;
492+
}): Promise<CoreAPIResponse<{ data_source: CoreAPIDataSource }>> {
493+
const response = await fetch(
494+
`${CORE_API}/projects/${projectId}/data_sources/${dataSourceId}`,
495+
{
496+
headers: {
497+
"Content-Type": "application/json",
498+
},
499+
}
500+
);
501+
502+
return _resultFromResponse(response);
503+
},
504+
485505
async deleteDataSource({
486506
projectId,
487507
dataSourceName,

front/lib/swr.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,16 @@ export function useDocuments(
159159
owner: WorkspaceType,
160160
dataSource: { name: string },
161161
limit: number,
162-
offset: number
162+
offset: number,
163+
asDustSuperUser?: boolean
163164
) {
164165
const documentsFetcher: Fetcher<GetDocumentsResponseBody> = fetcher;
165166
const { data, error } = useSWR(
166-
`/api/w/${owner.sId}/data_sources/${dataSource.name}/documents?limit=${limit}&offset=${offset}`,
167+
`/api/w/${owner.sId}/data_sources/${
168+
dataSource.name
169+
}/documents?limit=${limit}&offset=${offset}${
170+
asDustSuperUser ? "&asDustSuperUser=true" : ""
171+
}`,
167172
documentsFetcher
168173
);
169174

front/pages/api/w/[wId]/data_sources/[name]/documents/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ async function handler(
1616
res: NextApiResponse<GetDocumentsResponseBody>
1717
): Promise<void> {
1818
const session = await getSession(req, res);
19-
const auth = await Authenticator.fromSession(
20-
session,
21-
req.query.wId as string
22-
);
19+
const auth =
20+
req.query.asDustSuperUser === "true"
21+
? await Authenticator.fromSession(session, req.query.wId as string)
22+
: await Authenticator.fromSuperUserSession(
23+
session,
24+
req.query.wId as string
25+
);
2326

2427
const owner = auth.workspace();
2528
if (!owner) {

front/pages/poke/[wId]/data_sources/[name]/index.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import PokeNavbar from "@app/components/poke/PokeNavbar";
1414
import { getDataSource } from "@app/lib/api/data_sources";
1515
import { Authenticator, getSession } from "@app/lib/auth";
1616
import { ConnectorsAPI, ConnectorType } from "@app/lib/connectors_api";
17+
import { CoreAPI, CoreAPIDataSource } from "@app/lib/core_api";
1718
import { getDisplayNameForDocument } from "@app/lib/data_sources";
1819
import { useDocuments } from "@app/lib/swr";
1920
import { timeAgoFrom } from "@app/lib/utils";
@@ -23,6 +24,7 @@ import { WorkspaceType } from "@app/types/user";
2324
export const getServerSideProps: GetServerSideProps<{
2425
owner: WorkspaceType;
2526
dataSource: DataSourceType;
27+
coreDataSource: CoreAPIDataSource;
2628
connector: ConnectorType | null;
2729
}> = async (context) => {
2830
const wId = context.params?.wId;
@@ -66,6 +68,17 @@ export const getServerSideProps: GetServerSideProps<{
6668
};
6769
}
6870

71+
const coreDataSourceRes = await CoreAPI.getDataSource({
72+
projectId: dataSource.dustAPIProjectId,
73+
dataSourceId: dataSource.name,
74+
});
75+
76+
if (coreDataSourceRes.isErr()) {
77+
return {
78+
notFound: true,
79+
};
80+
}
81+
6982
let connector: ConnectorType | null = null;
7083
if (dataSource.connectorId) {
7184
const connectorRes = await ConnectorsAPI.getConnector(
@@ -80,6 +93,7 @@ export const getServerSideProps: GetServerSideProps<{
8093
props: {
8194
owner,
8295
dataSource,
96+
coreDataSource: coreDataSourceRes.value.data_source,
8397
connector,
8498
},
8599
};
@@ -88,13 +102,14 @@ export const getServerSideProps: GetServerSideProps<{
88102
const DataSourcePage = ({
89103
owner,
90104
dataSource,
105+
coreDataSource,
91106
connector,
92107
}: InferGetServerSidePropsType<typeof getServerSideProps>) => {
93108
const [limit] = useState(10);
94109
const [offset, setOffset] = useState(0);
95110

96111
const { documents, total, isDocumentsLoading, isDocumentsError } =
97-
useDocuments(owner, dataSource, limit, offset);
112+
useDocuments(owner, dataSource, limit, offset, true);
98113

99114
const [displayNameByDocId, setDisplayNameByDocId] = useState<
100115
Record<string, string>
@@ -134,9 +149,19 @@ const DataSourcePage = ({
134149

135150
<div className="my-8 flex flex-col gap-y-4">
136151
<JsonViewer value={dataSource} rootName={false} />
152+
<JsonViewer value={coreDataSource} rootName={false} />
137153
<JsonViewer value={connector} rootName={false} />
138154
</div>
139155

156+
<div className="flex flex-row">
157+
<a
158+
href={`https://app.datadoghq.eu/logs?query=service%3Acore%20%22DSSTAT%20Finished%20searching%20Qdrant%20documents%22%20%22${coreDataSource.qdrant_collection}%22%20&cols=host%2Cservice&index=%2A&messageDisplay=inline&refresh_mode=sliding&stream_sort=desc&view=spans&viz=stream&live=true`}
159+
className="text-sm text-blue-500"
160+
>
161+
Datadog: Logs DSSTAT Qdrant search
162+
</a>
163+
</div>
164+
140165
<div className="mt-4 flex flex-row">
141166
<div className="flex flex-1">
142167
<div className="flex flex-col">
@@ -201,7 +226,7 @@ const DataSourcePage = ({
201226
icon={EyeIcon}
202227
onClick={() => {
203228
window.confirm(
204-
"Are you sure you want to access this sensible user data?"
229+
"Are you sure you want to access this sensible user data? (Access will be logged)"
205230
);
206231
void router.push(
207232
`/poke/${owner.sId}/data_sources/${

0 commit comments

Comments
 (0)