From 55f63694b19ade097a09cc049ad5f2d80420e2c4 Mon Sep 17 00:00:00 2001 From: Ben Burgess <88810029+bx80@users.noreply.github.com> Date: Fri, 29 Dec 2023 11:39:29 +1300 Subject: [PATCH] Add archiving diagnostic commands (#21713) * Add archiving diagnostic commands * Fix missing list commas * Code tidy, return failure errorlevel if email send fails * Add segment definition display to the archiving invalidation queue command for segment invalidations * Linter nitpicking fixes * Wrap symphony console classes, adjust tests * Update test results * Cast int values for consistency in json tests --- core/DataAccess/ArchiveTableDao.php | 55 +++++ core/Plugin/ConsoleCommand.php | 10 + .../ConsoleCommandBufferedOutput.php | 21 ++ .../ConsoleCommandConsoleOutput.php | 21 ++ .../Diagnostics/Commands/ArchivingConfig.php | 112 +++++++++ .../Commands/ArchivingInstanceStatistics.php | 73 ++++++ .../Diagnostics/Commands/ArchivingMetrics.php | 68 ++++++ .../Diagnostics/Commands/ArchivingQueue.php | 45 ++++ .../Diagnostics/Commands/ArchivingStatus.php | 105 +++++++++ .../Commands/ArchivingConfigTest.php | 93 ++++++++ .../ArchivingInstanceStatisticsTest.php | 82 +++++++ .../Commands/ArchivingMetricsTest.php | 80 +++++++ .../Commands/ArchivingQueueTest.php | 74 ++++++ .../Commands/ArchivingStatusTest.php | 219 ++++++++++++++++++ 14 files changed, 1058 insertions(+) create mode 100644 core/Plugin/ConsoleCommand/ConsoleCommandBufferedOutput.php create mode 100644 core/Plugin/ConsoleCommand/ConsoleCommandConsoleOutput.php create mode 100644 plugins/Diagnostics/Commands/ArchivingConfig.php create mode 100644 plugins/Diagnostics/Commands/ArchivingInstanceStatistics.php create mode 100644 plugins/Diagnostics/Commands/ArchivingMetrics.php create mode 100644 plugins/Diagnostics/Commands/ArchivingQueue.php create mode 100644 plugins/Diagnostics/Commands/ArchivingStatus.php create mode 100644 plugins/Diagnostics/tests/Integration/Commands/ArchivingConfigTest.php create mode 100644 plugins/Diagnostics/tests/Integration/Commands/ArchivingInstanceStatisticsTest.php create mode 100644 plugins/Diagnostics/tests/Integration/Commands/ArchivingMetricsTest.php create mode 100644 plugins/Diagnostics/tests/Integration/Commands/ArchivingQueueTest.php create mode 100644 plugins/Diagnostics/tests/Integration/Commands/ArchivingStatusTest.php diff --git a/core/DataAccess/ArchiveTableDao.php b/core/DataAccess/ArchiveTableDao.php index b1baee844fd..449dae80148 100644 --- a/core/DataAccess/ArchiveTableDao.php +++ b/core/DataAccess/ArchiveTableDao.php @@ -9,7 +9,9 @@ namespace Piwik\DataAccess; use Piwik\Common; +use Piwik\Date; use Piwik\Db; +use Piwik\Metrics\Formatter; /** * Data Access class for querying numeric & blob archive tables. @@ -86,4 +88,57 @@ public function getArchiveTableAnalysis($tableDate) return $result; } + + /** + * Return invalidation queue table data + * + * @param bool $prettyTime + * + * @return array + * @throws \Exception + */ + public function getInvalidationQueueData(bool $prettyTime = false): array + { + $invalidationsTable = Common::prefixTable("archive_invalidations"); + $segmentsTable = Common::prefixTable("segment"); + $sql = " + SELECT ai.*, s.definition + FROM `$invalidationsTable` ai + LEFT JOIN `$segmentsTable` s ON SUBSTRING(ai.name, 5) = s.hash + GROUP BY ai.idinvalidation + ORDER BY ts_invalidated, idinvalidation ASC"; + $invalidations = Db::fetchAll($sql); + + $metricsFormatter = new Formatter(); + + $data = []; + foreach ($invalidations as $i) { + + $waiting = (int) Date::now()->getTimestampUTC() - Date::factory($i['ts_invalidated'])->getTimestampUTC(); + $processing = (int) $i['ts_started'] ? Date::now()->getTimestampUTC() - (int) $i['ts_started'] : ''; + + if ($prettyTime) { + $waiting = $metricsFormatter->getPrettyTimeFromSeconds($waiting, true); + if ($processing != '') { + $processing = $metricsFormatter->getPrettyTimeFromSeconds($processing, true); + } + } + + $d = []; + $d['Invalidation'] = (int) $i['idinvalidation']; + $d['Segment'] = $i['definition']; + $d['Site'] = (int) $i['idsite']; + $d['Period'] = ($i['period'] == 1 ? 'Day' : ($i['period'] == 2 ? 'Week' : ($i['period'] == 3 ? 'Month' : + ($i['period'] == 4 ? 'Year' : 'Range')))); + $d['Date'] = ($i['period'] == 1 ? $i['date1'] : ($i['period'] == 3 ? substr($i['date1'], 0, 7) : + ($i['period'] == 4 ? substr($i['date1'], 0, 4) : $i['date1'] . ' - ' . $i['date2']))); + $d['TimeQueued'] = $i['ts_invalidated']; + $d['Waiting'] = $waiting; + $d['Started'] = $i['ts_started']; + $d['Processing'] = $processing; + $d['Status'] = ($i['status'] == 1 ? 'Processing' : 'Queued'); + $data[] = $d; + } + return $data; + } } diff --git a/core/Plugin/ConsoleCommand.php b/core/Plugin/ConsoleCommand.php index 90ce6a0f1fb..dba6dd9722e 100644 --- a/core/Plugin/ConsoleCommand.php +++ b/core/Plugin/ConsoleCommand.php @@ -322,6 +322,16 @@ protected function getOutput(): OutputInterface return $this->output; } + /** + * @param OutputInterface $ouput + * + * @return void + */ + protected function setOutput(OutputInterface $output): void + { + $this->output = $output; + } + /** * @return InputInterface */ diff --git a/core/Plugin/ConsoleCommand/ConsoleCommandBufferedOutput.php b/core/Plugin/ConsoleCommand/ConsoleCommandBufferedOutput.php new file mode 100644 index 00000000000..219f42f8db5 --- /dev/null +++ b/core/Plugin/ConsoleCommand/ConsoleCommandBufferedOutput.php @@ -0,0 +1,21 @@ +setName('diagnostics:archiving-config'); + $this->addNoValueOption('json', null, + "If supplied, the command will return data in json format"); + $this->setDescription('Show configuration settings that can affect archiving performance'); + } + + protected function doExecute(): int + { + $input = $this->getInput(); + $output = $this->getOutput(); + + $metrics = $this->getArchivingConfig(); + + if ($input->getOption('json')) { + $output->write(json_encode($metrics)); + } else { + $headers = ['Section', 'Setting', 'Value']; + $this->renderTable($headers, $metrics); + } + + return self::SUCCESS; + } + + /** + * Retrieve various data statistics useful for diagnosing archiving performance + * + * @return array + */ + public function getArchivingConfig(): array + { + $configs = [ + 'database' => [ + 'enable_segment_first_table_join_prefix', + 'enable_first_table_join_prefix' + ], + 'general' => [ + 'browser_archiving_disabled_enforce', + 'enable_processing_unique_visitors_day', + 'enable_processing_unique_visitors_week', + 'enable_processing_unique_visitors_month', + 'enable_processing_unique_visitors_year', + 'enable_processing_unique_visitors_range', + 'enable_processing_unique_visitors_multiple_sites', + 'process_new_segments_from', + 'time_before_today_archive_considered_outdated', + 'time_before_week_archive_considered_outdated', + 'time_before_month_archive_considered_outdated', + 'time_before_year_archive_considered_outdated', + 'time_before_range_archive_considered_outdated', + 'enable_browser_archiving_triggering', + 'archiving_range_force_on_browser_request', + 'archiving_custom_ranges[]', + 'archiving_query_max_execution_time', + 'archiving_ranking_query_row_limit', + 'disable_archiving_segment_for_plugins', + 'disable_archive_actions_goals', + 'datatable_archiving_maximum_rows_referrers', + 'datatable_archiving_maximum_rows_subtable_referrers', + 'datatable_archiving_maximum_rows_userid_users', + 'datatable_archiving_maximum_rows_custom_dimensions', + 'datatable_archiving_maximum_rows_subtable_custom_dimensions', + 'datatable_archiving_maximum_rows_actions', + 'datatable_archiving_maximum_rows_subtable_actions', + 'datatable_archiving_maximum_rows_site_search', + 'datatable_archiving_maximum_rows_events', + 'datatable_archiving_maximum_rows_subtable_events', + 'datatable_archiving_maximum_rows_products', + 'datatable_archiving_maximum_rows_standard' + ] + ]; + + $data = []; + foreach ($configs as $section => $sectionConfigs) { + foreach ($sectionConfigs as $setting) { + switch ($section) { + case 'general': + $value = GeneralConfig::getConfigValue($setting); + break; + case 'database': + $value = DatabaseConfig::getConfigValue($setting); + break; + default: + $value = Config::getInstance()->{$section}[$setting] ?? ''; + } + $data[] = ['Section' => $section, 'Setting' => $setting, 'Value' => $value]; + } + } + return $data; + } +} diff --git a/plugins/Diagnostics/Commands/ArchivingInstanceStatistics.php b/plugins/Diagnostics/Commands/ArchivingInstanceStatistics.php new file mode 100644 index 00000000000..848a1e42267 --- /dev/null +++ b/plugins/Diagnostics/Commands/ArchivingInstanceStatistics.php @@ -0,0 +1,73 @@ +setName('diagnostics:archiving-instance-statistics'); + $this->addNoValueOption('json', null, + "If supplied, the command will return data in json format"); + $this->setDescription('Show data statistics which can affect archiving performance'); + } + + protected function doExecute(): int + { + $input = $this->getInput(); + $output = $this->getOutput(); + + $metrics = $this->getArchivingInstanceStatistics(); + + if ($input->getOption('json')) { + $output->write(json_encode($metrics)); + } else { + $headers = ['Statistic Name', 'Value']; + $this->renderTable($headers, $metrics); + } + + return self::SUCCESS; + } + + /** + * Retrieve various data statistics useful for diagnosing archiving performance + * + * @return array + */ + public function getArchivingInstanceStatistics(): array + { + $stats = []; + $stats[] = ['Site Count', (int) Db::fetchOne("SELECT COUNT(*) FROM " . Common::prefixTable("site"))]; + $stats[] = ['Segment Count', (int) Db::fetchOne("SELECT COUNT(*) FROM " . Common::prefixTable("segment"))]; + $stats[] = ['Database Version', defined('PIWIK_TEST_MODE') ? 'mysql-version-redacted' : Db::get()->getServerVersion()]; + $stats[] = ['Last full Month Hits', (int) Db::fetchOne( + "SELECT COUNT(*) FROM " . Common::prefixTable("log_link_visit_action") . " WHERE server_time >= ? AND server_time <= ?", + [ + Date::now()->setDay(1)->subMonth(1)->setTime('00:00:00')->toString('Y-m-d H:i:s'), + Date::now()->setDay(1)->subDay(1)->setTime('23:59:59')->toString('Y-m-d H:i:s') + ]) + ]; + $stats[] = ['Last 12 Month Hits', (int) Db::fetchOne( + "SELECT COUNT(*) FROM " . Common::prefixTable("log_link_visit_action") . " WHERE server_time >= ? AND server_time <= ?", + [ + Date::now()->setDay(1)->subMonth(12)->setTime('00:00:00')->toString('Y-m-d H:i:s'), + Date::now()->setDay(1)->subDay(1)->setTime('23:59:59')->toString('Y-m-d H:i:s') + ]) + ]; + return $stats; + } +} diff --git a/plugins/Diagnostics/Commands/ArchivingMetrics.php b/plugins/Diagnostics/Commands/ArchivingMetrics.php new file mode 100644 index 00000000000..d11024807f4 --- /dev/null +++ b/plugins/Diagnostics/Commands/ArchivingMetrics.php @@ -0,0 +1,68 @@ +setName('diagnostics:archiving-metrics'); + $this->addNoValueOption('json', null, + "If supplied, the command will return data in json format"); + $this->setDescription('Show metrics describing the current archiving status'); + } + + protected function doExecute(): int + { + $input = $this->getInput(); + $output = $this->getOutput(); + + $metrics = $this->getMetrics(); + + if ($input->getOption('json')) { + $output->write(json_encode($metrics)); + } else { + $headers = ['Metric', 'Value']; + $this->renderTable($headers, $metrics); + } + + return self::SUCCESS; + } + + /** + * Get an archiving metrics array from the diagnostics class + * + * @return array + * @throws \Piwik\Exception\DI\DependencyException + * @throws \Piwik\Exception\DI\NotFoundException + */ + public function getMetrics(): array + { + $metrics = []; + $informational = new ArchiveInvalidationsInformational(StaticContainer::get(Translator::class)); + $diags[] = $informational->execute(); + if (is_array($diags)) { + foreach (reset($diags) as $diag) { + $items = $diag->getItems(); + if (count($items) > 0) { + $metrics[] = [$diag->getLabel(), reset($items)->getComment()]; + } + } + } + return $metrics; + } +} diff --git a/plugins/Diagnostics/Commands/ArchivingQueue.php b/plugins/Diagnostics/Commands/ArchivingQueue.php new file mode 100644 index 00000000000..732ed4f79f8 --- /dev/null +++ b/plugins/Diagnostics/Commands/ArchivingQueue.php @@ -0,0 +1,45 @@ +setName('diagnostics:archiving-queue'); + $this->addNoValueOption('json', null, + "If supplied, the command will return table data in json format"); + $this->setDescription('Show the current state of the archive invalidations queue as a table'); + } + + protected function doExecute(): int + { + $input = $this->getInput(); + $output = $this->getOutput(); + + $archiveTableDao = StaticContainer::get('Piwik\DataAccess\ArchiveTableDao'); + + if ($input->getOption('json')) { + $queue = $archiveTableDao->getInvalidationQueueData(); + $output->write(json_encode($queue)); + } else { + $headers = ['Invalidation', 'Segment', 'Site', 'Period', 'Date', 'Time Queued', 'Waiting', 'Started', 'Processing', 'Status']; + $queue = $archiveTableDao->getInvalidationQueueData(true); + $this->renderTable($headers, $queue); + } + + return self::SUCCESS; + } +} diff --git a/plugins/Diagnostics/Commands/ArchivingStatus.php b/plugins/Diagnostics/Commands/ArchivingStatus.php new file mode 100644 index 00000000000..f21758301b2 --- /dev/null +++ b/plugins/Diagnostics/Commands/ArchivingStatus.php @@ -0,0 +1,105 @@ +setName('diagnostics:archiving-status'); + $this->addNoValueOption('with-stats', null, + "If supplied, the command will include instance statistics such as monthly hits and site count"); + $this->addOptionalValueOption('email', null, + "If supplied, the command will email the output to the supplied email address"); + $this->setDescription(''); + } + + protected function doExecute(): int + { + $input = $this->getInput(); + + // If using email option then buffer output + if ($input->getOption('email')) { + $output = new ConsoleCommandBufferedOutput(); + $this->setOutput($output); + } else { + $output = $this->getOutput(); + } + + // Queue + $this->outputSectionHeader($output, 'Invalidation Queue'); + $archiveTableDao = StaticContainer::get('Piwik\DataAccess\ArchiveTableDao'); + $headers = ['Invalidation', 'Segment', 'Site', 'Period', 'Date', 'Time Queued', 'Waiting', 'Started', 'Processing', 'Status']; + $queue = $archiveTableDao->getInvalidationQueueData(true); + $this->renderTable($headers, $queue); + + // Metrics + $this->outputSectionHeader($output, 'Archiving Metrics'); + $am = new ArchivingMetrics(); + $this->renderTable(['Metric', 'Value'], $am->getMetrics()); + + // Optional instance stats + if ($input->getOption('with-stats')) { + $this->outputSectionHeader($output, 'Instance Statistics'); + $ais = new ArchivingInstanceStatistics(); + $this->renderTable(['Statistic Name', 'Value'], $ais->getArchivingInstanceStatistics()); + } + + // Config + $this->outputSectionHeader($output, 'Archiving Configuration Settings'); + $am = new ArchivingConfig(); + $this->renderTable(['Section', 'Setting', 'Value'], $am->getArchivingConfig()); + + if ($input->getOption('email')) { + $address = $input->getOption('email'); + $content = 'This email was sent via the Matomo diagnostic:archiving-status command'; + $content .= '
';
+            $content .= $output->fetch();
+            $content .= '
'; + $mail = new Mail(); + $mail->setDefaultFromPiwik(); + $mail->addTo($address); + $mail->setSubject('Matomo Archiving Diagnostics'); + $mail->setWrappedHtmlBody($content); + $output = new ConsoleCommandConsoleOutput(); + $this->setOutput($output); + try { + $mail->send(); + $output->writeln("Archiving diagnostic email successfully sent to " . $address); + } catch (\Exception $e) { + $output->writeln("Failed to send email to " . $address . ", error: " . $e->getMessage()); + return self::FAILURE; + } + } + + return self::SUCCESS; + } + + /** + * Output a styled header string + * + * @param mixed $output + * @param string $title + * + * @return void + */ + private function outputSectionHeader($output, string $title): void + { + $output->writeln("\n" . $title . ""); + } +} diff --git a/plugins/Diagnostics/tests/Integration/Commands/ArchivingConfigTest.php b/plugins/Diagnostics/tests/Integration/Commands/ArchivingConfigTest.php new file mode 100644 index 00000000000..f2620e1aa51 --- /dev/null +++ b/plugins/Diagnostics/tests/Integration/Commands/ArchivingConfigTest.php @@ -0,0 +1,93 @@ +applicationTester->run([ + 'command' => 'diagnostics:archiving-config' + ]); + $actual = $this->applicationTester->getDisplay(); + + $this->assertStringMatchesFormat($expected, $actual); + } + + public function test_CommandOutput_withJsonOption_IsAsExpected() + { + $expected = '[["Total Invalidation Count","0"],["In Progress Invalidation Count","0"],["Scheduled Invalidation Count","0"],["Earliest invalidation ts_started",""],["Latest invalidation ts_started",""],["Earliest invalidation ts_invalidated",""],["Latest invalidation ts_invalidated",""],["Number of segment invalidations","0"],["Number of plugin invalidations","0"],["List of plugins being invalidated",""]]'; + $this->applicationTester->run([ + 'command' => 'diagnostics:archiving-metrics', + '--json' => true + ]); + $actual = $this->applicationTester->getDisplay(); + + $this->assertStringMatchesFormat($expected, $actual); + } +} + +ArchivingConfigTest::$fixture = new OneVisitorTwoVisits(); diff --git a/plugins/Diagnostics/tests/Integration/Commands/ArchivingInstanceStatisticsTest.php b/plugins/Diagnostics/tests/Integration/Commands/ArchivingInstanceStatisticsTest.php new file mode 100644 index 00000000000..4bdf03c2850 --- /dev/null +++ b/plugins/Diagnostics/tests/Integration/Commands/ArchivingInstanceStatisticsTest.php @@ -0,0 +1,82 @@ +get(self::$fixture->idSite, 'month', '2010-02-01'); + VisitsSummaryAPI::getInstance()->get(self::$fixture->idSite, 'month', '2010-02-01', 'browserCode==FF'); + VisitsSummaryAPI::getInstance()->get(self::$fixture->idSite, 'month', '2010-02-01', 'daysSinceFirstVisit==2'); + VisitsSummaryAPI::getInstance()->get(self::$fixture->idSite, 'month', '2010-03-01'); + VisitsSummaryAPI::getInstance()->get(self::$fixture->idSite, 'month', '2010-03-01', 'browserCode==FF'); + VisitsSummaryAPI::getInstance()->get(self::$fixture->idSite, 'month', '2010-03-01', 'daysSinceFirstVisit==2'); + + // Create a segment + SegmentEditorAPI::getInstance()->add('test segment', 'browserCode==IE', self::$fixture->idSite); + + Date::$now = strtotime('2010-04-07 06:00:00'); + } + + public function test_CommandOutput_IsAsExpected() + { + $expected = <<applicationTester->run([ + 'command' => 'diagnostics:archiving-instance-statistics' + ]); + $actual = $this->applicationTester->getDisplay(); + + $this->assertStringMatchesFormat($expected, $actual); + } + + public function test_CommandOutput_withJsonOption_IsAsExpected() + { + $expected = '[["Site Count",3],["Segment Count",1],["Database Version","mysql-version-redacted"],["Last full Month Hits",8],["Last 12 Month Hits",8]]'; + $this->applicationTester->run([ + 'command' => 'diagnostics:archiving-instance-statistics', + '--json' => true + ]); + $actual = $this->applicationTester->getDisplay(); + + $this->assertStringMatchesFormat($expected, $actual); + } +} + +ArchivingInstanceStatisticsTest::$fixture = new OneVisitorTwoVisits(); diff --git a/plugins/Diagnostics/tests/Integration/Commands/ArchivingMetricsTest.php b/plugins/Diagnostics/tests/Integration/Commands/ArchivingMetricsTest.php new file mode 100644 index 00000000000..fe25fd2a5e7 --- /dev/null +++ b/plugins/Diagnostics/tests/Integration/Commands/ArchivingMetricsTest.php @@ -0,0 +1,80 @@ +get(self::$fixture->idSite, 'month', '2010-03-01'); + VisitsSummaryAPI::getInstance()->get(self::$fixture->idSite, 'month', '2010-03-01', 'browserCode==FF'); + VisitsSummaryAPI::getInstance()->get(self::$fixture->idSite, 'month', '2010-03-01', 'daysSinceFirstVisit==2'); + + Date::$now = strtotime('2010-03-07 06:00:00'); + } + + public function test_CommandOutput_IsAsExpected() + { + $expected = <<applicationTester->run([ + 'command' => 'diagnostics:archiving-metrics' + ]); + $actual = $this->applicationTester->getDisplay(); + + $this->assertStringMatchesFormat($expected, $actual); + } + + public function test_CommandOutput_withJsonOption_IsAsExpected() + { + $expected = '[["Total Invalidation Count","4"],["In Progress Invalidation Count","0"],["Scheduled Invalidation Count","4"],["Earliest invalidation ts_started",""],["Latest invalidation ts_started",""],["Earliest invalidation ts_invalidated","2010-03-07 01:00:00"],["Latest invalidation ts_invalidated","2010-03-07 01:00:00"],["Number of segment invalidations","0"],["Number of plugin invalidations","0"],["List of plugins being invalidated",""]]'; + $this->applicationTester->run([ + 'command' => 'diagnostics:archiving-metrics', + '--json' => true + ]); + $actual = $this->applicationTester->getDisplay(); + + $this->assertStringMatchesFormat($expected, $actual); + } +} + +ArchivingMetricsTest::$fixture = new OneVisitorTwoVisits(); diff --git a/plugins/Diagnostics/tests/Integration/Commands/ArchivingQueueTest.php b/plugins/Diagnostics/tests/Integration/Commands/ArchivingQueueTest.php new file mode 100644 index 00000000000..5279ea68f5f --- /dev/null +++ b/plugins/Diagnostics/tests/Integration/Commands/ArchivingQueueTest.php @@ -0,0 +1,74 @@ +get(self::$fixture->idSite, 'month', '2010-03-01'); + VisitsSummaryAPI::getInstance()->get(self::$fixture->idSite, 'month', '2010-03-01', 'browserCode==FF'); + VisitsSummaryAPI::getInstance()->get(self::$fixture->idSite, 'month', '2010-03-01', 'daysSinceFirstVisit==2'); + + Date::$now = strtotime('2010-03-07 06:00:00'); + } + + public function test_CommandOutput_IsAsExpected() + { + $expected = <<applicationTester->run([ + 'command' => 'diagnostics:archiving-queue' + ]); + $actual = $this->applicationTester->getDisplay(); + + $this->assertStringMatchesFormat($expected, $actual); + } + + public function test_CommandOutput_withJsonOption_IsAsExpected() + { + $expected = '[{"Invalidation":1,"Segment":null,"Site":1,"Period":"Day","Date":"2010-03-06","TimeQueued":"2010-03-07 01:00:00","Waiting":18000,"Started":null,"Processing":"","Status":"Queued"},{"Invalidation":2,"Segment":null,"Site":1,"Period":"Week","Date":"2010-03-01 - 2010-03-07","TimeQueued":"2010-03-07 01:00:00","Waiting":18000,"Started":null,"Processing":"","Status":"Queued"},{"Invalidation":3,"Segment":null,"Site":1,"Period":"Month","Date":"2010-03","TimeQueued":"2010-03-07 01:00:00","Waiting":18000,"Started":null,"Processing":"","Status":"Queued"},{"Invalidation":4,"Segment":null,"Site":1,"Period":"Year","Date":"2010","TimeQueued":"2010-03-07 01:00:00","Waiting":18000,"Started":null,"Processing":"","Status":"Queued"}]'; + $this->applicationTester->run(array( + 'command' => 'diagnostics:archiving-queue', + '--json' => true + )); + $actual = $this->applicationTester->getDisplay(); + + $this->assertStringMatchesFormat($expected, $actual); + } +} + +ArchivingQueueTest::$fixture = new OneVisitorTwoVisits(); diff --git a/plugins/Diagnostics/tests/Integration/Commands/ArchivingStatusTest.php b/plugins/Diagnostics/tests/Integration/Commands/ArchivingStatusTest.php new file mode 100644 index 00000000000..5b1cf755b9e --- /dev/null +++ b/plugins/Diagnostics/tests/Integration/Commands/ArchivingStatusTest.php @@ -0,0 +1,219 @@ +get(self::$fixture->idSite, 'month', '2010-02-01'); + VisitsSummaryAPI::getInstance()->get(self::$fixture->idSite, 'month', '2010-02-01', 'browserCode==FF'); + VisitsSummaryAPI::getInstance()->get(self::$fixture->idSite, 'month', '2010-02-01', 'daysSinceFirstVisit==2'); + VisitsSummaryAPI::getInstance()->get(self::$fixture->idSite, 'month', '2010-03-01'); + VisitsSummaryAPI::getInstance()->get(self::$fixture->idSite, 'month', '2010-03-01', 'browserCode==FF'); + VisitsSummaryAPI::getInstance()->get(self::$fixture->idSite, 'month', '2010-03-01', 'daysSinceFirstVisit==2'); + + // Create a segment + SegmentEditorAPI::getInstance()->add('test segment', 'browserCode==IE', self::$fixture->idSite); + + Date::$now = strtotime('2010-04-07 06:00:00'); + } + + public function test_CommandOutput_IsAsExpected() + { + $expected = <<applicationTester->run([ + 'command' => 'diagnostics:archiving-status' + ]); + $actual = $this->applicationTester->getDisplay(); + + $this->assertStringMatchesFormat($expected, $actual); + } + + + public function test_CommandOutput_withStatsOption_IsAsExpected() + { + $expected = <<applicationTester->run(array( + 'command' => 'diagnostics:archiving-status', + '--with-stats' => true + )); + $actual = $this->applicationTester->getDisplay(); + + $this->assertStringMatchesFormat($expected, $actual); + } +} + +ArchivingStatusTest::$fixture = new OneVisitorTwoVisits();