Skip to content

Commit

Permalink
Merge branch 'master' into exceptions_rule
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Jul 28, 2020
2 parents fd23f03 + 5e62450 commit 3fdb90b
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 14 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/infra/common/http_api/snapshot_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export const SnapshotRequestRT = rt.intersection([
region: rt.string,
filterQuery: rt.union([rt.string, rt.null]),
includeTimeseries: rt.boolean,
overrideCompositeSize: rt.number,
}),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ describe('Metrics UI Observability Homepage Functions', () => {
groupBy: [],
nodeType: 'host',
includeTimeseries: true,
overrideCompositeSize: 5,
timerange: {
from: startTime.valueOf(),
to: endTime.valueOf(),
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/infra/public/metrics_overview_fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const createMetricsFetchData = (
groupBy: [],
nodeType: 'host',
includeTimeseries: true,
overrideCompositeSize: 5,
timerange: {
from: start,
to: end,
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/infra/server/lib/snapshot/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const requestGroupedNodes = async (
aggregations: {
nodes: {
composite: {
size: SNAPSHOT_COMPOSITE_REQUEST_SIZE,
size: options.overrideCompositeSize || SNAPSHOT_COMPOSITE_REQUEST_SIZE,
sources: getGroupedNodesSources(options),
},
aggs: {
Expand Down Expand Up @@ -142,7 +142,7 @@ const requestNodeMetrics = async (
aggregations: {
nodes: {
composite: {
size: SNAPSHOT_COMPOSITE_REQUEST_SIZE,
size: options.overrideCompositeSize || SNAPSHOT_COMPOSITE_REQUEST_SIZE,
sources: getMetricsSources(options),
},
aggregations: {
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/infra/server/routes/snapshot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const initSnapshotRoute = (libs: InfraBackendLibs) => {
accountId,
region,
includeTimeseries,
overrideCompositeSize,
} = pipe(
SnapshotRequestRT.decode(request.body),
fold(throwErrors(Boom.badRequest), identity)
Expand All @@ -59,6 +60,7 @@ export const initSnapshotRoute = (libs: InfraBackendLibs) => {
metrics,
timerange,
includeTimeseries,
overrideCompositeSize,
};

const searchES = <Hit = {}, Aggregation = undefined>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ const EventsViewerComponent: React.FC<Props> = ({
sourceId="default"
startDate={start}
endDate={end}
queryDeduplication="events_viewer"
>
{({
events,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ const StatefulEventsViewerComponent: React.FC<Props> = ({
}) => {
const [
{ docValueFields, browserFields, indexPatterns, isLoading: isLoadingIndexPattern },
] = useFetchIndexPatterns(defaultIndices ?? useUiSetting<string[]>(DEFAULT_INDEX_KEY));
] = useFetchIndexPatterns(
defaultIndices ?? useUiSetting<string[]>(DEFAULT_INDEX_KEY),
'events_viewer'
);

useEffect(() => {
if (createTimeline != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const mockEventViewerResponse = [
{ field: 'event.end', format: 'date_time' },
],
inspect: false,
queryDeduplication: 'events_viewer',
},
},
result: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ interface UseWithSourceState {
export const useWithSource = (
sourceId = 'default',
indexToAdd?: string[] | null,
onlyCheckIndexToAdd?: boolean
onlyCheckIndexToAdd?: boolean,
// Fun fact: When using this hook multiple times within a component (e.g. add_exception_modal & edit_exception_modal),
// the apolloClient will perform queryDeduplication and prevent the first query from executing. A deep compare is not
// performed on `indices`, so another field must be passed to circumvent this.
// For details, see https://github.com/apollographql/react-apollo/issues/2202
queryDeduplication = 'default'
) => {
const [configIndex] = useUiSetting$<string[]>(DEFAULT_INDEX_KEY);
const defaultIndex = useMemo<string[]>(() => {
Expand Down Expand Up @@ -154,12 +159,16 @@ export const useWithSource = (
setState((prevState) => ({ ...prevState, loading: true }));

try {
const result = await apolloClient.query<SourceQuery.Query, SourceQuery.Variables>({
const result = await apolloClient.query<
SourceQuery.Query,
SourceQuery.Variables & { queryDeduplication: string }
>({
query: sourceQuery,
fetchPolicy: 'network-only',
fetchPolicy: 'cache-first',
variables: {
sourceId,
defaultIndex,
queryDeduplication,
},
context: {
fetchOptions: {
Expand Down Expand Up @@ -206,7 +215,7 @@ export const useWithSource = (
isSubscribed = false;
return abortCtrl.abort();
};
}, [apolloClient, sourceId, defaultIndex]);
}, [apolloClient, sourceId, defaultIndex, queryDeduplication]);

return state;
};
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({
const [addExceptionModalState, setAddExceptionModalState] = useState<AddExceptionModalBaseProps>(
addExceptionModalInitialState
);
const [{ browserFields, indexPatterns }] = useFetchIndexPatterns(
signalsIndex !== '' ? [signalsIndex] : []
const [{ browserFields, indexPatterns, isLoading: indexPatternsLoading }] = useFetchIndexPatterns(
signalsIndex !== '' ? [signalsIndex] : [],
'alerts_table'
);
const kibana = useKibana();
const [, dispatchToaster] = useStateToaster();
Expand Down Expand Up @@ -433,7 +434,7 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({
closeAddExceptionModal,
]);

if (loading || isEmpty(signalsIndex)) {
if (loading || indexPatternsLoading || isEmpty(signalsIndex)) {
return (
<EuiPanel>
<HeaderSection title="" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ const StepAboutRuleComponent: FC<StepAboutRuleProps> = ({
const initialState = defaultValues ?? stepAboutDefaultValue;
const [myStepData, setMyStepData] = useState<AboutStepRule>(initialState);
const [{ isLoading: indexPatternLoading, indexPatterns }] = useFetchIndexPatterns(
defineRuleData?.index ?? []
defineRuleData?.index ?? [],
'step_about_rule'
);
const canUseExceptions =
defineRuleData?.ruleType &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const StepDefineRuleComponent: FC<StepDefineRuleProps> = ({
const [myStepData, setMyStepData] = useState<DefineStepRule>(initialState);
const [
{ browserFields, indexPatterns: indexPatternQueryBar, isLoading: indexPatternLoadingQueryBar },
] = useFetchIndexPatterns(myStepData.index);
] = useFetchIndexPatterns(myStepData.index, 'step_define_rule');

const { form } = useForm({
defaultValue: initialState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const useFetchIndexPatterns = (
apolloClient
.query<SourceQuery.Query, SourceQuery.Variables>({
query: sourceQuery,
fetchPolicy: 'network-only',
fetchPolicy: 'cache-first',
variables: {
sourceId: 'default',
defaultIndex: indices,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ export const TimelineComponent: React.FC<Props> = ({
filterQuery={combinedQueries!.filterQuery}
sortField={timelineQuerySortField}
startDate={start}
queryDeduplication="timeline"
>
{({
events,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface OwnProps extends QueryTemplateProps {
sortField: SortField;
fields: string[];
startDate: string;
queryDeduplication: string;
}

type TimelineQueryProps = OwnProps & PropsFromRedux & WithKibanaProps & CustomReduxProps;
Expand Down Expand Up @@ -93,6 +94,7 @@ class TimelineQueryComponent extends QueryTemplate<
sourceId,
sortField,
startDate,
queryDeduplication,
} = this.props;
const defaultKibanaIndex = kibana.services.uiSettings.get<string[]>(DEFAULT_INDEX_KEY);
const defaultIndex =
Expand All @@ -102,7 +104,11 @@ class TimelineQueryComponent extends QueryTemplate<
...(['all', 'alert', 'signal'].includes(eventType) ? indexToAdd : []),
]
: indexPattern?.title.split(',') ?? [];
const variables: GetTimelineQuery.Variables = {
// Fun fact: When using this hook multiple times within a component (e.g. add_exception_modal & edit_exception_modal),
// the apolloClient will perform queryDeduplication and prevent the first query from executing. A deep compare is not
// performed on `indices`, so another field must be passed to circumvent this.
// For details, see https://github.com/apollographql/react-apollo/issues/2202
const variables: GetTimelineQuery.Variables & { queryDeduplication: string } = {
fieldRequested: fields,
filterQuery: createFilter(filterQuery),
sourceId,
Expand All @@ -116,6 +122,7 @@ class TimelineQueryComponent extends QueryTemplate<
defaultIndex,
docValueFields: docValueFields ?? [],
inspect: isInspected,
queryDeduplication,
};

return (
Expand Down

0 comments on commit 3fdb90b

Please sign in to comment.