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

fix: Pipeline node logs kea logic types #22252

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 0 additions & 2 deletions frontend/src/scenes/pipeline/appCodeLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,8 @@
}

// Lazy-load prettier, as it's pretty big and its only use is formatting app source code
// @ts-expect-error
const prettier = (await import('prettier/standalone')).default

Check failure on line 120 in frontend/src/scenes/pipeline/appCodeLogic.tsx

View workflow job for this annotation

GitHub Actions / Code quality checks

Could not find a declaration file for module 'prettier/standalone'. '/home/runner/work/posthog/posthog/node_modules/.pnpm/prettier@2.8.8/node_modules/prettier/standalone.js' implicitly has an 'any' type.
// @ts-expect-error
const parserTypeScript = (await import('prettier/parser-typescript')).default

Check failure on line 121 in frontend/src/scenes/pipeline/appCodeLogic.tsx

View workflow job for this annotation

GitHub Actions / Code quality checks

Could not find a declaration file for module 'prettier/parser-typescript'. '/home/runner/work/posthog/posthog/node_modules/.pnpm/prettier@2.8.8/node_modules/prettier/parser-typescript.js' implicitly has an 'any' type.

return prettier.format(source, {
filepath: filename,
Expand Down
162 changes: 83 additions & 79 deletions frontend/src/scenes/pipeline/pipelineNodeLogsLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,90 +39,94 @@ export const pipelineNodeLogsLogic = kea<pipelineNodeLogsLogicType>([
markLogsEnd: true,
}),
loaders(({ props: { id }, values, actions, cache }) => ({
logs: {
__default: [] as PluginLogEntry[] | BatchExportLogEntry[],
loadLogs: async () => {
let results: LogEntry[]
if (values.nodeBackend === PipelineBackend.BatchExport) {
results = await api.batchExportLogs.search(
id as string,
values.searchTerm,
values.selectedLogLevels
)
} else {
results = await api.pluginLogs.search(
id as number,
values.searchTerm,
logLevelsToTypeFilters(values.selectedLogLevels)
)
}
logs: [
[] as LogEntry[],
{
loadLogs: async () => {
let results: LogEntry[]
if (values.nodeBackend === PipelineBackend.BatchExport) {
results = await api.batchExportLogs.search(
id as string,
values.searchTerm,
values.selectedLogLevels
)
} else {
results = await api.pluginLogs.search(
id as number,
values.searchTerm,
logLevelsToTypeFilters(values.selectedLogLevels)
)
}

if (!cache.pollingInterval) {
cache.pollingInterval = setInterval(actions.pollBackgroundLogs, 5000)
}
actions.clearBackgroundLogs()
return results
},
loadMoreLogs: async () => {
let results: LogEntry[]
if (values.nodeBackend === PipelineBackend.BatchExport) {
results = await api.batchExportLogs.search(
id as string,
values.searchTerm,
values.selectedLogLevels,
values.trailingEntry as BatchExportLogEntry | null
)
} else {
results = await api.pluginLogs.search(
id as number,
values.searchTerm,
logLevelsToTypeFilters(values.selectedLogLevels),
values.trailingEntry as PluginLogEntry | null
)
}
if (!cache.pollingInterval) {
cache.pollingInterval = setInterval(actions.pollBackgroundLogs, 5000)
}
actions.clearBackgroundLogs()
return results
},
loadMoreLogs: async () => {
let results: LogEntry[]
if (values.nodeBackend === PipelineBackend.BatchExport) {
results = await api.batchExportLogs.search(
id as string,
values.searchTerm,
values.selectedLogLevels,
values.trailingEntry as BatchExportLogEntry | null
)
} else {
results = await api.pluginLogs.search(
id as number,
values.searchTerm,
logLevelsToTypeFilters(values.selectedLogLevels),
values.trailingEntry as PluginLogEntry | null
)
}

if (results.length < LOGS_PORTION_LIMIT) {
actions.markLogsEnd()
}
return [...values.logs, ...results]
if (results.length < LOGS_PORTION_LIMIT) {
actions.markLogsEnd()
}
return [...values.logs, ...results]
},
revealBackground: () => {
const newArray = [...values.backgroundLogs, ...values.logs]
actions.clearBackgroundLogs()
return newArray
},
},
revealBackground: () => {
const newArray = [...values.backgroundLogs, ...values.logs]
actions.clearBackgroundLogs()
return newArray
},
},
backgroundLogs: {
__default: [] as PluginLogEntry[] | BatchExportLogEntry[],
pollBackgroundLogs: async () => {
// we fetch new logs in the background and allow the user to expand
// them into the array of visible logs
if (values.logsLoading) {
return values.backgroundLogs
}
],
backgroundLogs: [
[] as LogEntry[],
{
pollBackgroundLogs: async () => {
// we fetch new logs in the background and allow the user to expand
// them into the array of visible logs
if (values.logsLoading) {
return values.backgroundLogs
}

let results: LogEntry[]
if (values.nodeBackend === PipelineBackend.BatchExport) {
results = await api.batchExportLogs.search(
id as string,
values.searchTerm,
values.selectedLogLevels,
null,
values.leadingEntry as BatchExportLogEntry | null
)
} else {
results = await api.pluginLogs.search(
id as number,
values.searchTerm,
logLevelsToTypeFilters(values.selectedLogLevels),
null,
values.leadingEntry as PluginLogEntry | null
)
}
let results: LogEntry[]
if (values.nodeBackend === PipelineBackend.BatchExport) {
results = await api.batchExportLogs.search(
id as string,
values.searchTerm,
values.selectedLogLevels,
null,
values.leadingEntry as BatchExportLogEntry | null
)
} else {
results = await api.pluginLogs.search(
id as number,
values.searchTerm,
logLevelsToTypeFilters(values.selectedLogLevels),
null,
values.leadingEntry as PluginLogEntry | null
)
}

return [...results, ...values.backgroundLogs]
return [...results, ...values.backgroundLogs]
},
},
},
],
})),
reducers({
selectedLogLevels: [
Expand All @@ -132,7 +136,7 @@ export const pipelineNodeLogsLogic = kea<pipelineNodeLogsLogicType>([
},
],
backgroundLogs: [
[] as PluginLogEntry[] | BatchExportLogEntry[],
[] as LogEntry[],
{
clearBackgroundLogs: () => [],
},
Expand Down
Loading