Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] [Data table] Add telemetry for table vis split mode (#88604) #89112

Merged
merged 1 commit into from
Jan 25, 2021
Merged
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
30 changes: 30 additions & 0 deletions src/plugins/telemetry/schema/oss_plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5247,6 +5247,36 @@
}
}
},
"vis_type_table": {
"properties": {
"total": {
"type": "long"
},
"total_split": {
"type": "long"
},
"split_columns": {
"properties": {
"total": {
"type": "long"
},
"enabled": {
"type": "long"
}
}
},
"split_rows": {
"properties": {
"total": {
"type": "long"
},
"enabled": {
"type": "long"
}
}
}
}
},
"vis_type_vega": {
"properties": {
"vega_lib_specs_total": {
Expand Down
9 changes: 9 additions & 0 deletions src/plugins/vis_type_table/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* and the Server Side Public License, v 1; you may not use this file except in
* compliance with, at your election, the Elastic License or the Server Side
* Public License, v 1.
*/

export * from './types';
28 changes: 28 additions & 0 deletions src/plugins/vis_type_table/common/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* and the Server Side Public License, v 1; you may not use this file except in
* compliance with, at your election, the Elastic License or the Server Side
* Public License, v 1.
*/

export const VIS_TYPE_TABLE = 'table';

export enum AggTypes {
SUM = 'sum',
AVG = 'avg',
MIN = 'min',
MAX = 'max',
COUNT = 'count',
}

export interface TableVisParams {
perPage: number | '';
showPartialRows: boolean;
showMetricsAtAllLevels: boolean;
showToolbar: boolean;
showTotal: boolean;
totalFunc: AggTypes;
percentageCol: string;
row?: boolean;
}
1 change: 1 addition & 0 deletions src/plugins/vis_type_table/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ module.exports = {
rootDir: '../../..',
roots: ['<rootDir>/src/plugins/vis_type_table'],
testRunner: 'jasmine2',
collectCoverageFrom: ['<rootDir>/src/plugins/vis_type_table/**/*.{js,ts,tsx}'],
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
NumberInputOption,
VisOptionsProps,
} from '../../../vis_default_editor/public';
import { TableVisParams } from '../types';
import { TableVisParams } from '../../common';
import { totalAggregations } from './utils';

const { tabifyGetColumns } = search;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import React, { lazy, Suspense } from 'react';
import { EuiLoadingSpinner } from '@elastic/eui';
import { VisOptionsProps } from 'src/plugins/vis_default_editor/public';
import { TableVisParams } from '../types';
import { TableVisParams } from '../../common';

const TableOptionsComponent = lazy(() => import('./table_vis_options'));

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/vis_type_table/public/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { i18n } from '@kbn/i18n';
import { AggTypes } from '../types';
import { AggTypes } from '../../common';

const totalAggregations = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { i18n } from '@kbn/i18n';
import { ExpressionFunctionDefinition, Datatable, Render } from 'src/plugins/expressions/public';
import { tableVisLegacyResponseHandler, TableContext } from './table_vis_legacy_response_handler';
import { TableVisConfig } from '../types';
import { VIS_TYPE_TABLE } from '../../common';

export type Input = Datatable;

Expand All @@ -19,7 +20,7 @@ interface Arguments {

export interface TableVisRenderValue {
visData: TableContext;
visType: 'table';
visType: typeof VIS_TYPE_TABLE;
visConfig: TableVisConfig;
}

Expand Down Expand Up @@ -53,7 +54,7 @@ export const createTableVisLegacyFn = (): TableExpressionFunctionDefinition => (
as: 'table_vis',
value: {
visData: convertedData,
visType: 'table',
visType: VIS_TYPE_TABLE,
visConfig,
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import { BaseVisTypeOptions } from '../../../visualizations/public';

import { TableOptions } from '../components/table_vis_options_lazy';
import { VIS_EVENT_TO_TRIGGER } from '../../../visualizations/public';
import { TableVisParams, VIS_TYPE_TABLE } from '../../common';
import { toExpressionAst } from '../to_ast';
import { TableVisParams } from '../types';

export const tableVisLegacyTypeDefinition: BaseVisTypeOptions<TableVisParams> = {
name: 'table',
name: VIS_TYPE_TABLE,
title: i18n.translate('visTypeTable.tableVisTitle', {
defaultMessage: 'Data table',
}),
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/vis_type_table/public/table_vis_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { i18n } from '@kbn/i18n';
import { tableVisResponseHandler, TableContext } from './table_vis_response_handler';
import { ExpressionFunctionDefinition, Datatable, Render } from '../../expressions/public';
import { TableVisConfig } from './types';
import { VIS_TYPE_TABLE } from '../common';

export type Input = Datatable;

Expand All @@ -19,7 +20,7 @@ interface Arguments {

export interface TableVisRenderValue {
visData: TableContext;
visType: 'table';
visType: typeof VIS_TYPE_TABLE;
visConfig: TableVisConfig;
}

Expand Down Expand Up @@ -56,7 +57,7 @@ export const createTableVisFn = (): TableExpressionFunctionDefinition => ({
as: 'table_vis',
value: {
visData: convertedData,
visType: 'table',
visType: VIS_TYPE_TABLE,
visConfig,
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/vis_type_table/public/table_vis_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { i18n } from '@kbn/i18n';
import { AggGroupNames } from '../../data/public';
import { BaseVisTypeOptions } from '../../visualizations/public';

import { TableVisParams, VIS_TYPE_TABLE } from '../common';
import { TableOptions } from './components/table_vis_options_lazy';
import { VIS_EVENT_TO_TRIGGER } from '../../../plugins/visualizations/public';
import { toExpressionAst } from './to_ast';
import { TableVisParams } from './types';

export const tableVisTypeDefinition: BaseVisTypeOptions<TableVisParams> = {
name: 'table',
name: VIS_TYPE_TABLE,
title: i18n.translate('visTypeTable.tableVisTitle', {
defaultMessage: 'Data table',
}),
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/vis_type_table/public/to_ast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { Vis } from 'src/plugins/visualizations/public';
import { toExpressionAst } from './to_ast';
import { AggTypes, TableVisParams } from './types';
import { AggTypes, TableVisParams } from '../common';

const mockSchemas = {
metric: [{ accessor: 1, format: { id: 'number' }, params: {}, label: 'Count', aggType: 'count' }],
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/vis_type_table/public/to_ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import {
} from '../../data/public';
import { buildExpression, buildExpressionFunction } from '../../expressions/public';
import { getVisSchemas, Vis, BuildPipelineParams } from '../../visualizations/public';
import { TableVisParams } from '../common';
import { TableExpressionFunctionDefinition } from './table_vis_fn';
import { TableVisConfig, TableVisParams } from './types';
import { TableVisConfig } from './types';

const buildTableVisConfig = (
schemas: ReturnType<typeof getVisSchemas>,
Expand Down
19 changes: 1 addition & 18 deletions src/plugins/vis_type_table/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@

import { IFieldFormat } from 'src/plugins/data/public';
import { SchemaConfig } from 'src/plugins/visualizations/public';

export enum AggTypes {
SUM = 'sum',
AVG = 'avg',
MIN = 'min',
MAX = 'max',
COUNT = 'count',
}
import { TableVisParams } from '../common';

export interface Dimensions {
buckets: SchemaConfig[];
Expand Down Expand Up @@ -44,16 +37,6 @@ export interface TableVisUseUiStateProps {
setColumnsWidth: (column: ColumnWidthData) => void;
}

export interface TableVisParams {
perPage: number | '';
showPartialRows: boolean;
showMetricsAtAllLevels: boolean;
showToolbar: boolean;
showTotal: boolean;
totalFunc: AggTypes;
percentageCol: string;
}

export interface TableVisConfig extends TableVisParams {
title: string;
dimensions: Dimensions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import { useMemo } from 'react';
import { chain, findIndex } from 'lodash';

import { AggTypes } from '../../../common';
import { Table } from '../../table_vis_response_handler';
import { FormattedColumn, TableVisConfig, AggTypes } from '../../types';
import { FormattedColumn, TableVisConfig } from '../../types';
import { getFormatService } from '../../services';
import { addPercentageColumn } from '../add_percentage_column';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { useCallback, useEffect, useMemo, useState } from 'react';
import { TableVisParams } from '../../types';
import { TableVisParams } from '../../../common';

export const usePagination = (visParams: TableVisParams, rowCount: number) => {
const [pagination, setPagination] = useState({
Expand Down
10 changes: 8 additions & 2 deletions src/plugins/vis_type_table/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
* Public License, v 1.
*/

import { PluginConfigDescriptor } from 'kibana/server';
import { CoreSetup, PluginConfigDescriptor } from 'kibana/server';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';

import { configSchema, ConfigSchema } from '../config';
import { registerVisTypeTableUsageCollector } from './usage_collector';

export const config: PluginConfigDescriptor<ConfigSchema> = {
exposeToBrowser: {
Expand All @@ -21,6 +23,10 @@ export const config: PluginConfigDescriptor<ConfigSchema> = {
};

export const plugin = () => ({
setup() {},
setup(core: CoreSetup, plugins: { usageCollection?: UsageCollectionSetup }) {
if (plugins.usageCollection) {
registerVisTypeTableUsageCollector(plugins.usageCollection);
}
},
start() {},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* and the Server Side Public License, v 1; you may not use this file except in
* compliance with, at your election, the Elastic License or the Server Side
* Public License, v 1.
*/

import { SavedObjectsClientContract } from 'kibana/server';
import { getStats } from './get_stats';

const mockVisualizations = {
saved_objects: [
{
attributes: {
visState:
'{"type": "table","aggs": [{ "schema": "metric" }, { "schema": "bucket" }, { "schema": "split", "enabled": true }], "params": { "row": true }}',
},
},
{
attributes: {
visState:
'{"type": "table","aggs": [{ "schema": "metric" }, { "schema": "bucket" }, { "schema": "split", "enabled": false }], "params": { "row": true }}',
},
},
{
attributes: {
visState:
'{"type": "table","aggs": [{ "schema": "metric" }, { "schema": "split", "enabled": true }], "params": { "row": false }}',
},
},
{
attributes: {
visState: '{"type": "table","aggs": [{ "schema": "metric" }, { "schema": "bucket" }]}',
},
},
{
attributes: { visState: '{"type": "histogram"}' },
},
],
};

describe('vis_type_table getStats', () => {
const mockSoClient = ({
find: jest.fn().mockResolvedValue(mockVisualizations),
} as unknown) as SavedObjectsClientContract;

test('Returns stats from saved objects for table vis only', async () => {
const result = await getStats(mockSoClient);
expect(mockSoClient.find).toHaveBeenCalledWith({
type: 'visualization',
perPage: 10000,
});
expect(result).toEqual({
total: 4,
total_split: 3,
split_columns: {
total: 1,
enabled: 1,
},
split_rows: {
total: 2,
enabled: 1,
},
});
});
});
Loading