Skip to content

Commit

Permalink
chore(Telemetry) #30079 : Move telemetry plugin into core - Part 2 (#…
Browse files Browse the repository at this point in the history
…30570)

# IMPORTANT NOTE
Changes in the following classes:
* `DotRestApplication.java`
* `SimpleWebInterceptorDelegateImpl`
* `InterceptorFilter`

**Are 100% temporary**. They will just be there until we make sure that
the Telemetry migration is working as expected. Once that is done, we'll
get rid of them.

### Proposed Changes
* Second part of the Telemetry Plug-In migration.
* This PR introduces a new Feature Flag that allows you to enable the
Telemetry feature embedded in the `core` project, or fall back to using
the provided Telemetry Plug-In:
```
DOT_FEATURE_FLAG_TELEMETRY_CORE_ENABLED
```
* Such a flag will be disabled, by default.
* Several classes were refactored in order to comply with the new CDI
approach for inserting instances into classes.
* Additional debugging has been added to Telemetry classes.
* Some Javadoc has been added and formatted, as required.
  • Loading branch information
jcastro-dotcms authored Nov 8, 2024
1 parent 1e14290 commit 1f1e05d
Show file tree
Hide file tree
Showing 33 changed files with 822 additions and 667 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.dotcms.filters.interceptor;

import com.dotcms.repackage.com.google.common.annotations.VisibleForTesting;
import com.dotcms.rest.config.DotRestApplication;
import com.dotmarketing.util.Config;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.RegEX;
import io.vavr.Lazy;
import org.apache.commons.collections.iterators.ReverseListIterator;

import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -30,6 +34,9 @@ public class SimpleWebInterceptorDelegateImpl implements WebInterceptorDelegate
private final AtomicBoolean reverseOrderForPostInvoke =
new AtomicBoolean(false);

private static final Lazy<Boolean> ENABLE_TELEMETRY_FROM_CORE = Lazy.of(() ->
Config.getBooleanProperty("FEATURE_FLAG_TELEMETRY_CORE_ENABLED", false));

@Override
public void addBefore(final String webInterceptorName, final WebInterceptor webInterceptor) {

Expand Down Expand Up @@ -83,7 +90,11 @@ public void add(final int order, final WebInterceptor webInterceptor) {

@Override
public void addFirst(final WebInterceptor webInterceptor) {

if (Boolean.TRUE.equals(ENABLE_TELEMETRY_FROM_CORE.get()) &&
webInterceptor.getClass().getName().equalsIgnoreCase("com.dotcms.experience.collectors.api.ApiMetricWebInterceptor")) {
Logger.warn(DotRestApplication.class, "Bypassing addition of API Metric Web Interceptor from OSGi");
return;
}
this.interceptors.add(0, webInterceptor);
this.init(webInterceptor);
} // addFirst.
Expand Down
46 changes: 31 additions & 15 deletions dotCMS/src/main/java/com/dotcms/rest/config/DotRestApplication.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package com.dotcms.rest.config;

import com.dotcms.cdi.CDIUtils;
import com.dotcms.telemetry.rest.TelemetryResource;
import com.dotmarketing.util.Config;
import com.dotmarketing.util.Logger;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import io.swagger.v3.jaxrs2.integration.resources.AcceptHeaderOpenApiResource;
import io.swagger.v3.jaxrs2.integration.resources.OpenApiResource;
import org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.servers.Server;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.vavr.Lazy;
import org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.server.ResourceConfig;

import javax.ws.rs.ApplicationPath;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import javax.ws.rs.ApplicationPath;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.server.ResourceConfig;

/**
* This class provides the list of all the REST end-points in dotCMS. Every new
Expand Down Expand Up @@ -47,18 +52,24 @@
)
public class DotRestApplication extends ResourceConfig {

public DotRestApplication() {
private static final Lazy<Boolean> ENABLE_TELEMETRY_FROM_CORE = Lazy.of(() ->
Config.getBooleanProperty("FEATURE_FLAG_TELEMETRY_CORE_ENABLED", false));

public DotRestApplication() {
final List<String> packages = new ArrayList<>(List.of(
"com.dotcms.rest",
"com.dotcms.contenttype.model.field",
"com.dotcms.rendering.js",
"com.dotcms.ai.rest",
"io.swagger.v3.jaxrs2"));
if (Boolean.TRUE.equals(ENABLE_TELEMETRY_FROM_CORE.get())) {
packages.add(TelemetryResource.class.getPackageName());
}
register(MultiPartFeature.class).
register(JacksonJaxbJsonProvider.class).
registerClasses(customClasses.keySet()).
packages(
"com.dotcms.rest",
"com.dotcms.contenttype.model.field",
"com.dotcms.rendering.js",
"com.dotcms.ai.rest",
"io.swagger.v3.jaxrs2"
).register(CdiComponentProvider.class);
packages(packages.toArray(new String[0])).
register(CdiComponentProvider.class);
}

/**
Expand All @@ -70,10 +81,15 @@ public DotRestApplication() {
* adds a class and reloads
* @param clazz the class ot add
*/
public static synchronized void addClass(Class<?> clazz) {
public static synchronized void addClass(final Class<?> clazz) {
if(clazz==null){
return;
}
if (Boolean.TRUE.equals(ENABLE_TELEMETRY_FROM_CORE.get())
&& clazz.getName().equalsIgnoreCase("com.dotcms.experience.TelemetryResource")) {
Logger.warn(DotRestApplication.class, "Bypassing activation of Telemetry REST Endpoint from OSGi");
return;
}
if (Boolean.TRUE.equals(customClasses.computeIfAbsent(clazz,c -> true))) {
final Optional<ContainerReloader> reloader = CDIUtils.getBean(ContainerReloader.class);
reloader.ifPresent(ContainerReloader::reload);
Expand Down

This file was deleted.

Loading

0 comments on commit 1f1e05d

Please sign in to comment.