Skip to content

Commit

Permalink
trim ansi codes from log, optimize historical log queries
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsgstrabo committed Mar 12, 2024
1 parent 533c637 commit de35d6d
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 11 deletions.
98 changes: 92 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"react-select": "^5.8.0",
"react-toastify": "^9.1.3",
"sanitize.css": "^13.0.0",
"strip-ansi": "^7.1.0",
"styled-components": "^6.1.8",
"vite": "^5.0.12"
},
Expand Down
3 changes: 2 additions & 1 deletion src/components/code/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { clsx } from 'clsx';
import { FunctionComponent, UIEvent, useEffect, useRef, useState } from 'react';

import { copyToClipboard, copyToTextFile } from '../../utils/string';
import stripAnsi from 'strip-ansi';

import './style.css';

Expand Down Expand Up @@ -74,7 +75,7 @@ export const Code: FunctionComponent<CodeProps & { children?: string }> = ({
ref={containerRef}
onScroll={handleScroll}
>
{children}
{stripAnsi(children)}
</Card>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
} from '../../utils/sort-utils';
import { smallGithubCommitHash, smallReplicaName } from '../../utils/string';
import { TableSortIcon, getNewSortDir } from '../../utils/table-sort-utils';
import { addMinutes } from 'date-fns';

interface ComponentNameProps {
appName: string;
Expand Down Expand Up @@ -207,7 +208,14 @@ function ReplicaLogTableRow({
onClick={downloadLazyLogCb(
`${appName}_${envName}_${componentName}_${name}.txt`,
getLog as LazyQueryTriggerPlain<Parameters<typeof getLog>[0]>,
{ appName, envName, componentName, replicaName: name }
{
appName,
envName,
componentName,
replicaName: name,
start: created.toISOString(),
end: addMinutes(ended, 10).toISOString(),
}
)}
disabled={isFetching}
/>
Expand Down Expand Up @@ -262,7 +270,15 @@ function ReplicaContainerTableRow({
onClick={downloadLazyLogCb(
`${appName}_${envName}_${componentName}_${replicaName}_${id}.txt`,
getLog as LazyQueryTriggerPlain<Parameters<typeof getLog>[0]>,
{ appName, envName, componentName, replicaName, containerId: id }
{
appName,
envName,
componentName,
replicaName,
containerId: id,
start: created.toISOString(),
end: addMinutes(ended, 10).toISOString(),
}
)}
disabled={isFetching}
/>
Expand Down
12 changes: 11 additions & 1 deletion src/components/page-scheduled-job/replica-log-accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,15 @@ const ReplicaLogTableRow: FunctionComponent<
name
)}.txt`,
getLog as LazyQueryTriggerPlain<Parameters<typeof getLog>[0]>,
{ appName, envName, jobComponentName, jobName, replicaName: name }
{
appName,
envName,
jobComponentName,
jobName,
replicaName: name,
start: created.toISOString(),
end: addMinutes(ended, 10).toISOString(),
}
)}
disabled={isFetching}
/>
Expand Down Expand Up @@ -296,6 +304,8 @@ function ReplicaContainerTableRow({
jobName,
replicaName,
containerId: id,
start: created.toISOString(),
end: addMinutes(ended, 10).toISOString(),
}
)}
disabled={isFetching}
Expand Down
5 changes: 4 additions & 1 deletion src/store/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export function getFetchErrorData(error: FetchQueryError): {
const err = error as FetchBaseQueryError;
if (err.data?.['code'] || err.data?.['message'] || err.data?.['error']) {
// data is an object containing status
errObj.code = err.data['code'];
errObj.code = err.status;
if (err.data['code']) {
errObj.code = err.data['code'];
}
if (typeof err.data['message'] === 'string') {
errObj.message = err.data['message'];
}
Expand Down

0 comments on commit de35d6d

Please sign in to comment.