Skip to content

Commit

Permalink
consolidated most shared types at top level (opensearch-project#347) (o…
Browse files Browse the repository at this point in the history
…pensearch-project#362)

Signed-off-by: Amardeepsingh Siglani <[email protected]>

Signed-off-by: Amardeepsingh Siglani <[email protected]>
(cherry picked from commit dae16fa)

Co-authored-by: Amardeepsingh Siglani <[email protected]>
Signed-off-by: AWSHurneyt <[email protected]>
  • Loading branch information
2 people authored and AWSHurneyt committed Feb 22, 2023
1 parent ab08351 commit adc1a4c
Show file tree
Hide file tree
Showing 29 changed files with 785 additions and 88 deletions.
22 changes: 0 additions & 22 deletions public/pages/Categories/containers/Categories/Categories.tsx

This file was deleted.

8 changes: 0 additions & 8 deletions public/pages/Categories/containers/Categories/index.ts

This file was deleted.

8 changes: 0 additions & 8 deletions public/pages/Categories/index.ts

This file was deleted.

15 changes: 0 additions & 15 deletions public/pages/Detectors/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { Direction } from '@elastic/eui';

export interface DetectorItem {
id: string;
name: string;
}

export interface DetectorsQueryParams {
from: number;
size: number;
search: string;
sortField: keyof DetectorItem;
sortDirection: Direction;
}

export interface IndexOption {
label: string;
}
Expand Down
5 changes: 0 additions & 5 deletions public/pages/Findings/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

export interface FilterOption {
id: string;
label: string;
}

export interface Finding {
id: string;
detectorId: string;
Expand Down
4 changes: 1 addition & 3 deletions public/pages/Overview/models/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/ {
loading;
}
*/

import { EuiBasicTableColumn } from '@elastic/eui';
import { AlertItem, DetectorItem, FindingItem } from './interfaces';
Expand Down
3 changes: 0 additions & 3 deletions public/pages/Rules/models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { Rule } from '../../../../models/interfaces';
import { RuleInfo } from '../../../../server/models/interfaces';

export type RuleItemInfoBase = RuleInfo & { prePackaged: boolean };

export type RulePayload = Omit<Rule, 'category'>;
3 changes: 2 additions & 1 deletion public/services/DetectorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import {
} from '../../server/models/interfaces';
import { API } from '../../server/utils/constants';
import { Detector } from '../../models/interfaces';
import { IDetectorService } from '../../types';

export default class DetectorsService {
export default class DetectorsService implements IDetectorService {
constructor(private httpClient: HttpSetup) {}

createDetector = async (detector: Detector): Promise<ServerResponse<CreateDetectorResponse>> => {
Expand Down
23 changes: 0 additions & 23 deletions public/services/OpenSearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
SimpleSavedObject,
} from 'opensearch-dashboards/public';
import { ServerResponse } from '../../server/models/types';
import { SearchResponse, Plugin } from '../../server/models/interfaces';
import { API } from '../../server/utils/constants';

export default class OpenSearchService {
Expand All @@ -18,28 +17,6 @@ export default class OpenSearchService {
private savedObjectsClient: SavedObjectsClientContract
) {}

documentIdsQuery = async (
index: string,
documentIds: string[]
): Promise<ServerResponse<SearchResponse<any>>> => {
if (!index || !documentIds) return;
return (await this.httpClient.get(`..${API.DOCUMENT_IDS_QUERY}`, {
query: { index, documentIds },
})) as ServerResponse<SearchResponse<any>>;
};

timeRangeQuery = async (
index: string,
timeField = 'timestamp',
startTime = 'now-15m',
endTime = 'now'
): Promise<ServerResponse<SearchResponse<any>>> => {
if (!index) return;
return (await this.httpClient.get(`..${API.TIME_RANGE_QUERY}`, {
query: { index, timeField, startTime, endTime },
})) as ServerResponse<SearchResponse<any>>;
};

getPlugins = async (): Promise<ServerResponse<Plugin[]>> => {
let url = `..${API.PLUGINS}`;
return await this.httpClient.get(url);
Expand Down
94 changes: 94 additions & 0 deletions types/Alert.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export interface AlertCondition {
// Trigger fields
name: string;
id?: string;

// Detector types
types: string[];

// Trigger fields based on Rules
sev_levels: string[];
tags: string[];
ids: string[];

// Alert related fields
actions: TriggerAction[];
severity: string;
}

export interface TriggerAction {
id: string;
// Id of notification channel
destination_id: string;
subject_template: {
source: string;
lang: string;
};
name: string;
throttle_enabled: boolean;
message_template: {
source: string;
lang: string;
};
throttle: {
unit: string;
value: number;
};
}

/**
* API interfaces
*/

export type GetAlertsParams =
| {
detector_id: string;
detectorType?: string;
}
| {
detectorType: string;
detector_id?: string;
};

export interface GetAlertsResponse {
alerts: AlertResponse[];
}

export interface AlertItem {
id: string;
start_time: string;
trigger_name: string;
detector_id: string;
state: string;
severity: string;
finding_ids: string[];
last_notification_time: string;
acknowledged_time: string | null;
}

export interface AlertResponse extends AlertItem {
version: number;
schema_version: number;
trigger_id: string;
related_doc_ids: string[];
error_message: string | null;
alert_history: string[];
action_execution_results: {
action_id: string;
last_execution_time: number;
throttled_count: number;
}[];
end_time: string | null;
}

export interface AcknowledgeAlertsParams {
body: { alerts: string[] };
detector_id: string;
}

export interface AcknowledgeAlertsResponse {}
135 changes: 135 additions & 0 deletions types/Detector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { AlertCondition } from './Alert';
import { DetectorRuleInfo } from './Rule';

export interface DetectorInput {
detector_input: {
description: string;
indices: string[];
pre_packaged_rules: DetectorRuleInfo[];
custom_rules: DetectorRuleInfo[];
};
}

export interface DetectorSchedule {
period: {
interval: number;
unit: string;
};
}

export interface Detector {
id?: string;
type: 'detector';
detector_type: string;
name: string;
enabled: boolean;
createdBy: string;
schedule: DetectorSchedule;
inputs: DetectorInput[];
triggers: AlertCondition[];
}

export interface AlertConditionRuleOption {
name: string;
id: string;
severity: string;
tags: string[];
}

export interface RulesSharedState {
page: RulesPage;
rulesOptions: AlertConditionRuleOption[];
}

export interface RulesPage {
index: number;
}

export interface SourceIndexOption {
label: string;
}

export interface DetectorTypeOption {
id: string;
label: string;
}

export enum DetectorCreationStep {
DEFINE_DETECTOR = 1,
CONFIGURE_FIELD_MAPPING = 2,
CONFIGURE_ALERTS = 3,
REVIEW_CREATE = 4,
}

export interface DetectorHit {
_index: string;
_source: DetectorResponse;
_id: string;
}

/**
* API Interfaces
*/

export type DetectorResponse = Detector & {
last_update_time: number;
enabled_time: number;
};

export interface CreateDetectorParams {
body: Detector;
}

export interface CreateDetectorResponse {
_id: string;
_version: number;
detector: DetectorResponse;
}

export interface GetDetectorParams {
detectorId: string;
}

export interface GetDetectorResponse {}

export interface SearchDetectorsParams {
body: {
size: number;
query: object;
};
}

export interface SearchDetectorsResponse {
hits: {
total: { value: number };
hits: DetectorHit[];
};
}

export interface UpdateDetectorParams {
detectorId: string;
body: Detector;
}

export interface UpdateDetectorResponse {
_id: string;
_version: number;
detector: {
detector: Detector & {
last_update_time: number;
monitor_id: string;
rule_topic_index: string;
};
};
}

export interface DeleteDetectorParams {
detectorId: string;
}

export interface DeleteDetectorResponse {}
Loading

0 comments on commit adc1a4c

Please sign in to comment.