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

Adding plugin backend adaptor #126

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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`,
};
116 changes: 46 additions & 70 deletions server/adaptors/opensearch_observability_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* GitHub history for details.
*/

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

export function OpenSearchObservabilityPlugin(Client: any, config: any, components: any) {
Expand All @@ -18,124 +17,101 @@ export function OpenSearchObservabilityPlugin(Client: any, config: any, componen
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: {
fromIndex: {
type: 'number',
objectId: {
type: 'string',
},
objectIdList: {
type: 'string',
},
objectType: {
type: 'string',
},
sortField: {
type: 'string',
},
sortOrder: {
type: 'string',
},
fromIndex:{
type: 'string',
Copy link
Member

Choose a reason for hiding this comment

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

this should be 'number'?

},
maxItems: {
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: {
name: {
type: 'string',
required: true,
},
},
},
method: 'GET',
});

observability.updatePanelById = clientAction({
url: {
fmt: `${OPENSEARCH_PANELS_API.PANEL}/<%=panelId%>`,
req: {
panelId: {
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',
required: true,
},
},
},
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: {
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',
});

observability.createNotebook = clientAction({
// Create new Object
observability.createObject = clientAction({
url: {
fmt: OPENSEARCH_NOTEBOOKS_API.NOTEBOOK,
fmt: OPENSEARCH_PANELS_API.OBJECT,
},
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: {
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: {
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: {
fmt: OPENSEARCH_PANELS_API.OBJECT,
params: {
objectIdList: {
type: 'string',
required: true,
},
Expand Down