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
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: {
Copy link
Member

Choose a reason for hiding this comment

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

forgot to mention createdTimeMs is also supported, format is the same as lastUpdatedTimeMs

Copy link
Member Author

Choose a reason for hiding this comment

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

Will add this as well.

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",
});
}