Skip to content

Commit

Permalink
Revert "feat: Parse JSON structured logs in Argo UI. Fixes argoproj#6856
Browse files Browse the repository at this point in the history
 (argoproj#10145)"

This reverts commit 7da30bd.

Signed-off-by: Dillen Padhiar <[email protected]>
  • Loading branch information
terrytangyuan authored and dpadhiar committed May 9, 2024
1 parent 9c594f3 commit e56ab00
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 132 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import {useContext, useEffect, useState} from 'react';
import {useEffect, useState} from 'react';

import {Autocomplete} from 'argo-ui';
import moment = require('moment-timezone');
Expand All @@ -8,17 +8,13 @@ import {map, publishReplay, refCount} from 'rxjs/operators';
import * as models from '../../../../models';
import {execSpec} from '../../../../models';
import {ANNOTATION_KEY_POD_NAME_VERSION} from '../../../shared/annotations';
import {Button} from '../../../shared/components/button';
import {ErrorNotice} from '../../../shared/components/error-notice';
import {InfoIcon, WarningIcon} from '../../../shared/components/fa-icons';
import {Links} from '../../../shared/components/links';
import {Context} from '../../../shared/context';
import {useLocalStorage} from '../../../shared/hooks/uselocalstorage';
import {getPodName, getTemplateNameFromNode} from '../../../shared/pod-name';
import {ScopedLocalStorage} from '../../../shared/scoped-local-storage';
import {services} from '../../../shared/services';
import {FullHeightLogsViewer} from './full-height-logs-viewer';
import {extractJsonValue, JsonLogsFieldSelector, SelectedJsonFields} from './json-logs-field-selector';

const TZ_LOCALSTORAGE_KEY = 'DEFAULT_TZ';

Expand Down Expand Up @@ -74,12 +70,6 @@ const parseAndTransform = (formattedString: string, timezone: string) => {
};

export const WorkflowLogsViewer = ({workflow, nodeId, initialPodName, container, archived}: WorkflowLogsViewerProps) => {
const storage = new ScopedLocalStorage('workflow-logs-viewer');
const storedJsonFields = storage.getItem('jsonFields', {
values: []
} as SelectedJsonFields);

const {popup} = useContext(Context);
const [podName, setPodName] = useState(initialPodName || '');
const [selectedContainer, setContainer] = useState(container);
const [grep, setGrep] = useState('');
Expand All @@ -97,34 +87,12 @@ export const WorkflowLogsViewer = ({workflow, nodeId, initialPodName, container,
useEffect(() => {
setUITimezone(timezone);
}, [timezone]);
const [selectedJsonFields, setSelectedJsonFields] = useState<SelectedJsonFields>(storedJsonFields);

useEffect(() => {
setError(null);
setLoaded(false);
const source = services.workflows.getContainerLogs(workflow, podName, nodeId, selectedContainer, grep, archived).pipe(
// extract message from LogEntry
map(e => {
const values: string[] = [];
const content = e.content;
if (selectedJsonFields.values.length > 0) {
try {
const json = JSON.parse(content);
selectedJsonFields.values.forEach(selectedJsonField => {
const value = extractJsonValue(json, selectedJsonField);
if (value) {
values.push(value);
}
});
} catch (e) {
// if not json, show content directly
}
}
if (values.length === 0) {
values.push(content);
}
return `${!podName ? e.podName + ': ' : ''}${values.join(' ')}\n`;
}),
map(e => (!podName ? e.podName + ': ' : '') + e.content + '\n'),
// this next line highlights the search term in bold with a yellow background, white text
map(x => {
if (grep !== '') {
Expand All @@ -149,7 +117,7 @@ export const WorkflowLogsViewer = ({workflow, nodeId, initialPodName, container,
);
setLogsObservable(source);
return () => subscription.unsubscribe();
}, [workflow.metadata.namespace, workflow.metadata.name, podName, selectedContainer, grep, archived, selectedJsonFields, timezone]);
}, [workflow.metadata.namespace, workflow.metadata.name, podName, selectedContainer, grep, archived, timezone]);

// filter allows us to introduce a short delay, before we actually change grep
const [logFilter, setLogFilter] = useState('');
Expand Down Expand Up @@ -201,23 +169,6 @@ export const WorkflowLogsViewer = ({workflow, nodeId, initialPodName, container,
];
const [candidateContainer, setCandidateContainer] = useState(container);
const filteredTimezones = timezones.filter(tz => tz.startsWith(uiTimezone) || uiTimezone === '');

const popupJsonFieldSelector = async () => {
const fields = {...selectedJsonFields};
const updated = await popup.confirm('Select Json Fields', () => (
<JsonLogsFieldSelector
fields={selectedJsonFields}
onChange={values => {
fields.values = values;
}}
/>
));
if (updated) {
storage.setItem('jsonFields', fields, {values: []});
setSelectedJsonFields(fields);
}
};

return (
<div className='workflow-logs-viewer'>
<h3>Logs</h3>
Expand Down Expand Up @@ -256,9 +207,6 @@ export const WorkflowLogsViewer = ({workflow, nodeId, initialPodName, container,
/>
)}
/>
<Button onClick={popupJsonFieldSelector} icon={'exchange-alt'}>
Log Fields
</Button>
<span className='fa-pull-right'>
<div className='log-menu'>
<i className='fa fa-filter' />{' '}
Expand Down

0 comments on commit e56ab00

Please sign in to comment.