Skip to content

Commit

Permalink
Adding plugin backend adaptor (#126)
Browse files Browse the repository at this point in the history
* adding plugin backed adaptor

* resolved comments and beautification
  • Loading branch information
ps48 authored Oct 6, 2021
1 parent a059f2a commit afd0c78
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 85 deletions.
7 changes: 3 additions & 4 deletions common/constants/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ export const UI_DATE_FORMAT = 'MM/DD/YYYY hh:mm A';
export const PPL_DATE_FORMAT = 'YYYY-MM-DD HH:mm:ss';
export const PPL_INDEX_REGEX = /(search source|source|index)\s*=\s*([^|\s]+)/i;

// Observability plugin URI
// Observability plugin URI
const BASE_OBSERVABILITY_URI = '/_plugins/_observability';
export const OPENSEARCH_PANELS_API = {
GET_PANELS: `${BASE_OBSERVABILITY_URI}/panels`,
PANEL: `${BASE_OBSERVABILITY_URI}/panel`,
};
OBJECT: `${BASE_OBSERVABILITY_URI}/object`,
};
145 changes: 64 additions & 81 deletions server/adaptors/opensearch_observability_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,138 +9,121 @@
* GitHub history for details.
*/

import { OPENSEARCH_NOTEBOOKS_API } from '../../common/constants/notebooks';
import { OPENSEARCH_PANELS_API } from '../../common/constants/shared';
import { OPENSEARCH_PANELS_API } from "../../common/constants/shared";

export function OpenSearchObservabilityPlugin(Client: any, config: any, components: any) {
export function OpenSearchObservabilityPlugin(
Client: any,
config: any,
components: any
) {
const clientAction = components.clientAction.factory;

Client.prototype.observability = components.clientAction.namespaceFactory();
const observability = Client.prototype.observability.prototype;

observability.getPanels = clientAction({
// Get Object
observability.getObject = clientAction({
url: {
fmt: OPENSEARCH_PANELS_API.GET_PANELS,
fmt: OPENSEARCH_PANELS_API.OBJECT,
params: {
objectId: {
type: "string",
},
objectIdList: {
type: "string",
},
objectType: {
type: "string",
},
sortField: {
type: "string",
},
sortOrder: {
type: "string",
},
fromIndex: {
type: 'number',
type: "number",
},
maxItems: {
type: 'number',
type: "number",
},
},
},
method: 'GET',
});

observability.createPanel = clientAction({
url: {
fmt: OPENSEARCH_PANELS_API.PANEL,
},
method: 'POST',
needBody: true,
});

observability.getPanelById = clientAction({
url: {
fmt: `${OPENSEARCH_PANELS_API.PANEL}/<%=panelId%>`,
req: {
panelId: {
type: 'string',
required: true,
name: {
type: "string",
},
},
},
method: 'GET',
});

observability.updatePanelById = clientAction({
url: {
fmt: `${OPENSEARCH_PANELS_API.PANEL}/<%=panelId%>`,
req: {
panelId: {
type: 'string',
required: true,
lastUpdatedTimeMs: {
type: "string",
},
createdTimeMs: {
type: "string",
},
},
},
method: 'PUT',
needBody: true,
method: "GET",
});

observability.deletePanelById = clientAction({
// Get Object by Id
observability.getObjectById = clientAction({
url: {
fmt: `${OPENSEARCH_PANELS_API.PANEL}/<%=panelId%>`,
fmt: `${OPENSEARCH_PANELS_API.OBJECT}/<%=objectId%>`,
req: {
panelId: {
type: 'string',
objectId: {
type: "string",
required: true,
},
},
},
method: 'DELETE',
});

observability.getNotebooks = clientAction({
url: {
fmt: OPENSEARCH_NOTEBOOKS_API.GET_NOTEBOOKS,
params: {
fromIndex: {
type: 'number',
},
maxItems: {
type: 'number',
},
},
},
method: 'GET',
method: "GET",
});

observability.createNotebook = clientAction({
// Create new Object
observability.createObject = clientAction({
url: {
fmt: OPENSEARCH_NOTEBOOKS_API.NOTEBOOK,
fmt: OPENSEARCH_PANELS_API.OBJECT,
},
method: 'POST',
method: "POST",
needBody: true,
});

observability.getNotebookById = clientAction({
// Update Object by Id
observability.updateObjectById = clientAction({
url: {
fmt: `${OPENSEARCH_NOTEBOOKS_API.NOTEBOOK}/<%=notebookId%>`,
fmt: `${OPENSEARCH_PANELS_API.OBJECT}/<%=objectId%>`,
req: {
notebookId: {
type: 'string',
objectId: {
type: "string",
required: true,
},
},
},
method: 'GET',
method: "PUT",
needBody: true,
});

observability.updateNotebookById = clientAction({
// Delete Object by Id
observability.deleteObjectById = clientAction({
url: {
fmt: `${OPENSEARCH_NOTEBOOKS_API.NOTEBOOK}/<%=notebookId%>`,
fmt: `${OPENSEARCH_PANELS_API.OBJECT}/<%=objectId%>`,
req: {
notebookId: {
type: 'string',
objectId: {
type: "string",
required: true,
},
},
},
method: 'PUT',
needBody: true,
method: "DELETE",
});

observability.deleteNotebookById = clientAction({
// Delete Object by Id List
observability.deleteObjectByIdList = clientAction({
url: {
fmt: `${OPENSEARCH_NOTEBOOKS_API.NOTEBOOK}/<%=notebookId%>`,
req: {
notebookId: {
type: 'string',
fmt: OPENSEARCH_PANELS_API.OBJECT,
params: {
objectIdList: {
type: "string",
required: true,
},
},
},
method: 'DELETE',
method: "DELETE",
});
}

0 comments on commit afd0c78

Please sign in to comment.