Skip to content

Commit

Permalink
Merge branch '7.x' into backport/7.x/pr-114940
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Oct 15, 2021
2 parents 8350343 + b25dd4e commit 085f8c7
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 31 deletions.
6 changes: 5 additions & 1 deletion .buildkite/scripts/build_kibana.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ set -euo pipefail
export KBN_NP_PLUGINS_BUILT=true

echo "--- Build Kibana Distribution"
node scripts/build --debug
if [[ "${GITHUB_PR_LABELS:-}" == *"ci:build-all-platforms"* ]]; then
node scripts/build --all-platforms --skip-os-packages
else
node scripts/build
fi

echo "--- Archive Kibana Distribution"
linuxBuild="$(find "$KIBANA_DIR/target" -name 'kibana-*-linux-x86_64.tar.gz')"
Expand Down
5 changes: 2 additions & 3 deletions .buildkite/scripts/post_build_kibana.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fi
echo "--- Upload Build Artifacts"
# Moving to `target/` first will keep `buildkite-agent` from including directories in the artifact name
cd "$KIBANA_DIR/target"
mv kibana-*-linux-x86_64.tar.gz kibana-default.tar.gz
buildkite-agent artifact upload kibana-default.tar.gz
buildkite-agent artifact upload kibana-default-plugins.tar.gz
cp kibana-*-linux-x86_64.tar.gz kibana-default.tar.gz
buildkite-agent artifact upload "./*.tar.gz;./*.zip"
cd -
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ describe('Field editor Preview panel', () => {
subTitle: 'First doc - subTitle',
title: 'First doc - title',
},
documentId: '001',
index: 'testIndex',
script: {
source: 'echo("hello")',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ export const FieldPreviewProvider: FunctionComponent = ({ children }) => {
document: params.document!,
context: `${params.type!}_field` as FieldPreviewContext,
script: params.script!,
documentId: currentDocId,
});

if (currentApiCall !== previewCount.current) {
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/index_pattern_field_editor/public/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ export const initApi = (httpClient: HttpSetup) => {
context,
script,
document,
documentId,
}: {
index: string;
context: FieldPreviewContext;
script: { source: string } | null;
document: Record<string, any>;
documentId: string;
}) => {
return sendRequest<FieldPreviewResponse>(httpClient, {
path: `${API_BASE_PATH}/field_preview`,
Expand All @@ -30,6 +32,7 @@ export const initApi = (httpClient: HttpSetup) => {
context,
script,
document,
documentId,
},
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* Side Public License, v 1.
*/

import { estypes } from '@elastic/elasticsearch';
import { schema } from '@kbn/config-schema';
import { HttpResponsePayload } from 'kibana/server';

import { API_BASE_PATH } from '../../common/constants';
import { RouteDependencies } from '../types';
Expand All @@ -26,6 +26,7 @@ const bodySchema = schema.object({
schema.literal('long_field'),
]),
document: schema.object({}, { unknowns: 'allow' }),
documentId: schema.string(),
});

export const registerFieldPreviewRoute = ({ router }: RouteDependencies): void => {
Expand All @@ -39,30 +40,41 @@ export const registerFieldPreviewRoute = ({ router }: RouteDependencies): void =
async (ctx, req, res) => {
const { client } = ctx.core.elasticsearch;

const body = JSON.stringify({
script: req.body.script,
context: req.body.context,
context_setup: {
document: req.body.document,
index: req.body.index,
} as any,
});
const type = req.body.context.split('_field')[0] as estypes.MappingRuntimeFieldType;
const body = {
runtime_mappings: {
my_runtime_field: {
type,
script: req.body.script,
},
},
size: 1,
query: {
term: {
_id: req.body.documentId,
},
},
fields: ['my_runtime_field'],
};

try {
const response = await client.asCurrentUser.scriptsPainlessExecute({
// @ts-expect-error `ExecutePainlessScriptRequest.body` does not allow `string`
const response = await client.asCurrentUser.search({
index: req.body.index,
body,
});

const fieldValue = response.body.result as any[] as HttpResponsePayload;
const fieldValue = response.body.hits.hits[0]?.fields?.my_runtime_field ?? '';

return res.ok({ body: { values: fieldValue } });
} catch (error) {
} catch (error: any) {
// Assume invalid painless script was submitted
// Return 200 with error object
const handleCustomError = () => {
return res.ok({
body: { values: [], ...error.body },
body: {
values: [],
error: error.body.error.failed_shards[0]?.reason ?? {},
},
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ import { FtrProviderContext } from '../../ftr_provider_context';
import { API_BASE_PATH } from './constants';

const INDEX_NAME = 'api-integration-test-field-preview';
const DOC_ID = '1';

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const es = getService('es');

const document = { foo: 1, bar: 'hello' };

const createIndex = async () => {
await es.indices.create({
index: INDEX_NAME,
Expand All @@ -35,19 +38,29 @@ export default function ({ getService }: FtrProviderContext) {
});
};

const addDoc = async () => {
await es.index({
index: INDEX_NAME,
id: DOC_ID,
body: document,
refresh: 'wait_for',
});
};

const deleteIndex = async () => {
await es.indices.delete({
index: INDEX_NAME,
});
};

describe('Field preview', function () {
before(async () => await createIndex());
before(async () => {
await createIndex();
await addDoc();
});
after(async () => await deleteIndex());

describe('should return the script value', () => {
const document = { foo: 1, bar: 'hello' };

const tests = [
{
context: 'keyword_field',
Expand Down Expand Up @@ -77,6 +90,7 @@ export default function ({ getService }: FtrProviderContext) {
const payload = {
script: test.script,
document,
documentId: DOC_ID,
context: test.context,
index: INDEX_NAME,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const CurationSuggestion: React.FC = () => {
result={result}
isMetaEngine={isMetaEngine}
schemaForTypeHighlights={engine.schema}
resultPosition={index + 1}
resultPosition={index + existingCurationResults.length + 1}
/>
</EuiFlexItem>
))}
Expand All @@ -152,7 +152,7 @@ export const CurationSuggestion: React.FC = () => {
result={result}
isMetaEngine={isMetaEngine}
schemaForTypeHighlights={engine.schema}
resultPosition={index + 1}
resultPosition={index + suggestedPromotedDocuments.length + 1}
/>
</EuiFlexItem>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const getFixIssuesStep = ({
<p>
<FormattedMessage
id="xpack.upgradeAssistant.overview.fixIssuesStepDescription"
defaultMessage="Update your Elasticsearch and Kibana deployments to be compatible with {nextMajor}.0. Critical issues must be resolved before you upgrade."
defaultMessage="Update your Elasticsearch and Kibana deployments to be compatible with {nextMajor}.0. Critical issues must be resolved before you upgrade. Warning issues can be ignored at your discretion."
values={{ nextMajor }}
/>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
*/

import React, { FunctionComponent } from 'react';

import { EuiFlexGroup, EuiFlexItem, EuiHealth } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { LevelInfoTip } from './level_info_tip';

const i18nTexts = {
getCriticalStatusLabel: (count: number) =>
i18n.translate('xpack.upgradeAssistant.deprecationCount.criticalStatusLabel', {
Expand Down Expand Up @@ -39,14 +40,31 @@ export const DeprecationCount: FunctionComponent<Props> = ({
return (
<EuiFlexGroup>
<EuiFlexItem grow={false}>
<EuiHealth color="danger" data-test-subj="criticalDeprecationsCount">
{i18nTexts.getCriticalStatusLabel(totalCriticalDeprecations)}
</EuiHealth>
<EuiFlexGroup gutterSize="xs" alignItems="center">
<EuiFlexItem grow={false}>
<EuiHealth color="danger" data-test-subj="criticalDeprecationsCount">
{i18nTexts.getCriticalStatusLabel(totalCriticalDeprecations)}
</EuiHealth>
</EuiFlexItem>

<EuiFlexItem>
<LevelInfoTip level="critical" />
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>

<EuiFlexItem grow={false}>
<EuiHealth color="subdued" data-test-subj="warningDeprecationsCount">
{i18nTexts.getWarningStatusLabel(totalWarningDeprecations)}
</EuiHealth>
<EuiFlexGroup gutterSize="xs" alignItems="center">
<EuiFlexItem grow={false}>
<EuiHealth color="subdued" data-test-subj="warningDeprecationsCount">
{i18nTexts.getWarningStatusLabel(totalWarningDeprecations)}
</EuiHealth>
</EuiFlexItem>

<EuiFlexItem>
<LevelInfoTip level="warning" />
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
</EuiFlexGroup>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export { NoDeprecationsPrompt } from './no_deprecations';
export { DeprecationCount } from './deprecation_count';
export { DeprecationBadge } from './deprecation_badge';
export { DeprecationsPageLoadingError } from './deprecations_page_loading_error';
export { LevelInfoTip } from './level_info_tip';
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React, { FunctionComponent } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiIconTip } from '@elastic/eui';

const i18nTexts = {
critical: i18n.translate('xpack.upgradeAssistant.levelInfoTip.criticalLabel', {
defaultMessage: 'Critical issues must be resolved before you upgrade',
}),
warning: i18n.translate('xpack.upgradeAssistant.levelInfoTip.warningLabel', {
defaultMessage: 'Warning issues can be ignored at your discretion',
}),
};

interface Props {
level: 'critical' | 'warning';
}

export const LevelInfoTip: FunctionComponent<Props> = ({ level }) => {
return <EuiIconTip content={i18nTexts[level]} position="top" type="iInCircle" />;
};

0 comments on commit 085f8c7

Please sign in to comment.