Skip to content

Commit

Permalink
Merge branch 'master' into alerting/created_at-and-updated_at
Browse files Browse the repository at this point in the history
* master:
  Possibility to filter when testing scripted fields (elastic#35379) (elastic#44220)
  Update maps telemetry mappings to account for recent updates (elastic#53803)
  [Maps] Only show legend when layer is visible (elastic#53781)
  remove use of experimental fs.promises api (elastic#53346)
  [APM] Add log statements for flaky test (elastic#53775)
  • Loading branch information
gmmorris committed Dec 27, 2019
2 parents 1721ec2 + 3ed5264 commit 430fe9b
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 45 deletions.
24 changes: 24 additions & 0 deletions src/core/server/uuid/fs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import Fs from 'fs';
import { promisify } from 'util';

export const readFile = promisify(Fs.readFile);
export const writeFile = promisify(Fs.writeFile);
19 changes: 5 additions & 14 deletions src/core/server/uuid/resolve_uuid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,22 @@
* under the License.
*/

import { promises } from 'fs';
import { join } from 'path';
import { readFile, writeFile } from './fs';
import { resolveInstanceUuid } from './resolve_uuid';
import { configServiceMock } from '../config/config_service.mock';
import { loggingServiceMock } from '../logging/logging_service.mock';
import { BehaviorSubject } from 'rxjs';
import { Logger } from '../logging';

const { readFile, writeFile } = promises;

jest.mock('uuid', () => ({
v4: () => 'NEW_UUID',
}));

jest.mock('fs', () => {
const actual = jest.requireActual('fs');
return {
...actual,
promises: {
...actual.promises,
readFile: jest.fn(() => Promise.resolve('')),
writeFile: jest.fn(() => Promise.resolve('')),
},
};
});
jest.mock('./fs', () => ({
readFile: jest.fn(() => Promise.resolve('')),
writeFile: jest.fn(() => Promise.resolve('')),
}));

const DEFAULT_FILE_UUID = 'FILE_UUID';
const DEFAULT_CONFIG_UUID = 'CONFIG_UUID';
Expand Down
4 changes: 1 addition & 3 deletions src/core/server/uuid/resolve_uuid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@
*/

import uuid from 'uuid';
import { promises } from 'fs';
import { join } from 'path';
import { take } from 'rxjs/operators';
import { readFile, writeFile } from './fs';
import { IConfigService } from '../config';
import { PathConfigType, config as pathConfigDef } from '../path';
import { HttpConfigType, config as httpConfigDef } from '../http';
import { Logger } from '../logging';

const { readFile, writeFile } = promises;

const FILE_ENCODING = 'utf8';
const FILE_NAME = 'uuid';

Expand Down
1 change: 1 addition & 0 deletions src/legacy/ui/public/field_editor/_index.scss
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@import './components/field_format_editor/samples/index';
@import './components/scripting_help/test_script';

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.testScript__searchBar {
.globalQueryBar {
padding: $euiSize 0 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ jest.mock('ui/documentation_links', () => ({
getDocLink: doc => `(docLink for ${doc})`,
}));

jest.mock('./test_script', () => ({
TestScript: () => {
return `<div>mockTestScript</div>`;
},
}));

const indexPatternMock = {};

describe('ScriptingHelpFlyout', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ import {
EuiCallOut,
} from '@elastic/eui';

import { npStart } from 'ui/new_platform';
const { SearchBar } = npStart.plugins.data.ui;

const { uiSettings } = npStart.core;

import { esQuery } from '../../../../../../plugins/data/public';

export class TestScript extends Component {
state = {
isLoading: false,
Expand All @@ -43,7 +50,7 @@ export class TestScript extends Component {
}
}

previewScript = async () => {
previewScript = async searchContext => {
const { indexPattern, lang, name, script, executeScript } = this.props;

if (!script || script.length === 0) {
Expand All @@ -54,11 +61,23 @@ export class TestScript extends Component {
isLoading: true,
});

let query;
if (searchContext) {
const esQueryConfigs = esQuery.getEsQueryConfig(uiSettings);
query = esQuery.buildEsQuery(
this.props.indexPattern,
searchContext.query,
null,
esQueryConfigs
);
}

const scriptResponse = await executeScript({
name,
lang,
script,
indexPatternTitle: indexPattern.title,
query,
additionalFields: this.state.additionalFields.map(option => {
return option.value;
}),
Expand Down Expand Up @@ -161,24 +180,36 @@ export class TestScript extends Component {

return (
<Fragment>
<EuiFormRow label="Additional fields">
<EuiFormRow label="Additional fields" fullWidth>
<EuiComboBox
placeholder="Select..."
options={fields}
selectedOptions={this.state.additionalFields}
onChange={this.onAdditionalFieldsChange}
data-test-subj="additionalFieldsSelect"
fullWidth
/>
</EuiFormRow>

<EuiButton
onClick={this.previewScript}
disabled={this.props.script ? false : true}
isLoading={this.state.isLoading}
data-test-subj="runScriptButton"
>
Run script
</EuiButton>
<div className="testScript__searchBar">
<SearchBar
showFilterBar={false}
showDatePicker={false}
showQueryInput={true}
query={{ language: uiSettings.get('search:queryLanguage'), query: '' }}
onQuerySubmit={this.previewScript}
indexPatterns={[this.props.indexPattern]}
customSubmitButton={
<EuiButton
disabled={this.props.script ? false : true}
isLoading={this.state.isLoading}
data-test-subj="runScriptButton"
>
Run script
</EuiButton>
}
/>
</div>
</Fragment>
);
}
Expand All @@ -191,7 +222,8 @@ export class TestScript extends Component {
<h3>Preview results</h3>
<p>
Run your script to preview the first 10 results. You can also select some additional
fields to include in your results to gain more context.
fields to include in your results to gain more context or add a query to filter on
specific documents.
</p>
</EuiText>
<EuiSpacer />
Expand Down
5 changes: 5 additions & 0 deletions src/legacy/ui/public/field_editor/lib/validate_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const executeScript = async ({
lang,
script,
indexPatternTitle,
query,
additionalFields = [],
}) => {
// Using _msearch because _search with index name in path dorks everything up
Expand Down Expand Up @@ -52,6 +53,10 @@ export const executeScript = async ({
search._source = additionalFields;
}

if (query) {
search.query = query;
}

const body = `${JSON.stringify(header)}\n${JSON.stringify(search)}\n`;
const esResp = await kfetch({ method: 'POST', pathname: '/elasticsearch/_msearch', body });
// unwrap _msearch response
Expand Down
6 changes: 3 additions & 3 deletions utilities/visual_regression.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ async function compareScreenshots() {

const diffImagePath = path.resolve(DIFF_SCREENSHOTS_DIR, screenshot);

const sessionImage = PNG.sync.read(await fs.promises.readFile(sessionImagePath));
const baselineImage = PNG.sync.read(await fs.promises.readFile(baselineImagePath));
const sessionImage = PNG.sync.read(await readFileAsync(sessionImagePath));
const baselineImage = PNG.sync.read(await readFileAsync(baselineImagePath));
const { width, height } = sessionImage;
const diff = new PNG({ width, height });

Expand All @@ -117,7 +117,7 @@ async function compareScreenshots() {
{ threshold: 0 }
);

await fs.promises.writeFile(diffImagePath, PNG.sync.write(diff));
await writeFileAsync(diffImagePath, PNG.sync.write(diff));

const change = numDiffPixels / (width * height);
const changePercentage = (change * 100).toFixed(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,19 @@ export const createAgentConfigurationRoute = createRoute(() => ({
},
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
return await createOrUpdateConfiguration({
configuration: context.params.body,
const configuration = context.params.body;

// TODO: Remove logger. Only added temporarily to debug flaky test (https://github.com/elastic/kibana/issues/51764)
context.logger.info(
`Hitting: /api/apm/settings/agent-configuration/new with ${configuration.service.name}/${configuration.service.environment}`
);
const res = await createOrUpdateConfiguration({
configuration,
setup
});
context.logger.info(`Created agent configuration`);

return res;
}
}));

Expand Down Expand Up @@ -161,8 +170,14 @@ export const agentConfigurationSearchRoute = createRoute(core => ({
})
},
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const { body } = context.params;

// TODO: Remove logger. Only added temporarily to debug flaky test (https://github.com/elastic/kibana/issues/51764)
context.logger.info(
`Hitting: /api/apm/settings/agent-configuration/search for ${body.service.name}/${body.service.environment}`
);

const setup = await setupRequest(context, request);
const config = await searchConfigurations({
serviceName: body.service.name,
environment: body.service.environment,
Expand All @@ -176,6 +191,10 @@ export const agentConfigurationSearchRoute = createRoute(core => ({
throw new Boom('Not found', { statusCode: 404 });
}

context.logger.info(
`Config was found for ${body.service.name}/${body.service.environment}`
);

// update `applied_by_agent` field if etags match
if (body.etag === config._source.etag && !config._source.applied_by_agent) {
markAppliedByAgent({ id: config._id, body: config._source, setup });
Expand Down
12 changes: 11 additions & 1 deletion x-pack/legacy/plugins/maps/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
},
"maps-telemetry": {
"properties": {
"settings": {
"properties": {
"showMapVisualizationTypes": {
"type": "boolean"
}
}
},
"indexPatternsWithGeoFieldCount": {
"type": "long"
},
"mapsTotalCount": {
"type": "long"
},
Expand Down Expand Up @@ -72,4 +82,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ export class TOCEntry extends React.Component {
};

async _loadHasLegendDetails() {
const hasLegendDetails = await this.props.layer.hasLegendDetails();
const hasLegendDetails =
(await this.props.layer.hasLegendDetails()) &&
this.props.layer.isVisible() &&
this.props.layer.showAtZoomLevel(this.props.zoom);
if (this._isMounted && hasLegendDetails !== this.state.hasLegendDetails) {
this.setState({ hasLegendDetails });
}
Expand Down
Loading

0 comments on commit 430fe9b

Please sign in to comment.