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

[TSVB] Introducing Timerange Data Mode for Metric Style Visualizations #15760

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
60aae42
[TSVB] Introducing Timerange Data Mode for Metric Style Visualizations
simianhacker Dec 22, 2017
7651840
Adding intergration test for data timerange mode
simianhacker Apr 12, 2018
cf45e42
Fixing broken unit tests
simianhacker Apr 12, 2018
a8b4c24
Adding sleeps to allow for the UI to update.
simianhacker Apr 13, 2018
f4e24ff
Fixing tests
simianhacker Apr 13, 2018
567ba4d
Removing extra meta from date histogram
simianhacker Apr 13, 2018
9e1ea5f
Fixing tests
simianhacker Apr 13, 2018
3d9326b
fixing tests
simianhacker Apr 13, 2018
cc066f8
Refactoring agg select to be more clear
simianhacker Apr 16, 2018
9c092f3
Adding functional tests for filter ratio
simianhacker Apr 16, 2018
b105dfc
Changed interval to be disabled instead of hidden
simianhacker Apr 25, 2018
62ce472
Use isMetric to determine if panel is metric type
simianhacker Apr 27, 2018
0dcf65d
Adding test for drop_last_bucket
simianhacker Apr 27, 2018
39381d3
Use isMetric instead of includs on the metricTypes array
simianhacker Apr 27, 2018
5bb9374
Clean up code by removing redundent components
simianhacker Apr 27, 2018
9d7384e
Removing panel attribute
simianhacker Apr 27, 2018
51e3a59
Fixing partial bucket support; adding offset so we have whole buckets…
simianhacker Apr 30, 2018
2123553
Fixing unit test
simianhacker May 2, 2018
46091ff
updating values based on the new bucketing scheme
simianhacker May 2, 2018
16450f5
removing timezone from date histogram
simianhacker May 8, 2018
e5e3cca
Fixing vis_with_splits hoc; fixing z-index on color picker; adding he…
simianhacker Oct 3, 2018
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
},
"dependencies": {
"@elastic/eui": "4.0.1",
"@elastic/datemath": "4.0.2",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that our fork of the datemath package now lives in packages/, is this still required?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we suppose to link directly to those packages or rely on the links setup in package.json? Maybe @spalger could weigh in on this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind... I see we are suppose to be using @kbn/datemath instead which links to the packages directory

"@elastic/filesaver": "1.1.2",
"@elastic/numeral": "2.3.2",
"@elastic/ui-ace": "0.2.3",
Expand Down Expand Up @@ -344,4 +345,4 @@
"node": "8.11.4",
"yarn": "^1.6.0"
}
}
}
24 changes: 24 additions & 0 deletions src/core_plugins/metrics/common/metric_types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export const metricTypes = ['gauge', 'table', 'metric', 'top_n'];

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned below, a predicate like isMetric(panelType: PanelType): boolean could go well with this and make conditionals more readable.

export function isMetric(panelType) {
return metricTypes.includes(panelType);
}
24 changes: 22 additions & 2 deletions src/core_plugins/metrics/public/components/aggs/agg_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import React from 'react';
import {
EuiComboBox,
} from '@elastic/eui';
import { isMetric } from '../../../common/metric_types';

const metricAggs = [
{ label: 'Average', value: 'avg' },
Expand Down Expand Up @@ -79,8 +80,12 @@ function filterByPanelType(panelType) {
};
}

function includeCalculation() {
return agg => agg.value === 'calculation';
}

function AggSelect(props) {
const { siblings, panelType, value } = props;
const { siblings, panelType, value, timerangeMode, metricsOnly } = props;

const selectedOption = allAggOptions.find(option => {
return value === option.value;
Expand All @@ -93,8 +98,17 @@ function AggSelect(props) {
if (siblings.length <= 1) enablePipelines = false;

let options;
if (panelType === 'metrics') {
if (metricsOnly) {
options = metricAggs;
} else if (isMetric(panelType) && timerangeMode === 'all') {
options = [
{ label: 'Metric Aggregations', value: null, heading: true, disabled: true },
...metricAggs,
{ label: 'Parent Pipeline Aggregations', value: null, pipeline: true, heading: true, disabled: true },
...pipelineAggs.filter(filterByPanelType(panelType))
.filter(includeCalculation())
.map(agg => ({ ...agg, disabled: !enablePipelines })),
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a lot of overlap with the next if branch. And there seem to be two similar mechanisms at work to disable certain aggregations: .filter()ing and using enabledPipelines. How about unifying this to one mechanism to reduce the number of "special cases" that need to be handled?

} else {
options = [
{
Expand Down Expand Up @@ -137,11 +151,17 @@ function AggSelect(props) {
);
}

AggSelect.defaultProps = {
metricsOnly: false
};

AggSelect.propTypes = {
onChange: PropTypes.func,
panelType: PropTypes.string,
siblings: PropTypes.array,
value: PropTypes.string,
timerangeMode: PropTypes.oneOf(['all', 'last']),
metricsOnly: PropTypes.bool
};

export default AggSelect;
16 changes: 9 additions & 7 deletions src/core_plugins/metrics/public/components/aggs/calculation.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ import Vars from './vars';
import { htmlIdGenerator } from '@elastic/eui';

class CalculationAgg extends Component {

componentWillMount() {
if (!this.props.model.variables) {
this.props.onChange(_.assign({}, this.props.model, {
variables: [{ id: uuid.v1() }]
}));
this.props.onChange(
_.assign({}, this.props.model, {
variables: [{ id: uuid.v1() }],
})
);
}
}

Expand Down Expand Up @@ -66,6 +67,7 @@ class CalculationAgg extends Component {
<div className="vis_editor__label">Aggregation</div>
<AggSelect
panelType={this.props.panel.type}
timerangeMode={this.props.panel.timerange_mode}
siblings={this.props.siblings}
value={model.type}
onChange={handleSelectChange('type')}
Expand All @@ -82,8 +84,9 @@ class CalculationAgg extends Component {
<div className="vis_editor__row_item">
<label className="vis_editor__label" htmlFor={htmlId('painless')}>
Painless Script - Variables are keys on the <code>params</code>
object, i.e. <code>params.&lt;name&gt;</code>.
To access the bucket interval (in milliseconds) use <code>params._interval</code>.
object, i.e. <code>params.&lt;name&gt;</code>. To access the
bucket interval (in milliseconds) use{' '}
<code>params._interval</code>.
</label>
<input
id={htmlId('painless')}
Expand All @@ -98,7 +101,6 @@ class CalculationAgg extends Component {
</AggRow>
);
}

}

CalculationAgg.propTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function CumulativeSumAgg(props) {
<div className="vis_editor__row_item">
<div className="vis_editor__label">Aggregation</div>
<AggSelect
timerangeMode={props.panel.timerange_mode}
panelType={props.panel.type}
siblings={props.siblings}
value={model.type}
Expand All @@ -57,7 +58,6 @@ function CumulativeSumAgg(props) {
</div>
</AggRow>
);

}

CumulativeSumAgg.propTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const DerivativeAgg = props => {
<div className="vis_editor__label">Aggregation</div>
<AggSelect
panelType={props.panel.type}
timerangeMode={props.panel.timerange_mode}
siblings={props.siblings}
value={model.type}
onChange={handleSelectChange('type')}
Expand Down
18 changes: 10 additions & 8 deletions src/core_plugins/metrics/public/components/aggs/field_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ function FieldSelect(props) {
const selectedOptions = selectedOption ? [selectedOption] : [];

return (
<EuiComboBox
placeholder="Select field..."
isDisabled={disabled}
options={options}
selectedOptions={selectedOptions}
onChange={onChange}
singleSelection={true}
/>
<div data-test-subj="fieldSelector" className="vis_editor__row_item">
<EuiComboBox
placeholder="Select field..."
isDisabled={disabled}
options={options}
selectedOptions={selectedOptions}
onChange={onChange}
singleSelection={true}
/>
</div>
);
}

Expand Down
30 changes: 18 additions & 12 deletions src/core_plugins/metrics/public/components/aggs/filter_ratio.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,19 @@ import createTextHandler from '../lib/create_text_handler';
import { htmlIdGenerator } from '@elastic/eui';

export const FilterRatioAgg = props => {
const {
series,
fields,
panel
} = props;
const { series, fields, panel } = props;

const handleChange = createChangeHandler(props.onChange, props.model);
const handleSelectChange = createSelectHandler(handleChange);
const handleTextChange = createTextHandler(handleChange);
const indexPattern = series.override_index_pattern && series.series_index_pattern || panel.index_pattern;
const indexPattern =
(series.override_index_pattern && series.series_index_pattern) ||
panel.index_pattern;

const defaults = {
numerator: '*',
denominator: '*',
metric_agg: 'count'
metric_agg: 'count',
};

const model = { ...defaults, ...props.model };
Expand All @@ -63,6 +61,7 @@ export const FilterRatioAgg = props => {
<div className="vis_editor__row_item">
<div className="vis_editor__label">Aggregation</div>
<AggSelect
timerangeMode={props.panel.timerange_mode}
panelType={props.panel.type}
siblings={props.siblings}
value={model.type}
Expand All @@ -75,18 +74,23 @@ export const FilterRatioAgg = props => {
</label>
<input
id={htmlId('numerator')}
data-test-subj="filterRatioNumerator"
className="vis_editor__input-grows-100"
onChange={handleTextChange('numerator')}
value={model.numerator}
type="text"
/>
</div>
<div className="vis_editor__row_item">
<label className="vis_editor__label" htmlFor={htmlId('denominator')}>
<label
className="vis_editor__label"
htmlFor={htmlId('denominator')}
>
Denominator
</label>
<input
id={htmlId('denominator')}
data-test-subj="filterRatioDenominator"
className="vis_editor__input-grows-100"
onChange={handleTextChange('denominator')}
value={model.denominator}
Expand All @@ -95,16 +99,17 @@ export const FilterRatioAgg = props => {
</div>
</div>
<div style={{ flex: '1 0 auto', display: 'flex', marginTop: '10px' }}>
<div className="vis_editor__row_item">
<div className="vis_editor__row_item" data-test-subj="filterRatioMetricAgg">
<div className="vis_editor__label">Metric Aggregation</div>
<AggSelect
siblings={props.siblings}
panelType="metrics"
metricsOnly={true}
timerangeMode={props.panel.timerange_mode}
value={model.metric_agg}
onChange={handleSelectChange('metric_agg')}
/>
</div>
{ model.metric_agg !== 'count' ? (
{model.metric_agg !== 'count' ? (
<div className="vis_editor__row_item">
<label className="vis_editor__label" htmlFor={htmlId('aggField')}>
Field
Expand All @@ -118,7 +123,8 @@ export const FilterRatioAgg = props => {
value={model.field}
onChange={handleSelectChange('field')}
/>
</div>) : null }
</div>
) : null}
</div>
</div>
</AggRow>
Expand Down
21 changes: 13 additions & 8 deletions src/core_plugins/metrics/public/components/aggs/percentile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import AddDeleteButtons from '../add_delete_buttons';
import uuid from 'uuid';
import createChangeHandler from '../lib/create_change_handler';
import createSelectHandler from '../lib/create_select_handler';
import { createNewPercentile } from '../lib/create_new_percentile';
import {
htmlIdGenerator,
EuiComboBox,
Expand Down Expand Up @@ -69,7 +70,7 @@ class Percentiles extends Component {
const selectedModeOption = modeOptions.find(option => {
return model.mode === option.value;
});
return (
return (
<div className="vis_editor__percentiles-row" key={model.id}>
<div className="vis_editor__percentiles-content">
<input
Expand Down Expand Up @@ -128,12 +129,12 @@ class Percentiles extends Component {

render() {
const { model, name } = this.props;
if (!model[name]) return (<div/>);
if (!model[name]) return (<div />);

const rows = model[name].map(this.renderRow);
return (
<div className="vis_editor__percentiles">
{ rows }
{rows}
</div>
);
}
Expand All @@ -154,9 +155,11 @@ class PercentileAgg extends Component { // eslint-disable-line react/no-multi-co

componentWillMount() {
if (!this.props.model.percentiles) {
this.props.onChange(_.assign({}, this.props.model, {
percentiles: [newPercentile({ value: 50 })]
}));
this.props.onChange(
_.assign({}, this.props.model, {
percentiles: [createNewPercentile({ value: 50 })],
})
);
}
}

Expand All @@ -165,7 +168,9 @@ class PercentileAgg extends Component { // eslint-disable-line react/no-multi-co

const handleChange = createChangeHandler(this.props.onChange, model);
const handleSelectChange = createSelectHandler(handleChange);
const indexPattern = series.override_index_pattern && series.series_index_pattern || panel.index_pattern;
const indexPattern =
(series.override_index_pattern && series.series_index_pattern) ||
panel.index_pattern;

return (
<AggRow
Expand All @@ -181,6 +186,7 @@ class PercentileAgg extends Component { // eslint-disable-line react/no-multi-co
<div className="vis_editor__label">Aggregation</div>
<AggSelect
panelType={this.props.panel.type}
timerangeMode={this.props.panel.timerangeMode}
siblings={this.props.siblings}
value={model.type}
onChange={handleSelectChange('type')}
Expand All @@ -207,7 +213,6 @@ class PercentileAgg extends Component { // eslint-disable-line react/no-multi-co
</AggRow>
);
}

}

PercentileAgg.propTypes = {
Expand Down
13 changes: 10 additions & 3 deletions src/core_plugins/metrics/public/components/aggs/percentile_rank.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export const PercentileRankAgg = props => {
const handleSelectChange = createSelectHandler(handleChange);
const handleTextChange = createTextHandler(handleChange);

const indexPattern = series.override_index_pattern && series.series_index_pattern || panel.index_pattern;
const indexPattern =
(series.override_index_pattern && series.series_index_pattern) ||
panel.index_pattern;
const htmlId = htmlIdGenerator();

return (
Expand All @@ -51,13 +53,16 @@ export const PercentileRankAgg = props => {
<div className="vis_editor__label">Aggregation</div>
<AggSelect
panelType={props.panel.type}
timerangeMode={props.panel.timerange_mode}
siblings={props.siblings}
value={model.type}
onChange={handleSelectChange('type')}
/>
</div>
<div className="vis_editor__row_item">
<label className="vis_editor__label" htmlFor={htmlId('field')}>Field</label>
<label className="vis_editor__label" htmlFor={htmlId('field')}>
Field
</label>
<FieldSelect
id={htmlId('field')}
fields={fields}
Expand All @@ -69,7 +74,9 @@ export const PercentileRankAgg = props => {
/>
</div>
<div className="vis_editor__percentile_rank_value">
<label className="vis_editor__label" htmlFor={htmlId('value')}>Value</label>
<label className="vis_editor__label" htmlFor={htmlId('value')}>
Value
</label>
<input
id={htmlId('value')}
className="vis_editor__input-grows"
Expand Down
Loading