Skip to content

Commit c024745

Browse files
nicoschmdtpatrickelectric
authored andcommitted
frontend: kraken: use zenoh to show extension logs
1 parent 4a4098a commit c024745

3 files changed

Lines changed: 379 additions & 135 deletions

File tree

core/frontend/src/components/kraken/KrakenManager.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import zenoh from '@/libs/zenoh'
12
import {
23
ExtensionData,
34
ExtensionUploadResponse,
@@ -8,6 +9,7 @@ import {
89
UploadProgressEvent,
910
} from '@/types/kraken'
1011
import back_axios from '@/utils/api'
12+
import { QueryTarget, Sample, Subscriber } from '@eclipse-zenoh/zenoh-ts'
1113

1214
const KRAKEN_BASE_URL = '/kraken'
1315
const KRAKEN_API_V2_URL = `${KRAKEN_BASE_URL}/v2.0`
@@ -318,25 +320,6 @@ export async function getContainersStats(): Promise<any> {
318320
return response.data
319321
}
320322

321-
/**
322-
* Fetch logs of a given container.
323-
* @param {string} containerName The name of the container
324-
* @param {function} progressHandler The progress handler for the download
325-
* @param {AbortSignal} cancelToken The cancel token for the request
326-
*/
327-
export async function getContainerLogs(
328-
containerName: string,
329-
progressHandler: (event: any) => void,
330-
cancelToken: AbortSignal | undefined,
331-
): Promise<any> {
332-
await back_axios({
333-
method: 'GET',
334-
url: `${KRAKEN_API_V2_URL}/container/${containerName}/log`,
335-
onDownloadProgress: progressHandler,
336-
signal: cancelToken,
337-
})
338-
}
339-
340323
/**
341324
* Upload a tar file containing a Docker image and extract metadata
342325
* @param {File} file The tar file to upload
@@ -405,6 +388,30 @@ export async function finalizeExtension(
405388
})
406389
}
407390

391+
/**
392+
* Request historical logs for an extension
393+
* @param {string} identifier The identifier of the extension
394+
* @param {number} timeout The timeout for the query
395+
* @returns {Promise<any | null>}
396+
*/
397+
export async function getHistoricalLogsForExtension(identifier: string, timeout: number): Promise<any | null> {
398+
const queryKey = `kraken/extension/logs/request?extension_name=${identifier}`
399+
return await zenoh.query(queryKey, QueryTarget.BestMatching, timeout)
400+
}
401+
402+
/**
403+
* Create a new subscriber for a given topic
404+
* @param {string} topic The topic to subscribe to
405+
* @param {function} subscriberHandler The handler for the topic
406+
* @returns {Promise<Subscriber | null>}
407+
*/
408+
export async function createExtensionLogsSubscriber(
409+
topic: string,
410+
subscriberHandler: (sample: Sample) => Promise<void>,
411+
) : Promise<Subscriber | null> {
412+
return await zenoh.subscriber(topic, subscriberHandler)
413+
}
414+
408415
export default {
409416
fetchManifestSources,
410417
fetchManifestSource,
@@ -426,8 +433,9 @@ export default {
426433
restartExtension,
427434
listContainers,
428435
getContainersStats,
429-
getContainerLogs,
430436
uploadExtensionTarFile,
431437
keepTemporaryExtensionAlive,
432438
finalizeExtension,
439+
getHistoricalLogsForExtension,
440+
createExtensionLogsSubscriber,
433441
}

0 commit comments

Comments
 (0)