From 47de1649462818ee0a038aea9ed2233eb5e1cda4 Mon Sep 17 00:00:00 2001 From: Benjamin Gaussorgues Date: Thu, 21 Aug 2025 10:52:03 +0200 Subject: [PATCH] feat(comments): add basic OpenMetrics exporter Signed-off-by: Benjamin Gaussorgues --- apps/comments/appinfo/info.xml | 4 ++ .../composer/composer/autoload_classmap.php | 1 + .../composer/composer/autoload_static.php | 1 + .../lib/OpenMetrics/CommentsCountMetric.php | 52 +++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 apps/comments/lib/OpenMetrics/CommentsCountMetric.php diff --git a/apps/comments/appinfo/info.xml b/apps/comments/appinfo/info.xml index 956a8fe3914..efab11b68d8 100644 --- a/apps/comments/appinfo/info.xml +++ b/apps/comments/appinfo/info.xml @@ -38,6 +38,10 @@ + + OCA\Comments\OpenMetrics\CommentsCountMetric + + OCA\Comments\Collaboration\CommentersSorter diff --git a/apps/comments/composer/composer/autoload_classmap.php b/apps/comments/composer/composer/autoload_classmap.php index 6db5c6a232b..a6cd74eeaaa 100644 --- a/apps/comments/composer/composer/autoload_classmap.php +++ b/apps/comments/composer/composer/autoload_classmap.php @@ -22,5 +22,6 @@ return array( 'OCA\\Comments\\MaxAutoCompleteResultsInitialState' => $baseDir . '/../lib/MaxAutoCompleteResultsInitialState.php', 'OCA\\Comments\\Notification\\Listener' => $baseDir . '/../lib/Notification/Listener.php', 'OCA\\Comments\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php', + 'OCA\\Comments\\OpenMetrics\\CommentsCountMetric' => $baseDir . '/../lib/OpenMetrics/CommentsCountMetric.php', 'OCA\\Comments\\Search\\CommentsSearchProvider' => $baseDir . '/../lib/Search/CommentsSearchProvider.php', ); diff --git a/apps/comments/composer/composer/autoload_static.php b/apps/comments/composer/composer/autoload_static.php index 60359abb6d0..6dee6b1fc96 100644 --- a/apps/comments/composer/composer/autoload_static.php +++ b/apps/comments/composer/composer/autoload_static.php @@ -37,6 +37,7 @@ class ComposerStaticInitComments 'OCA\\Comments\\MaxAutoCompleteResultsInitialState' => __DIR__ . '/..' . '/../lib/MaxAutoCompleteResultsInitialState.php', 'OCA\\Comments\\Notification\\Listener' => __DIR__ . '/..' . '/../lib/Notification/Listener.php', 'OCA\\Comments\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php', + 'OCA\\Comments\\OpenMetrics\\CommentsCountMetric' => __DIR__ . '/..' . '/../lib/OpenMetrics/CommentsCountMetric.php', 'OCA\\Comments\\Search\\CommentsSearchProvider' => __DIR__ . '/..' . '/../lib/Search/CommentsSearchProvider.php', ); diff --git a/apps/comments/lib/OpenMetrics/CommentsCountMetric.php b/apps/comments/lib/OpenMetrics/CommentsCountMetric.php new file mode 100644 index 00000000000..d0c9233b7c3 --- /dev/null +++ b/apps/comments/lib/OpenMetrics/CommentsCountMetric.php @@ -0,0 +1,52 @@ +connection->getQueryBuilder(); + $result = $qb->select($qb->func()->count()) + ->from('comments') + ->where($qb->expr()->eq('verb', $qb->expr()->literal('comment'))) + ->executeQuery(); + + yield new Metric($result->fetchOne(), [], time()); + } +}