Skip to content

Commit

Permalink
expand fix conflicts solved
Browse files Browse the repository at this point in the history
  • Loading branch information
semd committed Aug 26, 2021
2 parents abd30d3 + b15b3ce commit 372abfe
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ describe('savedObjectsClient/decorateEsError', () => {
expect(SavedObjectsErrorHelpers.isNotFoundError(genericError)).toBe(true);
});

it('makes NotFound errors generic NotFoundEsUnavailableError errors when response is from unsupported server', () => {
const error = new esErrors.ResponseError(
// explicitly override the headers
elasticsearchClientMock.createApiResponse({ statusCode: 404, headers: {} })
);
expect(SavedObjectsErrorHelpers.isNotFoundError(error)).toBe(false);
const genericError = decorateEsError(error);
expect(genericError).not.toBe(error);
expect(SavedObjectsErrorHelpers.isNotFoundError(genericError)).toBe(false);
expect(SavedObjectsErrorHelpers.isEsUnavailableError(genericError)).toBe(true);
});

it('if saved objects index does not exist makes NotFound a SavedObjectsClient/generalError', () => {
const error = new esErrors.ResponseError(
elasticsearchClientMock.createApiResponse({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { errors as esErrors } from '@elastic/elasticsearch';
import { get } from 'lodash';
import { isSupportedEsServer } from '../../../elasticsearch';

const responseErrors = {
isServiceUnavailable: (statusCode: number) => statusCode === 503,
Expand Down Expand Up @@ -69,6 +70,11 @@ export function decorateEsError(error: EsErrors) {
if (match?.length > 0) {
return SavedObjectsErrorHelpers.decorateIndexAliasNotFoundError(error, match[1]);
}
// Throw EsUnavailable error if the 404 is not from elasticsearch
// Needed here to verify Product support for any non-ignored 404 responses from calls to ES
if (!isSupportedEsServer(error?.meta?.headers)) {
return SavedObjectsErrorHelpers.createGenericNotFoundEsUnavailableError();
}
return SavedObjectsErrorHelpers.createGenericNotFoundError();
}

Expand Down
22 changes: 7 additions & 15 deletions src/core/server/saved_objects/service/lib/repository.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2439,27 +2439,19 @@ describe('SavedObjectsRepository', () => {

it(`throws when ES is unable to find the document during delete`, async () => {
client.delete.mockResolvedValueOnce(
elasticsearchClientMock.createSuccessTransportRequestPromise(
{ result: 'not_found' },
{},
{}
)
elasticsearchClientMock.createSuccessTransportRequestPromise({ result: 'not_found' })
);
await expectNotFoundEsUnavailableError(type, id);
await expectNotFoundError(type, id);
expect(client.delete).toHaveBeenCalledTimes(1);
});

it(`throws when ES is unable to find the index during delete`, async () => {
client.delete.mockResolvedValueOnce(
elasticsearchClientMock.createSuccessTransportRequestPromise(
{
error: { type: 'index_not_found_exception' },
},
{},
{}
)
elasticsearchClientMock.createSuccessTransportRequestPromise({
error: { type: 'index_not_found_exception' },
})
);
await expectNotFoundEsUnavailableError(type, id);
await expectNotFoundError(type, id);
expect(client.delete).toHaveBeenCalledTimes(1);
});

Expand Down Expand Up @@ -3430,7 +3422,7 @@ describe('SavedObjectsRepository', () => {
client.get.mockResolvedValueOnce(
elasticsearchClientMock.createSuccessTransportRequestPromise(
{ found: false },
undefined,
{ statusCode: 404 },
{}
)
);
Expand Down
25 changes: 7 additions & 18 deletions src/core/server/saved_objects/service/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,10 @@ export class SavedObjectsRepository {
{ ignore: [404] }
);

if (isNotFoundFromUnsupportedServer({ statusCode, headers })) {
throw SavedObjectsErrorHelpers.createGenericNotFoundEsUnavailableError(type, id);
}

const deleted = body.result === 'deleted';
if (deleted) {
return {};
Expand All @@ -690,15 +694,9 @@ export class SavedObjectsRepository {
const deleteDocNotFound = body.result === 'not_found';
// @ts-expect-error @elastic/elasticsearch doesn't declare error on DeleteResponse
const deleteIndexNotFound = body.error && body.error.type === 'index_not_found_exception';
const esServerSupported = isSupportedEsServer(headers);
if (deleteDocNotFound || deleteIndexNotFound) {
if (esServerSupported) {
// see "404s from missing index" above
throw SavedObjectsErrorHelpers.createGenericNotFoundError(type, id);
} else {
// throw if we can't verify the response is from Elasticsearch
throw SavedObjectsErrorHelpers.createGenericNotFoundEsUnavailableError(type, id);
}
// see "404s from missing index" above
throw SavedObjectsErrorHelpers.createGenericNotFoundError(type, id);
}

throw new Error(
Expand Down Expand Up @@ -1084,7 +1082,7 @@ export class SavedObjectsRepository {
);
const indexNotFound = statusCode === 404;
// check if we have the elasticsearch header when index is not found and if we do, ensure it is Elasticsearch
if (!isFoundGetResponse(body) && !isSupportedEsServer(headers)) {
if (indexNotFound && !isSupportedEsServer(headers)) {
throw SavedObjectsErrorHelpers.createGenericNotFoundEsUnavailableError(type, id);
}
if (
Expand Down Expand Up @@ -1331,15 +1329,6 @@ export class SavedObjectsRepository {
_source_includes: ['namespace', 'namespaces', 'originId'],
require_alias: true,
})
.then((res) => {
const indexNotFound = res.statusCode === 404;
const esServerSupported = isSupportedEsServer(res.headers);
// check if we have the elasticsearch header when index is not found and if we do, ensure it is Elasticsearch
if (indexNotFound && !esServerSupported) {
throw SavedObjectsErrorHelpers.createGenericNotFoundEsUnavailableError(type, id);
}
return res;
})
.catch((err) => {
if (SavedObjectsErrorHelpers.isEsUnavailableError(err)) {
throw err;
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/field_formats/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,3 @@ export {
IFieldFormat,
FieldFormatsStartCommon,
} from './types';

export * from './errors';
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,26 @@ describe('EPM template', () => {
expect(template).toMatchSnapshot(path.basename(ymlPath));
});

it('tests processing long field with index false', () => {
const longWithIndexFalseYml = `
- name: longIndexFalse
type: long
index: false
`;
const longWithIndexFalseMapping = {
properties: {
longIndexFalse: {
type: 'long',
index: false,
},
},
};
const fields: Field[] = safeLoad(longWithIndexFalseYml);
const processedFields = processFields(fields);
const mappings = generateMappings(processedFields);
expect(mappings).toEqual(longWithIndexFalseMapping);
});

it('tests processing text field with multi fields', () => {
const textWithMultiFieldsLiteralYml = `
- name: textWithMultiFields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ function generateTextMapping(field: Field): IndexTemplateMapping {
function getDefaultProperties(field: Field): Properties {
const properties: Properties = {};

if (field.index) {
if (field.index !== undefined) {
properties.index = field.index;
}
if (field.doc_values) {
Expand Down
12 changes: 3 additions & 9 deletions x-pack/plugins/timelines/public/components/t_grid/body/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -652,22 +652,16 @@ export const BodyComponent = React.memo<StatefulBodyProps>(
const eventId = pageRowIndex < data.length ? data[pageRowIndex]._id : null;
const ecs = pageRowIndex < data.length ? data[pageRowIndex].ecs : null;

const defaultStyles = useMemo(
() => ({
overflow: 'hidden',
}),
[]
);
setCellProps({ style: { ...defaultStyles } });

useEffect(() => {
const defaultStyles = { overflow: 'hidden' };
setCellProps({ style: { ...defaultStyles } });
if (ecs && rowData) {
addBuildingBlockStyle(ecs, theme, setCellProps, defaultStyles);
} else {
// disable the cell when it has no data
setCellProps({ style: { display: 'none' } });
}
}, [rowIndex, setCellProps, defaultStyles, ecs, rowData]);
}, [rowIndex, setCellProps, ecs, rowData]);

if (rowData == null || header == null || eventId == null || ecs === null) {
return null;
Expand Down

0 comments on commit 372abfe

Please sign in to comment.