Skip to content

Commit f443d8a

Browse files
authored
[SIEM] Fixes FTUE when APM node is present (#56574)
## Summary This PR resolves #56363 found in `7.6 BC4`, where configuring a cloud instance with an APM node would circumvent our FTUE checks and would show the Overview Page when no data is present. As detailed in the above issue, this resolves the problem by performing a similar check as to what APM performs to determine their `empty data` state. As can be observed in the gifs below, this check adds additional latency to the full-app flicker, which is not ideal... Perhaps we can tweak the query further to improve this? #### Deployment w/o APM node: ![ftue_no_apm](https://user-images.githubusercontent.com/2946766/73584819-a7212700-4458-11ea-9df8-f600fd6b1434.gif) #### Deployment w/ APM node: ![ftue_with_apm](https://user-images.githubusercontent.com/2946766/73584817-a38da000-4458-11ea-824c-c42924c58fa0.gif) ### Checklist Use ~~strikethroughs~~ to remove checklist items you don't feel are applicable to this PR. - [ ] ~This was checked for cross-browser compatibility, [including a check against IE11](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility)~ - [ ] ~Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/README.md)~ - [ ] ~[Documentation](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#writing-documentation) was added for features that require explanation or tutorials~ - [ ] ~[Unit or functional tests](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) were updated or added to match the most common scenarios~ - [ ] ~This was checked for [keyboard-only and screenreader accessibility](https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Accessibility#Accessibility_testing_checklist)~ ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process) - [ ] This includes a feature addition or change that requires a release note and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process)
1 parent ebb2989 commit f443d8a

File tree

3 files changed

+83
-17
lines changed

3 files changed

+83
-17
lines changed

x-pack/legacy/plugins/siem/server/lib/source_status/elasticsearch_adapter.ts

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,54 @@
66

77
import { FrameworkAdapter, FrameworkRequest } from '../framework';
88
import { SourceStatusAdapter } from './index';
9+
import { buildQuery } from './query.dsl';
10+
import { ApmServiceNameAgg } from './types';
11+
12+
const APM_INDEX_NAME = 'apm-*-transaction*';
913

1014
export class ElasticsearchSourceStatusAdapter implements SourceStatusAdapter {
1115
constructor(private readonly framework: FrameworkAdapter) {}
1216

13-
public async hasIndices(request: FrameworkRequest, indexNames: string | string[]) {
14-
return this.framework
15-
.callWithRequest(request, 'search', {
16-
index: indexNames,
17-
size: 0,
18-
terminate_after: 1,
19-
allow_no_indices: true,
20-
})
21-
.then(
22-
response => response._shards.total > 0,
23-
err => {
24-
if (err.status === 404) {
25-
return false;
26-
}
27-
throw err;
28-
}
29-
);
17+
public async hasIndices(request: FrameworkRequest, indexNames: string[]) {
18+
// Intended flow to determine app-empty state is to first check siem indices (as this is a quick shard count), and
19+
// if no shards exist only then perform the heavier APM query. This optimizes for normal use when siem data exists
20+
try {
21+
// Remove APM index if exists, and only query if length > 0 in case it's the only index provided
22+
const nonApmIndexNames = indexNames.filter(name => name !== APM_INDEX_NAME);
23+
const indexCheckResponse = await (nonApmIndexNames.length > 0
24+
? this.framework.callWithRequest(request, 'search', {
25+
index: nonApmIndexNames,
26+
size: 0,
27+
terminate_after: 1,
28+
allow_no_indices: true,
29+
})
30+
: Promise.resolve(undefined));
31+
32+
if ((indexCheckResponse?._shards.total ?? -1) > 0) {
33+
return true;
34+
}
35+
36+
// Note: Additional check necessary for APM-specific index. For details see: https://github.com/elastic/kibana/issues/56363
37+
// Only verify if APM data exists if indexNames includes `apm-*-transaction*` (default included apm index)
38+
const includesApmIndex = indexNames.includes(APM_INDEX_NAME);
39+
const hasApmDataResponse = await (includesApmIndex
40+
? this.framework.callWithRequest<{}, ApmServiceNameAgg>(
41+
request,
42+
'search',
43+
buildQuery({ defaultIndex: [APM_INDEX_NAME] })
44+
)
45+
: Promise.resolve(undefined));
46+
47+
if ((hasApmDataResponse?.aggregations?.total_service_names?.value ?? -1) > 0) {
48+
return true;
49+
}
50+
} catch (e) {
51+
if (e.status === 404) {
52+
return false;
53+
}
54+
throw e;
55+
}
56+
57+
return false;
3058
}
3159
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
const SERVICE_NAME = 'service.name';
8+
9+
export const buildQuery = ({ defaultIndex }: { defaultIndex: string[] }) => {
10+
return {
11+
allowNoIndices: true,
12+
index: defaultIndex,
13+
ignoreUnavailable: true,
14+
terminate_after: 1,
15+
body: {
16+
size: 0,
17+
aggs: {
18+
total_service_names: {
19+
cardinality: {
20+
field: SERVICE_NAME,
21+
},
22+
},
23+
},
24+
},
25+
track_total_hits: false,
26+
};
27+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export interface ApmServiceNameAgg {
8+
total_service_names: {
9+
value: number;
10+
};
11+
}

0 commit comments

Comments
 (0)