ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestDatabaseInconsistencyMetricsCollectedObjective.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 use ILIAS\Setup;
23 use ILIAS\DI;
24 
25 class ilTestDatabaseInconsistencyMetricsCollectedObjective extends Setup\Metrics\CollectedObjective
26 {
30  protected function getTentativePreconditions(Setup\Environment $environment): array
31  {
32  return [
33  new \ilDatabaseInitializedObjective()
34  ];
35  }
36 
37  protected function collectFrom(Setup\Environment $environment, Setup\Metrics\Storage $storage): void
38  {
39  $db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
40  $metrics = [
41  "database_available" => new Metric(
42  Metric::STABILITY_VOLATILE,
43  Metric::TYPE_BOOL,
44  !is_null($db),
45  "This metric is a canary to check for the general existence of this collection."
46  )
47  ];
48 
49  if ($db) {
50  $this->collectMantis37759($metrics, $db);
51  }
52 
53  $storage->store("database_inconsistencies", new Metric(
54  Metric::STABILITY_MIXED,
55  Metric::TYPE_COLLECTION,
56  $metrics,
57  "These metrics collect information about inconsistencies in the database of the T&A."
58  ));
59  }
60 
61  protected function collectMantis37759(array &$metrics, \ilDBInterface $db)
62  {
63  $result = $db->query("
64  SELECT COUNT(*) as cnt
65  FROM tst_active
66  LEFT JOIN object_data ON tst_active.test_fi = object_data.obj_id
67  WHERE object_data.obj_id IS NULL
68  ");
69 
70  $metrics["mantis_37759"] = new Metric(
71  Metric::STABILITY_VOLATILE,
72  Metric::TYPE_GAUGE,
73  $db->fetchAssoc($result)["cnt"],
74  "Measures active tests runs where the corresponding Test object does not exist anymore."
75  );
76  }
77 }
fetchAssoc(ilDBStatement $statement)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Container.php:19
A metric is something we can measure about the system.
Definition: Metric.php:33
collectFrom(Setup\Environment $environment, Setup\Metrics\Storage $storage)
query(string $query)
Run a (read-only) Query on the database.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An environment holds resources to be used in the setup process.
Definition: Environment.php:27