From 895ef527018b18d6180fd6dc9e14fd51c56b2625 Mon Sep 17 00:00:00 2001 From: Nidhi Date: Tue, 27 Jun 2023 11:19:28 +0530 Subject: [PATCH] chore: Removed spring security and redis traces (#24758) ## Description Adds a filter for http endpoints that are recorded in our traces. We have discarded the actuator endpoints since we don't care about their metrics. We have also filtered spans to only contain the ones that we have manually declared across the project. All spans need to use the `appsmith.` prefix to pass through this filter. This change discards spring security and redis spans as of today. Fixes #24757 #### Type of change - Chore (housekeeping or task changes that don't impact user perception) > ## Testing > #### How Has This Been Tested? - [x] Manual > > ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag --- .../external/constants/spans/ActionSpan.java | 21 +++++++ .../external/constants/spans/ActionSpans.java | 21 ------- .../external/constants/spans/BaseSpan.java | 5 ++ .../external/plugins/PluginExecutor.java | 2 +- .../server/configurations/TracingConfig.java | 56 +++++++++++++++++++ .../services/ce/NewActionServiceCEImpl.java | 6 +- .../ce/ActionExecutionSolutionCEImpl.java | 10 ++-- 7 files changed, 91 insertions(+), 30 deletions(-) create mode 100644 app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/spans/ActionSpan.java delete mode 100644 app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/spans/ActionSpans.java create mode 100644 app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/spans/BaseSpan.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/TracingConfig.java diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/spans/ActionSpan.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/spans/ActionSpan.java new file mode 100644 index 00000000000..ff999406434 --- /dev/null +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/spans/ActionSpan.java @@ -0,0 +1,21 @@ +package com.appsmith.external.constants.spans; + +import static com.appsmith.external.constants.spans.BaseSpan.APPSMITH_SPAN_PREFIX; + +public final class ActionSpan { + + // Action execution spans + public static final String ACTION_EXECUTION_REQUEST_PARSING = APPSMITH_SPAN_PREFIX + "request.parsing"; + public static final String ACTION_EXECUTION_CACHED_DATASOURCE = APPSMITH_SPAN_PREFIX + "get.datasource.cached"; + public static final String ACTION_EXECUTION_DATASOURCE_CONTEXT = APPSMITH_SPAN_PREFIX + "get.datasource.context"; + public static final String ACTION_EXECUTION_EDITOR_CONFIG = APPSMITH_SPAN_PREFIX + "get.editorConfig.cached"; + public static final String ACTION_EXECUTION_PLUGIN_EXECUTION = APPSMITH_SPAN_PREFIX + "total.plugin.execution"; + public static final String ACTION_EXECUTION_SERVER_EXECUTION = APPSMITH_SPAN_PREFIX + "total.server.execution"; + + // Getter spans + public static final String GET_UNPUBLISHED_ACTION = APPSMITH_SPAN_PREFIX + "get.action.unpublished"; + public static final String GET_VIEW_MODE_ACTION = APPSMITH_SPAN_PREFIX + "get.action.viewmode"; + public static final String GET_ACTION_REPOSITORY_CALL = APPSMITH_SPAN_PREFIX + "get.action.repository.call"; + + +} diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/spans/ActionSpans.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/spans/ActionSpans.java deleted file mode 100644 index 84656b36cf3..00000000000 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/spans/ActionSpans.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.appsmith.external.constants.spans; - -public final class ActionSpans { - - // Action execution spans - public static final String ACTION_EXECUTION_REQUEST_PARSING = "request.parsing"; - public static final String ACTION_EXECUTION_CACHED_ACTION = "get.action.cached"; - public static final String ACTION_EXECUTION_CACHED_DATASOURCE = "get.datasource.cached"; - public static final String ACTION_EXECUTION_CACHED_PLUGIN = "get.plugin.cached"; - public static final String ACTION_EXECUTION_DATASOURCE_CONTEXT = "get.datasource.context"; - public static final String ACTION_EXECUTION_DATASOURCE_CONTEXT_REMOTE = "get.datasource.context.remote"; - public static final String ACTION_EXECUTION_EDITOR_CONFIG = "get.editorConfig.cached"; - public static final String ACTION_EXECUTION_VALIDATE_AUTHENTICATION = "validate.authentication"; - public static final String ACTION_EXECUTION_PLUGIN_EXECUTION = "total.plugin.execution"; - public static final String ACTION_EXECUTION_SERVER_EXECUTION = "total.server.execution"; - public static final String GET_UNPUBLISHED_ACTION = "get.action.unpublished"; - public static final String GET_VIEW_MODE_ACTION = "get.action.viewmode"; - public static final String GET_ACTION_REPOSITORY_CALL = "get.action.repository.call"; - - -} diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/spans/BaseSpan.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/spans/BaseSpan.java new file mode 100644 index 00000000000..5da675c7cf3 --- /dev/null +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/spans/BaseSpan.java @@ -0,0 +1,5 @@ +package com.appsmith.external.constants.spans; + +public class BaseSpan { + public static final String APPSMITH_SPAN_PREFIX = "appsmith."; +} diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/plugins/PluginExecutor.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/plugins/PluginExecutor.java index b943ee15bdd..b2398dbd755 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/plugins/PluginExecutor.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/plugins/PluginExecutor.java @@ -26,7 +26,7 @@ import java.util.Set; import java.util.stream.Collectors; -import static com.appsmith.external.constants.spans.ActionSpans.ACTION_EXECUTION_PLUGIN_EXECUTION; +import static com.appsmith.external.constants.spans.ActionSpan.ACTION_EXECUTION_PLUGIN_EXECUTION; import static com.appsmith.external.helpers.PluginUtils.getHintMessageForLocalhostUrl; import static org.springframework.util.CollectionUtils.isEmpty; diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/TracingConfig.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/TracingConfig.java new file mode 100644 index 00000000000..a6cb5092d50 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/TracingConfig.java @@ -0,0 +1,56 @@ +package com.appsmith.server.configurations; + +import io.micrometer.observation.Observation; +import io.micrometer.observation.ObservationPredicate; +import io.micrometer.observation.ObservationView; +import io.micrometer.tracing.Span; +import io.micrometer.tracing.exporter.SpanExportingPredicate; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.server.reactive.observation.ServerRequestObservationContext; + +import static com.appsmith.external.constants.spans.BaseSpan.APPSMITH_SPAN_PREFIX; + +/** + * This configuration file creates beans that are required to filter just Appsmith specific spans + */ +@Configuration +public class TracingConfig { + + private Observation.Context getRoot(Observation.Context current) { + ObservationView parent = current.getParentObservation(); + if (parent == null) { + return current; + } else { + return getRoot((Observation.Context) parent.getContextView()); + } + } + + @Bean + ObservationPredicate noActuatorServerObservations() { + return (name, context) -> { + Observation.Context root = getRoot(context); + if (root instanceof ServerRequestObservationContext serverContext) { + // For endpoint spans, which would be the parent for the trace, + // ignore actuator endpoints + // This gets rid of the prometheus calls as well as the health check + return !serverContext.getCarrier().getPath().value().startsWith("/actuator"); + } else { + return true; + } + }; + } + + @Bean + SpanExportingPredicate onlyAppsmithSpans() { + return (finishedSpan) -> { + if ((finishedSpan.getKind() != null && finishedSpan.getKind().equals(Span.Kind.SERVER)) + || finishedSpan.getName().startsWith(APPSMITH_SPAN_PREFIX)) { + // A span is either an http server request root or Appsmith specific + return true; + } else { + return false; + } + }; + } +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/NewActionServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/NewActionServiceCEImpl.java index 91e58f40eae..36a5d1f776e 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/NewActionServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/NewActionServiceCEImpl.java @@ -80,9 +80,9 @@ import java.util.function.Function; import java.util.stream.Collectors; -import static com.appsmith.external.constants.spans.ActionSpans.GET_ACTION_REPOSITORY_CALL; -import static com.appsmith.external.constants.spans.ActionSpans.GET_UNPUBLISHED_ACTION; -import static com.appsmith.external.constants.spans.ActionSpans.GET_VIEW_MODE_ACTION; +import static com.appsmith.external.constants.spans.ActionSpan.GET_ACTION_REPOSITORY_CALL; +import static com.appsmith.external.constants.spans.ActionSpan.GET_UNPUBLISHED_ACTION; +import static com.appsmith.external.constants.spans.ActionSpan.GET_VIEW_MODE_ACTION; import static com.appsmith.external.helpers.AppsmithBeanUtils.copyNewFieldValuesIntoOldObject; import static com.appsmith.external.helpers.PluginUtils.setValueSafelyInFormData; import static com.appsmith.server.acl.AclPermission.EXECUTE_DATASOURCES; diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImpl.java index e97fc6733ec..1bca048661f 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImpl.java @@ -80,11 +80,11 @@ import java.util.stream.Collectors; import static com.appsmith.external.constants.CommonFieldName.REDACTED_DATA; -import static com.appsmith.external.constants.spans.ActionSpans.ACTION_EXECUTION_CACHED_DATASOURCE; -import static com.appsmith.external.constants.spans.ActionSpans.ACTION_EXECUTION_DATASOURCE_CONTEXT; -import static com.appsmith.external.constants.spans.ActionSpans.ACTION_EXECUTION_EDITOR_CONFIG; -import static com.appsmith.external.constants.spans.ActionSpans.ACTION_EXECUTION_REQUEST_PARSING; -import static com.appsmith.external.constants.spans.ActionSpans.ACTION_EXECUTION_SERVER_EXECUTION; +import static com.appsmith.external.constants.spans.ActionSpan.ACTION_EXECUTION_CACHED_DATASOURCE; +import static com.appsmith.external.constants.spans.ActionSpan.ACTION_EXECUTION_DATASOURCE_CONTEXT; +import static com.appsmith.external.constants.spans.ActionSpan.ACTION_EXECUTION_EDITOR_CONFIG; +import static com.appsmith.external.constants.spans.ActionSpan.ACTION_EXECUTION_REQUEST_PARSING; +import static com.appsmith.external.constants.spans.ActionSpan.ACTION_EXECUTION_SERVER_EXECUTION; import static com.appsmith.external.helpers.DataTypeStringUtils.getDisplayDataTypes; import static com.appsmith.server.helpers.WidgetSuggestionHelper.getSuggestedWidgets; import static java.lang.Boolean.FALSE;