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

Error classification UI #1257

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions app/cdap/api/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export const MyPipelineApi = {
getStatistics: apiCreator(dataSrc, 'GET', 'REQUEST', statsPath),
getMetadataEndpoints: apiCreator(dataSrc, 'GET', 'REQUEST', metadataPath),
getRunDetails: apiCreator(dataSrc, 'GET', 'REQUEST', `${programPath}/runs/:runid`),
getRunErrorDetails: apiCreator(dataSrc, 'POST', 'REQUEST', `${programPath}/runs/:runid/classify`),

getRuns: apiCreator(dataSrc, 'GET', 'REQUEST', `${programPath}/runs`),
getVersionedRuns: apiCreator(dataSrc, 'GET', 'REQUEST', `${versionedProgramPath}/runs`),
pollRuns: apiCreator(dataSrc, 'GET', 'POLL', `${programPath}/runs`),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
/*
* Copyright © 2024 Cask Data, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

import React, { useEffect, useState } from 'react';
import T from 'i18n-react';
import { useSelector, Provider, useDispatch } from 'react-redux';
import { Button, Table, TableBody, TableCell, TableHead, TableRow } from '@material-ui/core';
import LaunchIcon from '@material-ui/icons/Launch';
import styled from 'styled-components';
import PipelineMetricsStore from 'services/PipelineMetricsStore';
import PipelineLogViewer from '../RunLevelInfo/PipelineLogViewer';
import ThemeWrapper from 'components/ThemeWrapper';
import { ACTIONS } from '../store';
import { MyPipelineApi } from 'api/pipeline';
import { getCurrentNamespace } from 'services/NamespaceStore';
import { getDataTestid } from '@cdap-ui/testids/TestidsProvider';

const PREFIX = 'features.PipelineDetails.ErrorDetails';
const TEST_PREFIX = 'features.pipelineDetails.errorDetails';

const PipelineRunErrorDetailsWrapper = styled.div`
width: 100%;
background: red;
position: relative;
color: white;
`;

const ShortErrorMessage = styled.div`
width: 100%;
display: flex;
padding: 0 20px;
gap: 40px;
align-items: center;
justify-content: space-between;

p {
margin: 0;
}
`;

const ErrorDetailsContainer = styled.div`
position: absolute;
top: 100%;
left: 0;
right: 0;
background: #ffefef;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be any theming/standard color palette?

box-shadow: 0 4px 4px rgba(0, 0, 0, 0.2);
z-index: 1000;
padding: 20px;
color: black;

p {
margin: 0;
}

.LogViewerContainer-logsContainer-60 {
top: 140px;
}

a[target='_blank'] > svg {
font-size: 10px;
}
`;

const ErrorImprovementMessage = styled.div`
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
margin-top: 20px;
`;

const PipelineErrorCountMessage = ({ classifiedErrorCount }) => {
const logsMetrics = useSelector((state) => state?.logsMetrics || {});
const metricsErrorCount = logsMetrics['system.app.log.error'] || 0;

return (
<p data-testid={getDataTestid(`${TEST_PREFIX}.crrorCountMessage`)}>
{T.translate(`${PREFIX}.errorCountMessage`, {
context: classifiedErrorCount || metricsErrorCount,
})}
</p>
);
};

interface IErrorEntry {
errorCategory: string;
errorMessage: string;
errorReason: string;
stageName: string;
supportedDocumentationUrl?: string;
}

export default function PipelineRunErrorDetails() {
const [detailsExpanded, setDetailsExpanded] = useState<boolean>(false);
const [logsOpened, setLogsOpened] = useState<boolean>(false);
const [loading, setLoading] = useState<boolean>(false);

const appId = useSelector((state) => state.name);
const currentRun = useSelector((state) => state.currentRun);
const errorDetails = useSelector((state) => state.runErrorDetails[currentRun?.runid]);
const dispatch = useDispatch();

// TODO: add feature flag here
const improvementSurveyEnabled = false;

function setErrorDetails(runid: string, errors: IErrorEntry[]) {
dispatch({
type: ACTIONS.SET_RUN_ERROR_DETAILS,
payload: {
runid,
errors,
},
});
}

function toggleErrorDetails() {
setDetailsExpanded((x) => !x);
}

useEffect(() => {
document.body.classList.add('with-error-banner');

return () => {
document.body.classList.remove('with-error-banner');
};
}, []);

async function fetchErrorDetails() {
setLoading(true);
// POST `/namespaces/:namespace/apps/:appid/:programType/:programName/runs/:runid/classify?isPreview`
MyPipelineApi.getRunErrorDetails({
namespace: getCurrentNamespace(),
appId,
programType: 'workflows',
programName: 'DataPipelineWorkflow',
runid: currentRun?.runid,
}).subscribe(
(res: IErrorEntry[]) => {
setErrorDetails(currentRun?.runid, res);
setLoading(false);
},
(err) => {
setErrorDetails(currentRun?.runid, []);
setLoading(false);
}
);
}

function viewLogs() {
setDetailsExpanded(false);
setLogsOpened(true);
}

function toggleLogs() {
setLogsOpened((x) => !x);
}

useEffect(() => {
if (!errorDetails && !loading && currentRun?.status === 'FAILED') {
fetchErrorDetails();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this result in multiple or dangling subscriptions if multiple errors occur while the component is present?

}
}, [currentRun?.runid, currentRun?.status, errorDetails, loading]);

if (currentRun?.status !== 'FAILED' || loading) {
return null;
}

function renderWithLink(strToRender, link) {
if (strToRender.indexOf(link) < 0) {
return strToRender;
}

const chunks = strToRender.split(link);
const nodes = [chunks[0]];
for (let i = 1; i < chunks.length; i++) {
nodes.push(
<a href={link} target="_blank">
{link} <LaunchIcon fontSize="small" />
</a>
);
nodes.push(chunks[i]);
}

return nodes;
}

return (
<>
<PipelineRunErrorDetailsWrapper>
<Provider store={PipelineMetricsStore}>
<ShortErrorMessage>
<PipelineErrorCountMessage classifiedErrorCount={errorDetails?.length} />
<Button
color="inherit"
onClick={toggleErrorDetails}
data-testid={getDataTestid(
detailsExpanded ? `${TEST_PREFIX}.closeButton` : `${TEST_PREFIX}.viewDetailsButton`
)}
>
{detailsExpanded
? T.translate(`${PREFIX}.closeButton`)
: T.translate(`${PREFIX}.viewDetailsButton`)}
</Button>
</ShortErrorMessage>
{detailsExpanded && (
<ErrorDetailsContainer>
<Table>
<TableHead>
<TableRow>
<TableCell>{T.translate(`${PREFIX}.errorCategoryHeader`)}</TableCell>
<TableCell>{T.translate(`${PREFIX}.errorMessageHeader`)}</TableCell>
<TableCell>{T.translate(`${PREFIX}.errorReasonHeader`)}</TableCell>
</TableRow>
</TableHead>
<TableBody>
{errorDetails?.map((err) => (
<TableRow>
<TableCell>{err.errorCategory}</TableCell>
<TableCell>
{renderWithLink(err.errorMessage, err.supportedDocumentationUrl)}
</TableCell>
<TableCell>
{renderWithLink(err.errorReason, err.supportedDocumentationUrl)}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
<ErrorImprovementMessage>
{improvementSurveyEnabled ? (
<p>
Help us improve the error classification. Raise improvement <a href="#">here</a>
.
</p>
) : (
<p />
)}
<Button
color="secondary"
onClick={viewLogs}
data-testid={getDataTestid(`${TEST_PREFIX}.viewLogsButton`)}
>
{T.translate(`${PREFIX}.viewLogsButton`)}
</Button>
</ErrorImprovementMessage>
</ErrorDetailsContainer>
)}
</Provider>
</PipelineRunErrorDetailsWrapper>
{logsOpened && (
<ThemeWrapper>
<PipelineLogViewer toggleLogViewer={toggleLogs} withErrorBanner={true} />
</ThemeWrapper>
)}
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import React, { useEffect } from 'react';
import styled from 'styled-components';
import { Provider, connect } from 'react-redux';
import PipelineDetailsMetadata from 'components/PipelineDetails/PipelineDetailsTopPanel/PipelineDetailsMetadata';
import PipelineDetailsButtons from 'components/PipelineDetails/PipelineDetailsTopPanel/PipelineDetailsButtons';
Expand All @@ -27,6 +28,7 @@ import PlusButton from 'components/shared/PlusButton';
import { fetchAndUpdateRuntimeArgs } from 'components/PipelineConfigurations/Store/ActionCreator';
import { FeatureProvider } from 'services/react/providers/featureFlagProvider';
import { setEditDraftId } from '../store/ActionCreator';
import PipelineRunErrorDetails from './PipelineRunErrorDetails';

require('./PipelineDetailsTopPanel.scss');

Expand All @@ -51,6 +53,12 @@ const mapStateToButtonsProps = (state) => {

const ConnectedPipelineDetailsButtons = connect(mapStateToButtonsProps)(PipelineDetailsButtons);

const PipelineDetailsWrapper = styled.div`
width: 100%;
height: 100%;
position: relative;
`;

export const PipelineDetailsTopPanel = () => {
useEffect(() => {
const pipelineDetailStore = PipelineDetailStore.getState();
Expand All @@ -73,15 +81,19 @@ export const PipelineDetailsTopPanel = () => {
window.localStorage.removeItem('editDraftId');
}
}, []);

return (
<FeatureProvider>
<Provider store={PipelineDetailStore}>
<div className="pipeline-details-top-panel">
<PipelineDetailsMetadata />
<ConnectedPipelineDetailsButtons />
<PipelineDetailsDetailsActions />
<PlusButton mode={PlusButton.MODE.resourcecenter} />
</div>
<PipelineDetailsWrapper>
<PipelineRunErrorDetails />
<div className="pipeline-details-top-panel">
<PipelineDetailsMetadata />
<ConnectedPipelineDetailsButtons />
<PipelineDetailsDetailsActions />
<PlusButton mode={PlusButton.MODE.resourcecenter} />
</div>
</PipelineDetailsWrapper>
</Provider>
</FeatureProvider>
);
Expand Down
Loading