You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by jo...@apache.org on 2022/02/04 15:56:21 UTC

[sling-org-apache-sling-event] branch improvement/SLING-11091-improve-observability created (now 8ae7eb8)

This is an automated email from the ASF dual-hosted git repository.

joerghoh pushed a change to branch improvement/SLING-11091-improve-observability
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-event.git.


      at 8ae7eb8  SLING-11091: expose the number of scheduled jobs as metric

This branch includes the following new commits:

     new 8ae7eb8  SLING-11091: expose the number of scheduled jobs as metric

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[sling-org-apache-sling-event] 01/01: SLING-11091: expose the number of scheduled jobs as metric

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joerghoh pushed a commit to branch improvement/SLING-11091-improve-observability
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-event.git

commit 8ae7eb80c76693e6f121eeed12f9e4c93c3acd6a
Author: Joerg Hoh <jh...@adobe.com>
AuthorDate: Fri Feb 4 16:56:02 2022 +0100

    SLING-11091: expose the number of scheduled jobs as metric
---
 .../apache/sling/event/impl/jobs/JobManagerImpl.java   | 18 +++++++++++++++++-
 .../event/impl/jobs/scheduling/JobSchedulerImpl.java   |  8 ++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/event/impl/jobs/JobManagerImpl.java b/src/main/java/org/apache/sling/event/impl/jobs/JobManagerImpl.java
index 388b5cf..c3e963a 100644
--- a/src/main/java/org/apache/sling/event/impl/jobs/JobManagerImpl.java
+++ b/src/main/java/org/apache/sling/event/impl/jobs/JobManagerImpl.java
@@ -67,6 +67,7 @@ import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Deactivate;
 import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
 import org.osgi.service.component.annotations.ReferencePolicyOption;
 import org.osgi.service.event.Event;
 import org.osgi.service.event.EventAdmin;
@@ -75,6 +76,9 @@ import org.osgi.service.event.EventHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.codahale.metrics.Gauge;
+import com.codahale.metrics.MetricRegistry;
+
 
 /**
  * Implementation of the job manager.
@@ -91,6 +95,8 @@ import org.slf4j.LoggerFactory;
     })
 public class JobManagerImpl
     implements JobManager, EventHandler, Runnable {
+    
+    private static final String GAUGE_TOTAL_SCHEDULED_JOBS = "totalScheduledJobs";
 
     /** Default logger. */
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
@@ -116,6 +122,10 @@ public class JobManagerImpl
 
     @Reference
     private StatisticsManager statisticsManager;
+    
+    
+    @Reference(target = "(name=sling)", cardinality = ReferenceCardinality.OPTIONAL)
+    private MetricRegistry metricRegistry;
 
     @Reference
     private QueueManager qManager;
@@ -134,6 +144,10 @@ public class JobManagerImpl
     @Activate
     protected void activate(final BundleContext ctx, final Map<String, Object> props) throws LoginException {
         this.jobScheduler = new org.apache.sling.event.impl.jobs.scheduling.JobSchedulerImpl(this.configuration, this.scheduler, this);
+        if (metricRegistry != null) {
+            Gauge<Integer> sup = () -> jobScheduler.getTotalNumberOfScheduledJobs();
+            metricRegistry.gauge(GAUGE_TOTAL_SCHEDULED_JOBS, () -> sup);
+        }
         this.maintenanceTask = new CleanUpTask(this.configuration, this.jobScheduler);
 
         final Dictionary<String, Object> regProps = new Hashtable<>();
@@ -160,7 +174,9 @@ public class JobManagerImpl
             this.changeListenerReg.unregister();
             this.changeListenerReg = null;
         }
-
+        if (metricRegistry != null) {
+            metricRegistry.remove(GAUGE_TOTAL_SCHEDULED_JOBS);
+        }
         this.jobScheduler.deactivate();
 
         this.maintenanceTask = null;
diff --git a/src/main/java/org/apache/sling/event/impl/jobs/scheduling/JobSchedulerImpl.java b/src/main/java/org/apache/sling/event/impl/jobs/scheduling/JobSchedulerImpl.java
index 4f7de0e..40d2039 100644
--- a/src/main/java/org/apache/sling/event/impl/jobs/scheduling/JobSchedulerImpl.java
+++ b/src/main/java/org/apache/sling/event/impl/jobs/scheduling/JobSchedulerImpl.java
@@ -455,6 +455,14 @@ public class JobSchedulerImpl
         }
         return jobs;
     }
+    
+    /**
+     * Provide the total number of jobs registered in the system, irrespective of topics
+     * @return the total number of scheduled jobs
+     */
+    public int getTotalNumberOfScheduledJobs() {
+       return this.scheduledJobs.size(); 
+    }
 
     /**
      * Change the suspended flag for a scheduled job