forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
annotations.ts
150 lines (133 loc) · 3.98 KB
/
annotations.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
// The Annotation interface is based on annotation documents stored in the
// `.ml-annotations-6` index, accessed via the `.ml-annotations-[read|write]` aliases.
// Annotation document mapping:
// PUT .ml-annotations-6
// {
// "mappings": {
// "annotation": {
// "properties": {
// "annotation": {
// "type": "text"
// },
// "create_time": {
// "type": "date",
// "format": "epoch_millis"
// },
// "create_username": {
// "type": "keyword"
// },
// "timestamp": {
// "type": "date",
// "format": "epoch_millis"
// },
// "end_timestamp": {
// "type": "date",
// "format": "epoch_millis"
// },
// "job_id": {
// "type": "keyword"
// },
// "modified_time": {
// "type": "date",
// "format": "epoch_millis"
// },
// "modified_username": {
// "type": "keyword"
// },
// "type": {
// "type": "keyword"
// }
// }
// }
// }
// }
// Alias
// POST /_aliases
// {
// "actions" : [
// { "add" : { "index" : ".ml-annotations-6", "alias" : ".ml-annotations-read" } },
// { "add" : { "index" : ".ml-annotations-6", "alias" : ".ml-annotations-write" } }
// ]
// }
import { PartitionFieldsType } from './anomalies';
import { ANNOTATION_TYPE } from '../constants/annotations';
export type AnnotationFieldName = 'partition_field_name' | 'over_field_name' | 'by_field_name';
export type AnnotationFieldValue = 'partition_field_value' | 'over_field_value' | 'by_field_value';
export function getAnnotationFieldName(fieldType: PartitionFieldsType): AnnotationFieldName {
return `${fieldType}_name` as AnnotationFieldName;
}
export function getAnnotationFieldValue(fieldType: PartitionFieldsType): AnnotationFieldValue {
return `${fieldType}_value` as AnnotationFieldValue;
}
export interface Annotation {
_id?: string;
create_time?: number;
create_username?: string;
modified_time?: number;
modified_username?: string;
key?: string;
timestamp: number;
end_timestamp?: number;
annotation: string;
job_id: string;
type: ANNOTATION_TYPE.ANNOTATION | ANNOTATION_TYPE.COMMENT;
event?:
| 'user'
| 'delayed_data'
| 'model_snapshot_stored'
| 'model_change'
| 'categorization_status_change';
detector_index?: number;
partition_field_name?: string;
partition_field_value?: string;
over_field_name?: string;
over_field_value?: string;
by_field_name?: string;
by_field_value?: string;
}
export function isAnnotation(arg: any): arg is Annotation {
return (
arg.timestamp !== undefined &&
typeof arg.annotation === 'string' &&
typeof arg.job_id === 'string' &&
(arg.type === ANNOTATION_TYPE.ANNOTATION || arg.type === ANNOTATION_TYPE.COMMENT)
);
}
export type Annotations = Annotation[];
export function isAnnotations(arg: any): arg is Annotations {
if (Array.isArray(arg) === false) {
return false;
}
return arg.every((d: Annotation) => isAnnotation(d));
}
export interface FieldToBucket {
field: string;
missing?: string | number;
}
export interface FieldToBucketResult {
key: string;
doc_count: number;
}
export interface TermAggregationResult {
doc_count_error_upper_bound: number;
sum_other_doc_count: number;
buckets: FieldToBucketResult[];
}
export type EsAggregationResult = Record<string, TermAggregationResult>;
export interface GetAnnotationsResponse {
aggregations?: EsAggregationResult;
annotations: Record<string, Annotations>;
error?: string;
success: boolean;
}
export interface AnnotationsTable {
annotationsData: Annotations;
aggregations: EsAggregationResult;
error?: string;
}