Skip to content

Commit

Permalink
Merge branch 'main' into chore-xorwith
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsonpl authored May 17, 2023
2 parents dacf7bf + 0eb1d0f commit 593c161
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 22 deletions.
2 changes: 1 addition & 1 deletion fleet_packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
[
{
"name": "apm",
"version": "8.9.0-preview-1684223038",
"version": "8.9.0-preview-1684289323",
"forceAlignStackVersion": true,
"allowSyncToPrerelease": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export function validate(
): { body: unknown; params: unknown; query: unknown } {
const validator = RouteValidator.from(runtimeSchema);
return {
body: validator.getBody(data.body, `get ${version} body`),
params: validator.getParams(data.params, `get ${version} params`),
query: validator.getQuery(data.query, `get ${version} query`),
params: validator.getParams(data.params, 'request params'),
query: validator.getQuery(data.query, 'request query'),
body: validator.getBody(data.body, 'request body'),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CoreSetup } from '@kbn/core/server';
import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server';
import { getTelemetry, initTelemetry, Telemetry } from './telemetry';
import { telemetryMappingsType } from './mappings';
import { setInternalRepository } from './internal_repository';
import { getInternalRepository, setInternalRepository } from './internal_repository';

export function initFileUploadTelemetry(
coreSetup: CoreSetup,
Expand All @@ -33,7 +33,7 @@ function registerUsageCollector(usageCollectionSetup: UsageCollectionSetup): voi
},
},
fetch: async () => {
const mlUsage = await getTelemetry();
const mlUsage = await getTelemetry(getInternalRepository()!);
if (!mlUsage) {
return initTelemetry();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ export function EditorFrame(props: EditorFrameProps) {
visualizationMap,
datasourceMap[activeDatasourceId],
field,
framePublicAPI.dataViews
framePublicAPI.dataViews,
true
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function getSuggestions({
activeData,
dataViews,
mainPalette,
allowMixed,
}: {
datasourceMap: DatasourceMap;
datasourceStates: DatasourceStates;
Expand All @@ -65,6 +66,7 @@ export function getSuggestions({
activeData?: Record<string, Datatable>;
dataViews: DataViewsState;
mainPalette?: PaletteOutput;
allowMixed?: boolean;
}): Suggestion[] {
const datasources = Object.entries(datasourceMap).filter(
([datasourceId]) => datasourceStates[datasourceId] && !datasourceStates[datasourceId].isLoading
Expand Down Expand Up @@ -164,7 +166,8 @@ export function getSuggestions({
subVisualizationId,
palette,
visualizeTriggerFieldContext && 'isVisualizeAction' in visualizeTriggerFieldContext,
activeData
activeData,
allowMixed
);
});
})
Expand Down Expand Up @@ -233,7 +236,8 @@ function getVisualizationSuggestions(
subVisualizationId?: string,
mainPalette?: PaletteOutput,
isFromContext?: boolean,
activeData?: Record<string, Datatable>
activeData?: Record<string, Datatable>,
allowMixed?: boolean
) {
try {
return visualization
Expand All @@ -245,6 +249,7 @@ function getVisualizationSuggestions(
mainPalette,
isFromContext,
activeData,
allowMixed,
})
.map(({ state, ...visualizationSuggestion }) => ({
...visualizationSuggestion,
Expand Down Expand Up @@ -296,7 +301,8 @@ export function getTopSuggestionForField(
visualizationMap: Record<string, Visualization<unknown>>,
datasource: Datasource,
field: DragDropIdentifier,
dataViews: DataViewsState
dataViews: DataViewsState,
allowMixed?: boolean
) {
const hasData = Object.values(datasourceLayers).some(
(datasourceLayer) => datasourceLayer && datasourceLayer.getTableSpec().length > 0
Expand All @@ -319,6 +325,7 @@ export function getTopSuggestionForField(
field,
mainPalette,
dataViews,
allowMixed,
});
return (
suggestions.find((s) => s.visualizationId === visualization.activeId) ||
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/lens/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ export interface SuggestionRequest<T = unknown> {
*/
subVisualizationId?: string;
activeData?: Record<string, Datatable>;
allowMixed?: boolean;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,69 @@ describe('xy_suggestions', () => {
]);
});

test('suggests mixed xy chart keeping original subType when switching from another x y chart with multiple layers', () => {
(generateId as jest.Mock).mockReturnValueOnce('aaa');
const suggestions = getSuggestions({
allowMixed: true,
table: {
isMultiRow: true,
columns: [numCol('bytes'), dateCol('date')],
layerId: 'first',
changeType: 'unchanged',
},
keptLayerIds: ['first', 'second'],
state: {
legend: { isVisible: true, position: 'bottom' },
valueLabels: 'hide',
preferredSeriesType: 'bar',
layers: [
{
layerId: 'first',
layerType: LayerTypes.DATA,
seriesType: 'bar',
xAccessor: 'date',
accessors: ['bytes'],
splitAccessor: undefined,
},
{
layerId: 'second',
layerType: LayerTypes.DATA,
seriesType: 'line',
xAccessor: undefined,
accessors: [],
splitAccessor: undefined,
},
],
},
});

expect(suggestions).toHaveLength(visualizationTypes.length);
expect(suggestions.map(({ state }) => xyVisualization.getVisualizationTypeId(state))).toEqual([
'line', // line + line = line
'mixed', // any other combination is mixed
'mixed',
'mixed',
'mixed',
'mixed',
'mixed',
'mixed',
'mixed',
'mixed',
]);
expect(suggestions.map(({ state }) => state.layers.map((l) => l.layerId))).toEqual([
['first', 'second'],
['first', 'second'],
['first', 'second'],
['first', 'second'],
['first', 'second'],
['first', 'second'],
['first', 'second'],
['first', 'second'],
['first', 'second'],
['first', 'second'],
]);
});

test('suggests all basic x y chart with date on x', () => {
(generateId as jest.Mock).mockReturnValueOnce('aaa');
const [suggestion, ...rest] = getSuggestions({
Expand Down
28 changes: 21 additions & 7 deletions x-pack/plugins/lens/public/visualizations/xy/xy_suggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export function getSuggestions({
subVisualizationId,
mainPalette,
isFromContext,
allowMixed,
}: SuggestionRequest<State>): Array<VisualizationSuggestion<State>> {
const incompleteTable =
!table.isMultiRow ||
Expand All @@ -79,10 +80,11 @@ export function getSuggestions({
keptLayerIds,
state,
subVisualizationId as SeriesType | undefined,
mainPalette
mainPalette,
allowMixed
);

if (suggestions && suggestions instanceof Array) {
if (Array.isArray(suggestions)) {
return suggestions;
}

Expand All @@ -94,7 +96,8 @@ function getSuggestionForColumns(
keptLayerIds: string[],
currentState?: State,
seriesType?: SeriesType,
mainPalette?: PaletteOutput
mainPalette?: PaletteOutput,
allowMixed?: boolean
): VisualizationSuggestion<State> | Array<VisualizationSuggestion<State>> | undefined {
const [buckets, values] = partition(table.columns, (col) => col.operation.isBucketed);

Expand All @@ -111,6 +114,7 @@ function getSuggestionForColumns(
keptLayerIds,
requestedSeriesType: seriesType,
mainPalette,
allowMixed,
});
} else if (buckets.length === 0) {
const [yValues, [xValue, splitBy]] = partition(
Expand All @@ -128,6 +132,7 @@ function getSuggestionForColumns(
keptLayerIds,
requestedSeriesType: seriesType,
mainPalette,
allowMixed,
});
}
}
Expand Down Expand Up @@ -214,6 +219,7 @@ function getSuggestionsForLayer({
keptLayerIds,
requestedSeriesType,
mainPalette,
allowMixed,
}: {
layerId: string;
changeType: TableChangeType;
Expand All @@ -225,6 +231,7 @@ function getSuggestionsForLayer({
keptLayerIds: string[];
requestedSeriesType?: SeriesType;
mainPalette?: PaletteOutput;
allowMixed?: boolean;
}): VisualizationSuggestion<State> | Array<VisualizationSuggestion<State>> {
const title = getSuggestionTitle(yValues, xValue, tableLabel);
const seriesType: SeriesType =
Expand All @@ -242,6 +249,7 @@ function getSuggestionsForLayer({
keptLayerIds,
// only use palette if there is a breakdown by dimension
mainPalette: splitBy ? mainPalette : undefined,
allowMixed,
};

// handles the simplest cases, acting as a chart switcher
Expand Down Expand Up @@ -473,6 +481,7 @@ function buildSuggestion({
keptLayerIds,
hide,
mainPalette,
allowMixed,
}: {
currentState: XYState | undefined;
seriesType: SeriesType;
Expand All @@ -485,6 +494,7 @@ function buildSuggestion({
keptLayerIds: string[];
hide?: boolean;
mainPalette?: PaletteOutput;
allowMixed?: boolean;
}) {
if (seriesType.includes('percentage') && xValue?.operation.scale === 'ordinal' && !splitBy) {
splitBy = xValue;
Expand Down Expand Up @@ -526,10 +536,14 @@ function buildSuggestion({
// Update in place
.map((layer) => (layer.layerId === layerId ? newLayer : layer))
// Replace the seriesType on all previous layers
.map((layer) => ({
...layer,
seriesType,
}))
.map((layer) =>
allowMixed
? layer
: {
...layer,
seriesType,
}
)
: [];

const state: State = {
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/transform/common/types/transform_stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export interface TransformStats {
percent_complete: number;
};
};
operations_behind: number;
changes_last_detected_at: number;
last_search_time?: number;
operations_behind?: number;
};
health: {
status: TransformHealth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"checkpoint": 1,
"timestamp_millis": 1564388281199
},
"operations_behind": 0
"changes_last_detected_at": 1564388281199
},
"mode": "batch",
"stats": {
Expand All @@ -61,7 +61,7 @@
"checkpoint": 1,
"timestamp_millis": 1564388281199
},
"operations_behind": 0
"changes_last_detected_at": 1564388281199
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@
},
"timestamp_millis" : 1568021396011
},
"operations_behind" : 21139495
"operations_behind" : 21139495,
"changes_last_detected_at": 1568021396000,
"last_search_time": 1568021396000
}
},
{
Expand All @@ -123,7 +125,7 @@
"checkpoint" : 1,
"timestamp_millis" : 1568021396011
},
"operations_behind" : 0
"changes_last_detected_at": 1568021396011
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ export const ExpandedRow: FC<Props> = ({ item, onAlertEdit }) => {
};

const checkpointingItems: Item[] = [];
if (item.stats.checkpointing.changes_last_detected_at !== undefined) {
checkpointingItems.push({
title: 'changes_last_detected_at',
description: formatHumanReadableDateTimeSeconds(
item.stats.checkpointing.changes_last_detected_at
),
});
}

if (item.stats.checkpointing.last !== undefined) {
checkpointingItems.push({
title: 'last.checkpoint',
Expand All @@ -157,6 +166,13 @@ export const ExpandedRow: FC<Props> = ({ item, onAlertEdit }) => {
}
}

if (item.stats.checkpointing.last_search_time !== undefined) {
checkpointingItems.push({
title: 'last_search_time',
description: formatHumanReadableDateTimeSeconds(item.stats.checkpointing.last_search_time),
});
}

if (item.stats.checkpointing.next !== undefined) {
checkpointingItems.push({
title: 'next.checkpoint',
Expand All @@ -178,6 +194,13 @@ export const ExpandedRow: FC<Props> = ({ item, onAlertEdit }) => {
}
}

if (item.stats.checkpointing.operations_behind !== undefined) {
checkpointingItems.push({
title: 'operations_behind',
description: item.stats.checkpointing.operations_behind,
});
}

const alertRuleItems: Item[] | undefined = item.alerting_rules?.map((rule) => {
return {
title: (
Expand Down

0 comments on commit 593c161

Please sign in to comment.