Skip to content

Commit

Permalink
Merge branch 'main' into lens_choropleth_chart
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Mar 17, 2022
2 parents dfbaf5b + f4c4fd6 commit b714030
Show file tree
Hide file tree
Showing 272 changed files with 4,498 additions and 2,472 deletions.
12 changes: 6 additions & 6 deletions src/dev/precommit_hook/casing_check_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ export const TEMPORARILY_IGNORED_PATHS = [
'x-pack/plugins/monitoring/public/icons/health-green.svg',
'x-pack/plugins/monitoring/public/icons/health-red.svg',
'x-pack/plugins/monitoring/public/icons/health-yellow.svg',
'x-pack/plugins/reporting/server/export_types/common/assets/fonts/noto/NotoSansCJKtc-Medium.ttf',
'x-pack/plugins/reporting/server/export_types/common/assets/fonts/noto/NotoSansCJKtc-Regular.ttf',
'x-pack/plugins/reporting/server/export_types/common/assets/fonts/roboto/Roboto-Italic.ttf',
'x-pack/plugins/reporting/server/export_types/common/assets/fonts/roboto/Roboto-Medium.ttf',
'x-pack/plugins/reporting/server/export_types/common/assets/fonts/roboto/Roboto-Regular.ttf',
'x-pack/plugins/reporting/server/export_types/common/assets/img/logo-grey.png',
'x-pack/plugins/screenshotting/server/formats/pdf/pdf_maker/assets/fonts/noto/NotoSansCJKtc-Medium.ttf',
'x-pack/plugins/screenshotting/server/formats/pdf/pdf_maker/assets/fonts/noto/NotoSansCJKtc-Regular.ttf',
'x-pack/plugins/screenshotting/server/formats/pdf/pdf_maker/assets/fonts/roboto/Roboto-Italic.ttf',
'x-pack/plugins/screenshotting/server/formats/pdf/pdf_maker/assets/fonts/roboto/Roboto-Medium.ttf',
'x-pack/plugins/screenshotting/server/formats/pdf/pdf_maker/assets/fonts/roboto/Roboto-Regular.ttf',
'x-pack/plugins/screenshotting/server/formats/pdf/pdf_maker/assets/img/logo-grey.png',
];
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ export const HeatmapComponent: FC<HeatmapRenderProps> = memo(
return null;
}

let chartData = table.rows.filter((v) => typeof v[valueAccessor!] === 'number');
let chartData = table.rows.filter(
(v) => v[valueAccessor!] === null || typeof v[valueAccessor!] === 'number'
);
if (!chartData || !chartData.length) {
return <EmptyPlaceholder icon={HeatmapIcon} />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ import { RouteDependencies } from '../../../';
import { Body, Query } from './validation_config';

function toURL(base: string, path: string) {
const [p, query = ''] = path.split('?');

// if there is a '+' sign in query e.g. ?q=create_date:[2020-05-10T08:00:00.000+08:00 TO *]
// node url encodes it as a whitespace which results in a faulty request
// we need to replace '+' with '%2b' to encode it correctly
if (/\+/g.test(query)) {
path = `${p}?${query.replace(/\+/g, '%2b')}`;
}
const urlResult = new url.URL(`${trimEnd(base, '/')}/${trimStart(path, '/')}`);
// Appending pretty here to have Elasticsearch do the JSON formatting, as doing
// in JS can lead to data loss (7.0 will get munged into 7, thus losing indication of
Expand Down Expand Up @@ -116,7 +124,7 @@ export const createHandler =
}: RouteDependencies): RequestHandler<unknown, Query, Body> =>
async (ctx, request, response) => {
const { body, query } = request;
const { path, method, withProductOrigin } = query;
const { method, path, withProductOrigin } = query;

if (kibanaVersion.major < 8) {
// The "console.proxyFilter" setting in kibana.yaml has been deprecated in 8.x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { createHandler } from './create_handler';

describe('Console Proxy Route', () => {
let request: (method: string, path: string) => Promise<IKibanaResponse> | IKibanaResponse;
const proxyRequestMock = requestModule.proxyRequest as jest.Mock;

beforeEach(() => {
(requestModule.proxyRequest as jest.Mock).mockResolvedValue(createResponseStub('foo'));

Expand All @@ -39,27 +41,40 @@ describe('Console Proxy Route', () => {
describe('contains full url', () => {
it('treats the url as a path', async () => {
await request('GET', 'http://evil.com/test');
expect((requestModule.proxyRequest as jest.Mock).mock.calls.length).toBe(1);
expect(proxyRequestMock.mock.calls.length).toBe(1);
const [[args]] = (requestModule.proxyRequest as jest.Mock).mock.calls;
expect(args.uri.href).toBe('http://localhost:9200/http://evil.com/test?pretty=true');
});
});
describe('starts with a slash', () => {
it('combines well with the base url', async () => {
await request('GET', '/index/id');
expect((requestModule.proxyRequest as jest.Mock).mock.calls.length).toBe(1);
expect(proxyRequestMock.mock.calls.length).toBe(1);
const [[args]] = (requestModule.proxyRequest as jest.Mock).mock.calls;
expect(args.uri.href).toBe('http://localhost:9200/index/id?pretty=true');
});
});
describe(`doesn't start with a slash`, () => {
it('combines well with the base url', async () => {
await request('GET', 'index/id');
expect((requestModule.proxyRequest as jest.Mock).mock.calls.length).toBe(1);
expect(proxyRequestMock.mock.calls.length).toBe(1);
const [[args]] = (requestModule.proxyRequest as jest.Mock).mock.calls;
expect(args.uri.href).toBe('http://localhost:9200/index/id?pretty=true');
});
});
describe('contains special characters', () => {
it('correctly encodes plus sign', async () => {
const path = '/_search?q=create_date:[2022-03-10T08:00:00.000+08:00 TO *]';

const { status } = await request('GET', path);
expect(status).toBe(200);
expect(proxyRequestMock.mock.calls.length).toBe(1);
const [[args]] = proxyRequestMock.mock.calls;
expect(args.uri.search).toEqual(
'?q=create_date%3A%5B2022-03-10T08%3A00%3A00.000%2B08%3A00+TO+*%5D&pretty=true'
);
});
});
});
});
});
17 changes: 17 additions & 0 deletions src/plugins/data/common/search/aggs/buckets/histogram.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ describe('Histogram Agg', () => {
"chain": Array [
Object {
"arguments": Object {
"autoExtendBounds": Array [
false,
],
"enabled": Array [
true,
],
Expand Down Expand Up @@ -399,6 +402,20 @@ describe('Histogram Agg', () => {
expect(output.extended_bounds).toHaveProperty('max', 100);
});

test('writes when auto bounds and autoExtendBounds are set', () => {
const aggConfigs = getAggConfigs({
autoExtendBounds: true,
field: {
name: 'field',
},
});
(aggConfigs.aggs[0] as IBucketHistogramAggConfig).setAutoBounds({ min: 0, max: 1000 });
const output = aggConfigs.aggs[0].toDsl()[BUCKET_TYPES.HISTOGRAM];

expect(output.extended_bounds).toHaveProperty('min', 0);
expect(output.extended_bounds).toHaveProperty('max', 1000);
});

test('does not write when nothing is set', () => {
const output = getParams({
has_extended_bounds: true,
Expand Down
11 changes: 11 additions & 0 deletions src/plugins/data/common/search/aggs/buckets/histogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface AggParamsHistogram extends BaseAggParams {
min_doc_count?: boolean;
has_extended_bounds?: boolean;
extended_bounds?: ExtendedBounds;
autoExtendBounds?: boolean;
}

export const getHistogramBucketAgg = ({
Expand Down Expand Up @@ -97,6 +98,14 @@ export const getHistogramBucketAgg = ({
default: null,
write: () => {},
},
{
/*
* Set to true to extend bounds to the domain of the data. This makes sure each interval bucket within these bounds will create a separate table row
*/
name: 'autoExtendBounds',
default: false,
write: () => {},
},
{
name: 'interval',
default: autoInterval,
Expand Down Expand Up @@ -202,6 +211,8 @@ export const getHistogramBucketAgg = ({

if (aggConfig.params.has_extended_bounds && (min || min === 0) && (max || max === 0)) {
output.params.extended_bounds = { min, max };
} else if (aggConfig.params.autoExtendBounds && aggConfig.getAutoBounds()) {
output.params.extended_bounds = aggConfig.getAutoBounds();
}
},
shouldShow: (aggConfig: IBucketAggConfig) => aggConfig.params.has_extended_bounds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('agg_expression_functions', () => {
"enabled": true,
"id": undefined,
"params": Object {
"autoExtendBounds": undefined,
"customLabel": undefined,
"extended_bounds": undefined,
"field": "field",
Expand All @@ -50,6 +51,7 @@ describe('agg_expression_functions', () => {
maxBars: 25,
min_doc_count: false,
has_extended_bounds: false,
autoExtendBounds: true,
extended_bounds: {
type: 'extended_bounds',
min: 1,
Expand All @@ -62,6 +64,7 @@ describe('agg_expression_functions', () => {
"enabled": true,
"id": undefined,
"params": Object {
"autoExtendBounds": true,
"customLabel": undefined,
"extended_bounds": Object {
"max": 2,
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/data/common/search/aggs/buckets/histogram_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ export const aggHistogram = (): FunctionDefinition => ({
defaultMessage: 'Calculate interval to get approximately this many bars',
}),
},
autoExtendBounds: {
types: ['boolean'],
help: i18n.translate('data.search.aggs.buckets.histogram.autoExtendBounds.help', {
defaultMessage:
'Set to true to extend bounds to the domain of the data. This makes sure each interval bucket within these bounds will create a separate table row',
}),
},
has_extended_bounds: {
types: ['boolean'],
help: i18n.translate('data.search.aggs.buckets.histogram.hasExtendedBounds.help', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type { GetStateReturn } from '../../services/discover_state';
import { AvailableFields$, DataRefetch$ } from '../../utils/use_saved_search';

export interface DataVisualizerGridEmbeddableInput extends EmbeddableInput {
indexPattern: DataView;
dataView: DataView;
savedSearch?: SavedSearch;
query?: Query;
visibleFieldNames?: string[];
Expand Down Expand Up @@ -148,7 +148,7 @@ export const FieldStatisticsTable = (props: FieldStatisticsTableProps) => {
if (embeddable && !isErrorEmbeddable(embeddable)) {
// Update embeddable whenever one of the important input changes
embeddable.updateInput({
indexPattern,
dataView: indexPattern,
savedSearch,
query,
filters,
Expand Down Expand Up @@ -194,7 +194,7 @@ export const FieldStatisticsTable = (props: FieldStatisticsTableProps) => {
// Initialize embeddable with information available at mount
const initializedEmbeddable = await factory.create({
id: 'discover_data_visualizer_grid',
indexPattern,
dataView: indexPattern,
savedSearch,
query,
showPreviewByDefault,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import expect from '@kbn/expect';
import { ExpectExpression, expectExpressionProvider } from './helpers';
import { FtrProviderContext } from '../../../functional/ftr_provider_context';

export default function ({
getService,
updateBaselines,
}: FtrProviderContext & { updateBaselines: boolean }) {
let expectExpression: ExpectExpression;

describe('esaggs number histogram tests', () => {
before(() => {
expectExpression = expectExpressionProvider({ getService, updateBaselines });
});

const timeRange = {
from: '2015-09-21T00:00:00Z',
to: '2015-09-22T00:00:00Z',
};

it('auto-extends bounds to total range', async () => {
const expression = `
kibana_context timeRange={timerange from='${timeRange.from}' to='${timeRange.to}'}
| esaggs index={indexPatternLoad id='logstash-*'}
aggs={aggTerms id="0" enabled=true schema="bucket" field="extension.raw" size=3}
aggs={aggHistogram id="1" enabled=true schema="bucket" field="bytes" interval=5000 autoExtendBounds=true min_doc_count=true}
aggs={aggCount id="2" enabled=true schema="metric"}
`;
const result = await expectExpression(
'esaggs_histogram_auto_extend',
expression
).getResponse();
expect(result.rows).to.eql([
{ 'col-0-0': 'jpg', 'col-1-1': 0, 'col-2-2': 1251 },
{ 'col-0-0': 'jpg', 'col-1-1': 5000, 'col-2-2': 1759 },
// filling in empty buckets even though the histogram wouldn't extend to those
{ 'col-0-0': 'jpg', 'col-1-1': 10000, 'col-2-2': 0 },
{ 'col-0-0': 'jpg', 'col-1-1': 15000, 'col-2-2': 0 },
{ 'col-0-0': 'css', 'col-1-1': 0, 'col-2-2': 294 },
{ 'col-0-0': 'css', 'col-1-1': 5000, 'col-2-2': 402 },
// filling in empty buckets even though the histogram wouldn't extend to those
{ 'col-0-0': 'css', 'col-1-1': 10000, 'col-2-2': 0 },
{ 'col-0-0': 'css', 'col-1-1': 15000, 'col-2-2': 0 },
{ 'col-0-0': 'png', 'col-1-1': 0, 'col-2-2': 90 },
{ 'col-0-0': 'png', 'col-1-1': 5000, 'col-2-2': 128 },
{ 'col-0-0': 'png', 'col-1-1': 10000, 'col-2-2': 126 },
{ 'col-0-0': 'png', 'col-1-1': 15000, 'col-2-2': 112 },
]);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ export default function ({ getService, getPageObjects, loadTestFile }: FtrProvid
loadTestFile(require.resolve('./esaggs_significanttext'));
loadTestFile(require.resolve('./esaggs_rareterms'));
loadTestFile(require.resolve('./esaggs_topmetrics'));
loadTestFile(require.resolve('./esaggs_histogram'));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from '../../../../common/tutorial/instructions/apm_agent_instructions';
import { AgentName } from '../../../../typings/es_schemas/ui/fields/agent';
// TODO: Uncomment once https://github.com/elastic/beats/issues/29631 has been closed
// import { JavaRuntimeAttachment } from './runtime_attachment/supported_agents/java_runtime_attachment';
import { JavaRuntimeAttachment } from './runtime_attachment/supported_agents/java_runtime_attachment';
import {
NewPackagePolicy,
PackagePolicy,
Expand Down Expand Up @@ -56,8 +56,7 @@ export const ApmAgentInstructionsMappings: Array<{
title: 'Java',
variantId: 'java',
createAgentInstructions: createJavaAgentInstructions,
// TODO: Uncomment once https://github.com/elastic/beats/issues/29631 has been closed
// AgentRuntimeAttachment: JavaRuntimeAttachment,
AgentRuntimeAttachment: JavaRuntimeAttachment,
},
{
agentName: 'rum-js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const getFakeFindings = (): CspFinding & { id: string } => ({
uid: chance.string(),
mode: chance.string(),
},
run_id: chance.string(),
cycle_id: chance.string(),
host: {} as any,
ecs: {} as any,
'@timestamp': new Date().toISOString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// TODO: this needs to be defined in a versioned schema
export interface CspFinding {
'@timestamp': string;
run_id: string;
cycle_id: string;
result: CspFindingResult;
resource: CspFindingResource;
rule: CspRule;
Expand Down
Loading

0 comments on commit b714030

Please sign in to comment.