Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/elastic/kibana into alert…
Browse files Browse the repository at this point in the history
…ing/default-es-index-schema
  • Loading branch information
ymao1 committed Apr 7, 2021
2 parents 55e75a5 + c8e23ad commit 38e5519
Show file tree
Hide file tree
Showing 56 changed files with 1,004 additions and 857 deletions.
4 changes: 2 additions & 2 deletions docs/canvas/canvas-expression-lifecycle.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ Since all of the sub-expressions are now resolved into actual values, the <<imag
demodata
| image dataurl={
if condition={getCell price | gte 100}
then={asset 3cb3ec3a-84d7-48fa-8709-274ad5cc9e0b}
else={asset cbc11a1f-8f25-4163-94b4-2c3a060192e7}
then={asset "asset-3cb3ec3a-84d7-48fa-8709-274ad5cc9e0b"}
else={asset "asset-cbc11a1f-8f25-4163-94b4-2c3a060192e7"}
}
----

Expand Down
31 changes: 31 additions & 0 deletions docs/canvas/canvas-function-reference.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,37 @@ Clears the _context_, and returns `null`.
*Returns:* `null`


[float]
[[clog_fn]]
=== `clog`

It outputs the _context_ in the console. This function is for debug purpose.

*Expression syntax*
[source,js]
----
clog
----

*Code example*
[source,text]
----
filters
| demodata
| clog
| filterrows fn={getCell "age" | gt 70}
| clog
| pointseries x="time" y="mean(price)"
| plot defaultStyle={seriesStyle lines=1 fill=1}
| render
----
This prints the `datatable` objects in the browser console before and after the `filterrows` function.

*Accepts:* `any`

*Returns:* `any`


[float]
[[columns_fn]]
=== `columns`
Expand Down
34 changes: 34 additions & 0 deletions docs/user/dashboard/timelion.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,40 @@ If the value of your parameter contains spaces or commas you have to put the val

.es(q='some query', index=logstash-*)

[float]
[[customize-data-series-y-axis]]
===== .yaxis() function

{kib} supports many y-axis scales and ranges for your data series.

The `.yaxis()` function supports the following parameters:

* *yaxis* &mdash; The numbered y-axis to plot the series on. For example, use `.yaxis(2)` to display a second y-axis.
* *min* &mdash; The minimum value for the y-axis range.
* *max* &mdash; The maximum value for the y-axis range.
* *position* &mdash; The location of the units. Values include `left` or `right`.
* *label* &mdash; The label for the axis.
* *color* &mdash; The color of the axis label.
* *units* &mdash; The function to use for formatting the y-axis labels. Values include `bits`, `bits/s`, `bytes`, `bytes/s`, `currency(:ISO 4217 currency code)`, `percent`, and `custom(:prefix:suffix)`.
* *tickDecimals* &mdash; The tick decimal precision.

Example:

[source,text]
----------------------------------
.es(index= kibana_sample_data_logs,
timefield='@timestamp',
metric='avg:bytes')
.label('Average Bytes for request')
.title('Memory consumption over time in bytes').yaxis(1,units=bytes,position=left), <1>
.es(index= kibana_sample_data_logs,
timefield='@timestamp',
metric=avg:machine.ram)
.label('Average Machine RAM amount').yaxis(2,units=bytes,position=right) <2>
----------------------------------

<1> `.yaxis(1,units=bytes,position=left)` &mdash; Specifies the first y-axis for the first data series, and changes the units on the left.
<2> `.yaxis(2,units=bytes,position=left)` &mdash; Specifies the second y-axis for the second data series, and changes the units on the right.

[float]
==== Tutorial: Create visualizations with Timelion
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@
"content-disposition": "0.5.3",
"copy-to-clipboard": "^3.0.8",
"core-js": "^3.6.5",
"css-minimizer-webpack-plugin": "^1.3.0",
"custom-event-polyfill": "^0.3.0",
"cytoscape": "^3.10.0",
"cytoscape-dagre": "^2.2.2",
Expand Down Expand Up @@ -682,6 +681,7 @@
"copy-webpack-plugin": "^6.0.2",
"cpy": "^8.1.1",
"css-loader": "^3.4.2",
"css-minimizer-webpack-plugin": "^1.3.0",
"cypress": "^6.8.0",
"cypress-cucumber-preprocessor": "^2.5.2",
"cypress-multi-reporters": "^1.4.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import LRU from 'lru-cache';
import {
IndexPatternsFetcher,
FieldDescriptor,
Expand All @@ -19,11 +18,6 @@ export interface IndexPatternTitleAndFields {
fields: FieldDescriptor[];
}

const cache = new LRU<string, IndexPatternTitleAndFields | undefined>({
max: 100,
maxAge: 1000 * 60,
});

// TODO: this is currently cached globally. In the future we might want to cache this per user
export const getDynamicIndexPattern = ({
context,
Expand All @@ -33,11 +27,6 @@ export const getDynamicIndexPattern = ({
return withApmSpan('get_dynamic_index_pattern', async () => {
const indexPatternTitle = context.config['apm_oss.indexPattern'];

const CACHE_KEY = `apm_dynamic_index_pattern_${indexPatternTitle}`;
if (cache.has(CACHE_KEY)) {
return cache.get(CACHE_KEY);
}

const indexPatternsFetcher = new IndexPatternsFetcher(
context.core.elasticsearch.client.asCurrentUser
);
Expand All @@ -57,11 +46,8 @@ export const getDynamicIndexPattern = ({
title: indexPatternTitle,
};

cache.set(CACHE_KEY, indexPattern);
return indexPattern;
} catch (e) {
// since `getDynamicIndexPattern` can be called multiple times per request it can be expensive not to cache failed lookups
cache.set(CACHE_KEY, undefined);
const notExists = e.output?.statusCode === 404;
if (notExists) {
context.logger.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const EnginesOverviewHeader: React.FC = () => {
rightSideItems={[
// eslint-disable-next-line @elastic/eui/href-or-on-click
<EuiButton
fill
size="s"
iconType="popout"
href={getAppSearchUrl()}
target="_blank"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ export const EnginesOverview: React.FC = () => {
<EuiPageContentHeaderSection>
{canManageEngines && (
<EuiButtonTo
color="primary"
fill
color="secondary"
size="s"
iconType="plusInCircle"
data-test-subj="appSearchEnginesEngineCreationButton"
to={ENGINE_CREATION_PATH}
>
Expand All @@ -108,6 +109,7 @@ export const EnginesOverview: React.FC = () => {
</EuiPageContentHeaderSection>
</EuiPageContentHeader>
<EuiPageContentBody data-test-subj="appSearchEngines">
<EuiSpacer />
<EnginesTable
items={engines}
loading={enginesLoading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const RelevanceTuningForm: React.FC = () => {
return (
<section className="relevanceTuningForm">
<form>
<EuiSpacer size="s" />
<EuiTitle size="m">
<h2>
{i18n.translate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const RelevanceTuningPreview: React.FC = () => {
const { engineName, isMetaEngine } = useValues(EngineLogic);

return (
<EuiPanel hasBorder>
<EuiPanel color="subdued">
<EuiTitle size="m">
<h2>
{i18n.translate('xpack.enterpriseSearch.appSearch.engine.relevanceTuning.preview.title', {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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.
*/

export { QueryPerformance } from './query_performance';
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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { setMockValues } from '../../../../__mocks__/kea.mock';

import React from 'react';

import { shallow } from 'enzyme';

import { EuiBadge } from '@elastic/eui';

import { QueryPerformance } from './query_performance';

describe('QueryPerformance', () => {
const values = {
queryPerformanceScore: 1,
};

beforeEach(() => {
jest.clearAllMocks();
setMockValues(values);
});

it('renders as green with the text "optimal" for a performance score of less than 6', () => {
const wrapper = shallow(<QueryPerformance />);
expect(wrapper.find(EuiBadge).prop('color')).toEqual('#59deb4');
expect(wrapper.find(EuiBadge).children().text()).toEqual('Query performance: optimal');
});

it('renders as blue with the text "good" for a performance score of less than 11', () => {
setMockValues({
queryPerformanceScore: 10,
});
const wrapper = shallow(<QueryPerformance />);
expect(wrapper.find(EuiBadge).prop('color')).toEqual('#40bfff');
expect(wrapper.find(EuiBadge).children().text()).toEqual('Query performance: good');
});

it('renders as yellow with the text "standard" for a performance score of less than 21', () => {
setMockValues({
queryPerformanceScore: 20,
});
const wrapper = shallow(<QueryPerformance />);
expect(wrapper.find(EuiBadge).prop('color')).toEqual('#fed566');
expect(wrapper.find(EuiBadge).children().text()).toEqual('Query performance: standard');
});

it('renders as red with the text "delayed" for a performance score of 21 or more', () => {
setMockValues({
queryPerformanceScore: 100,
});
const wrapper = shallow(<QueryPerformance />);
expect(wrapper.find(EuiBadge).prop('color')).toEqual('#ff9173');
expect(wrapper.find(EuiBadge).children().text()).toEqual('Query performance: delayed');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* 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 from 'react';

import { useValues } from 'kea';

import { EuiBadge } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { ResultSettingsLogic } from '../result_settings_logic';

enum QueryPerformanceRating {
Optimal = 'Optimal',
Good = 'Good',
Standard = 'Standard',
Delayed = 'Delayed',
}

const QUERY_PERFORMANCE_LABEL = (performanceValue: string) =>
i18n.translate('xpack.enterpriseSearch.appSearch.engine.resultSettings.queryPerformanceLabel', {
defaultMessage: 'Query performance: {performanceValue}',
values: {
performanceValue,
},
});

const QUERY_PERFORMANCE_OPTIMAL = i18n.translate(
'xpack.enterpriseSearch.appSearch.engine.resultSettings.queryPerformance.optimalValue',
{ defaultMessage: 'optimal' }
);

const QUERY_PERFORMANCE_GOOD = i18n.translate(
'xpack.enterpriseSearch.appSearch.engine.resultSettings.queryPerformance.goodValue',
{ defaultMessage: 'good' }
);

const QUERY_PERFORMANCE_STANDARD = i18n.translate(
'xpack.enterpriseSearch.appSearch.engine.resultSettings.queryPerformance.standardValue',
{ defaultMessage: 'standard' }
);

const QUERY_PERFORMANCE_DELAYED = i18n.translate(
'xpack.enterpriseSearch.appSearch.engine.resultSettings.queryPerformance.delayedValue',
{ defaultMessage: 'delayed' }
);

const badgeText: Record<QueryPerformanceRating, string> = {
[QueryPerformanceRating.Optimal]: QUERY_PERFORMANCE_LABEL(QUERY_PERFORMANCE_OPTIMAL),
[QueryPerformanceRating.Good]: QUERY_PERFORMANCE_LABEL(QUERY_PERFORMANCE_GOOD),
[QueryPerformanceRating.Standard]: QUERY_PERFORMANCE_LABEL(QUERY_PERFORMANCE_STANDARD),
[QueryPerformanceRating.Delayed]: QUERY_PERFORMANCE_LABEL(QUERY_PERFORMANCE_DELAYED),
};

const badgeColors: Record<QueryPerformanceRating, string> = {
[QueryPerformanceRating.Optimal]: '#59deb4',
[QueryPerformanceRating.Good]: '#40bfff',
[QueryPerformanceRating.Standard]: '#fed566',
[QueryPerformanceRating.Delayed]: '#ff9173',
};

const getPerformanceRating = (score: number) => {
switch (true) {
case score < 6:
return QueryPerformanceRating.Optimal;
case score < 11:
return QueryPerformanceRating.Good;
case score < 21:
return QueryPerformanceRating.Standard;
default:
return QueryPerformanceRating.Delayed;
}
};

export const QueryPerformance: React.FC = () => {
const { queryPerformanceScore } = useValues(ResultSettingsLogic);
const performanceRating = getPerformanceRating(queryPerformanceScore);
return (
<EuiBadge role="region" aria-live="polite" color={badgeColors[performanceRating]}>
{badgeText[performanceRating]}
</EuiBadge>
);
};
Loading

0 comments on commit 38e5519

Please sign in to comment.