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

Update validation for observability notebooks integration #174

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,11 @@ export function ReportSettings(props: ReportSettingProps) {
});

await httpClientProps
.get('../api/notebooks/')
.get('../api/observability/notebooks/')
.catch((error: any) => {
console.error('error fetching notebooks, retrying with legacy api', error)
return httpClientProps.get('../api/notebooks/')
})
.then(async (response: any) => {
let notebooksOptions = getNotebooksOptions(response.data);
reportSourceOptions.notebooks = notebooksOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ const createReportInput: ReportSchemaType = {
report_definition: createReportDefinitionInput,
};

const createReportDefinitionNotebookInput: ReportDefinitionSchemaType = {
// this is the url format used before notebooks merged into observability
const createReportDefinitionNotebookLegacyInput: ReportDefinitionSchemaType = {
report_params: {
report_name: 'test notebooks report',
report_source: REPORT_TYPE.notebook,
Expand All @@ -90,6 +91,31 @@ const createReportDefinitionNotebookInput: ReportDefinitionSchemaType = {
},
}

const createReportDefinitionNotebookInput: ReportDefinitionSchemaType = {
report_params: {
report_name: 'test notebooks report',
report_source: REPORT_TYPE.notebook,
description: 'Hi this is your Notebook on demand',
core_params: {
base_url: `/app/observability#/notebooks/${SAMPLE_SAVED_OBJECT_ID}`,
window_width: 1300,
window_height: 900,
report_format: FORMAT.pdf,
time_duration: 'PT5M',
origin: 'http://localhost:5601',
},
},
delivery: {
configIds: [],
title: 'title',
textDescription: 'text description',
htmlDescription: 'html description'
},
trigger: {
trigger_type: TRIGGER_TYPE.onDemand,
},
}

describe('test input validation', () => {
test('create report with correct saved object id', async () => {
const savedObjectIds = [`dashboard:${SAMPLE_SAVED_OBJECT_ID}`];
Expand Down Expand Up @@ -118,6 +144,16 @@ describe('test input validation', () => {
expect(report).toBeDefined();
});

test('create notebook report definition with legacy base url format', async () => {
const savedObjectIds = [`notebook:${SAMPLE_SAVED_OBJECT_ID}`];
const client = mockOpenSearchClient(savedObjectIds);
const report = await validateReportDefinition(
client,
createReportDefinitionNotebookLegacyInput
);
expect(report).toBeDefined();
});

test('create notebook report definition with correct base url format', async () => {
const savedObjectIds = [`notebook:${SAMPLE_SAVED_OBJECT_ID}`];
const client = mockOpenSearchClient(savedObjectIds);
Expand Down
7 changes: 5 additions & 2 deletions dashboards-reports/server/utils/validationHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ import { REPORT_TYPE } from '../../server/routes/utils/constants';

export const isValidRelativeUrl = (relativeUrl: string) => {
let normalizedRelativeUrl = relativeUrl
if (!relativeUrl.includes('notebooks-dashboards')) {
if (
!relativeUrl.includes('observability#/notebooks') &&
!relativeUrl.includes('notebooks-dashboards')
) {
normalizedRelativeUrl = path.posix.normalize(relativeUrl);
}

Expand All @@ -55,7 +58,7 @@ export const isValidRelativeUrl = (relativeUrl: string) => {
export const regexDuration = /^(-?)P(?=\d|T\d)(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)([DW]))?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$/;
export const regexEmailAddress = /\S+@\S+\.\S+/;
export const regexReportName = /^[\w\-\s\(\)\[\]\,\_\-+]+$/;
export const regexRelativeUrl = /^\/(_plugin\/kibana\/|_dashboards\/)?app\/(dashboards|visualize|discover|notebooks-dashboards\?view=output_only)([?&]security_tenant=.+|)#\/(view\/|edit\/)?[^\/]+$/;
export const regexRelativeUrl = /^\/(_plugin\/kibana\/|_dashboards\/)?app\/(dashboards|visualize|discover|observability|notebooks-dashboards\?view=output_only)([?&]security_tenant=.+|)#\/(notebooks\/|view\/|edit\/)?[^\/]+$/;

export const validateReport = async (
client: ILegacyScopedClusterClient,
Expand Down
6 changes: 6 additions & 0 deletions dashboards-reports/test/httpMockClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ httpClientMock.get = jest.fn(() => ({
})),
catch: jest.fn(),
})),
catch: jest.fn(() => ({
then: jest.fn(() => ({
catch: jest.fn()
})),
catch: jest.fn(),
})),
}));
httpClientMock.head = jest.fn();
httpClientMock.post = jest.fn(() => ({
Expand Down