Skip to content

Commit

Permalink
Merge pull request #547 from Swiddis/osints/main
Browse files Browse the repository at this point in the history
Stub router for integrations project
  • Loading branch information
Swiddis authored Jun 19, 2023
2 parents 7a5caaa + 55f98e7 commit 82fa8a7
Show file tree
Hide file tree
Showing 8 changed files with 453 additions and 5 deletions.
6 changes: 6 additions & 0 deletions common/constants/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const DSL_SEARCH = '/search';
export const DSL_CAT = '/cat.indices';
export const DSL_MAPPING = '/indices.getFieldMapping';
export const OBSERVABILITY_BASE = '/api/observability';
export const INTEGRATIONS_BASE = '/api/integrations';
export const EVENT_ANALYTICS = '/event_analytics';
export const SAVED_OBJECTS = '/saved_objects';
export const SAVED_QUERY = '/query';
Expand Down Expand Up @@ -51,6 +52,10 @@ export const observabilityPanelsID = 'observability-dashboards';
export const observabilityPanelsTitle = 'Dashboards';
export const observabilityPanelsPluginOrder = 5095;

export const observabilityIntegrationsID = 'observability-integrations';
export const observabilityIntegrationsTitle = 'Integrations';
export const observabilityIntegrationsPluginOrder = 5096;

// Shared Constants
export const SQL_DOCUMENTATION_URL = 'https://opensearch.org/docs/latest/search-plugins/sql/index/';
export const PPL_DOCUMENTATION_URL =
Expand All @@ -69,6 +74,7 @@ export const PPL_NEWLINE_REGEX = /[\n\r]+/g;

// Observability plugin URI
const BASE_OBSERVABILITY_URI = '/_plugins/_observability';
const BASE_INTEGRATIONS_URI = '/_plugins/_integrations'; // Used later in front-end for routing
export const OPENSEARCH_PANELS_API = {
OBJECT: `${BASE_OBSERVABILITY_URI}/object`,
};
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
"@reduxjs/toolkit": "^1.6.1",
"ag-grid-community": "^27.3.0",
"ag-grid-react": "^27.3.0",
"ajv": "^8.11.0",
"antlr4": "4.8.0",
"antlr4ts": "^0.5.0-alpha.4",
"mime": "^3.0.0",
"performance-now": "^2.1.0",
"plotly.js-dist": "^2.2.0",
"postinstall": "^0.7.4",
Expand All @@ -41,6 +43,7 @@
"devDependencies": {
"@cypress/skip-test": "^2.6.1",
"@types/enzyme-adapter-react-16": "^1.0.6",
"@types/mime": "^3.0.1",
"@types/react-plotly.js": "^2.5.0",
"@types/react-test-renderer": "^16.9.1",
"antlr4ts-cli": "^0.5.0-alpha.4",
Expand All @@ -50,6 +53,7 @@
"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 @@ -70,4 +74,4 @@
"node_modules/*",
"target/*"
]
}
}
32 changes: 32 additions & 0 deletions server/adaptors/integrations/integrations_adaptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export interface IntegrationsAdaptor {
getIntegrationTemplates: (
query?: IntegrationTemplateQuery
) => Promise<IntegrationTemplateSearchResult>;

getIntegrationInstances: (
query?: IntegrationInstanceQuery
) => Promise<IntegrationInstancesSearchResult>;

getIntegrationInstance: (query?: IntegrationInstanceQuery) => Promise<IntegrationInstanceResult>;

loadIntegrationInstance: (
templateName: string,
name: string,
dataSource: string
) => Promise<IntegrationInstance>;

deleteIntegrationInstance: (id: string) => Promise<unknown>;

getStatic: (templateName: string, path: string) => Promise<Buffer>;

getSchemas: (
templateName: string
) => Promise<{ mappings: { [key: string]: unknown }; schemas: { [key: string]: unknown } }>;

getAssets: (templateName: string) => Promise<{ savedObjects?: unknown }>;
}
84 changes: 84 additions & 0 deletions server/adaptors/integrations/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

interface IntegrationTemplate {
name: string;
version: string;
displayName?: string;
integrationType: string;
license: string;
type: string;
author?: string;
description?: string;
sourceUrl?: string;
statics?: {
logo?: StaticAsset;
gallery?: StaticAsset[];
darkModeLogo?: StaticAsset;
darkModeGallery?: StaticAsset[];
};
components: IntegrationComponent[];
assets: {
savedObjects?: {
name: string;
version: string;
};
};
}

interface StaticAsset {
annotation?: string;
path: string;
}

interface IntegrationComponent {
name: string;
version: string;
}

interface DisplayAsset {
body: string;
}

interface IntegrationTemplateSearchResult {
hits: IntegrationTemplate[];
}

interface IntegrationTemplateQuery {
name?: string;
}

interface IntegrationInstance {
name: string;
templateName: string;
dataSource: {
sourceType: string;
dataset: string;
namespace: string;
};
creationDate: string;
assets: AssetReference[];
}

interface IntegrationInstanceResult extends IntegrationInstance {
id: string;
status: string;
}

interface AssetReference {
assetType: string;
assetId: string;
isDefaultAsset: boolean;
description: string;
}

interface IntegrationInstancesSearchResult {
hits: IntegrationInstanceResult[];
}

interface IntegrationInstanceQuery {
added?: boolean;
id?: string;
}
9 changes: 5 additions & 4 deletions server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ import { registerSqlRoute } from './notebooks/sqlRouter';
import { registerEventAnalyticsRouter } from './event_analytics/event_analytics_router';
import { registerAppAnalyticsRouter } from './application_analytics/app_analytics_router';
import { registerMetricsRoute } from './metrics/metrics_rounter';

import { registerIntegrationsRoute } from './integrations/integrations_router';

export function setupRoutes({ router, client }: { router: IRouter; client: ILegacyClusterClient }) {
PanelsRouter(router);
VisualizationsRouter(router);
registerPplRoute({ router, facet: new PPLFacet(client) });
registerDslRoute({ router, facet: new DSLFacet(client)});
registerDslRoute({ router, facet: new DSLFacet(client) });
registerEventAnalyticsRouter({ router, savedObjectFacet: new SavedObjectFacet(client) });
registerAppAnalyticsRouter(router);

// TODO remove trace analytics route when DSL route for autocomplete is added
registerTraceAnalyticsDslRouter(router);

Expand All @@ -41,4 +41,5 @@ export function setupRoutes({ router, client }: { router: IRouter; client: ILega
registerSqlRoute(router, queryService);

registerMetricsRoute(router);
};
registerIntegrationsRoute(router);
}
53 changes: 53 additions & 0 deletions server/routes/integrations/__tests__/integrations_router.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { OpenSearchDashboardsResponseFactory } from '../../../../../../src/core/server/http/router';
import { handleWithCallback } from '../integrations_router';
import { IntegrationsAdaptor } from 'server/adaptors/integrations/integrations_adaptor';

describe('handleWithCallback', () => {
let adaptorMock: jest.Mocked<IntegrationsAdaptor>;
let responseMock: jest.Mocked<OpenSearchDashboardsResponseFactory>;

beforeEach(() => {
adaptorMock = {} as any;
responseMock = {
custom: jest.fn((data) => data),
ok: jest.fn((data) => data),
} as any;
});

it('retrieves data from the callback method', async () => {
const callback = jest.fn((_) => {
return { test: 'data' };
});

const result = await handleWithCallback(
adaptorMock as IntegrationsAdaptor,
responseMock as OpenSearchDashboardsResponseFactory,
callback
);

expect(callback).toHaveBeenCalled();
expect(responseMock.ok).toHaveBeenCalled();
expect(result.body.data).toEqual({ test: 'data' });
});

it('passes callback errors through', async () => {
const callback = jest.fn((_) => {
throw new Error('test error');
});

const result = await handleWithCallback(
adaptorMock as IntegrationsAdaptor,
responseMock as OpenSearchDashboardsResponseFactory,
callback
);

expect(callback).toHaveBeenCalled();
expect(responseMock.custom).toHaveBeenCalled();
expect(result.body).toEqual('test error');
});
});
Loading

0 comments on commit 82fa8a7

Please sign in to comment.