Skip to content

Commit

Permalink
Merge branch 'master' into fix-failing-test-conflict-error
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Jul 16, 2020
2 parents ef39106 + 78b39e8 commit 1b6a29f
Show file tree
Hide file tree
Showing 52 changed files with 377 additions and 228 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { get } from 'lodash';
import { i18n } from '@kbn/i18n';
import { VisResponseValue, PersistedState } from '../../../../plugins/visualizations/public';
import { ExpressionFunctionDefinition, Render } from '../../../../plugins/expressions/public';
import { getTypes, getIndexPatterns, getFilterManager } from '../services';
import { getTypes, getIndexPatterns, getFilterManager, getSearch } from '../services';

interface Arguments {
index?: string | null;
Expand All @@ -31,6 +31,7 @@ interface Arguments {
schemas?: string;
visConfig?: string;
uiState?: string;
aggConfigs?: string;
}

export type ExpressionFunctionVisualization = ExpressionFunctionDefinition<
Expand Down Expand Up @@ -84,6 +85,11 @@ export const visualization = (): ExpressionFunctionVisualization => ({
default: '"{}"',
help: 'User interface state',
},
aggConfigs: {
types: ['string'],
default: '"{}"',
help: 'Aggregation configurations',
},
},
async fn(input, args, { inspectorAdapters }) {
const visConfigParams = args.visConfig ? JSON.parse(args.visConfig) : {};
Expand All @@ -94,6 +100,11 @@ export const visualization = (): ExpressionFunctionVisualization => ({
const uiStateParams = args.uiState ? JSON.parse(args.uiState) : {};
const uiState = new PersistedState(uiStateParams);

const aggConfigsState = args.aggConfigs ? JSON.parse(args.aggConfigs) : [];
const aggs = indexPattern
? getSearch().aggs.createAggConfigs(indexPattern, aggConfigsState)
: undefined;

if (typeof visType.requestHandler === 'function') {
input = await visType.requestHandler({
partialRows: args.partialRows,
Expand All @@ -107,6 +118,7 @@ export const visualization = (): ExpressionFunctionVisualization => ({
inspectorAdapters,
queryFilter: getFilterManager(),
forceFetch: true,
aggs,
});
}

Expand Down
5 changes: 4 additions & 1 deletion src/plugins/visualizations/public/legacy/build_pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,10 @@ export const buildPipeline = async (
metricsAtAllLevels=${vis.isHierarchical()}
partialRows=${vis.type.requiresPartialRows || vis.params.showPartialRows || false} `;
if (indexPattern) {
pipeline += `${prepareString('index', indexPattern.id)}`;
pipeline += `${prepareString('index', indexPattern.id)} `;
if (vis.data.aggs) {
pipeline += `${prepareJson('aggConfigs', vis.data.aggs!.aggs)}`;
}
}
}

Expand Down
20 changes: 12 additions & 8 deletions x-pack/plugins/ingest_manager/common/services/agent_status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import {
AGENT_POLLING_THRESHOLD_MS,
AGENT_TYPE_PERMANENT,
AGENT_SAVED_OBJECT_TYPE,
} from '../constants';
import { AGENT_POLLING_THRESHOLD_MS, AGENT_SAVED_OBJECT_TYPE } from '../constants';
import { Agent, AgentStatus } from '../types';

export function getAgentStatus(agent: Agent, now: number = Date.now()): AgentStatus {
Expand Down Expand Up @@ -41,16 +37,24 @@ export function getAgentStatus(agent: Agent, now: number = Date.now()): AgentSta
return 'online';
}

export function buildKueryForEnrollingAgents() {
return `not ${AGENT_SAVED_OBJECT_TYPE}.last_checkin:*`;
}

export function buildKueryForUnenrollingAgents() {
return `${AGENT_SAVED_OBJECT_TYPE}.unenrollment_started_at:*`;
}

export function buildKueryForOnlineAgents() {
return `not (${buildKueryForOfflineAgents()}) AND not (${buildKueryForErrorAgents()})`;
return `not (${buildKueryForOfflineAgents()}) AND not (${buildKueryForErrorAgents()}) AND not (${buildKueryForEnrollingAgents()}) AND not (${buildKueryForUnenrollingAgents()})`;
}

export function buildKueryForErrorAgents() {
return `( ${AGENT_SAVED_OBJECT_TYPE}.last_checkin_status:error or ${AGENT_SAVED_OBJECT_TYPE}.last_checkin_status:degraded )`;
}

export function buildKueryForOfflineAgents() {
return `((${AGENT_SAVED_OBJECT_TYPE}.type:${AGENT_TYPE_PERMANENT} AND ${AGENT_SAVED_OBJECT_TYPE}.last_checkin < now-${
return `${AGENT_SAVED_OBJECT_TYPE}.last_checkin < now-${
(4 * AGENT_POLLING_THRESHOLD_MS) / 1000
}s) AND not ( ${buildKueryForErrorAgents()} ))`;
}s AND not (${buildKueryForErrorAgents()})`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,6 @@ export interface GetAgentStatusResponse {
online: number;
error: number;
offline: number;
other: number;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const DonutChart = ({ height, width, data }: DonutChartProps) => {
.ordinal()
// @ts-ignore
.domain(data)
.range(['#017D73', '#98A2B3', '#BD271E']);
.range(['#017D73', '#98A2B3', '#BD271E', '#F5A700']);
const pieGenerator = d3.layout
.pie()
.value(({ value }: any) => value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const ListLayout: React.FunctionComponent<{}> = ({ children }) => {
online: agentStatus?.online || 0,
offline: agentStatus?.offline || 0,
error: agentStatus?.error || 0,
other: agentStatus?.other || 0,
}}
/>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ export async function getAgentStatusForConfig(
soClient: SavedObjectsClientContract,
configId?: string
) {
const [all, error, offline] = await Promise.all(
const [all, online, error, offline] = await Promise.all(
[
undefined,
AgentStatusKueryHelper.buildKueryForOnlineAgents(),
AgentStatusKueryHelper.buildKueryForErrorAgents(),
AgentStatusKueryHelper.buildKueryForOfflineAgents(),
].map((kuery) =>
Expand All @@ -47,9 +48,10 @@ export async function getAgentStatusForConfig(
return {
events: await getEventsCount(soClient, configId),
total: all.total,
online: all.total - error.total - offline.total,
online: online.total,
error: error.total,
offline: offline.total,
other: all.total - online.total - error.total - offline.total,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ export type DataMeta = Partial<VectorSourceRequestMeta> &
Partial<VectorStyleRequestMeta> &
Partial<ESSearchSourceResponseMeta>;

type NumericalStyleFieldData = {
avg: number;
max: number;
min: number;
std_deviation: number;
};

type CategoricalStyleFieldData = {
buckets: Array<{ key: string; doc_count: number }>;
};

export type StyleMetaData = {
// key is field name for field requiring style meta
[key: string]: NumericalStyleFieldData | CategoricalStyleFieldData;
};

export type DataRequestDescriptor = {
dataId: string;
dataMetaAtStart?: DataMeta | null;
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/maps/public/classes/joins/inner_join.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ export class InnerJoin implements IJoin {
getRightJoinSource(): IESTermSource;

toDescriptor(): JoinDescriptor;

getSourceMetaDataRequestId(): string;
}
2 changes: 2 additions & 0 deletions x-pack/plugins/maps/public/classes/joins/join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ export interface IJoin {
getRightJoinSource(): IESTermSource;

toDescriptor(): JoinDescriptor;

getSourceMetaDataRequestId(): string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
VectorStyleDescriptor,
SizeDynamicOptions,
DynamicStylePropertyOptions,
StylePropertyOptions,
VectorLayerDescriptor,
} from '../../../../common/descriptor_types';
import { IStyle } from '../../styles/style';
Expand All @@ -44,7 +45,7 @@ interface CountData {
isSyncClustered: boolean;
}

function getAggType(dynamicProperty: IDynamicStyleProperty): AGG_TYPE {
function getAggType(dynamicProperty: IDynamicStyleProperty<DynamicStylePropertyOptions>): AGG_TYPE {
return dynamicProperty.isOrdinal() ? AGG_TYPE.AVG : AGG_TYPE.TERMS;
}

Expand Down Expand Up @@ -100,52 +101,57 @@ function getClusterStyleDescriptor(
},
},
};
documentStyle.getAllStyleProperties().forEach((styleProperty: IStyleProperty) => {
const styleName = styleProperty.getStyleName();
if (
[VECTOR_STYLES.LABEL_TEXT, VECTOR_STYLES.ICON_SIZE].includes(styleName) &&
(!styleProperty.isDynamic() || !styleProperty.isComplete())
) {
// Do not migrate static label and icon size properties to provide unique cluster styling out of the box
return;
}
documentStyle
.getAllStyleProperties()
.forEach((styleProperty: IStyleProperty<StylePropertyOptions>) => {
const styleName = styleProperty.getStyleName();
if (
[VECTOR_STYLES.LABEL_TEXT, VECTOR_STYLES.ICON_SIZE].includes(styleName) &&
(!styleProperty.isDynamic() || !styleProperty.isComplete())
) {
// Do not migrate static label and icon size properties to provide unique cluster styling out of the box
return;
}

if (styleName === VECTOR_STYLES.SYMBOLIZE_AS || styleName === VECTOR_STYLES.LABEL_BORDER_SIZE) {
// copy none static/dynamic styles to cluster style
clusterStyleDescriptor.properties[styleName] = {
if (
styleName === VECTOR_STYLES.SYMBOLIZE_AS ||
styleName === VECTOR_STYLES.LABEL_BORDER_SIZE
) {
// copy none static/dynamic styles to cluster style
clusterStyleDescriptor.properties[styleName] = {
// @ts-expect-error
options: { ...styleProperty.getOptions() },
};
} else if (styleProperty.isDynamic()) {
// copy dynamic styles to cluster style
const options = styleProperty.getOptions() as DynamicStylePropertyOptions;
const field =
options && options.field && options.field.name
? {
...options.field,
name: clusterSource.getAggKey(
getAggType(styleProperty as IDynamicStyleProperty<DynamicStylePropertyOptions>),
options.field.name
),
}
: undefined;
// @ts-expect-error
options: { ...styleProperty.getOptions() },
};
} else if (styleProperty.isDynamic()) {
// copy dynamic styles to cluster style
const options = styleProperty.getOptions() as DynamicStylePropertyOptions;
const field =
options && options.field && options.field.name
? {
...options.field,
name: clusterSource.getAggKey(
getAggType(styleProperty as IDynamicStyleProperty),
options.field.name
),
}
: undefined;
// @ts-expect-error
clusterStyleDescriptor.properties[styleName] = {
type: STYLE_TYPE.DYNAMIC,
options: {
...options,
field,
},
};
} else {
// copy static styles to cluster style
// @ts-expect-error
clusterStyleDescriptor.properties[styleName] = {
type: STYLE_TYPE.STATIC,
options: { ...styleProperty.getOptions() },
};
}
});
clusterStyleDescriptor.properties[styleName] = {
type: STYLE_TYPE.DYNAMIC,
options: {
...options,
field,
},
};
} else {
// copy static styles to cluster style
// @ts-expect-error
clusterStyleDescriptor.properties[styleName] = {
type: STYLE_TYPE.STATIC,
options: { ...styleProperty.getOptions() },
};
}
});

return clusterStyleDescriptor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface IESAggSource extends IESSource {
getAggKey(aggType: AGG_TYPE, fieldName: string): string;
getAggLabel(aggType: AGG_TYPE, fieldName: string): string;
getMetricFields(): IESAggField[];
hasMatchingMetricField(fieldName: string): boolean;
}

export class AbstractESAggSource extends AbstractESSource implements IESAggSource {
Expand All @@ -22,4 +23,5 @@ export class AbstractESAggSource extends AbstractESSource implements IESAggSourc
getAggKey(aggType: AGG_TYPE, fieldName: string): string;
getAggLabel(aggType: AGG_TYPE, fieldName: string): string;
getMetricFields(): IESAggField[];
hasMatchingMetricField(fieldName: string): boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import { AbstractVectorSource } from '../vector_source';
import { IVectorSource } from '../vector_source';
import { IndexPattern, ISearchSource } from '../../../../../../../src/plugins/data/public';
import { VectorSourceRequestMeta } from '../../../../common/descriptor_types';
import {
DynamicStylePropertyOptions,
VectorSourceRequestMeta,
} from '../../../../common/descriptor_types';
import { VectorStyle } from '../../styles/vector/vector_style';
import { IDynamicStyleProperty } from '../../styles/vector/properties/dynamic_style_property';

Expand All @@ -25,7 +28,7 @@ export interface IESSource extends IVectorSource {
loadStylePropsMeta(
layerName: string,
style: VectorStyle,
dynamicStyleProps: IDynamicStyleProperty[],
dynamicStyleProps: Array<IDynamicStyleProperty<DynamicStylePropertyOptions>>,
registerCancelCallback: (requestToken: symbol, callback: () => void) => void,
searchFilters: VectorSourceRequestMeta
): Promise<unknown>;
Expand All @@ -45,7 +48,7 @@ export class AbstractESSource extends AbstractVectorSource implements IESSource
loadStylePropsMeta(
layerName: string,
style: VectorStyle,
dynamicStyleProps: IDynamicStyleProperty[],
dynamicStyleProps: Array<IDynamicStyleProperty<DynamicStylePropertyOptions>>,
registerCancelCallback: (requestToken: symbol, callback: () => void) => void,
searchFilters: VectorSourceRequestMeta
): Promise<unknown>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ import React from 'react';
import { EuiFormRow, EuiSwitch, EuiSwitchEvent } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FieldMetaPopover } from './field_meta_popover';
import { IDynamicStyleProperty } from '../../properties/dynamic_style_property';
import { FieldMetaOptions } from '../../../../../../common/descriptor_types';

type Props = {
styleProperty: IDynamicStyleProperty;
fieldMetaOptions: FieldMetaOptions;
onChange: (fieldMetaOptions: FieldMetaOptions) => void;
};

export function CategoricalFieldMetaPopover(props: Props) {
const onIsEnabledChange = (event: EuiSwitchEvent) => {
props.onChange({
...props.styleProperty.getFieldMetaOptions(),
...props.fieldMetaOptions,
isEnabled: event.target.checked,
});
};
Expand All @@ -32,7 +31,7 @@ export function CategoricalFieldMetaPopover(props: Props) {
label={i18n.translate('xpack.maps.styles.fieldMetaOptions.isEnabled.categoricalLabel', {
defaultMessage: 'Get categories from indices',
})}
checked={props.styleProperty.getFieldMetaOptions().isEnabled}
checked={props.fieldMetaOptions.isEnabled}
onChange={onIsEnabledChange}
compressed
/>
Expand Down
Loading

0 comments on commit 1b6a29f

Please sign in to comment.