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

Update VisLayer data models #3374

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
51 changes: 17 additions & 34 deletions src/plugins/vis_augmenter/common/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,39 @@

import { VisLayerTypes, VisLayer, isPointInTimeEventsVisLayer, isValidVisLayer } from './types';

const generateVisLayer = (type: any): VisLayer => {
ohltyler marked this conversation as resolved.
Show resolved Hide resolved
return {
type,
originPlugin: 'test-plugin',
pluginResource: {
type: 'test-resource-type',
id: 'test-resource-id',
name: 'test-resource-name',
urlPath: 'test-resource-url-path',
},
};
};

describe('isPointInTimeEventsVisLayer()', function () {
it('should return false if type does not match', function () {
const visLayer = ({
type: 'incorrect-type',
name: 'visLayerName',
field1: 'value1',
field2: 'value2',
} as unknown) as VisLayer;
const visLayer = generateVisLayer('unknown-vis-layer-type');
expect(isPointInTimeEventsVisLayer(visLayer)).toBe(false);
});

it('should return true if type matches', function () {
const visLayer = {
type: VisLayerTypes.PointInTimeEvents,
name: 'testName',
events: [
{
timestamp: 123,
resourceId: 'testId',
resourceName: 'testName',
},
],
} as VisLayer;
const visLayer = generateVisLayer(VisLayerTypes.PointInTimeEvents);
expect(isPointInTimeEventsVisLayer(visLayer)).toBe(true);
});
});

describe('isValidVisLayer()', function () {
it('should return false if no valid type', function () {
const visLayer = ({
type: 'incorrect-type',
name: 'visLayerName',
field1: 'value1',
field2: 'value2',
} as unknown) as VisLayer;
const visLayer = generateVisLayer('unknown-vis-layer-type');
expect(isValidVisLayer(visLayer)).toBe(false);
});

it('should return true if type matches', function () {
const visLayer = {
type: VisLayerTypes.PointInTimeEvents,
name: 'testName',
events: [
{
timestamp: 123,
resourceId: 'testId',
resourceName: 'testName',
},
],
} as VisLayer;
const visLayer = generateVisLayer(VisLayerTypes.PointInTimeEvents);
expect(isValidVisLayer(visLayer)).toBe(true);
});
});
18 changes: 12 additions & 6 deletions src/plugins/vis_augmenter/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,25 @@ export enum VisLayerTypes {
PointInTimeEvents = 'PointInTimeEvents',
}

export type PluginResourceType = string;

export interface PluginResource {
type: PluginResourceType;
id: string;
name: string;
urlPath: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

What would be an example of this urlPath look like?

Copy link
Member Author

Choose a reason for hiding this comment

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

It would be something like anomaly-detection-dashboards#/detectors/<detector-id>/configurations. The base path would come from core services.

Full example:

<EuiLink href={`${getCore().http.basePath.prepend(`${urlPath}`)}`}>{name}</EuiLink>

Copy link
Member

Choose a reason for hiding this comment

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

@ohltyler Is there an updated design doc for these data models? Mostly just want to make sure our docs stay in sync with these changes that come out of the actual implementation. We also just may want to have a placeholder issue to remind us to document example usage (you may have already created one).

Copy link
Member

Choose a reason for hiding this comment

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

Is it enough for urlPath to be a static string? In your example, it seems like maybe you'd want to be able to pass something like a detector-id?

}

export interface VisLayer {
type: keyof typeof VisLayerTypes;
name: string;
originPlugin: string;
pluginResource: PluginResource;
}

export type VisLayers = VisLayer[];

// resourceId & resourceName are required so that the
// events flyout can partition data based on these attributes
// (e.g., partitioning anomalies based on the detector they came from)
export interface EventMetadata {
resourceId: string;
resourceName: string;
pluginResourceId: string;
tooltip?: string;
}

Expand Down