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

Refactor adaptor #1

Closed
wants to merge 8 commits into from
Closed
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
1 change: 1 addition & 0 deletions common/constants/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const OPENSEARCH_INTEGRATIONS_API = {
OBJECT: `${BASE_INTEGRATIONS_URI}/object`,
ALL: `${BASE_INTEGRATIONS_URI}/store/list_all`,
ADDED: `${BASE_INTEGRATIONS_URI}/store/list_added`,
ADDED_POP: `${BASE_INTEGRATIONS_URI}/store/list_added_pop`,
};
export const OPENSEARCH_PANELS_API = {
OBJECT: `${BASE_OBSERVABILITY_URI}/object`,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"devDependencies": {
"@cypress/skip-test": "^2.6.1",
"@types/enzyme-adapter-react-16": "^1.0.6",
"@types/node-fetch": "^2.6.3",
"@types/react-plotly.js": "^2.5.0",
"@types/react-test-renderer": "^16.9.1",
"antlr4ts-cli": "^0.5.0-alpha.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export function AddedIntegrationsTable(props: AddedIntegrationsTableProps) {
render: (value, record) => (
<EuiLink
data-test-subj={`${record.templateName}IntegrationLink`}
href={`#/added/${record.id}`}
// href={`#/added/${record.id}`}
href={record.dashboardUrl}
>
{_.truncate(record.id, { length: 100 })}
</EuiLink>
Expand Down Expand Up @@ -154,8 +155,7 @@ export function AddedIntegrationsTable(props: AddedIntegrationsTableProps) {
<EuiText textAlign="center">
<h2>
There are currently no added integrations. Add them{' '}
<EuiLink href={'#/available'}>here</EuiLink> to start using pre-canned
assets!
<EuiLink href={'#/available'}>here</EuiLink> to start using pre-canned assets!
</h2>
</EuiText>
<EuiSpacer size="m" />
Expand Down
61 changes: 32 additions & 29 deletions server/adaptors/opensearch_observability_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { OPENSEARCH_INTEGRATIONS_API, OPENSEARCH_PANELS_API } from "../../common/constants/shared";
import { OPENSEARCH_INTEGRATIONS_API, 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();
Expand All @@ -22,14 +18,21 @@ export function OpenSearchObservabilityPlugin(
url: {
fmt: OPENSEARCH_INTEGRATIONS_API.ALL,
},
method: "GET",
method: 'GET',
});

integrations.getAdded = clientAction({
url: {
fmt: OPENSEARCH_INTEGRATIONS_API.ADDED
fmt: OPENSEARCH_INTEGRATIONS_API.ADDED,
},
method: "GET",
method: 'GET',
});

integrations.getAddedPop = clientAction({
url: {
fmt: OPENSEARCH_INTEGRATIONS_API.ADDED_POP,
},
method: 'GET',
});

// Get Object
Expand All @@ -38,38 +41,38 @@ export function OpenSearchObservabilityPlugin(
fmt: OPENSEARCH_PANELS_API.OBJECT,
params: {
objectId: {
type: "string",
type: 'string',
},
objectIdList: {
type: "string",
type: 'string',
},
objectType: {
type: "string",
type: 'string',
},
sortField: {
type: "string",
type: 'string',
},
sortOrder: {
type: "string",
type: 'string',
},
fromIndex: {
type: "number",
type: 'number',
},
maxItems: {
type: "number",
type: 'number',
},
name: {
type: "string",
type: 'string',
},
lastUpdatedTimeMs: {
type: "string",
type: 'string',
},
createdTimeMs: {
type: "string",
type: 'string',
},
},
},
method: "GET",
method: 'GET',
});

// Get Object by Id
Expand All @@ -78,20 +81,20 @@ export function OpenSearchObservabilityPlugin(
fmt: `${OPENSEARCH_PANELS_API.OBJECT}/<%=objectId%>`,
req: {
objectId: {
type: "string",
type: 'string',
required: true,
},
},
},
method: "GET",
method: 'GET',
});

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

Expand All @@ -101,12 +104,12 @@ export function OpenSearchObservabilityPlugin(
fmt: `${OPENSEARCH_PANELS_API.OBJECT}/<%=objectId%>`,
req: {
objectId: {
type: "string",
type: 'string',
required: true,
},
},
},
method: "PUT",
method: 'PUT',
needBody: true,
});

Expand All @@ -116,12 +119,12 @@ export function OpenSearchObservabilityPlugin(
fmt: `${OPENSEARCH_PANELS_API.OBJECT}/<%=objectId%>`,
req: {
objectId: {
type: "string",
type: 'string',
required: true,
},
},
},
method: "DELETE",
method: 'DELETE',
});

// Delete Object by Id List
Expand All @@ -130,11 +133,11 @@ export function OpenSearchObservabilityPlugin(
fmt: OPENSEARCH_PANELS_API.OBJECT,
params: {
objectIdList: {
type: "string",
type: 'string',
required: true,
},
},
},
method: "DELETE",
method: 'DELETE',
});
}
123 changes: 13 additions & 110 deletions server/adaptors/placeholder/placeholder_adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,127 +13,30 @@ export class PlaceholderAdaptor {
// Fetch all existing integrations
fetchApps = async (client: ILegacyScopedClusterClient): Promise<any[]> => {
try {
console.log('poopy')
console.log('poopy');
const response = await client.callAsCurrentUser('integrations.getObject');
console.log(response)
// return response.observabilityObjectList.map((object: any) => {
return response
// return {
// };
// });
console.log(response);
return response;
} catch (err: any) {
throw new Error('Fetch All Applications Error: ' + err);
}
};

fetchAdded = async (client: ILegacyScopedClusterClient): Promise<any[]> => {
fetchAdded = async (
client: ILegacyScopedClusterClient,
added: boolean = false
): Promise<any[]> => {
try {
const response = await client.callAsCurrentUser('integrations.getAdded', {});
console.log(response)
const endpoint = added ? 'integrations.getAddedPop' : 'integrations.getAdded';
const response = await client.callAsCurrentUser(endpoint, {});
console.log(response);
// return response.observabilityObjectList.map((object: any) => {
return response.list
return response.test;
// return {
// };
// });
} catch (err: any) {
throw new Error('Fetch All Applications Error: ' + err);
throw new Error('Fetch Added Applications Error: ' + err);
}
}

// // Fetch application by id
// fetchAppById = async (
// client: ILegacyScopedClusterClient,
// appId: string
// ): Promise<ApplicationType> => {
// try {
// const response = await client.callAsCurrentUser('observability.getObjectById', {
// objectId: appId,
// });
// const app = response.observabilityObjectList[0];
// return {
// id: appId,
// dateCreated: app.createdTimeMs,
// dateModified: app.lastUpdatedTimeMs,
// name: app.application.name,
// description: app.application.description,
// baseQuery: app.application.baseQuery,
// servicesEntities: app.application.servicesEntities.map((rec: string) => decodeURI(rec)),
// traceGroups: app.application.traceGroups.map((rec: string) => decodeURI(rec)),
// panelId: app.application.panelId,
// availability: {
// name: '',
// color: '',
// availabilityVisId: app.application.availabilityVisId || '',
// },
// };
// } catch (err: any) {
// throw new Error('Fetch Application By Id Error: ' + err);
// }
// };

// // Create a new application
// createNewApp = async (
// client: ILegacyScopedClusterClient,
// appBody: Partial<ApplicationRequestType>
// ) => {
// try {
// const response = await client.callAsCurrentUser('observability.createObject', {
// body: {
// application: appBody,
// },
// });
// return response.objectId;
// } catch (err) {
// throw new Error('Create New Application Error: ' + err);
// }
// };

// // Rename an existing application
// renameApp = async (client: ILegacyScopedClusterClient, appId: string, name: string) => {
// const updateApplicationBody = {
// name,
// };
// try {
// const response = await client.callAsCurrentUser('observability.updateObjectById', {
// objectId: appId,
// body: {
// application: updateApplicationBody,
// },
// });
// return response.objectId;
// } catch (err: any) {
// throw new Error('Rename Application Error: ' + err);
// }
// };

// // Update an existing application
// updateApp = async (
// client: ILegacyScopedClusterClient,
// appId: string,
// updateAppBody: Partial<ApplicationRequestType>
// ) => {
// try {
// const response = await client.callAsCurrentUser('observability.updateObjectById', {
// objectId: appId,
// body: {
// application: updateAppBody,
// },
// });
// return response.objectId;
// } catch (err: any) {
// throw new Error('Update Panel Error: ' + err);
// }
// };

// // Delete existing applications
// deleteApp = async (client: ILegacyScopedClusterClient, appList: string) => {
// try {
// const response = await client.callAsCurrentUser('observability.deleteObjectByIdList', {
// objectIdList: appList,
// });
// return { status: 'OK', message: response };
// } catch (err: any) {
// throw new Error('Delete Application Error: ' + err);
// }
// };
};
}
21 changes: 21 additions & 0 deletions server/routes/placeholder/__tests__/ndjson.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { readNDJson } from '../placeholder_router';
import { Readable } from 'stream';
import { createReadStream } from 'fs';

describe('ReadNDJsonStream', () => {
it('should successfully parse simple ndjson', async () => {
const stream = Readable.from(['{"key":1}\n{"key":2}\n{"key":3}']);
const array = await readNDJson(stream);
expect(array).toEqual([{ key: 1 }, { key: 2 }, { key: 3 }]);
});
it('should succeed if chunks split objects', async () => {
const stream = Readable.from(['{"key":1}\n{"ke', 'y":2}\n{"key":3}']);
const array = await readNDJson(stream);
expect(array).toEqual([{ key: 1 }, { key: 2 }, { key: 3 }]);
});
it('should succeed on test ndjson file', async () => {
const file = createReadStream(__dirname + '/test.ndjson');
const array = await readNDJson(file);
expect(array.length).toBeGreaterThan(0);
});
});
Loading