Skip to content
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
5 changes: 3 additions & 2 deletions common/constants/notebooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
*/

export const NOTEBOOKS_API_PREFIX = '/api/observability/notebooks';
export const NOTEBOOKS_SELECTED_BACKEND = 'DEFAULT'; // ZEPPELIN || DEFAULT
export const NOTEBOOKS_SELECTED_BACKEND: 'ZEPPELIN' | 'DEFAULT' = 'DEFAULT';
Comment thread
derek-ho marked this conversation as resolved.
export const NOTEBOOKS_FETCH_SIZE = 1000;
export const CREATE_NOTE_MESSAGE = 'Enter a name to describe the purpose of this notebook.';
export const NOTEBOOKS_DOCUMENTATION_URL = 'https://opensearch.org/docs/latest/observability-plugin/notebooks/';
export const NOTEBOOKS_DOCUMENTATION_URL =
'https://opensearch.org/docs/latest/observability-plugin/notebooks/';

export const zeppelinURL = 'http://localhost:8080';

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"husky": "6.0.0",
"jest-dom": "^4.0.0",
"lint-staged": "^13.1.0",
"mock-fs": "^4.12.0",
"ts-jest": "^29.1.0"
},
"resolutions": {
Expand All @@ -81,4 +80,4 @@
"node_modules/*",
"target/*"
]
}
}
19 changes: 9 additions & 10 deletions server/adaptors/custom_panels/custom_panel_adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { PanelType, VisualizationType } from '../../../common/types/custom_panel
import { ILegacyScopedClusterClient } from '../../../../../src/core/server';
import { createDemoPanel } from '../../../common/constants/custom_panels';

interface boxType {
interface BoxType {
x1: number;
y1: number;
x2: number;
Expand Down Expand Up @@ -142,7 +142,6 @@ export class CustomPanelsAdaptor {
}
};


// Rename an existing panel
renamePanel = async (client: ILegacyScopedClusterClient, panelId: string, panelName: string) => {
const updatePanelBody = {
Expand Down Expand Up @@ -275,14 +274,14 @@ export class CustomPanelsAdaptor {
}
};

calculatOverlapArea = (bb1: boxType, bb2: boxType) => {
const x_left = Math.max(bb1.x1, bb2.x1);
const y_top = Math.max(bb1.y1, bb2.y1);
const x_right = Math.min(bb1.x2, bb2.x2);
const y_bottom = Math.min(bb1.y2, bb2.y2);
calculatOverlapArea = (bb1: BoxType, bb2: BoxType) => {
const xLeft = Math.max(bb1.x1, bb2.x1);
const yTop = Math.max(bb1.y1, bb2.y1);
const xRight = Math.min(bb1.x2, bb2.x2);
const yBottom = Math.min(bb1.y2, bb2.y2);

if (x_right < x_left || y_bottom < y_top) return 0;
return (x_right - x_left) * (y_bottom - y_top);
if (xRight < xLeft || yBottom < yTop) return 0;
return (xRight - xLeft) * (yBottom - yTop);
};

getTotalOverlapArea = (panelVisualizations: VisualizationType[]) => {
Expand Down Expand Up @@ -380,7 +379,7 @@ export class CustomPanelsAdaptor {
savedVisualizationIds: string[]
) => {
try {
let allPanelVisualizations = await this.getVisualizations(client, panelId);
const allPanelVisualizations = await this.getVisualizations(client, panelId);

let newDimensions;
let visualizationsList = [...allPanelVisualizations];
Expand Down
16 changes: 8 additions & 8 deletions server/adaptors/notebooks/default_backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class DefaultBackend implements NotebookAdaptor {
objectId: noteId,
});
if (response.observabilityObjectList.length === 0) {
throw 'notebook id not found';
throw new Error('notebook id not found');
}
return response.observabilityObjectList[0];
} catch (error) {
Expand Down Expand Up @@ -262,7 +262,7 @@ export class DefaultBackend implements NotebookAdaptor {
_wreckOptions: optionsType
) {
try {
let newNoteObject = { ...noteObj };
const newNoteObject = { ...noteObj };
newNoteObject.id = 'note_' + uuid();
newNoteObject.dateCreated = new Date().toISOString();
newNoteObject.dateModified = new Date().toISOString();
Expand All @@ -283,7 +283,7 @@ export class DefaultBackend implements NotebookAdaptor {
* paragraphInput -> Input to be added
*/
updateParagraph = function (
paragraphs: Array<DefaultParagraph>,
paragraphs: DefaultParagraph[],
paragraphId: string,
paragraphInput: string,
paragraphType?: string
Expand Down Expand Up @@ -324,7 +324,7 @@ export class DefaultBackend implements NotebookAdaptor {
inputType: paragraphType,
inputText: paragraphInput,
};
const outputObjects: Array<DefaultOutput> = [
const outputObjects: DefaultOutput[] = [
{
outputType: paragraphType,
result: '',
Expand All @@ -350,7 +350,7 @@ export class DefaultBackend implements NotebookAdaptor {
* UI renders Markdown
*/
runParagraph = async function (
paragraphs: Array<DefaultParagraph>,
paragraphs: DefaultParagraph[],
paragraphId: string,
client: ILegacyScopedClusterClient
) {
Expand Down Expand Up @@ -526,7 +526,7 @@ export class DefaultBackend implements NotebookAdaptor {
const newParagraph = this.createParagraph(params.paragraphInput, params.inputType);
paragraphs.splice(params.paragraphIndex, 0, newParagraph);
const updateNotebook = {
paragraphs: paragraphs,
paragraphs,
dateModified: new Date().toISOString(),
};
const opensearchClientResponse = await this.updateNote(client, params.noteId, updateNotebook);
Expand Down Expand Up @@ -586,10 +586,10 @@ export class DefaultBackend implements NotebookAdaptor {
) {
try {
const opensearchClientGetResponse = await this.getNote(client, params.noteId);
let updatedparagraphs: DefaultParagraph[] = [];
const updatedparagraphs: DefaultParagraph[] = [];
opensearchClientGetResponse.notebook.paragraphs.map(
(paragraph: DefaultParagraph, index: number) => {
let updatedParagraph = { ...paragraph };
const updatedParagraph = { ...paragraph };
updatedParagraph.output = [];
updatedparagraphs.push(updatedParagraph);
}
Expand Down
6 changes: 2 additions & 4 deletions server/adaptors/notebooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import { DefaultBackend } from './default_backend';
import { NOTEBOOKS_SELECTED_BACKEND } from '../../../common/constants/notebooks';

// Selects backend based on config
let BACKEND = new DefaultBackend();
export let BACKEND: DefaultBackend | ZeppelinBackend = new DefaultBackend();

if (NOTEBOOKS_SELECTED_BACKEND == 'ZEPPELIN') {
if (NOTEBOOKS_SELECTED_BACKEND === 'ZEPPELIN') {
BACKEND = new ZeppelinBackend();
}

export default BACKEND;
Comment on lines 10 to -17
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we get rid of the Zeppelin backend since it is hard coded to never use it? That will also avoid more confusion in the future

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you create an issue for this, I'll work on it to remove Zeppelin.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Created and assigned to you: #955. @Swiddis lets not block this PR for this, thanks!

37 changes: 14 additions & 23 deletions server/adaptors/ppl_datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@
*/

import _ from 'lodash';
import {
IPPLEventsDataSource,
IPPLVisualizationDataSource
} from '../common/types';
import { IPPLEventsDataSource, IPPLVisualizationDataSource } from '../common/types';

type PPLResponse = IPPLEventsDataSource & IPPLVisualizationDataSource;

export class PPLDataSource {

constructor(
private pplDataSource: PPLResponse,
private dataType: string
) {
constructor(private pplDataSource: PPLResponse, private dataType: string) {
if (this.dataType === 'jdbc') {
this.addSchemaRowMapping();
} else if (this.dataType === 'viz') {
Expand All @@ -42,9 +35,9 @@ export class PPLDataSource {
* agent: "chrome",
* avg(bytes): 5648
* ...
* }]
* }]
*/
let res = [];
const res = [];
if (visData?.metadata?.fields) {
const queriedFields = visData.metadata.fields;
for (let i = 0; i < visData.size; i++) {
Expand All @@ -55,29 +48,27 @@ export class PPLDataSource {
});
res.push(entry);
}
visData['jsonData'] = res;
visData.jsonData = res;
}
}
};

/**
* Add 'schemaName: data' entries for UI rendering
*/
private addSchemaRowMapping = () => {

const pplRes = this.pplDataSource;

const data: any[] = [];

_.forEach(pplRes.datarows, (row) => {
const record: any = {};

for (let i = 0; i < pplRes.schema.length; i++) {

const cur = pplRes.schema[i];
if (typeof(row[i]) === 'object') {

if (typeof row[i] === 'object') {
record[cur.name] = JSON.stringify(row[i]);
} else if (typeof(row[i]) === 'boolean') {
} else if (typeof row[i] === 'boolean') {
record[cur.name] = row[i].toString();
} else {
record[cur.name] = row[i];
Expand All @@ -86,8 +77,8 @@ export class PPLDataSource {

data.push(record);
});
pplRes['jsonData'] = data;
pplRes.jsonData = data;
};

public getDataSource = () : PPLResponse => this.pplDataSource;
}
public getDataSource = (): PPLResponse => this.pplDataSource;
}
20 changes: 10 additions & 10 deletions server/common/helpers/notebooks/default_notebook_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@

// Default Backend Notebook Schema

export type DefaultInput = {
export interface DefaultInput {
inputType: string;
inputText: string;
};
}

export type DefaultOutput = {
export interface DefaultOutput {
outputType: string;
result: string;
execution_time: string;
};
export type DefaultParagraph = {
}
export interface DefaultParagraph {
id: string;
dateCreated: string;
dateModified: string;
input: DefaultInput;
output: Array<DefaultOutput>;
};
export type DefaultNotebooks = {
output: DefaultOutput[];
}
export interface DefaultNotebooks {
name: string;
dateCreated: string;
dateModified: string;
backend: string;
paragraphs: Array<DefaultParagraph>;
};
paragraphs: DefaultParagraph[];
}
25 changes: 13 additions & 12 deletions server/common/helpers/notebooks/query_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,34 @@
* SPDX-License-Identifier: Apache-2.0
*/

import QueryService from "../../../services/queryService";
import { QueryService } from '../../../services/queryService';

export const inputIsQuery = (inputText: string) => {
return (inputIsSQL(inputText) || inputIsPPL(inputText));
}
return inputIsSQL(inputText) || inputIsPPL(inputText);
};

export const inputIsSQL = (inputText: string) => {
return inputText.substring(0, 4) === '%sql';
}
};

export const inputIsPPL = (inputText: string) => {
return inputText.substring(0, 4) === '%ppl';
}
};

export const getQueryOutput = async (inputText: string, queryService: QueryService) => {
let output = {};
if (inputIsSQL(inputText)) {
output = await queryService.describeSQLQuery(inputText);
}
else if (inputIsPPL(inputText)) {
} else if (inputIsPPL(inputText)) {
output = await queryService.describePPLQuery(inputText);
}
return output;
}
};

export const formatNotRecognized = (inputText: string) => {
return (inputText.substring(0, 4) != '%sql' &&
inputText.substring(0, 4) != '%ppl' &&
inputText.substring(0, 3) != '%md')
}
return (
inputText.substring(0, 4) !== '%sql' &&
inputText.substring(0, 4) !== '%ppl' &&
inputText.substring(0, 3) !== '%md'
);
};
Loading