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

reschke pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git


The following commit(s) were added to refs/heads/master by this push:
     new 166800f  SLING-12018: resource resolver: add metrics for resources 
with sling:alias/vanityPath found on startup (#99)
166800f is described below

commit 166800f90a67597fd7e2cb66ce2812bfc6da4059
Author: Julian Reschke <julian.resc...@gmx.de>
AuthorDate: Tue Sep 5 09:55:15 2023 +0200

    SLING-12018: resource resolver: add metrics for resources with 
sling:alias/vanityPath found on startup (#99)
    
    * SLING-12018: resource resolver: add metrics for resources with 
sling:alias/vanityPath found on startup
    
    * Update 
src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
    
    Co-authored-by: Jörg Hoh <joerg...@users.noreply.github.com>
    
    * Update 
src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
    
    Co-authored-by: Jörg Hoh <joerg...@users.noreply.github.com>
    
    ---------
    
    Co-authored-by: Jörg Hoh <joerg...@users.noreply.github.com>
---
 .../impl/ResourceResolverMetrics.java              | 46 ++++++++++++++++++----
 .../resourceresolver/impl/mapping/MapEntries.java  | 20 ++++++++--
 2 files changed, 54 insertions(+), 12 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverMetrics.java
 
b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverMetrics.java
index 8f0bbdf..46ea806 100644
--- 
a/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverMetrics.java
+++ 
b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverMetrics.java
@@ -35,6 +35,8 @@ import org.osgi.service.component.annotations.Reference;
 /**
  *  Export metrics for the resource resolver bundle:
  *
+ *  org.apache.sling.resourceresolver.numberOfResourcesWithAliasesOnStartup -- 
the total number of resources with sling:alias properties found on startup
+ *  
org.apache.sling.resourceresolver.numberOfResourcesWithVanityPathsOnStartup -- 
the total number of resources with sling:vanityPath properties found on startup
  *  org.apache.sling.resourceresolver.numberOfVanityPaths -- the total number 
of vanity paths in the cache
  *  org.apache.sling.resourceresolver.numberOfVanityPathLookups -- the total 
number of vanity path lookups
  *  org.apache.sling.resourceresolver.numberOfVanityPathBloomNegatives -- the 
total number of vanity path lookups filtered by the bloom filter
@@ -47,18 +49,22 @@ import org.osgi.service.component.annotations.Reference;
 
 @Component(service=ResourceResolverMetrics.class)
 public class ResourceResolverMetrics {
-    
+
     protected static final String METRICS_PREFIX = 
"org.apache.sling.resourceresolver";
-    
+
     @Reference
     MetricsService metricsService;
-    
+
     private static final Supplier<Long> ZERO_SUPPLIER = () -> 0L;
-    
+
     // number of vanity paths
     private ServiceRegistration<Gauge<Long>> numberOfVanityPathsGauge;
     private Supplier<Long> numberOfVanityPathsSupplier = ZERO_SUPPLIER;
 
+    // number of resources with vanity paths on startup
+    private ServiceRegistration<Gauge<Long>> 
numberOfResourcesWithVanityPathsOnStartupGauge;
+    private Supplier<Long> numberOfResourcesWithVanityPathsOnStartupSupplier = 
ZERO_SUPPLIER;
+
     // total number of vanity path lookups
     private ServiceRegistration<Gauge<Long>> numberOfVanityPathLookupsGauge;
     private Supplier<Long> numberOfVanityPathLookupsSupplier = ZERO_SUPPLIER;
@@ -74,26 +80,34 @@ public class ResourceResolverMetrics {
     // number of aliases
     private ServiceRegistration<Gauge<Long>> numberOfAliasesGauge;
     private Supplier<Long> numberOfAliasesSupplier = ZERO_SUPPLIER;
-    
+
+    // number of aliases
+    private ServiceRegistration<Gauge<Long>> 
numberOfResourcesWithAliasesOnStartupGauge;
+    private Supplier<Long> numberOfResourcesWithAliasesOnStartupSupplier = 
ZERO_SUPPLIER;
+
     private Counter unclosedResourceResolvers;
-    
-    
+
+
     @Activate
     protected void activate(BundleContext bundleContext) {
         numberOfVanityPathsGauge = registerGauge(bundleContext, METRICS_PREFIX 
+ ".numberOfVanityPaths", () -> numberOfVanityPathsSupplier );
+        numberOfResourcesWithVanityPathsOnStartupGauge = 
registerGauge(bundleContext, METRICS_PREFIX + 
".numberOfResourcesWithVanityPathsOnStartup", () -> 
numberOfResourcesWithVanityPathsOnStartupSupplier );
         numberOfVanityPathLookupsGauge = registerGauge(bundleContext, 
METRICS_PREFIX + ".numberOfVanityPathLookups", () -> 
numberOfVanityPathLookupsSupplier );
         numberOfVanityPathBloomNegativeGauge = registerGauge(bundleContext, 
METRICS_PREFIX + ".numberOfVanityPathBloomNegatives", () -> 
numberOfVanityPathBloomNegativeSupplier );
         numberOfVanityPathBloomFalsePositiveGauge = 
registerGauge(bundleContext, METRICS_PREFIX + 
".numberOfVanityPathBloomFalsePositives", () -> 
numberOfVanityPathBloomFalsePositiveSupplier );
         numberOfAliasesGauge = registerGauge(bundleContext, METRICS_PREFIX + 
".numberOfAliases", () -> numberOfAliasesSupplier );
+        numberOfResourcesWithAliasesOnStartupGauge = 
registerGauge(bundleContext, METRICS_PREFIX + 
".numberOfResourcesWithAliasesOnStartup", () -> 
numberOfResourcesWithAliasesOnStartupSupplier );
         unclosedResourceResolvers = metricsService.counter(METRICS_PREFIX  + 
".unclosedResourceResolvers");
     }
 
     @Deactivate
     protected void deactivate() {
         numberOfVanityPathsGauge.unregister();
+        numberOfResourcesWithVanityPathsOnStartupGauge.unregister();
         numberOfVanityPathLookupsGauge.unregister();
         numberOfVanityPathBloomNegativeGauge.unregister();
         numberOfVanityPathBloomFalsePositiveGauge.unregister();
+        numberOfResourcesWithAliasesOnStartupGauge.unregister();
         numberOfAliasesGauge.unregister();
     }
 
@@ -105,6 +119,14 @@ public class ResourceResolverMetrics {
         numberOfVanityPathsSupplier = supplier;
     }
 
+    /**
+     * Set the supplier for the number of resources with vanity paths on 
startup
+     * @param supplier a supplier returning number of resources with vanity 
paths on startup
+     */
+    public void 
setNumberOfResourcesWithVanityPathsOnStartupSupplier(Supplier<Long> supplier) {
+        numberOfResourcesWithVanityPathsOnStartupSupplier = supplier;
+    }
+
     /**
      * Set the number of vanity path lookups in the system
      * @param supplier a supplier returning the number of vanity path lookups
@@ -136,7 +158,15 @@ public class ResourceResolverMetrics {
     public void setNumberOfAliasesSupplier(Supplier<Long> supplier) {
         numberOfAliasesSupplier = supplier;
     }
-    
+
+    /**
+     * Set the supplier for the number of resources with aliases on startup
+     * @param supplier a supplier returning the number of resources with 
aliases on startup
+     */
+    public void 
setNumberOfResourcesWithAliasesOnStartupSupplier(Supplier<Long> supplier) {
+        numberOfResourcesWithAliasesOnStartupSupplier = supplier;
+    }
+
     /**
      * Increment the counter for the number of unresolved resource resolvers
      */
diff --git 
a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java 
b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
index bba9712..9c7eaf0 100644
--- 
a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
+++ 
b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
@@ -142,9 +142,12 @@ public class MapEntries implements
 
     private Map<String, Map<String, String>> aliasMap;
 
+    private final AtomicLong aliasResourcesOnStartup;
+
     private final ReentrantLock initializing = new ReentrantLock();
 
     private final AtomicLong vanityCounter;
+    private final AtomicLong vanityResourcesOnStartup;
     private final AtomicLong vanityPathLookups;
     private final AtomicLong vanityPathBloomNegative;
     private final AtomicLong vanityPathBloomFalsePositive;
@@ -174,11 +177,14 @@ public class MapEntries implements
         this.aliasMap = Collections.<String, Map<String, String>>emptyMap();
         this.stringInterpolationProvider = stringInterpolationProvider;
 
+        this.aliasResourcesOnStartup = new AtomicLong(0);
+
         this.useOptimizeAliasResolution = doInit();
 
         this.registration = registerResourceChangeListener(bundleContext);
 
         this.vanityCounter = new AtomicLong(0);
+        this.vanityResourcesOnStartup = new AtomicLong(0);
         this.vanityPathLookups = new AtomicLong(0);
         this.vanityPathBloomNegative = new AtomicLong(0);
         this.vanityPathBloomFalsePositive = new AtomicLong(0);
@@ -187,10 +193,12 @@ public class MapEntries implements
         this.metrics = metrics;
         if (metrics.isPresent()) {
             
this.metrics.get().setNumberOfVanityPathsSupplier(vanityCounter::get);
+            
this.metrics.get().setNumberOfResourcesWithVanityPathsOnStartupSupplier(vanityResourcesOnStartup::get);
             
this.metrics.get().setNumberOfVanityPathLookupsSupplier(vanityPathLookups::get);
             
this.metrics.get().setNumberOfVanityPathBloomNegativeSupplier(vanityPathBloomNegative::get);
             
this.metrics.get().setNumberOfVanityPathBloomFalsePositiveSupplier(vanityPathBloomFalsePositive::get);
             this.metrics.get().setNumberOfAliasesSupplier(() -> (long) 
aliasMap.size());
+            
this.metrics.get().setNumberOfResourcesWithAliasesOnStartupSupplier(aliasResourcesOnStartup::get);
         }
     }
 
@@ -1165,7 +1173,9 @@ public class MapEntries implements
             loadAlias(i.next(), map);
         }
         long processElapsed = System.nanoTime() - processStart;
-        log.debug("processed {} aliases in {}ms", count, 
TimeUnit.NANOSECONDS.toMillis(processElapsed));
+        log.debug("processed {} resources with sling:alias properties in 
{}ms", count, TimeUnit.NANOSECONDS.toMillis(processElapsed));
+
+        this.aliasResourcesOnStartup.set(count);
 
         return map;
     }
@@ -1407,15 +1417,17 @@ public class MapEntries implements
             }
         }
         long processElapsed = System.nanoTime() - processStart;
-        log.debug("processed {} vanityPaths (of which {} in scope) in {}ms", 
count, countInScope, TimeUnit.NANOSECONDS.toMillis(processElapsed));
+        log.debug("processed {} resources with sling:vanityPath properties (of 
which {} in scope) in {}ms", count, countInScope, 
TimeUnit.NANOSECONDS.toMillis(processElapsed));
         if (!isAllVanityPathEntriesCached()) {
             if (countInScope > this.factory.getMaxCachedVanityPathEntries()) {
-                log.warn("Number of vanity paths in scope ({}) exceeds 
configured cache size ({}); handling of uncached vanity paths will be much 
slower. Consider increasing the cache size or decreasing the number of vanity 
paths.", countInScope, this.factory.getMaxCachedVanityPathEntries());
+                log.warn("Number of resources with sling:vanityPath property 
({}) exceeds configured cache size ({}); handling of uncached vanity paths will 
be much slower. Consider increasing the cache size or decreasing the number of 
vanity paths.", countInScope, this.factory.getMaxCachedVanityPathEntries());
             } else if (countInScope > 
(this.factory.getMaxCachedVanityPathEntries() / 10) * 9) {
-                log.info("Number of vanity paths in scope ({}) within 10% of 
configured cache size ({})", countInScope, 
this.factory.getMaxCachedVanityPathEntries());
+                log.info("Number of resources with sling:vanityPath property 
in scope ({}) within 10% of configured cache size ({})", countInScope, 
this.factory.getMaxCachedVanityPathEntries());
             }
         }
 
+        this.vanityResourcesOnStartup.set(count);
+
         return targetPaths;
     }
 

Reply via email to