Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a button to download flow run logs #2629

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/FlowRunLogs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
<p-list-header>
<template #controls>
<LogLevelSelect v-model:selected="logLevel" />
</template>
<template #sort>
<LogsSort v-model:selected="logsSort" />
<FlowRunLogsDownloadButton :flow-run />
</template>
</p-list-header>

Expand Down Expand Up @@ -45,6 +44,7 @@
import { differenceInSeconds } from 'date-fns'
import { ref, computed } from 'vue'
import { LogLevelSelect, LogsContainer, LogsSort } from '@/components'
import FlowRunLogsDownloadButton from '@/components/FlowRunLogsDownloadButton.vue'
import { useLogsSort, useWorkspaceApi } from '@/compositions'
import { usePaginatedSubscription } from '@/compositions/usePaginatedSubscription'
import { isTerminalStateType } from '@/models'
Expand Down
33 changes: 33 additions & 0 deletions src/components/FlowRunLogsDownloadButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<template>
<p-tooltip text="Download a csv of all logs" avoid-collisions>
<p-button class="flow-run-logs-download-button" icon="Download" :loading @click="download" />
</p-tooltip>
</template>

<script lang="ts" setup>
import { showToast } from '@prefecthq/prefect-design'
import { ref } from 'vue'
import { useWorkspaceApi } from '@/compositions'
import { FlowRun } from '@/models/FlowRun'

const { flowRun } = defineProps<{
flowRun: FlowRun,
}>()

const api = useWorkspaceApi()
const loading = ref(false)

async function download(): Promise<void> {
loading.value = true

try {
await api.flowRuns.downloadFlowRunLogsCsv(flowRun.id, flowRun.name)
} catch (error) {
console.error(error)

showToast('There was an error downloading logs', 'error')
}

loading.value = false
}
</script>
16 changes: 16 additions & 0 deletions src/services/WorkspaceFlowRunsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,20 @@ export class WorkspaceFlowRunsApi extends WorkspaceApi {
return this.delete(`/${flowRunId}`)
}

public async downloadFlowRunLogsCsv(flowRunId: string, flowRunName: string | null): Promise<void> {
const { data } = await this.get<string>(`/${flowRunId}/download-logs-csv`, {
responseType: 'stream',
})

const url = URL.createObjectURL(new Blob([data]))
const link = document.createElement('a')
const filename = flowRunName ?? 'logs'

link.href = url
link.setAttribute('download', `${filename}.csv`)
link.click()

URL.revokeObjectURL(url)
}

}
Loading