Skip to content

Commit

Permalink
Merge branch '7.17' of github.com:elastic/kibana into issue-126508-op…
Browse files Browse the repository at this point in the history
…timization-for-metric-threshold-rule-7-17
  • Loading branch information
simianhacker committed Mar 2, 2022
2 parents 847a2e1 + 68a2c39 commit dcd7587
Show file tree
Hide file tree
Showing 32 changed files with 1,086 additions and 112 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@
"@types/redux-actions": "^2.6.1",
"@types/redux-logger": "^3.0.8",
"@types/seedrandom": ">=2.0.0 <4.0.0",
"@types/selenium-webdriver": "^4.0.16",
"@types/selenium-webdriver": "^4.0.18",
"@types/semver": "^7",
"@types/set-value": "^2.0.0",
"@types/sinon": "^7.0.13",
Expand Down Expand Up @@ -672,7 +672,7 @@
"callsites": "^3.1.0",
"chai": "3.5.0",
"chance": "1.0.18",
"chromedriver": "^97.0.2",
"chromedriver": "^98.0.0",
"clean-webpack-plugin": "^3.0.0",
"cmd-shim": "^2.1.0",
"compression-webpack-plugin": "^4.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-es/src/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ exports.Cluster = class Cluster {
const esArgs = [
'action.destructive_requires_name=true',
'ingest.geoip.downloader.enabled=false',
'cluster.routing.allocation.disk.threshold_enabled=false',
].concat(options.esArgs || []);

// Add to esArgs if ssl is enabled
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-es/src/integration_tests/cluster.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ describe('#start(installPath)', () => {
Array [
"action.destructive_requires_name=true",
"ingest.geoip.downloader.enabled=false",
"cluster.routing.allocation.disk.threshold_enabled=false",
],
undefined,
Object {
Expand Down Expand Up @@ -387,6 +388,7 @@ describe('#run()', () => {
Array [
"action.destructive_requires_name=true",
"ingest.geoip.downloader.enabled=false",
"cluster.routing.allocation.disk.threshold_enabled=false",
],
undefined,
Object {
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/ml/common/types/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*/

// The Annotation interface is based on annotation documents stored in the
// `.ml-annotations-6` index, accessed via the `.ml-annotations-[read|write]` aliases.
// `.ml-annotations-*` index, accessed via the `.ml-annotations-[read|write]` aliases.

// Annotation document mapping:
// PUT .ml-annotations-6
// PUT .ml-annotations-000001
// {
// "mappings": {
// "annotation": {
Expand Down Expand Up @@ -54,8 +54,8 @@
// POST /_aliases
// {
// "actions" : [
// { "add" : { "index" : ".ml-annotations-6", "alias" : ".ml-annotations-read" } },
// { "add" : { "index" : ".ml-annotations-6", "alias" : ".ml-annotations-write" } }
// { "add" : { "index" : ".ml-annotations-000001", "alias" : ".ml-annotations-read" } },
// { "add" : { "index" : ".ml-annotations-000001", "alias" : ".ml-annotations-write" } }
// ]
// }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"max_score": 0,
"hits": [
{
"_index": ".ml-annotations-6",
"_type": "doc",
"_index": ".ml-annotations-000001",
"_id": "T-CNvmgBQUJYQVn7TCPA",
"_score": 0,
"_source": {
Expand All @@ -32,8 +31,7 @@
}
},
{
"_index": ".ml-annotations-6",
"_type": "doc",
"_index": ".ml-annotations-000001",
"_id": "3lVpvmgB5xYzd3PM-MSe",
"_score": 0,
"_source": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('annotation_service', () => {

const annotationMockId = 'mockId';
const deleteParamsMock: DeleteParams = {
index: '.ml-annotations-6',
index: '.ml-annotations-000001',
id: annotationMockId,
refresh: 'wait_for',
};
Expand Down
50 changes: 28 additions & 22 deletions x-pack/plugins/ml/server/models/annotation_service/annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,31 @@ export interface DeleteParams {
}

export function annotationProvider({ asInternalUser }: IScopedClusterClient) {
// Find the index the annotation is stored in.
async function fetchAnnotationIndex(id: string) {
const searchParams: estypes.SearchRequest = {
index: ML_ANNOTATIONS_INDEX_ALIAS_READ,
size: 1,
body: {
query: {
ids: {
values: [id],
},
},
},
};

const { body } = await asInternalUser.search(searchParams);
const totalCount =
typeof body.hits.total === 'number' ? body.hits.total : body.hits.total!.value;

if (totalCount === 0) {
throw Boom.notFound(`Cannot find annotation with ID ${id}`);
}

return body.hits.hits[0]._index;
}

async function indexAnnotation(annotation: Annotation, username: string) {
if (isAnnotation(annotation) === false) {
// No need to translate, this will not be exposed in the UI.
Expand All @@ -95,6 +120,8 @@ export function annotationProvider({ asInternalUser }: IScopedClusterClient) {

if (typeof annotation._id !== 'undefined') {
params.id = annotation._id;
params.index = await fetchAnnotationIndex(annotation._id);
params.require_alias = false;
delete params.body._id;
delete params.body.key;
}
Expand Down Expand Up @@ -385,28 +412,7 @@ export function annotationProvider({ asInternalUser }: IScopedClusterClient) {
}

async function deleteAnnotation(id: string) {
// Find the index the annotation is stored in.
const searchParams: estypes.SearchRequest = {
index: ML_ANNOTATIONS_INDEX_ALIAS_READ,
size: 1,
body: {
query: {
ids: {
values: [id],
},
},
},
};

const { body } = await asInternalUser.search(searchParams);
const totalCount =
typeof body.hits.total === 'number' ? body.hits.total : body.hits.total.value;

if (totalCount === 0) {
throw Boom.notFound(`Cannot find annotation with ID ${id}`);
}

const index = body.hits.hits[0]._index;
const index = await fetchAnnotationIndex(id);

const deleteParams: DeleteParams = {
index,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const defaultReindexStatusMeta: ReindexStatusResponse['meta'] = {
aliases: [],
};

// Note: The reindexing flyout UX is subject to change; more tests should be added here once functionality is built out
describe('Reindex deprecation flyout', () => {
let testBed: ElasticsearchTestBed;
const { server, httpRequestsMockHelpers } = setupEnvironment();
Expand Down Expand Up @@ -50,6 +49,7 @@ describe('Reindex deprecation flyout', () => {
aliases: [],
},
});
httpRequestsMockHelpers.setLoadNodeDiskSpaceResponse([]);

await act(async () => {
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
Expand Down Expand Up @@ -236,4 +236,32 @@ describe('Reindex deprecation flyout', () => {
expect(find('reindexChecklistTitle').text()).toEqual('Reindexing process');
});
});

describe('low disk space', () => {
it('renders a warning callout if nodes detected with low disk space', async () => {
httpRequestsMockHelpers.setLoadNodeDiskSpaceResponse([
{
nodeId: '9OFkjpAKS_aPzJAuEOSg7w',
nodeName: 'MacBook-Pro.local',
available: '25%',
lowDiskWatermarkSetting: '50%',
},
]);

await act(async () => {
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});

testBed.component.update();
const { actions, find } = testBed;

await actions.table.clickDeprecationRowAt('reindex', 0);

expect(find('lowDiskSpaceCallout').text()).toContain('Nodes with low disk space');
expect(find('impactedNodeListItem').length).toEqual(1);
expect(find('impactedNodeListItem').at(0).text()).toContain(
'MacBook-Pro.local (25% available)'
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,17 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
]);
};

const setLoadNodeDiskSpaceResponse = (response?: object, error?: ResponseError) => {
const status = error ? error.statusCode || 400 : 200;
const body = error ? error : response;

server.respondWith('GET', `${API_BASE_PATH}/node_disk_space`, [
status,
{ 'Content-Type': 'application/json' },
JSON.stringify(body),
]);
};

const setClusterSettingsResponse = (response?: object, error?: ResponseError) => {
const status = error ? error.statusCode || 400 : 200;
const body = error ? error : response;
Expand Down Expand Up @@ -242,6 +253,7 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
setLoadMlUpgradeModeResponse,
setGetUpgradeStatusResponse,
setLoadRemoteClustersResponse,
setLoadNodeDiskSpaceResponse,
setClusterSettingsResponse,
};
};
Expand Down
Loading

0 comments on commit dcd7587

Please sign in to comment.