diff --git a/Modules/Test/classes/Setup/class.ilTestDatabaseInconsistencyMetricsCollectedObjective.php b/Modules/Test/classes/Setup/class.ilTestDatabaseInconsistencyMetricsCollectedObjective.php new file mode 100644 index 000000000000..932283d920aa --- /dev/null +++ b/Modules/Test/classes/Setup/class.ilTestDatabaseInconsistencyMetricsCollectedObjective.php @@ -0,0 +1,77 @@ + + */ + protected function getTentativePreconditions(Setup\Environment $environment): array + { + return [ + new \ilDatabaseInitializedObjective() + ]; + } + + protected function collectFrom(Setup\Environment $environment, Setup\Metrics\Storage $storage): void + { + $db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE); + $metrics = [ + "database_available" => new Metric( + Metric::STABILITY_VOLATILE, + Metric::TYPE_BOOL, + !is_null($db), + "This metric is a canary to check for the general existence of this collection." + ) + ]; + + if ($db) { + $this->collectMantis37759($metrics, $db); + } + + $storage->store("database_inconsistencies", new Metric( + Metric::STABILITY_MIXED, + Metric::TYPE_COLLECTION, + $metrics, + "These metrics collect information about inconsistencies in the database of the T&A." + )); + } + + protected function collectMantis37759(array &$metrics, \ilDBInterface $db) + { + $result = $db->query(" + SELECT COUNT(*) as cnt + FROM tst_active + LEFT JOIN object_data ON tst_active.test_fi = object_data.obj_id + WHERE object_data.obj_id IS NULL + "); + + $metrics["mantis_37759"] = new Metric( + Metric::STABILITY_VOLATILE, + Metric::TYPE_GAUGE, + $db->fetchAssoc($result)["cnt"], + "Measures active tests runs where the corresponding Test object does not exist anymore." + ); + } +} diff --git a/Modules/Test/classes/Setup/class.ilTestSetupAgent.php b/Modules/Test/classes/Setup/class.ilTestSetupAgent.php index 138c095d7862..1818ca4b2a06 100644 --- a/Modules/Test/classes/Setup/class.ilTestSetupAgent.php +++ b/Modules/Test/classes/Setup/class.ilTestSetupAgent.php @@ -39,7 +39,12 @@ public function getUpdateObjective(ILIAS\Setup\Config $config = null): Objective public function getStatusObjective(Metrics\Storage $storage): Objective { - return new ilDatabaseUpdateStepsMetricsCollectedObjective($storage, new ilTest9DBUpdateSteps()); + return new Setup\ObjectiveCollection( + "Metrics from the Test & Assessment", + false, + new ilDatabaseUpdateStepsMetricsCollectedObjective($storage, new ilTest9DBUpdateSteps()), + new ilTestDatabaseInconsistencyMetricsCollectedObjective($storage) + ); } public function hasConfig(): bool