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] Timeseries Drop last bucket set default to false #97257

Merged
merged 20 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a3df9c0
[TSVB] Timeseries Drop last bucket should default to false
DianaDerevyankina Apr 15, 2021
624e1a0
Merge branch 'master' into issues/95756
kibanamachine Apr 16, 2021
c7749f4
Rename isLastBucketDropped prop and move series domain calculation to…
DianaDerevyankina Apr 16, 2021
b9f9b9b
Merge branch 'master' into issues/95756
kibanamachine Apr 16, 2021
e2b0bd0
Merge branch 'master' into issues/95756
kibanamachine Apr 19, 2021
3e614b5
Merge branch 'master' into issues/95756
DianaDerevyankina Apr 19, 2021
f9b2f3d
Fix failing tests because of wrong default value
DianaDerevyankina Apr 19, 2021
84ee389
Merge branch 'master' into issues/95756
kibanamachine Apr 20, 2021
bb1b7ec
update drop_last_bucket.js
alexwizp Apr 20, 2021
a2e7fcc
Refactor drop_last_bucket and some functional tests
DianaDerevyankina Apr 21, 2021
7099e4d
Change infra metrics test values because of last bucket value changed
DianaDerevyankina Apr 21, 2021
cdeed0f
Merge branch 'master' into issues/95756
DianaDerevyankina Apr 22, 2021
3064714
Refactor series_domain_calculation and related code
DianaDerevyankina Apr 22, 2021
1e62d9f
Update series_domain_calculations.test
DianaDerevyankina Apr 22, 2021
d05be47
Update series_domain_calculations.test
DianaDerevyankina Apr 22, 2021
46cc8e3
Merge branch 'issues/95756' of https://github.com/DianaDerevyankina/k…
DianaDerevyankina Apr 22, 2021
c11e3ca
Merge branch 'master' into issues/95756
DianaDerevyankina Apr 26, 2021
a160c45
Fix tooltip showing wrong time
DianaDerevyankina Apr 26, 2021
15048f1
Refactor index
DianaDerevyankina Apr 26, 2021
9dc60a8
Merge branch 'master' into issues/95756
kibanamachine Apr 30, 2021
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 @@ -113,7 +113,7 @@ export const IndexPattern = ({
const defaults = {
[indexPatternName]: '',
[intervalName]: AUTO_INTERVAL,
[dropBucketName]: 1,
[dropBucketName]: 0,
[maxBarsName]: config.get(UI_SETTINGS.HISTOGRAM_BAR_TARGET),
[TIME_RANGE_MODE_KEY]: timeRangeOptions[0].value,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ export class TimeseriesPanelConfig extends Component<
<EuiTab
isSelected={selectedTab === PANEL_CONFIG_TABS.DATA}
onClick={() => this.switchTab(PANEL_CONFIG_TABS.DATA)}
data-test-subj="timeSeriesEditorDataBtn"
>
<FormattedMessage
id="visTypeTimeseries.timeseries.dataTab.dataButtonLabel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { createTickFormatter } from '../../lib/tick_formatter';
import { TimeSeries } from '../../../visualizations/views/timeseries';
import { MarkdownSimple } from '../../../../../../../plugins/kibana_react/public';
import { replaceVars } from '../../lib/replace_vars';
import { getAxisLabelString } from '../../lib/get_axis_label_string';
import { getInterval } from '../../lib/get_interval';
import { createIntervalBasedFormatter } from '../../lib/create_interval_based_formatter';
import { STACKED_OPTIONS } from '../../../visualizations/constants';
Expand Down Expand Up @@ -235,11 +234,15 @@ class TimeseriesVisualization extends Component {
legend={Boolean(model.show_legend)}
legendPosition={model.legend_position}
tooltipMode={model.tooltip_mode}
xAxisLabel={getAxisLabelString(interval)}
xAxisFormatter={this.xAxisFormatter(interval)}
annotations={this.prepareAnnotations()}
syncColors={syncColors}
palettesService={palettesService}
interval={interval}
isLastBucketDropped={Boolean(
model.drop_last_bucket ||
model.series.some((series) => series.series_drop_last_bucket)
)}
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import { getStackAccessors } from './utils/stack_format';
import { getBaseTheme, getChartClasses } from './utils/theme';
import { emptyLabel } from '../../../../../common/empty_label';
import { getSplitByTermsColor } from '../../../lib/get_split_by_terms_color';
import { renderEndzoneTooltip } from '../../../../../../charts/public';
import { getAxisLabelString } from '../../../components/lib/get_axis_label_string';
import { calculateDomainForSeries } from './utils/series_domain_calculation';

const generateAnnotationData = (values, formatter) =>
values.map(({ key, docs }) => ({
Expand All @@ -54,14 +57,15 @@ export const TimeSeries = ({
legend,
legendPosition,
tooltipMode,
xAxisLabel,
series,
yAxis,
onBrush,
xAxisFormatter,
annotations,
syncColors,
palettesService,
interval,
isLastBucketDropped,
}) => {
const chartRef = useRef();
// const [palettesRegistry, setPalettesRegistry] = useState(null);
Expand All @@ -80,7 +84,17 @@ export const TimeSeries = ({
};
}, []);

const tooltipFormatter = decorateFormatter(xAxisFormatter);
let tooltipFormatter = decorateFormatter(xAxisFormatter);
if (!isLastBucketDropped) {
const domainBounds = calculateDomainForSeries(series);
tooltipFormatter = renderEndzoneTooltip(
interval,
domainBounds?.domainStart,
domainBounds?.domainEnd,
xAxisFormatter
);
}

const uiSettings = getUISettings();
const timeZone = getTimezone(uiSettings);
const hasBarChart = series.some(({ bars }) => bars?.show);
Expand Down Expand Up @@ -281,7 +295,7 @@ export const TimeSeries = ({
<Axis
id="bottom"
position={Position.Bottom}
title={xAxisLabel}
title={getAxisLabelString(interval)}
tickFormat={xAxisFormatter}
gridLine={{
...GRID_LINE_CONFIG,
Expand All @@ -303,10 +317,11 @@ TimeSeries.propTypes = {
showGrid: PropTypes.bool,
legend: PropTypes.bool,
legendPosition: PropTypes.string,
xAxisLabel: PropTypes.string,
series: PropTypes.array,
yAxis: PropTypes.array,
onBrush: PropTypes.func,
xAxisFormatter: PropTypes.func,
annotations: PropTypes.array,
interval: PropTypes.number,
isLastBucketDropped: PropTypes.bool,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { PanelData } from '../../../../../../common/types';

export const calculateDomainForSeries = (series: PanelData[]) => {
const seriesData = series[0]?.data || [];

return seriesData?.length
? {
domainStart: seriesData[0][0],
domainEnd: seriesData[Math.max(seriesData.length - 1, 0)][0],
}
: undefined;
};
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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { calculateDomainForSeries } from './series_domain_calculation';
import { PanelData } from 'src/plugins/vis_type_timeseries/common/types';

describe('calculateDomainForSeries', () => {
it('should return 0 for domainStart and 3 for domainEnd', () => {
const series = [
{
data: [
[0, 0],
[1, 1],
[2, 2],
[3, 3],
],
},
] as PanelData[];
const domainBounds = calculateDomainForSeries(series);

expect(domainBounds?.domainStart).toBe(0);
expect(domainBounds?.domainEnd).toBe(3);
});

it('should return undefined when series is empty', () => {
const domainBounds = calculateDomainForSeries([]);

expect(domainBounds).toBeUndefined();
});
});
1 change: 1 addition & 0 deletions src/plugins/vis_type_timeseries/public/metrics_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const metricsVisDefinition = {
show_legend: 1,
show_grid: 1,
tooltip_mode: 'show_all',
drop_last_bucket: 0,
},
},
editorConfig: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ export function dropLastBucket(resp, panel, series) {
const shouldDropLastBucket = isLastValueTimerangeMode(panel, series);

if (shouldDropLastBucket) {
const seriesDropLastBucket = get(series, 'override_drop_last_bucket', 1);
const dropLastBucket = get(panel, 'drop_last_bucket', seriesDropLastBucket);
const dropLastBucket = series.override_index_pattern
? get(series, 'series_drop_last_bucket', 0)
: get(panel, 'drop_last_bucket', 0);

if (dropLastBucket) {
results.forEach((item) => {
Expand Down
6 changes: 6 additions & 0 deletions test/functional/apps/visualize/_tsvb_chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.visualBuilder.checkMetricTabIsPresent();
await PageObjects.visualBuilder.clickPanelOptions('metric');
await PageObjects.visualBuilder.setMetricsDataTimerangeMode('Last value');
await PageObjects.visualBuilder.setDropLastBucket(true);
await PageObjects.visualBuilder.clickDataTab('metric');
});

Expand Down Expand Up @@ -106,6 +107,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.visualBuilder.checkTopNTabIsPresent();
await PageObjects.visualBuilder.clickPanelOptions('topN');
await PageObjects.visualBuilder.setMetricsDataTimerangeMode('Last value');
await PageObjects.visualBuilder.setDropLastBucket(true);
await PageObjects.visualBuilder.clickDataTab('topN');
});

Expand All @@ -129,6 +131,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.visualBuilder.checkMetricTabIsPresent();
await PageObjects.visualBuilder.clickPanelOptions('metric');
await PageObjects.visualBuilder.setMetricsDataTimerangeMode('Last value');
await PageObjects.visualBuilder.setDropLastBucket(true);
await PageObjects.visualBuilder.clickDataTab('metric');
await PageObjects.timePicker.setAbsoluteRange(
'Sep 22, 2019 @ 00:00:00.000',
Expand Down Expand Up @@ -215,6 +218,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const finalLegendItems = ['jpg: 106', 'css: 22', 'png: 14', 'gif: 8', 'php: 6'];

log.debug('Group metrics by terms: extension.raw');
await PageObjects.visualBuilder.clickPanelOptions('timeSeries');
await PageObjects.visualBuilder.setDropLastBucket(true);
await PageObjects.visualBuilder.clickDataTab('timeSeries');
await PageObjects.visualBuilder.setMetricsGroupByTerms('extension.raw');
await PageObjects.visChart.waitForVisualizationRenderingStabilized();
const legendItems1 = await PageObjects.visualBuilder.getLegendItemsContent();
Expand Down
1 change: 1 addition & 0 deletions test/functional/apps/visualize/_tsvb_markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
);
await visualBuilder.markdownSwitchSubTab('options');
await visualBuilder.setMetricsDataTimerangeMode('Last value');
await visualBuilder.setDropLastBucket(true);
await visualBuilder.markdownSwitchSubTab('markdown');
});

Expand Down
1 change: 1 addition & 0 deletions test/functional/apps/visualize/_tsvb_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function ({ getPageObjects }: FtrProviderContext) {
await visualBuilder.checkTableTabIsPresent();
await visualBuilder.clickPanelOptions('table');
await visualBuilder.setMetricsDataTimerangeMode('Last value');
await visualBuilder.setDropLastBucket(true);
await visualBuilder.clickDataTab('table');
await visualBuilder.selectGroupByField('machine.os.raw');
await visualBuilder.setColumnLabelValue('OS');
Expand Down
3 changes: 3 additions & 0 deletions test/functional/apps/visualize/_tsvb_time_series.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
describe('Time Series', () => {
beforeEach(async () => {
await visualBuilder.resetPage();
await visualBuilder.clickPanelOptions('timeSeries');
await visualBuilder.setDropLastBucket(true);
await visualBuilder.clickDataTab('timeSeries');
});

it('should render all necessary components', async () => {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/test/api_integration/apis/metrics_ui/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export default function ({ getService }: FtrProviderContext) {
expect(series).to.have.property('id', 'user');
expect(series).to.have.property('data');
const datapoint = last(series.data) as any;
expect(datapoint).to.have.property('timestamp', 1547571720000);
expect(datapoint).to.have.property('value', 0.0018333333333333333);
expect(datapoint).to.have.property('timestamp', 1547571780000);
expect(datapoint).to.have.property('value', 0.0015);
});
});

Expand Down