Skip to content

Commit

Permalink
Merge branch 'master' into a11yContextViewTests
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine committed Mar 5, 2020
2 parents 92358c8 + 4883d4b commit 325e04a
Show file tree
Hide file tree
Showing 445 changed files with 8,445 additions and 11,758 deletions.
4 changes: 0 additions & 4 deletions docs/setup/settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,6 @@ deprecation warning at startup. This setting cannot end in a slash (`/`).
proxy sitting in front of it. This determines whether HTTP compression may be used for responses, based on the request's `Referer` header.
This setting may not be used when `server.compression.enabled` is set to `false`.

[[server-cors]]`server.cors:`:: *Default: `false`* Set to `true` to enable CORS support. This setting is required to configure `server.cors.origin`.

`server.cors.origin:`:: *Default: none* Specifies origins. "origin" must be an array. To use this setting, you must set `server.cors` to `true`. To accept all origins, use `server.cors.origin: ["*"]`.

`server.customResponseHeaders:`:: *Default: `{}`* Header names and values to
send on all responses to the client from the Kibana server.

Expand Down
7 changes: 1 addition & 6 deletions examples/search_explorer/public/es_strategy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ import {
import { DoSearch } from './do_search';
import { GuideSection } from './guide_section';

// @ts-ignore
import serverPlugin from '!!raw-loader!./../../../src/plugins/data/server/search/es_search/es_search_service';
// @ts-ignore
import serverStrategy from '!!raw-loader!./../../../src/plugins/data/server/search/es_search/es_search_strategy';

Expand Down Expand Up @@ -127,10 +125,7 @@ export class EsSearchTest extends React.Component<Props, State> {
},
{
title: 'Server',
code: [
{ description: 'es_search_service.ts', snippet: serverPlugin },
{ description: 'es_search_strategy.ts', snippet: serverStrategy },
],
code: [{ description: 'es_search_strategy.ts', snippet: serverStrategy }],
},
]}
demo={this.renderDemo()}
Expand Down
78 changes: 77 additions & 1 deletion src/core/public/http/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import fetchMock from 'fetch-mock/es5/client';
import { readFileSync } from 'fs';
import { join } from 'path';
import { first } from 'rxjs/operators';

import { Fetch } from './fetch';
import { BasePath } from './base_path';
Expand All @@ -30,16 +31,91 @@ function delay<T>(duration: number) {
return new Promise<T>(r => setTimeout(r, duration));
}

const BASE_PATH = 'http://localhost/myBase';

describe('Fetch', () => {
const fetchInstance = new Fetch({
basePath: new BasePath('http://localhost/myBase'),
basePath: new BasePath(BASE_PATH),
kibanaVersion: 'VERSION',
});
afterEach(() => {
fetchMock.restore();
fetchInstance.removeAllInterceptors();
});

describe('getRequestCount$', () => {
const getCurrentRequestCount = () =>
fetchInstance
.getRequestCount$()
.pipe(first())
.toPromise();

it('should increase and decrease when request receives success response', async () => {
fetchMock.get('*', 200);

const fetchResponse = fetchInstance.fetch('/path');
expect(await getCurrentRequestCount()).toEqual(1);

await expect(fetchResponse).resolves.not.toThrow();
expect(await getCurrentRequestCount()).toEqual(0);
});

it('should increase and decrease when request receives error response', async () => {
fetchMock.get('*', 500);

const fetchResponse = fetchInstance.fetch('/path');
expect(await getCurrentRequestCount()).toEqual(1);

await expect(fetchResponse).rejects.toThrow();
expect(await getCurrentRequestCount()).toEqual(0);
});

it('should increase and decrease when request fails', async () => {
fetchMock.get('*', Promise.reject('Network!'));

const fetchResponse = fetchInstance.fetch('/path');
expect(await getCurrentRequestCount()).toEqual(1);

await expect(fetchResponse).rejects.toThrow();
expect(await getCurrentRequestCount()).toEqual(0);
});

it('should change for multiple requests', async () => {
fetchMock.get(`${BASE_PATH}/success`, 200);
fetchMock.get(`${BASE_PATH}/fail`, 400);
fetchMock.get(`${BASE_PATH}/network-fail`, Promise.reject('Network!'));

const requestCounts: number[] = [];
const subscription = fetchInstance
.getRequestCount$()
.subscribe(count => requestCounts.push(count));

const success1 = fetchInstance.fetch('/success');
const success2 = fetchInstance.fetch('/success');
const failure1 = fetchInstance.fetch('/fail');
const failure2 = fetchInstance.fetch('/fail');
const networkFailure1 = fetchInstance.fetch('/network-fail');
const success3 = fetchInstance.fetch('/success');
const failure3 = fetchInstance.fetch('/fail');
const networkFailure2 = fetchInstance.fetch('/network-fail');

const swallowError = (p: Promise<any>) => p.catch(() => {});
await Promise.all([
success1,
success2,
success3,
swallowError(failure1),
swallowError(failure2),
swallowError(failure3),
swallowError(networkFailure1),
swallowError(networkFailure2),
]);

expect(requestCounts).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0]);
subscription.unsubscribe();
});
});

describe('http requests', () => {
it('should fail with invalid arguments', async () => {
fetchMock.get('*', {});
Expand Down
9 changes: 9 additions & 0 deletions src/core/public/http/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import { merge } from 'lodash';
import { format } from 'url';
import { BehaviorSubject } from 'rxjs';

import {
IBasePath,
Expand All @@ -43,6 +44,7 @@ const NDJSON_CONTENT = /^(application\/ndjson)(;.*)?$/;

export class Fetch {
private readonly interceptors = new Set<HttpInterceptor>();
private readonly requestCount$ = new BehaviorSubject(0);

constructor(private readonly params: Params) {}

Expand All @@ -57,6 +59,10 @@ export class Fetch {
this.interceptors.clear();
}

public getRequestCount$() {
return this.requestCount$.asObservable();
}

public readonly delete = this.shorthand('DELETE');
public readonly get = this.shorthand('GET');
public readonly head = this.shorthand('HEAD');
Expand All @@ -76,6 +82,7 @@ export class Fetch {
// a halt is called we do not resolve or reject, halting handling of the promise.
return new Promise<TResponseBody | HttpResponse<TResponseBody>>(async (resolve, reject) => {
try {
this.requestCount$.next(this.requestCount$.value + 1);
const interceptedOptions = await interceptRequest(
optionsWithPath,
this.interceptors,
Expand All @@ -98,6 +105,8 @@ export class Fetch {
if (!(error instanceof HttpInterceptHaltError)) {
reject(error);
}
} finally {
this.requestCount$.next(this.requestCount$.value - 1);
}
});
};
Expand Down
13 changes: 13 additions & 0 deletions src/core/public/http/http_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { loadingServiceMock } from './http_service.test.mocks';
import { fatalErrorsServiceMock } from '../fatal_errors/fatal_errors_service.mock';
import { injectedMetadataServiceMock } from '../injected_metadata/injected_metadata_service.mock';
import { HttpService } from './http_service';
import { Observable } from 'rxjs';

describe('interceptors', () => {
afterEach(() => fetchMock.restore());
Expand Down Expand Up @@ -52,6 +53,18 @@ describe('interceptors', () => {
});
});

describe('#setup()', () => {
it('registers Fetch#getLoadingCount$() with LoadingCountSetup#addLoadingCountSource()', () => {
const injectedMetadata = injectedMetadataServiceMock.createSetupContract();
const fatalErrors = fatalErrorsServiceMock.createSetupContract();
const httpService = new HttpService();
httpService.setup({ fatalErrors, injectedMetadata });
const loadingServiceSetup = loadingServiceMock.setup.mock.results[0].value;
// We don't verify that this Observable comes from Fetch#getLoadingCount$() to avoid complex mocking
expect(loadingServiceSetup.addLoadingCountSource).toHaveBeenCalledWith(expect.any(Observable));
});
});

describe('#stop()', () => {
it('calls loadingCount.stop()', () => {
const injectedMetadata = injectedMetadataServiceMock.createSetupContract();
Expand Down
1 change: 1 addition & 0 deletions src/core/public/http/http_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class HttpService implements CoreService<HttpSetup, HttpStart> {
);
const fetchService = new Fetch({ basePath, kibanaVersion });
const loadingCount = this.loadingCount.setup({ fatalErrors });
loadingCount.addLoadingCountSource(fetchService.getRequestCount$());

this.service = {
basePath,
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export {
convertIPRangeToString,
intervalOptions, // only used in Discover
isDateHistogramBucketAggConfig,
setBounds,
isStringType,
isType,
isValidInterval,
Expand All @@ -80,6 +79,7 @@ export {
Schemas,
siblingPipelineType,
termsAggFilter,
toAbsoluteDates,
// search_source
getRequestInspectorStats,
getResponseInspectorStats,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { identity } from 'lodash';

import { AggConfig, IAggConfig } from './agg_config';
import { AggConfigs, CreateAggConfigParams } from './agg_configs';
import { AggType } from './agg_types';
import { AggType } from './agg_type';
import { AggTypesRegistryStart } from './agg_types_registry';
import { mockDataServices, mockAggTypesRegistry } from './test_helpers';
import { IndexPatternField, IndexPattern } from '../../../../../../plugins/data/public';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ export class AggConfig {
fieldIsTimeField() {
const indexPattern = this.getIndexPattern();
if (!indexPattern) return false;
// @ts-ignore
const timeFieldName = indexPattern.timeFieldName;
return timeFieldName && this.fieldName() === timeFieldName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('AggConfigs', () => {
let typesRegistry: AggTypesRegistryStart;

beforeEach(() => {
mockDataServices();
indexPattern = stubIndexPatternWithFields as IndexPattern;
typesRegistry = mockAggTypesRegistry();
});
Expand Down Expand Up @@ -296,7 +297,6 @@ describe('AggConfigs', () => {
]);

beforeEach(() => {
mockDataServices();
indexPattern = stubIndexPattern as IndexPattern;
indexPattern.fields.getByName = name => (name as unknown) as IndexPatternField;
});
Expand Down
24 changes: 0 additions & 24 deletions src/legacy/core_plugins/data/public/search/aggs/agg_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,3 @@ export const aggTypes = {
geoTileBucketAgg,
],
};

export { AggType } from './agg_type';
export { AggConfig } from './agg_config';
export { AggConfigs } from './agg_configs';
export { FieldParamType } from './param_types';
export { aggTypeFieldFilters } from './param_types/filter';
export { parentPipelineAggHelper } from './metrics/lib/parent_pipeline_agg_helper';

// static code
export { AggParamType } from './param_types/agg';
export { AggGroupNames, aggGroupNamesMap } from './agg_groups';
export { intervalOptions } from './buckets/_interval_options'; // only used in Discover
export { isDateHistogramBucketAggConfig, setBounds } from './buckets/date_histogram';
export { termsAggFilter } from './buckets/terms';
export { isType, isStringType } from './buckets/migrate_include_exclude_format';
export { CidrMask } from './buckets/lib/cidr_mask';
export { convertDateRangeToString } from './buckets/date_range';
export { convertIPRangeToString } from './buckets/ip_range';
export { aggTypeFilters, propFilter } from './filter';
export { OptionedParamType } from './param_types/optioned';
export { isValidJson, isValidInterval } from './utils';
export { BUCKET_TYPES } from './buckets/bucket_agg_types';
export { METRIC_TYPES } from './metrics/metric_agg_types';
export { ISchemas, Schema, Schemas } from './schemas';
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ import { dateHistogramBucketAgg, IBucketDateHistogramAggConfig } from '../date_h
import { BUCKET_TYPES } from '../bucket_agg_types';
import { RangeFilter } from '../../../../../../../../plugins/data/public';

// TODO: remove this once time buckets is migrated
jest.mock('ui/new_platform');

describe('AggConfig Filters', () => {
describe('date_histogram', () => {
beforeEach(() => {
Expand Down
Loading

0 comments on commit 325e04a

Please sign in to comment.