Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into add-metrics-t…
Browse files Browse the repository at this point in the history
…o-node-details

* 'master' of github.com:elastic/kibana:
  Derive the port from the protocol in cases where it's not explicitly stated (elastic#83583)
  [CI] Build docker image during packer_cache (elastic#82145)
  [esaggs][inspector]: Refactor to prep for esaggs move to server. (elastic#83199)
  • Loading branch information
phillipb committed Nov 18, 2020
2 parents 913a83b + e07d6d0 commit fe54d88
Show file tree
Hide file tree
Showing 38 changed files with 663 additions and 494 deletions.
10 changes: 10 additions & 0 deletions .ci/build_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -euo pipefail

cd "$(dirname "${0}")"

cp /usr/local/bin/runbld ./
cp /usr/local/bin/bash_standard_lib.sh ./

docker build -t kibana-ci -f ./Dockerfile .
2 changes: 2 additions & 0 deletions .ci/packer_cache_for_branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ tar -cf "$HOME/.kibana/bootstrap_cache/$branch.tar" \

echo "created $HOME/.kibana/bootstrap_cache/$branch.tar"

.ci/build_docker.sh

if [[ "$branch" != "master" ]]; then
rm --preserve-root -rf "$checkoutDir"
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-embeddable-public](./kibana-plugin-plugins-embeddable-public.md) &gt; [Adapters](./kibana-plugin-plugins-embeddable-public.adapters.md) &gt; [data](./kibana-plugin-plugins-embeddable-public.adapters.data.md)

## Adapters.data property

<b>Signature:</b>

```typescript
data?: DataAdapter;
```
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@ The interface that the adapters used to open an inspector have to fullfill.
```typescript
export interface Adapters
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [data](./kibana-plugin-plugins-embeddable-public.adapters.data.md) | <code>DataAdapter</code> | |
| [requests](./kibana-plugin-plugins-embeddable-public.adapters.requests.md) | <code>RequestAdapter</code> | |

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-embeddable-public](./kibana-plugin-plugins-embeddable-public.md) &gt; [Adapters](./kibana-plugin-plugins-embeddable-public.adapters.md) &gt; [requests](./kibana-plugin-plugins-embeddable-public.adapters.requests.md)

## Adapters.requests property

<b>Signature:</b>

```typescript
requests?: RequestAdapter;
```
4 changes: 2 additions & 2 deletions src/plugins/data/common/search/aggs/agg_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface AggTypeConfig<
aggConfigs: IAggConfigs,
aggConfig: TAggConfig,
searchSource: ISearchSource,
inspectorRequestAdapter: RequestAdapter,
inspectorRequestAdapter?: RequestAdapter,
abortSignal?: AbortSignal
) => Promise<any>;
getSerializedFormat?: (agg: TAggConfig) => SerializedFieldFormat;
Expand Down Expand Up @@ -189,7 +189,7 @@ export class AggType<
aggConfigs: IAggConfigs,
aggConfig: TAggConfig,
searchSource: ISearchSource,
inspectorRequestAdapter: RequestAdapter,
inspectorRequestAdapter?: RequestAdapter,
abortSignal?: AbortSignal
) => Promise<any>;
/**
Expand Down
42 changes: 24 additions & 18 deletions src/plugins/data/common/search/aggs/buckets/terms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import { noop } from 'lodash';
import { i18n } from '@kbn/i18n';
import type { RequestAdapter } from 'src/plugins/inspector/common';

import { BucketAggType, IBucketAggConfig } from './bucket_agg_type';
import { BUCKET_TYPES } from './bucket_agg_types';
Expand Down Expand Up @@ -111,27 +112,32 @@ export const getTermsBucketAgg = () =>

nestedSearchSource.setField('aggs', filterAgg);

const request = inspectorRequestAdapter.start(
i18n.translate('data.search.aggs.buckets.terms.otherBucketTitle', {
defaultMessage: 'Other bucket',
}),
{
description: i18n.translate('data.search.aggs.buckets.terms.otherBucketDescription', {
defaultMessage:
'This request counts the number of documents that fall ' +
'outside the criterion of the data buckets.',
let request: ReturnType<RequestAdapter['start']> | undefined;
if (inspectorRequestAdapter) {
request = inspectorRequestAdapter.start(
i18n.translate('data.search.aggs.buckets.terms.otherBucketTitle', {
defaultMessage: 'Other bucket',
}),
}
);
nestedSearchSource.getSearchRequestBody().then((body) => {
request.json(body);
});
request.stats(getRequestInspectorStats(nestedSearchSource));
{
description: i18n.translate('data.search.aggs.buckets.terms.otherBucketDescription', {
defaultMessage:
'This request counts the number of documents that fall ' +
'outside the criterion of the data buckets.',
}),
}
);
nestedSearchSource.getSearchRequestBody().then((body) => {
request!.json(body);
});
request.stats(getRequestInspectorStats(nestedSearchSource));
}

const response = await nestedSearchSource.fetch({ abortSignal });
request
.stats(getResponseInspectorStats(response, nestedSearchSource))
.ok({ json: response });
if (request) {
request
.stats(getResponseInspectorStats(response, nestedSearchSource))
.ok({ json: response });
}
resp = mergeOtherBucketAggResponse(aggConfigs, resp, response, aggConfig, filterAgg());
}
if (aggConfig.params.missingBucket) {
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/data/public/autocomplete/autocomplete_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import { CoreSetup, PluginInitializerContext } from 'src/core/public';
import { TimefilterSetup } from '../query';
import { QuerySuggestionGetFn } from './providers/query_suggestion_provider';
import {
getEmptyValueSuggestions,
Expand Down Expand Up @@ -57,9 +58,9 @@ export class AutocompleteService {
private hasQuerySuggestions = (language: string) => this.querySuggestionProviders.has(language);

/** @public **/
public setup(core: CoreSetup) {
public setup(core: CoreSetup, { timefilter }: { timefilter: TimefilterSetup }) {
this.getValueSuggestions = this.autocompleteConfig.valueSuggestions.enabled
? setupValueSuggestionProvider(core)
? setupValueSuggestionProvider(core, { timefilter })
: getEmptyValueSuggestions;

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,10 @@
*/

import { stubIndexPattern, stubFields } from '../../stubs';
import { TimefilterSetup } from '../../query';
import { setupValueSuggestionProvider, ValueSuggestionsGetFn } from './value_suggestion_provider';
import { IUiSettingsClient, CoreSetup } from 'kibana/public';

jest.mock('../../services', () => ({
getQueryService: () => ({
timefilter: {
timefilter: {
createFilter: () => {
return {
time: 'fake',
};
},
getTime: () => {
return {
to: 'now',
from: 'now-15m',
};
},
},
},
}),
}));

describe('FieldSuggestions', () => {
let getValueSuggestions: ValueSuggestionsGetFn;
let http: any;
Expand All @@ -50,7 +31,23 @@ describe('FieldSuggestions', () => {
const uiSettings = { get: (key: string) => shouldSuggestValues } as IUiSettingsClient;
http = { fetch: jest.fn() };

getValueSuggestions = setupValueSuggestionProvider({ http, uiSettings } as CoreSetup);
getValueSuggestions = setupValueSuggestionProvider({ http, uiSettings } as CoreSetup, {
timefilter: ({
timefilter: {
createFilter: () => {
return {
time: 'fake',
};
},
getTime: () => {
return {
to: 'now',
from: 'now-15m',
};
},
},
} as unknown) as TimefilterSetup,
});
});

describe('with value suggestions disabled', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import dateMath from '@elastic/datemath';
import { memoize } from 'lodash';
import { CoreSetup } from 'src/core/public';
import { IIndexPattern, IFieldType, UI_SETTINGS, buildQueryFromFilters } from '../../../common';
import { getQueryService } from '../../services';
import { TimefilterSetup } from '../../query';

function resolver(title: string, field: IFieldType, query: string, filters: any[]) {
// Only cache results for a minute
Expand All @@ -40,8 +40,10 @@ interface ValueSuggestionsGetFnArgs {
signal?: AbortSignal;
}

const getAutocompleteTimefilter = (indexPattern: IIndexPattern) => {
const { timefilter } = getQueryService().timefilter;
const getAutocompleteTimefilter = (
{ timefilter }: TimefilterSetup,
indexPattern: IIndexPattern
) => {
const timeRange = timefilter.getTime();

// Use a rounded timerange so that memoizing works properly
Expand All @@ -54,7 +56,10 @@ const getAutocompleteTimefilter = (indexPattern: IIndexPattern) => {

export const getEmptyValueSuggestions = (() => Promise.resolve([])) as ValueSuggestionsGetFn;

export const setupValueSuggestionProvider = (core: CoreSetup): ValueSuggestionsGetFn => {
export const setupValueSuggestionProvider = (
core: CoreSetup,
{ timefilter }: { timefilter: TimefilterSetup }
): ValueSuggestionsGetFn => {
const requestSuggestions = memoize(
(index: string, field: IFieldType, query: string, filters: any = [], signal?: AbortSignal) =>
core.http.fetch(`/api/kibana/suggestions/values/${index}`, {
Expand Down Expand Up @@ -86,7 +91,9 @@ export const setupValueSuggestionProvider = (core: CoreSetup): ValueSuggestionsG
return [];
}

const timeFilter = useTimeRange ? getAutocompleteTimefilter(indexPattern) : undefined;
const timeFilter = useTimeRange
? getAutocompleteTimefilter(timefilter, indexPattern)
: undefined;
const filterQuery = timeFilter ? buildQueryFromFilters([timeFilter], indexPattern).filter : [];
const filters = [...(boolFilter ? boolFilter : []), ...filterQuery];
return await requestSuggestions(title, field, query, filters, signal);
Expand Down
11 changes: 0 additions & 11 deletions src/plugins/data/public/index_patterns/index_pattern.stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,9 @@
import sinon from 'sinon';

import { CoreSetup } from 'src/core/public';
import { FieldFormat as FieldFormatImpl } from '../../common/field_formats';
import { IFieldType, FieldSpec } from '../../common/index_patterns';
import { FieldFormatsStart } from '../field_formats';
import { IndexPattern, indexPatterns, KBN_FIELD_TYPES, fieldList } from '../';
import { getFieldFormatsRegistry } from '../test_utils';
import { setFieldFormats } from '../services';

setFieldFormats(({
getDefaultInstance: () =>
({
getConverterFor: () => (value: any) => value,
convert: (value: any) => JSON.stringify(value),
} as FieldFormatImpl),
} as unknown) as FieldFormatsStart);

export function getStubIndexPattern(
pattern: string,
Expand Down
24 changes: 17 additions & 7 deletions src/plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,14 @@ import {
UiSettingsPublicToCommon,
} from './index_patterns';
import {
setFieldFormats,
setIndexPatterns,
setNotifications,
setOverlays,
setQueryService,
setSearchService,
setUiSettings,
} from './services';
import { createSearchBar } from './ui/search_bar/create_search_bar';
import { esaggs } from './search/expressions';
import { getEsaggs } from './search/expressions';
import {
SELECT_RANGE_TRIGGER,
VALUE_CLICK_TRIGGER,
Expand Down Expand Up @@ -111,8 +109,22 @@ export class DataPublicPlugin
): DataPublicPluginSetup {
const startServices = createStartServicesGetter(core.getStartServices);

expressions.registerFunction(esaggs);
expressions.registerFunction(indexPatternLoad);
expressions.registerFunction(
getEsaggs({
getStartDependencies: async () => {
const [, , self] = await core.getStartServices();
const { fieldFormats, indexPatterns, query, search } = self;
return {
addFilters: query.filterManager.addFilters.bind(query.filterManager),
aggs: search.aggs,
deserializeFieldFormat: fieldFormats.deserialize.bind(fieldFormats),
indexPatterns,
searchSource: search.searchSource,
};
},
})
);

this.usageCollection = usageCollection;

Expand Down Expand Up @@ -145,7 +157,7 @@ export class DataPublicPlugin
});

return {
autocomplete: this.autocomplete.setup(core),
autocomplete: this.autocomplete.setup(core, { timefilter: queryService.timefilter }),
search: searchService,
fieldFormats: this.fieldFormatsService.setup(core),
query: queryService,
Expand All @@ -162,7 +174,6 @@ export class DataPublicPlugin
setUiSettings(uiSettings);

const fieldFormats = this.fieldFormatsService.start();
setFieldFormats(fieldFormats);

const indexPatterns = new IndexPatternsService({
uiSettings: new UiSettingsPublicToCommon(uiSettings),
Expand All @@ -186,7 +197,6 @@ export class DataPublicPlugin
savedObjectsClient: savedObjects.client,
uiSettings,
});
setQueryService(query);

const search = this.searchService.start(core, { fieldFormats, indexPatterns });
setSearchService(search);
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { EuiButtonEmptyProps } from '@elastic/eui';
import { EuiComboBoxProps } from '@elastic/eui';
import { EuiConfirmModalProps } from '@elastic/eui';
import { EuiGlobalToastListToast } from '@elastic/eui';
import { EventEmitter } from 'events';
import { ExclusiveUnion } from '@elastic/eui';
import { ExecutionContext } from 'src/plugins/expressions/common';
import { ExpressionAstFunction } from 'src/plugins/expressions/common';
Expand Down Expand Up @@ -66,7 +67,7 @@ import * as React_2 from 'react';
import { RecursiveReadonly } from '@kbn/utility-types';
import { Reporter } from '@kbn/analytics';
import { RequestAdapter } from 'src/plugins/inspector/common';
import { RequestStatistics } from 'src/plugins/inspector/common';
import { RequestStatistics as RequestStatistics_2 } from 'src/plugins/inspector/common';
import { Required } from '@kbn/utility-types';
import * as Rx from 'rxjs';
import { SavedObject } from 'src/core/server';
Expand Down
Loading

0 comments on commit fe54d88

Please sign in to comment.