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

Fixes #19860: Added Diagnostic tab to display diagnostic information || Added Sync offset button #19980

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,37 @@ test('Alert operations for a user with and without permissions', async ({
await deleteAlert(userWithPermissionsPage, data.alertDetails, false);
});
});

test('Alert Diagnostic Info', async ({ page }) => {
const ALERT_NAME = generateAlertName();

await test.step('Create alert', async () => {
await visitObservabilityAlertPage(page);
data.alertDetails = await createAlert({
page,
alertName: ALERT_NAME,
sourceName: SOURCE_NAME_1,
sourceDisplayName: SOURCE_DISPLAY_NAME_1,
user: user1,
createButtonId: 'create-observability',
selectId: 'Owner Name',
addTrigger: true,
});
});

await test.step('Verify diagnostic info tab', async () => {
await visitObservabilityAlertPage(page);
await visitAlertDetailsPage(page, data.alertDetails);

const diagnosticTab = page.getByRole('tab', { name: /diagnostic info/i });
const diagnosticInfoResponse = page.waitForResponse(
`/api/v1/events/subscriptions/**/diagnosticInfo`
);
await diagnosticTab.click();
await diagnosticInfoResponse;
});

await test.step('Delete alert', async () => {
await deleteAlert(page, data.alertDetails, false);
Copy link
Member

Choose a reason for hiding this comment

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

We don't need to create a separate alert just for the diagnostics info check. Can we add a test for a created alert somewhere above?

});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2024 Collate.
* 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.
*/

export interface AlertDiagnosticData {
latestOffset: number;
currentOffset: number;
startingOffset: number;
hasProcessedAllEvents: boolean;
successfulEventsCount: number;
failedEventsCount: number;
relevantUnprocessedEventsCount: number;
totalUnprocessedEventsCount: number;
}

export interface AlertDiagnosticInfoTabProps {
diagnosticData: AlertDiagnosticData;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2025 Collate.
* 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 { render, screen } from '@testing-library/react';
import React from 'react';
import {
mockDiagnosticData,
mockEmptyDiagnosticData,
} from '../../../../mocks/Alerts.mock';
import AlertDiagnosticInfoTab from './AlertDiagnosticInfoTab';

describe('AlertDiagnosticInfoTab', () => {
it('should render all offset information correctly', () => {
render(<AlertDiagnosticInfoTab diagnosticData={mockDiagnosticData} />);

const inputs = screen.getAllByTestId('input-field');

// Check labels
expect(screen.getByText('label.latest-offset:')).toBeInTheDocument();
expect(screen.getByText('label.current-offset:')).toBeInTheDocument();
expect(screen.getByText('label.starting-offset:')).toBeInTheDocument();
expect(
screen.getByText('label.successful-event-plural:')
).toBeInTheDocument();
expect(screen.getByText('label.failed-event-plural:')).toBeInTheDocument();
expect(
screen.getByText('label.processed-all-event-plural:')
).toBeInTheDocument();

// Check input values
expect(inputs[0]).toHaveValue('100');
expect(inputs[1]).toHaveValue('80');
expect(inputs[2]).toHaveValue('0');
expect(inputs[3]).toHaveValue('75');
expect(inputs[4]).toHaveValue('5');
expect(inputs[5]).toHaveValue('Yes');
});

it('should render processed all events status as "No" when false', () => {
render(<AlertDiagnosticInfoTab diagnosticData={mockEmptyDiagnosticData} />);

const inputs = screen.getAllByTestId('input-field');

expect(inputs[5]).toHaveValue('No');
});

it('should render with empty/zero values correctly', () => {
render(<AlertDiagnosticInfoTab diagnosticData={mockEmptyDiagnosticData} />);

const inputs = screen.getAllByTestId('input-field');

// Check numeric fields have value "0"
expect(inputs[0]).toHaveValue('0'); // latestOffset
expect(inputs[1]).toHaveValue('0'); // currentOffset
expect(inputs[2]).toHaveValue('0'); // startingOffset
expect(inputs[3]).toHaveValue('0'); // successfulEventsCount
expect(inputs[4]).toHaveValue('0'); // failedEventsCount
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright 2024 Collate.
* 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 { InfoCircleOutlined } from '@ant-design/icons';
import { Card, Col, Input, Row, Tooltip } from 'antd';
import React, { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { GRAYED_OUT_COLOR } from '../../../../constants/constants';
import './alert-diagnostic-info-tab.less';
import { AlertDiagnosticInfoTabProps } from './AlertDiagnosticInfoTab.interface';

interface DiagnosticItem {
key: string;
value: string | number | boolean;
description: string;
}

const DiagnosticItemRow = ({ item }: { item: DiagnosticItem }) => {
const { t } = useTranslation();

return (
<Col span={12}>
<Row align="middle">
<Col className="d-flex items-center" span={10}>
<span className="d-flex items-center gap-1">
<p className="text-grey-muted m-0">{t(item.key)}:</p>
<Tooltip placement="bottom" title={item.description}>
<InfoCircleOutlined
className="info-icon"
style={{ color: GRAYED_OUT_COLOR }}
/>
</Tooltip>
</span>
</Col>
<Col span={10}>
<Input
readOnly
className="w-full border-none"
data-testid="input-field"
value={
typeof item.value === 'boolean'
? item.value
? 'Yes'
: 'No'
: item.value
}
/>
</Col>
</Row>
</Col>
);
};

function AlertDiagnosticInfoTab({
diagnosticData,
}: AlertDiagnosticInfoTabProps) {
const diagnosticItems = useMemo(
() => [
{
key: 'label.latest-offset',
value: diagnosticData?.latestOffset,
description: 'The latest offset of the event in the system.',
},
{
key: 'label.current-offset',
value: diagnosticData?.currentOffset,
description: 'The current offset of the event subscription.',
},
{
key: 'label.starting-offset',
value: diagnosticData?.startingOffset,
description:
'The initial offset of the event subscription when it started processing.',
},
{
key: 'label.successful-event-plural',
value: diagnosticData?.successfulEventsCount,
description: 'Count of successful events for specific alert.',
},
{
key: 'label.failed-event-plural',
value: diagnosticData?.failedEventsCount,
description: 'Count of failed events for specific alert.',
},
{
key: 'label.processed-all-event-plural',
value: diagnosticData?.hasProcessedAllEvents,
description: 'Indicates whether all events have been processed.',
},
],
[diagnosticData]
);

return (
<Card>
<Row className="w-full" gutter={[16, 16]}>
{diagnosticItems.map((item) => (
<DiagnosticItemRow item={item} key={item.key} />
))}
</Row>
</Card>
);
}

export default React.memo(AlertDiagnosticInfoTab);
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2025 Collate.
* 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.
*/
.alert-diagnostic-container {
.ant-card {
border-radius: 8px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
transition: all 0.3s ease;

&:hover {
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.ant-input {
&[readonly] {
background-color: transparent;
cursor: default;
}
}
}

.ant-statistic {
.ant-statistic-title {
color: rgba(0, 0, 0, 0.45);
font-size: 14px;
}

.ant-statistic-content {
font-size: 24px;
font-weight: 600;
}
}

.ant-typography {
margin-bottom: 16px;
}

.text-grey-muted {
color: rgba(0, 0, 0, 0.45);
}
}

.label-info-wrapper {
display: inline-flex;
flex-wrap: wrap;
align-items: center;
gap: 2px !important;

.info-icon {
color: #c4c4c4;
font-size: 14px;
display: flex;
align-items: center;
}

.text-grey-muted {
display: inline;
}
Copy link
Member

Choose a reason for hiding this comment

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

The styles do not match the class name we are giving. Use a completely different class with all the stylings if there are many, or just use the pre-defined classes for the specific style. Ex. in this case inline already exists with the display:inline style.

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
export enum AlertDetailTabs {
CONFIGURATION = 'configuration',
RECENT_EVENTS = 'recentEvents',
DIAGNOSTIC_INFO = 'diagnostic info',
}

export enum AlertRecentEventFilters {
Expand Down
Loading
Loading