Skip to content

Commit

Permalink
Merge branch 'master' into search-session-enhanced
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Dec 3, 2020
2 parents 4ce9fef + 8ab43da commit 7537e69
Show file tree
Hide file tree
Showing 52 changed files with 3,863 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const generalSettings: RawSettingDefinition[] = [
{ text: 'critical', value: 'critical' },
{ text: 'off', value: 'off' },
],
includeAgents: ['dotnet', 'ruby', 'java'],
includeAgents: ['dotnet', 'ruby', 'java', 'python'],
},

// Recording
Expand Down Expand Up @@ -235,7 +235,7 @@ export const generalSettings: RawSettingDefinition[] = [
'Sometimes it is necessary to sanitize, i.e., remove, sensitive data sent to Elastic APM. This config accepts a list of wildcard patterns of field names which should be sanitized. These apply to HTTP headers (including cookies) and `application/x-www-form-urlencoded` data (POST form fields). The query string and the captured request body (such as `application/json` data) will not get sanitized.',
}
),
includeAgents: ['java'],
includeAgents: ['java', 'python'],
},

// Ignore transactions based on URLs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ describe('filterByAgent', () => {
'api_request_time',
'capture_body',
'capture_headers',
'log_level',
'recording',
'sanitize_field_names',
'span_frames_min_duration',
'transaction_max_spans',
'transaction_sample_rate',
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/maps/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export enum SOURCE_TYPES {
EMS_TMS = 'EMS_TMS',
EMS_FILE = 'EMS_FILE',
ES_GEO_GRID = 'ES_GEO_GRID',
ES_GEO_LINE = 'ES_GEO_LINE',
ES_SEARCH = 'ES_SEARCH',
ES_PEW_PEW = 'ES_PEW_PEW',
ES_TERM_SOURCE = 'ES_TERM_SOURCE',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ type ESGeoGridSourceSyncMeta = {
requestType: RENDER_AS;
};

export type VectorSourceSyncMeta = ESSearchSourceSyncMeta | ESGeoGridSourceSyncMeta | null;
type ESGeoLineSourceSyncMeta = {
splitField: string;
sortField: string;
};

export type VectorSourceSyncMeta =
| ESSearchSourceSyncMeta
| ESGeoGridSourceSyncMeta
| ESGeoLineSourceSyncMeta
| null;

export type VectorSourceRequestMeta = MapFilters & {
applyGlobalQuery: boolean;
Expand Down Expand Up @@ -66,12 +75,21 @@ export type ESSearchSourceResponseMeta = {
totalEntities?: number;
};

export type ESGeoLineSourceResponseMeta = {
areResultsTrimmed: boolean;
areEntitiesTrimmed: boolean;
entityCount: number;
numTrimmedTracks: number;
totalEntities: number;
};

// Partial because objects are justified downstream in constructors
export type DataMeta = Partial<
VectorSourceRequestMeta &
VectorJoinSourceRequestMeta &
VectorStyleRequestMeta &
ESSearchSourceResponseMeta
ESSearchSourceResponseMeta &
ESGeoLineSourceResponseMeta
>;

type NumericalStyleFieldData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ export type ESGeoGridSourceDescriptor = AbstractESAggSourceDescriptor & {
resolution: GRID_RESOLUTION;
};

export type ESGeoLineSourceDescriptor = AbstractESAggSourceDescriptor & {
geoField: string;
splitField: string;
sortField: string;
};

export type ESSearchSourceDescriptor = AbstractESSourceDescriptor & {
geoField: string;
filterByMapBounds?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export type LayerWizard = {
categories: LAYER_WIZARD_CATEGORY[];
checkVisibility?: () => Promise<boolean>;
description: string;
disabledReason?: string;
icon: string | FunctionComponent<any>;
getIsDisabled?: () => boolean;
prerequisiteSteps?: Array<{ id: string; label: string }>;
renderWizard(renderWizardArguments: RenderWizardArguments): ReactElement<any>;
title: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { uploadLayerWizardConfig } from './file_upload_wizard';
import { esDocumentsLayerWizardConfig } from '../sources/es_search_source';
// @ts-ignore
import { clustersLayerWizardConfig, heatmapLayerWizardConfig } from '../sources/es_geo_grid_source';
import { geoLineLayerWizardConfig } from '../sources/es_geo_line_source';
// @ts-ignore
import { point2PointLayerWizardConfig } from '../sources/es_pew_pew_source';
// @ts-ignore
Expand Down Expand Up @@ -45,6 +46,7 @@ export function registerLayerWizards() {
registerLayerWizard(clustersLayerWizardConfig);
// @ts-ignore
registerLayerWizard(heatmapLayerWizardConfig);
registerLayerWizard(geoLineLayerWizardConfig);
// @ts-ignore
registerLayerWizard(point2PointLayerWizardConfig);
// @ts-ignore
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { convertToGeoJson } from './convert_to_geojson';

const esResponse = {
aggregations: {
tracks: {
buckets: {
ios: {
doc_count: 1,
path: {
type: 'Feature',
geometry: {
type: 'LineString',
coordinates: [
[-95.339639, 41.584389],
[-95.339639, 41.0],
],
},
properties: {
complete: true,
},
},
},
osx: {
doc_count: 1,
path: {
type: 'Feature',
geometry: {
type: 'LineString',
coordinates: [
[-97.902775, 48.940572],
[-97.902775, 48.0],
],
},
properties: {
complete: false,
},
},
},
},
},
},
};

it('Should convert elasticsearch aggregation response into feature collection', () => {
const geoJson = convertToGeoJson(esResponse, 'machine.os.keyword');
expect(geoJson.numTrimmedTracks).toBe(1);
expect(geoJson.featureCollection.features.length).toBe(2);
expect(geoJson.featureCollection.features[0]).toEqual({
geometry: {
coordinates: [
[-95.339639, 41.584389],
[-95.339639, 41.0],
],
type: 'LineString',
},
id: 'ios',
properties: {
complete: true,
doc_count: 1,
['machine.os.keyword']: 'ios',
},
type: 'Feature',
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import _ from 'lodash';
import { Feature, FeatureCollection } from 'geojson';
import { extractPropertiesFromBucket } from '../../../../common/elasticsearch_util';

const KEYS_TO_IGNORE = ['key', 'path'];

export function convertToGeoJson(esResponse: any, entitySplitFieldName: string) {
const features: Feature[] = [];
let numTrimmedTracks = 0;

const buckets = _.get(esResponse, 'aggregations.tracks.buckets', {});
const entityKeys = Object.keys(buckets);
for (let i = 0; i < entityKeys.length; i++) {
const entityKey = entityKeys[i];
const bucket = buckets[entityKey];
const feature = bucket.path as Feature;
if (!feature.properties!.complete) {
numTrimmedTracks++;
}
feature.id = entityKey;
feature.properties = {
[entitySplitFieldName]: entityKey,
...feature.properties,
...extractPropertiesFromBucket(bucket, KEYS_TO_IGNORE),
};
features.push(feature);
}

return {
featureCollection: {
type: 'FeatureCollection',
features,
} as FeatureCollection,
numTrimmedTracks,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React, { Component } from 'react';

import { IndexPattern } from 'src/plugins/data/public';
import { i18n } from '@kbn/i18n';
import { EuiFormRow, EuiPanel } from '@elastic/eui';
import { SingleFieldSelect } from '../../../components/single_field_select';
import { GeoIndexPatternSelect } from '../../../components/geo_index_pattern_select';

import { getGeoPointFields } from '../../../index_pattern_util';
import { GeoLineForm } from './geo_line_form';

interface Props {
onSourceConfigChange: (
sourceConfig: {
indexPatternId: string;
geoField: string;
splitField: string;
sortField: string;
} | null
) => void;
}

interface State {
indexPattern: IndexPattern | null;
geoField: string;
splitField: string;
sortField: string;
}

export class CreateSourceEditor extends Component<Props, State> {
state: State = {
indexPattern: null,
geoField: '',
splitField: '',
sortField: '',
};

_onIndexPatternSelect = (indexPattern: IndexPattern) => {
const pointFields = getGeoPointFields(indexPattern.fields);
this.setState(
{
indexPattern,
geoField: pointFields.length ? pointFields[0].name : '',
sortField: indexPattern.timeFieldName ? indexPattern.timeFieldName : '',
},
this.previewLayer
);
};

_onGeoFieldSelect = (geoField?: string) => {
if (geoField === undefined) {
return;
}

this.setState(
{
geoField,
},
this.previewLayer
);
};

_onSplitFieldSelect = (newValue: string) => {
this.setState(
{
splitField: newValue,
},
this.previewLayer
);
};

_onSortFieldSelect = (newValue: string) => {
this.setState(
{
sortField: newValue,
},
this.previewLayer
);
};

previewLayer = () => {
const { indexPattern, geoField, splitField, sortField } = this.state;

const sourceConfig =
indexPattern && indexPattern.id && geoField && splitField && sortField
? { indexPatternId: indexPattern.id, geoField, splitField, sortField }
: null;
this.props.onSourceConfigChange(sourceConfig);
};

_renderGeoSelect() {
if (!this.state.indexPattern) {
return null;
}

return (
<EuiFormRow
label={i18n.translate('xpack.maps.source.esGeoLine.geofieldLabel', {
defaultMessage: 'Geospatial field',
})}
>
<SingleFieldSelect
placeholder={i18n.translate('xpack.maps.source.esGeoLine.geofieldPlaceholder', {
defaultMessage: 'Select geo field',
})}
value={this.state.geoField}
onChange={this._onGeoFieldSelect}
fields={getGeoPointFields(this.state.indexPattern.fields)}
/>
</EuiFormRow>
);
}

_renderGeoLineForm() {
if (!this.state.indexPattern || !this.state.geoField) {
return null;
}

return (
<GeoLineForm
indexPattern={this.state.indexPattern}
onSortFieldChange={this._onSortFieldSelect}
onSplitFieldChange={this._onSplitFieldSelect}
sortField={this.state.sortField}
splitField={this.state.splitField}
/>
);
}

render() {
return (
<EuiPanel>
<GeoIndexPatternSelect
value={
this.state.indexPattern && this.state.indexPattern.id ? this.state.indexPattern.id : ''
}
onChange={this._onIndexPatternSelect}
isGeoPointsOnly={true}
/>
{this._renderGeoSelect()}
{this._renderGeoLineForm()}
</EuiPanel>
);
}
}
Loading

0 comments on commit 7537e69

Please sign in to comment.