Skip to content

Commit

Permalink
Fix all yarn lints for server directory (opensearch-project#953)
Browse files Browse the repository at this point in the history
* Apply yarn auto-lints

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Fix equalities

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Fix naming conventions

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Fix non-export issues

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Fix default exports

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Remove unused dependency

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

---------

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
  • Loading branch information
Swiddis authored and paulstn committed Sep 8, 2023
1 parent f08518f commit 790e1bf
Show file tree
Hide file tree
Showing 26 changed files with 470 additions and 463 deletions.
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';
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;
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

0 comments on commit 790e1bf

Please sign in to comment.