Skip to content

Commit

Permalink
T&A: add metric to collect inconsistencies for #37759
Browse files Browse the repository at this point in the history
  • Loading branch information
klees committed Apr 25, 2024
1 parent 2cfb410 commit ac9db57
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

use ILIAS\Setup;
use ILIAS\Setup\Metrics\Metric;
use ILIAS\DI;

class ilTestDatabaseInconsistencyMetricsCollectedObjective extends Setup\Metrics\CollectedObjective
{
/**
* @return array<\ilDatabaseInitializedObjective|\ilIniFilesLoadedObjective>
*/
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."
);
}
}
7 changes: 6 additions & 1 deletion Modules/Test/classes/Setup/class.ilTestSetupAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ac9db57

Please sign in to comment.