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

[RAC] [RBAC] working find route for alerts as data client #107982

Merged
merged 25 commits into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3c18dba
working find route
dhurley14 Aug 9, 2021
ba914ec
adds types find to prevent usage of aggs except for metrics and bucke…
dhurley14 Aug 11, 2021
7808549
Merge branch 'master' into alerts_client_find_api
dhurley14 Aug 11, 2021
a435c70
adds jest tests, partially working integration tests, unauthorized te…
dhurley14 Aug 11, 2021
d6fa4e2
fixes integration tests for find api
dhurley14 Aug 11, 2021
68d0f41
updates alerts count panel UI to use rule registry alerts as data fin…
dhurley14 Aug 12, 2021
50200d1
Merge remote-tracking branch 'upstream/master' into alerts_client_fin…
dhurley14 Aug 12, 2021
6d826b3
fix some newly renamed things after merge with master
dhurley14 Aug 12, 2021
ff5226e
Merge remote-tracking branch 'upstream/master' into alerts_client_fin…
dhurley14 Aug 13, 2021
de44247
do not 404 when there are empty hits, just return empty hits, fixes a…
dhurley14 Aug 13, 2021
e69493d
Merge remote-tracking branch 'upstream/master' into alerts_client_fin…
dhurley14 Aug 13, 2021
21f27f6
update histograms on overview page
dhurley14 Aug 13, 2021
e00a071
little cleanup
dhurley14 Aug 13, 2021
85ea8ed
remove logs and undo unnecessary changes in timeline
dhurley14 Aug 13, 2021
a442929
fix describe in the integration test
dhurley14 Aug 13, 2021
3976697
fixes integration test, alerting authorization filter will return emp…
dhurley14 Aug 13, 2021
9596697
fix merge conflicts after merge with master
dhurley14 Aug 14, 2021
e08c2cd
fix other failing integration tests
dhurley14 Aug 14, 2021
42f5a94
remove commented out code
dhurley14 Aug 15, 2021
4d89998
updates alerts client docs
dhurley14 Aug 15, 2021
628cd86
merge with master
dhurley14 Aug 17, 2021
862b5ad
allow nested aggs but disallow scripts fields and other extraneous fi…
dhurley14 Aug 17, 2021
a8188db
fixes bug where date_histogram was disallowed, removes ts-expect-erro…
dhurley14 Aug 17, 2021
5de23b5
removes debug log, removes unnecessary ts expect error, fixes bug whe…
dhurley14 Aug 18, 2021
4602b35
adds integration test for histogram query on rule details page
dhurley14 Aug 18, 2021
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
264 changes: 264 additions & 0 deletions x-pack/plugins/rule_registry/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,270 @@

import { estypes } from '@elastic/elasticsearch';

import * as t from 'io-ts';

// note: these schemas are not exhaustive. See the `Sort` type of `@elastic/elasticsearch` if you need to enhance it.
const fieldSchema = t.string;
export const sortOrderSchema = t.union([t.literal('asc'), t.literal('desc'), t.literal('_doc')]);
type SortOrderSchema = 'asc' | 'desc' | '_doc';
const sortModeSchema = t.union([
t.literal('min'),
t.literal('max'),
t.literal('sum'),
t.literal('avg'),
t.literal('median'),
]);
const fieldSortSchema = t.exact(
t.partial({
missing: t.union([t.string, t.number, t.boolean]),
mode: sortModeSchema,
order: sortOrderSchema,
// nested and unmapped_type not implemented yet
})
);
const sortContainerSchema = t.record(t.string, t.union([sortOrderSchema, fieldSortSchema]));
const sortCombinationsSchema = t.union([fieldSchema, sortContainerSchema]);
export const sortSchema = t.union([sortCombinationsSchema, t.array(sortCombinationsSchema)]);

export const minDocCount = t.number;

interface BucketAggsSchemas {
filter?: {
term?: { [x: string]: string | boolean | number };
};
histogram?: {
field?: string;
interval?: number;
min_doc_count?: number;
extended_bounds?: {
min: number;
max: number;
};
hard_bounds?: {
min: number;
max: number;
};
missing?: number;
keyed?: boolean;
order?: {
_count: string;
_key: string;
};
};
nested?: {
path: string;
};
terms?: {
field?: string;
collect_mode?: string;
exclude?: string | string[];
include?: string | string[];
execution_hint?: string;
missing?: number;
min_doc_count?: number;
size?: number;
show_term_doc_count_error?: boolean;
order?:
| SortOrderSchema
| { [x: string]: SortOrderSchema }
| Array<{ [x: string]: SortOrderSchema }>;
};
aggs?: {
[x: string]: BucketAggsSchemas;
};
}

/**
* Schemas for the Bucket aggregations.
*
* Currently supported:
* - filter
* - histogram
* - nested
* - terms
*
* Not implemented:
* - adjacency_matrix
* - auto_date_histogram
* - children
* - composite
* - date_histogram
* - date_range
* - diversified_sampler
* - filters
* - geo_distance
* - geohash_grid
* - geotile_grid
* - global
* - ip_range
* - missing
* - multi_terms
* - parent
* - range
* - rare_terms
* - reverse_nested
* - sampler
* - significant_terms
* - significant_text
* - variable_width_histogram
*/
export const BucketAggsSchemas: t.Type<BucketAggsSchemas> = t.recursion('BucketAggsSchemas', () =>
t.exact(
t.partial({
filter: t.exact(
t.partial({
term: t.record(t.string, t.union([t.string, t.boolean, t.number])),
})
),
date_histogram: t.exact(
t.partial({
field: t.string,
fixed_interval: t.string,
min_doc_count: t.number,
extended_bounds: t.type({
min: t.string,
max: t.string,
}),
})
),
histogram: t.exact(
t.partial({
field: t.string,
interval: t.number,
min_doc_count: t.number,
extended_bounds: t.exact(
t.type({
min: t.number,
max: t.number,
})
),
hard_bounds: t.exact(
t.type({
min: t.number,
max: t.number,
})
),
missing: t.number,
keyed: t.boolean,
order: t.exact(
t.type({
_count: t.string,
_key: t.string,
})
),
})
),
nested: t.type({
path: t.string,
}),
terms: t.exact(
t.partial({
field: t.string,
collect_mode: t.string,
exclude: t.union([t.string, t.array(t.string)]),
include: t.union([t.string, t.array(t.string)]),
execution_hint: t.string,
missing: t.number,
min_doc_count: t.number,
size: t.number,
show_term_doc_count_error: t.boolean,
order: t.union([
sortOrderSchema,
t.record(t.string, sortOrderSchema),
t.array(t.record(t.string, sortOrderSchema)),
]),
})
),
aggs: t.record(t.string, BucketAggsSchemas),
})
)
);

/**
* Schemas for the metrics Aggregations
*
* Currently supported:
* - avg
* - cardinality
* - min
* - max
* - sum
* - top_hits
* - weighted_avg
*
* Not implemented:
* - boxplot
* - extended_stats
* - geo_bounds
* - geo_centroid
* - geo_line
* - matrix_stats
* - median_absolute_deviation
* - percentile_ranks
* - percentiles
* - rate
* - scripted_metric
* - stats
* - string_stats
* - t_test
* - value_count
*/
export const metricsAggsSchemas = t.partial({
avg: t.partial({
field: t.string,
missing: t.union([t.string, t.number, t.boolean]),
}),
cardinality: t.partial({
field: t.string,
precision_threshold: t.number,
rehash: t.boolean,
missing: t.union([t.string, t.number, t.boolean]),
}),
min: t.partial({
field: t.string,
missing: t.union([t.string, t.number, t.boolean]),
format: t.string,
}),
max: t.partial({
field: t.string,
missing: t.union([t.string, t.number, t.boolean]),
format: t.string,
}),
sum: t.partial({
field: t.string,
missing: t.union([t.string, t.number, t.boolean]),
}),
top_hits: t.partial({
explain: t.boolean,
docvalue_fields: t.union([t.string, t.array(t.string)]),
stored_fields: t.union([t.string, t.array(t.string)]),
from: t.number,
size: t.number,
sort: sortSchema,
seq_no_primary_term: t.boolean,
version: t.boolean,
track_scores: t.boolean,
highlight: t.any,
_source: t.union([t.boolean, t.string, t.array(t.string)]),
}),
weighted_avg: t.partial({
format: t.string,
value_type: t.string,
value: t.partial({
field: t.string,
missing: t.number,
}),
weight: t.partial({
field: t.string,
missing: t.number,
}),
}),
});

export type PutIndexTemplateRequest = estypes.IndicesPutIndexTemplateRequest & {
body?: { composed_of?: string[] };
};
Comment on lines +270 to +272
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be deleted, estypes.IndicesPutIndexTemplateRequest contains composed_of:

export interface IndicesPutIndexTemplateRequest extends RequestBase {
  name: Name
  body?: {
    index_patterns?: Indices
    composed_of?: Name[]
    template?: IndicesPutIndexTemplateIndexTemplateMapping
    data_stream?: EmptyObject
    priority?: integer
    version?: VersionNumber
    _meta?: Metadata
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah good catch. I copied some of these types from elsewhere in kibana so didn't look too deeply at the types but I will update this. Thanks!


export interface ClusterPutComponentTemplateBody {
template: {
settings: {
Expand Down
Loading