Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag to disable MP Metrics for the NSF (fixes #354) #434

Merged
merged 1 commit into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ application_rest_Sample_hello_total 2.0
application_rest_Sample_hello_elapsedTime_seconds 8.252E-4
```

This capability can be disabled by setting `rest.mpmetrics.enable=false` in your Xsp Properties. Note that Fault Tolerance has an implicit dependency on this, and so will also be unavailable if you set this flag.

Note: the semantics and output of this component are likely to change in the future. MicroProfile Metrics 5.0 and above move to being based on Micrometer. As part of MicroProfile 6.0, however, this version requires Java 11 and will only be adopted here when Domino supports at least that Java version.

#### CORS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ Import-Package: com.ibm.xsp.application,
org.openntf.xsp.jakartaee;version="2.2.0",
org.openntf.xsp.jakartaee.util;version="2.3.0",
org.openntf.xsp.microprofile.config;version="2.11.0",
org.openntf.xsp.microprofile.metrics;version="2.13.0",
org.osgi.framework;version="1.8.0"
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.openntf.xsp.cdi.discovery.WeldBeanClassContributor;
import org.openntf.xsp.jakartaee.util.LibraryUtil;
import org.openntf.xsp.microprofile.config.ConfigLibrary;
import org.openntf.xsp.microprofile.metrics.MetricsResourceContributor;

import io.smallrye.faulttolerance.FaultToleranceExtension;
import jakarta.enterprise.inject.spi.Extension;

Expand All @@ -34,7 +36,12 @@ public Collection<Class<?>> getBeanClasses() {
@Override
public Collection<Extension> getExtensions() {
if(LibraryUtil.isLibraryActive(FaultToleranceLibrary.LIBRARY_ID, ConfigLibrary.LIBRARY_ID)) {
return Collections.singleton(new FaultToleranceExtension());
// SmallRye Fault Tolerance has an implicit dependency on Metrics
if(!"false".equals(LibraryUtil.getApplicationProperty(MetricsResourceContributor.PROP_ENABLED, "true"))) { //$NON-NLS-1$ //$NON-NLS-2$
return Collections.singleton(new FaultToleranceExtension());
} else {
return Collections.emptySet();
}
} else {
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Collections;

import org.openntf.xsp.cdi.discovery.WeldBeanClassContributor;
import org.openntf.xsp.jakartaee.util.LibraryUtil;

import io.smallrye.metrics.setup.MetricCdiInjectionExtension;
import jakarta.enterprise.inject.spi.Extension;
Expand All @@ -32,8 +33,11 @@ public Collection<Class<?>> getBeanClasses() {

@Override
public Collection<Extension> getExtensions() {
// TODO add opt-in for NSFs
return Collections.singleton(new MetricCdiInjectionExtension());
if(!"false".equals(LibraryUtil.getApplicationProperty(MetricsResourceContributor.PROP_ENABLED, "true"))) { //$NON-NLS-1$ //$NON-NLS-2$
return Collections.singleton(new MetricCdiInjectionExtension());
} else {
return Collections.emptySet();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@
import org.openntf.xsp.microprofile.metrics.jaxrs.RestMetricsFilter;

public class MetricsResourceContributor implements JAXRSClassContributor {
public static final String PROP_ENABLED = "rest.mpmetrics.enable"; //$NON-NLS-1$

@Override
public Collection<Class<?>> getClasses() {
if(LibraryUtil.isLibraryActive(CDILibrary.LIBRARY_ID)) {
return Arrays.asList(
RestMetricsFilter.class,
MetricsResource.class
);
if(!"false".equals(LibraryUtil.getApplicationProperty(PROP_ENABLED, "true"))) { //$NON-NLS-1$ //$NON-NLS-2$
return Arrays.asList(
RestMetricsFilter.class,
MetricsResource.class
);
} else {
return Collections.emptySet();
}
} else {
return Collections.emptySet();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
*/
package org.openntf.xsp.microprofile.metrics.config;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.openntf.xsp.jakartaee.module.ComponentModuleLocator;
import org.openntf.xsp.jakartaee.util.LibraryUtil;
import org.openntf.xsp.microprofile.config.ext.ImplicitAppConfigProvider;
import org.openntf.xsp.microprofile.metrics.MetricsResourceContributor;

/**
* This MP Config provider produces the current app's context path as a prefix
Expand All @@ -34,13 +37,17 @@ public class MetricsAppConfigSource implements ImplicitAppConfigProvider {

@Override
public Map<String, String> get() {
Map<String, String> result = new HashMap<>();
ComponentModuleLocator.getDefault()
.flatMap(ComponentModuleLocator::getServletContext)
.ifPresent(ctx -> {
result.put(CONFIG_APPNAME, '/' + ctx.getContextPath());
});
return result;
if(!"false".equals(LibraryUtil.getApplicationProperty(MetricsResourceContributor.PROP_ENABLED, "true"))) { //$NON-NLS-1$ //$NON-NLS-2$
Map<String, String> result = new HashMap<>();
ComponentModuleLocator.getDefault()
.flatMap(ComponentModuleLocator::getServletContext)
.ifPresent(ctx -> {
result.put(CONFIG_APPNAME, '/' + ctx.getContextPath());
});
return result;
} else {
return Collections.emptyMap();
}
}

}