From 14bf7d2a5730ab38d7e3e88d2c4051fedbce2e6c Mon Sep 17 00:00:00 2001 From: Joe White Date: Thu, 30 Apr 2020 16:42:16 -0400 Subject: [PATCH] Fix regression bug when paging datasets. Fix regression bug introduced in timeseries plot optimizations. Steps to reproduce: Use the metric explorer to plot multiple datasets with different number of series in each. Switch on paging and page past the max series in one of the datasets. A test has been added to prove the fix. --- .../DataWarehouse/Data/TimeseriesDataset.php | 5 ++ .../Controllers/MetricExplorerChartsTest.php | 66 ++++++++++++++++++- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/classes/DataWarehouse/Data/TimeseriesDataset.php b/classes/DataWarehouse/Data/TimeseriesDataset.php index f95f89c539..c9aefb5e6d 100644 --- a/classes/DataWarehouse/Data/TimeseriesDataset.php +++ b/classes/DataWarehouse/Data/TimeseriesDataset.php @@ -129,6 +129,11 @@ public function getDatasets($limit, $offset, $summarize) } $this->query->addWhereAndJoin($spaceGroup->getId(), 'IN', $seriesIds); + } else { + // this happens when the offset is greater than the number of series. This + // can occur when muliple datasets with different numbers of series + // are plotted on the same chart. + return array(); } $statement = $this->query->getRawStatement(); diff --git a/tests/regression/lib/Controllers/MetricExplorerChartsTest.php b/tests/regression/lib/Controllers/MetricExplorerChartsTest.php index 03367c4577..eaaff0a62e 100644 --- a/tests/regression/lib/Controllers/MetricExplorerChartsTest.php +++ b/tests/regression/lib/Controllers/MetricExplorerChartsTest.php @@ -129,6 +129,66 @@ private function getDimensionValues($helper, $realm, $dimension) return $response[0]['data']; } + /** + * Tests the scenario where multiple datasets are plotted but they have different + * number of dataseries and the paging has paged past the max of one of the series. + */ + public function testChartPaging() + { + $helper = new \TestHarness\XdmodTestHelper(); + $helper->authenticate('cd'); + + $requestData = $this->getChartRequest( + array( + array('realm' => 'Jobs', 'group_by' => 'username', 'metric' => 'total_cpu_hours'), + array('realm' => 'Jobs', 'group_by' => 'none', 'metric' => 'total_cpu_hours'), + ), + array( + 'start' => '4', + 'showRemainder' => 'false' + ) + ); + + $expected = array ( + 'total' => '55', + 'series_data' => array( + array('name' => 'aytinis [CPU Hours: Total]', 'y' => 10091.8844, 'percentage' => null), + array('name' => 'sarwa [CPU Hours: Total]', 'y' => 6955.7733, 'percentage' => null), + array('name' => 'crane [CPU Hours: Total]', 'y' => 6839.52, 'percentage' => null), + array('name' => 'duswa [CPU Hours: Total]', 'y' => 5701.5467, 'percentage' => null) + ) + ); + + $response = $helper->post('controllers/metric_explorer.php', null, $requestData); + + $this->assertEquals(200, $response[1]['http_code']); + + $chartData = json_decode($response[0]); + $this->assertNotNull($chartData); + + if ($expected === null) { + $this->output($chartData); + $this->markTestSkipped(); + return; + } + + $this->assertEquals($expected['total'], $chartData->totalCount); + + $series = $chartData->data[0]->series; + $this->assertCount(count($expected['series_data']), $series); + + $sdata = reset($expected['series_data']); + + foreach ($series as $s) { + $this->assertEquals($sdata['name'], $s->name); + $this->assertEquals($sdata['y'], $s->data[0]->y, '', 1.0E-6); + $this->assertEquals($sdata['percentage'], $s->data[0]->percentage); + $sdata = next($expected['series_data']); + } + + $helper->logout(); + } + /** * @dataProvider remainderChartProvider */ @@ -182,6 +242,8 @@ public function getChartRequest($data_settings, $global_settings = null) ); $testdate = isset($global_settings['date']) ? $global_settings['date'] : '2016-12-31'; + $startOffset = isset($global_settings['start']) ? $global_settings['start'] : '0'; + $showRemainder = isset($global_settings['showRemainder']) ? $global_settings['showRemainder'] : 'true'; $chartSettings = array( 'show_title' => 'y', @@ -193,8 +255,8 @@ public function getChartRequest($data_settings, $global_settings = null) 'title' => 'Metric Explorer Test Chart', 'show_filters' => 'true', 'show_warnings' => 'true', - 'show_remainder' => 'true', - 'start' => '0', + 'show_remainder' => $showRemainder, + 'start' => $startOffset, 'limit' => '4', 'timeframe_label' => 'User Defined', 'operation' => 'get_data',