Skip to content

Commit

Permalink
feat: Batch export logs frontend (#17605)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Ben White <[email protected]>
  • Loading branch information
3 people authored Oct 6, 2023
1 parent 1ec2380 commit dcf8928
Show file tree
Hide file tree
Showing 7 changed files with 578 additions and 143 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import posthog from 'posthog-js'
import {
ActionType,
BatchExportLogEntry,
CohortType,
DashboardCollaboratorType,
DashboardTemplateEditorType,
Expand Down Expand Up @@ -541,6 +542,10 @@ class ApiRequest {
return this.batchExports(teamId).addPathComponent(id)
}

public batchExportLogs(id: BatchExportConfiguration['id'], teamId?: TeamType['id']): ApiRequest {
return this.batchExport(id, teamId).addPathComponent('logs')
}

public batchExportRuns(id: BatchExportConfiguration['id'], teamId?: TeamType['id']): ApiRequest {
return this.batchExports(teamId).addPathComponent(id).addPathComponent('runs')
}
Expand All @@ -553,6 +558,14 @@ class ApiRequest {
return this.batchExportRuns(id, teamId).addPathComponent(runId)
}

public batchExportRunLogs(
id: BatchExportConfiguration['id'],
runId: BatchExportRun['id'],
teamId?: TeamType['id']
): ApiRequest {
return this.batchExportRun(id, runId, teamId).addPathComponent('logs')
}

// Request finalization
public async get(options?: ApiMethodOptions): Promise<any> {
return await api.get(this.assembleFullUrl(), options)
Expand Down Expand Up @@ -1191,6 +1204,65 @@ const api = {
},
},

batchExportLogs: {
async search(
batchExportId: string,
currentTeamId: number | null,
searchTerm: string | null = null,
typeFilters: CheckboxValueType[] = [],
trailingEntry: BatchExportLogEntry | null = null,
leadingEntry: BatchExportLogEntry | null = null
): Promise<BatchExportLogEntry[]> {
const params = toParams(
{
limit: LOGS_PORTION_LIMIT,
type_filter: typeFilters,
search: searchTerm || undefined,
before: trailingEntry?.timestamp,
after: leadingEntry?.timestamp,
},
true
)

const response = await new ApiRequest()
.batchExportLogs(batchExportId, currentTeamId || undefined)
.withQueryString(params)
.get()

return response.results
},
},

batchExportRunLogs: {
async search(
batchExportId: string,
batchExportRunId: string,
currentTeamId: number | null,
searchTerm: string | null = null,
typeFilters: CheckboxValueType[] = [],
trailingEntry: BatchExportLogEntry | null = null,
leadingEntry: BatchExportLogEntry | null = null
): Promise<BatchExportLogEntry[]> {
const params = toParams(
{
limit: LOGS_PORTION_LIMIT,
type_filter: typeFilters,
search: searchTerm || undefined,
before: trailingEntry?.timestamp,
after: leadingEntry?.timestamp,
},
true
)

const response = await new ApiRequest()
.batchExportRunLogs(batchExportId, batchExportRunId, currentTeamId || undefined)
.withQueryString(params)
.get()

return response.results
},
},

annotations: {
async get(annotationId: RawAnnotationType['id']): Promise<RawAnnotationType> {
return await new ApiRequest().annotation(annotationId).get()
Expand Down
Loading

0 comments on commit dcf8928

Please sign in to comment.