This is an automated email from the ASF dual-hosted git repository.
joerghoh pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-models-impl.git
The following commit(s) were added to refs/heads/master by this push:
new f5b8eff SLING-12369 add metric to report the number of entries in the
request… (#53)
f5b8eff is described below
commit f5b8effbbc9651fa0f01b7fee85fdf5f52fbbe18
Author: Jörg Hoh <[email protected]>
AuthorDate: Mon Jul 8 18:35:42 2024 +0200
SLING-12369 add metric to report the number of entries in the request… (#53)
* SLING-12369 add metric to report the number of entries in the
requestDisposalCallbacks map
---
pom.xml | 6 ++++++
.../org/apache/sling/models/impl/ModelAdapterFactory.java | 11 +++++++++++
.../java/org/apache/sling/models/impl/AdapterFactoryTest.java | 2 ++
.../sling/models/impl/StaticInjectionAPFLoadOrderTest.java | 3 +++
4 files changed, 22 insertions(+)
diff --git a/pom.xml b/pom.xml
index 7fb1d5d..b2f7530 100644
--- a/pom.xml
+++ b/pom.xml
@@ -142,6 +142,12 @@
<artifactId>annotations</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.commons.metrics</artifactId>
+ <version>1.2.12</version>
+ <scope>provided</scope>
+ </dependency>
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
diff --git
a/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
b/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
index 44e8ca3..8a4c821 100644
--- a/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
+++ b/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
@@ -54,6 +54,8 @@ import org.apache.sling.api.adapter.Adaptable;
import org.apache.sling.api.adapter.AdapterFactory;
import org.apache.sling.api.adapter.AdapterManager;
import org.apache.sling.api.resource.Resource;
+import org.apache.sling.commons.metrics.Gauge;
+import org.apache.sling.commons.metrics.MetricsService;
import org.apache.sling.commons.osgi.RankedServices;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.ValidationStrategy;
@@ -207,6 +209,8 @@ public class ModelAdapterFactory implements AdapterFactory,
Runnable, ModelFacto
private ConcurrentMap<java.lang.ref.Reference<Object>, Disposable>
disposalCallbacks;
private RequestDisposalCallbacks requestDisposalCallbacks;
+ // exposes the number of elements in the RequestDisposableCallback's map
+ Gauge<Integer> requestsPendingCleanup;
@Override
public void run() {
@@ -261,6 +265,9 @@ public class ModelAdapterFactory implements AdapterFactory,
Runnable, ModelFacto
@Reference
AdapterManager adapterManager;
+ @Reference
+ MetricsService metricsService;
+
ModelPackageBundleListener listener;
final AdapterImplementations adapterImplementations = new
AdapterImplementations();
@@ -1295,6 +1302,10 @@ public class ModelAdapterFactory implements
AdapterFactory, Runnable, ModelFacto
this.configPrinterRegistration = bundleContext.registerService(
Object.class, new ModelConfigurationPrinter(this,
bundleContext, adapterImplementations), printerProps);
+
+ requestsPendingCleanup = metricsService.gauge(
+
"org.apache.sling.models.ModelAdapterFactory.requestsPendingCleanup",
+ requestDisposalCallbacks.callbacks::size);
}
@Deactivate
diff --git a/src/test/java/org/apache/sling/models/impl/AdapterFactoryTest.java
b/src/test/java/org/apache/sling/models/impl/AdapterFactoryTest.java
index 314dd3d..a09ed67 100644
--- a/src/test/java/org/apache/sling/models/impl/AdapterFactoryTest.java
+++ b/src/test/java/org/apache/sling/models/impl/AdapterFactoryTest.java
@@ -27,6 +27,7 @@ import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;
+import org.apache.sling.commons.metrics.MetricsService;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.apache.sling.models.export.spi.ModelExporter;
@@ -83,6 +84,7 @@ public class AdapterFactoryTest {
Converter c = Converters.standardConverter();
Map<String, String> map = new HashMap<>();
ModelAdapterFactoryConfiguration config =
c.convert(map).to(ModelAdapterFactoryConfiguration.class);
+ factory.metricsService = Mockito.mock(MetricsService.class);
factory.activate(componentCtx, config);
factory.injectAnnotationProcessorFactories = Collections.emptyList();
factory.injectAnnotationProcessorFactories2 = Collections.emptyList();
diff --git
a/src/test/java/org/apache/sling/models/impl/StaticInjectionAPFLoadOrderTest.java
b/src/test/java/org/apache/sling/models/impl/StaticInjectionAPFLoadOrderTest.java
index 71090ac..2d20bf4 100644
---
a/src/test/java/org/apache/sling/models/impl/StaticInjectionAPFLoadOrderTest.java
+++
b/src/test/java/org/apache/sling/models/impl/StaticInjectionAPFLoadOrderTest.java
@@ -21,6 +21,7 @@ package org.apache.sling.models.impl;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.adapter.AdapterManager;
import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.commons.metrics.MetricsService;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
@@ -33,6 +34,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import static org.junit.Assert.assertFalse;
@@ -124,6 +126,7 @@ public class StaticInjectionAPFLoadOrderTest {
private void registerServices() {
context.registerService(BindingsValuesProvidersByContext.class,
bindingsValuesProvidersByContext);
context.registerService(AdapterManager.class, adapterManager);
+ context.registerService(MetricsService.class,
Mockito.mock(MetricsService.class));
factory = context.registerInjectActivateService(new
ModelAdapterFactory());
}