Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*/

export * from './converters/raw_color_mappings';
export { trackRuntimeMigration } from './telemetry';
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { trackUiCounterEvents } from '../lens_ui_telemetry';

const events = {
rawColorMappings: 'raw_color_mappings',
legendStats: 'legend_stats',
metric: 'metric_refactor',
};

type ChartTypes = 'xy' | 'tagcloud' | 'partition' | 'metric' | 'datatable';

/**
* Track runtime migration events
*
* @param event
* @param chartType - optional event qualifier
*/
export function trackRuntimeMigration(event: 'metric'): void;
export function trackRuntimeMigration(
event: 'legendStats',
chartType?: Extract<ChartTypes, 'xy' | 'partition'>
): void;
export function trackRuntimeMigration(
event: 'rawColorMappings',
chartType?: Extract<ChartTypes, 'xy' | 'tagcloud' | 'partition' | 'datatable'>
): void;
export function trackRuntimeMigration(event: keyof typeof events, chartType?: ChartTypes): void {
trackUiCounterEvents(`runtime_migrations_${events[event]}${chartType ? `_${chartType}` : ''}`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import type { ColumnState } from '../../../../../common/expressions';
import { trackRuntimeMigration } from '../../../../runtime_state';
import type { DeprecatedColorMappingConfig } from '../../../../runtime_state/converters/raw_color_mappings';
import {
convertToRawColorMappings,
Expand Down Expand Up @@ -43,6 +44,8 @@ export const convertToRawColorMappingsFn = (

if (!hasDeprecatedColorMappings) return state as DatatableVisualizationState;

trackRuntimeMigration('rawColorMappings', 'datatable');

const convertedColumns = state.columns.map((column) => {
if (column.colorMapping?.assignments || column.colorMapping?.specialAssignments) {
const columnMeta = getColumnMeta?.(state.layerId, column.columnId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { trackRuntimeMigration } from '../../../runtime_state';
import type { MetricVisualizationState } from '../types';

export const convertToRunTimeState = (
Expand All @@ -13,8 +14,10 @@ export const convertToRunTimeState = (
// Remove legacy state properties if they exist
const { secondaryPrefix, valuesTextAlign, ...restState } = state;
let newState = { ...restState };
let wasMigrated = false;

if (valuesTextAlign) {
wasMigrated = true;
newState = {
...newState,
primaryAlign: state.primaryAlign ?? valuesTextAlign,
Expand All @@ -23,11 +26,16 @@ export const convertToRunTimeState = (
}

if (secondaryPrefix && !newState.secondaryLabel) {
wasMigrated = true;
newState = {
...newState,
secondaryLabel: secondaryPrefix,
};
}

if (wasMigrated) {
trackRuntimeMigration('metric');
}

return newState;
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { LegendValue } from '@elastic/charts';

import type { PieLayerState, PieVisualizationState } from '../../../../../common/types';
import { trackRuntimeMigration } from '../../../../runtime_state';

/** @deprecated */
type DeprecatedLegendValueLayer = PieLayerState & {
Expand All @@ -28,6 +29,8 @@ export function convertToLegendStats(
) {
state.layers.forEach((l) => {
if ('showValuesInLegend' in l) {
trackRuntimeMigration('legendStats', 'partition');

l.legendStats = [
...new Set([
...(l.showValuesInLegend ? [LegendValue.Value] : []),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import type { PieLayerState, PieVisualizationState } from '../../../../../common/types';
import { trackRuntimeMigration } from '../../../../runtime_state';
import type { DeprecatedColorMappingConfig } from '../../../../runtime_state/converters/raw_color_mappings';
import {
convertToRawColorMappings,
Expand Down Expand Up @@ -43,6 +44,8 @@ export const convertToRawColorMappingsFn = (

if (!hasDeprecatedColorMappings) return state as PieVisualizationState;

trackRuntimeMigration('rawColorMappings', 'partition');

const convertedLayers = state.layers.map((layer) => {
if (
layer.layerType === 'data' &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { trackRuntimeMigration } from '../../../../runtime_state';
import type { DeprecatedColorMappingConfig } from '../../../../runtime_state/converters/raw_color_mappings';
import {
convertToRawColorMappings,
Expand Down Expand Up @@ -35,6 +36,8 @@ export const convertToRawColorMappingsFn = (

if (!hasDeprecatedColorMapping) return state as TagcloudState;

trackRuntimeMigration('rawColorMappings', 'tagcloud');

const columnMeta = state.tagAccessor ? getColumnMeta?.(state.layerId, state.tagAccessor) : null;

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { LegendValue } from '@elastic/charts';

import type { XYState } from '../../types';
import { trackRuntimeMigration } from '../../../../runtime_state';

/**
* Old color mapping state meant for type safety during runtime migrations of old configurations
Expand All @@ -20,6 +21,8 @@ interface DeprecatedLegendValueXYState extends XYState {

export function convertToLegendStats(state: DeprecatedLegendValueXYState | XYState): XYState {
if ('valuesInLegend' in state) {
trackRuntimeMigration('legendStats', 'xy');

const valuesInLegend = state.valuesInLegend;
delete state.valuesInLegend;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getColumnMetaFn,
isDeprecatedColorMapping,
} from '../../../../runtime_state/converters/raw_color_mappings';
import { trackRuntimeMigration } from '../../../../runtime_state';
import type { GeneralDatasourceStates } from '../../../../state_management';
import type { XYDataLayerConfig, XYLayerConfig, XYState } from '../../types';

Expand Down Expand Up @@ -40,6 +41,8 @@ export const convertToRawColorMappingsFn = (

if (!hasDeprecatedColorMappings) return state as XYState;

trackRuntimeMigration('rawColorMappings', 'xy');

const convertedLayers = state.layers.map<XYLayerConfig>((layer) => {
if (
layer.layerType === 'data' &&
Expand Down