Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public class ActionSpanCE {
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 PLUGIN_EXECUTE_COMMON = APPSMITH_SPAN_PREFIX + "pluginExecuteCommon";
public static final String MONGO_OUTPUT_MONO = APPSMITH_SPAN_PREFIX + "mongoOutputMono";

public static final String CREATE_AND_EXECUTE_QUERY_FROM_CONNECTION =
APPSMITH_SPAN_PREFIX + "createAndExecuteQueryFromConnection";

public static final String TRIGGER_API_CALL = APPSMITH_SPAN_PREFIX + "triggerApiCall";

public static final String ACTION_EXECUTION_SERVER_EXECUTION = APPSMITH_SPAN_PREFIX + "total.server.execution";

public static final String GET_ENVIRONMENT_ID = APPSMITH_SPAN_PREFIX + "getEnvironmentId";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@
import com.external.plugins.exceptions.GSheetsPluginError;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import io.micrometer.observation.ObservationRegistry;
import lombok.extern.slf4j.Slf4j;
import org.pf4j.Extension;
import org.pf4j.PluginWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.util.CollectionUtils;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.Exceptions;
import reactor.core.observability.micrometer.Micrometer;
import reactor.core.publisher.Mono;

import java.io.IOException;
Expand All @@ -46,6 +49,7 @@
import java.util.Map;
import java.util.Set;

import static com.appsmith.external.constants.spans.ce.ActionSpanCE.PLUGIN_EXECUTE_COMMON;
import static com.appsmith.external.helpers.PluginUtils.OBJECT_TYPE;
import static com.appsmith.external.helpers.PluginUtils.STRING_TYPE;
import static com.appsmith.external.helpers.PluginUtils.getDataValueSafelyFromFormData;
Expand Down Expand Up @@ -75,6 +79,13 @@ public static class GoogleSheetsPluginExecutor implements PluginExecutor<Void>,
private static final Set<String> jsonFields =
new HashSet<>(Arrays.asList(FieldName.ROW_OBJECT, FieldName.ROW_OBJECTS));

private final ObservationRegistry observationRegistry;

@Autowired
public GoogleSheetsPluginExecutor(ObservationRegistry observationRegistry) {
this.observationRegistry = observationRegistry;
}

@Override
public Mono<ActionExecutionResult> executeParameterized(
Void connection,
Expand Down Expand Up @@ -150,7 +161,9 @@ public Mono<ActionExecutionResult> executeParameterizedWithFlags(

prepareConfigurationsForExecution(executeActionDTO, actionConfiguration, datasourceConfiguration);

return this.executeCommon(connection, datasourceConfiguration, actionConfiguration, featureFlagMap);
return this.executeCommon(connection, datasourceConfiguration, actionConfiguration, featureFlagMap)
.name(PLUGIN_EXECUTE_COMMON)
.tap(Micrometer.observation(observationRegistry));
}

public Mono<ActionExecutionResult> executeCommon(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.appsmith.external.models.PaginationType;
import com.external.constants.ErrorMessages;
import com.external.plugins.GoogleSheetsPlugin;
import io.micrometer.observation.ObservationRegistry;
import org.junit.jupiter.api.Test;

import java.util.Collections;
Expand All @@ -21,7 +22,8 @@

public class RowsAppendMethodTest {

GoogleSheetsPlugin.GoogleSheetsPluginExecutor pluginExecutor = new GoogleSheetsPlugin.GoogleSheetsPluginExecutor();
GoogleSheetsPlugin.GoogleSheetsPluginExecutor pluginExecutor =
new GoogleSheetsPlugin.GoogleSheetsPluginExecutor(ObservationRegistry.NOOP);

@Test
public void testRowAppendMethodWithEmptyBody() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.external.constants.ErrorMessages;
import com.external.plugins.GoogleSheetsPlugin;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.micrometer.observation.ObservationRegistry;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
Expand All @@ -25,7 +26,8 @@
public class RowsBulkAppendMethodTest {
final ObjectMapper objectMapper = new ObjectMapper();

GoogleSheetsPlugin.GoogleSheetsPluginExecutor pluginExecutor = new GoogleSheetsPlugin.GoogleSheetsPluginExecutor();
GoogleSheetsPlugin.GoogleSheetsPluginExecutor pluginExecutor =
new GoogleSheetsPlugin.GoogleSheetsPluginExecutor(ObservationRegistry.NOOP);

/**
* To Test if it passes the empty Mono criteria,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.appsmith.external.models.PaginationType;
import com.external.constants.ErrorMessages;
import com.external.plugins.GoogleSheetsPlugin;
import io.micrometer.observation.ObservationRegistry;
import org.junit.jupiter.api.Test;

import java.util.Collections;
Expand All @@ -21,7 +22,8 @@

public class RowsBulkUpdateMethodTest {

GoogleSheetsPlugin.GoogleSheetsPluginExecutor pluginExecutor = new GoogleSheetsPlugin.GoogleSheetsPluginExecutor();
GoogleSheetsPlugin.GoogleSheetsPluginExecutor pluginExecutor =
new GoogleSheetsPlugin.GoogleSheetsPluginExecutor(ObservationRegistry.NOOP);

@Test
public void testRowBulkUpdateMethodWithEmptyBody() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.appsmith.external.models.PaginationType;
import com.external.constants.ErrorMessages;
import com.external.plugins.GoogleSheetsPlugin;
import io.micrometer.observation.ObservationRegistry;
import org.junit.jupiter.api.Test;

import java.util.Collections;
Expand All @@ -21,7 +22,8 @@

public class RowsUpdateMethodTest {

GoogleSheetsPlugin.GoogleSheetsPluginExecutor pluginExecutor = new GoogleSheetsPlugin.GoogleSheetsPluginExecutor();
GoogleSheetsPlugin.GoogleSheetsPluginExecutor pluginExecutor =
new GoogleSheetsPlugin.GoogleSheetsPluginExecutor(ObservationRegistry.NOOP);

@Test
public void testRowUpdateMethodWithEmptyBody() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import com.mongodb.reactivestreams.client.MongoClient;
import com.mongodb.reactivestreams.client.MongoClients;
import com.mongodb.reactivestreams.client.MongoDatabase;
import io.micrometer.observation.ObservationRegistry;
import lombok.extern.slf4j.Slf4j;
import org.bson.Document;
import org.bson.codecs.BsonTypeClassMap;
Expand All @@ -68,8 +69,10 @@
import org.pf4j.Extension;
import org.pf4j.PluginWrapper;
import org.reactivestreams.Publisher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import reactor.core.observability.micrometer.Micrometer;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler;
Expand Down Expand Up @@ -97,6 +100,8 @@
import java.util.stream.Collectors;

import static com.appsmith.external.constants.ActionConstants.ACTION_CONFIGURATION_BODY;
import static com.appsmith.external.constants.spans.ce.ActionSpanCE.MONGO_OUTPUT_MONO;
import static com.appsmith.external.constants.spans.ce.ActionSpanCE.PLUGIN_EXECUTE_COMMON;
import static com.appsmith.external.helpers.PluginUtils.OBJECT_TYPE;
import static com.appsmith.external.helpers.PluginUtils.STRING_TYPE;
import static com.appsmith.external.helpers.PluginUtils.getDataValueSafelyFromFormData;
Expand Down Expand Up @@ -223,6 +228,12 @@ public MongoPlugin(PluginWrapper wrapper) {
@Slf4j
@Extension
public static class MongoPluginExecutor implements PluginExecutor<MongoClient>, SmartSubstitutionInterface {
private final ObservationRegistry observationRegistry;

@Autowired
public MongoPluginExecutor(ObservationRegistry observationRegistry) {
this.observationRegistry = observationRegistry;
}

private final Scheduler scheduler = Schedulers.boundedElastic();

Expand Down Expand Up @@ -287,7 +298,9 @@ public Mono<ActionExecutionResult> executeParameterized(

actionConfiguration.setFormData(formData);

return this.executeCommon(mongoClient, datasourceConfiguration, actionConfiguration, parameters);
return this.executeCommon(mongoClient, datasourceConfiguration, actionConfiguration, parameters)
.name(PLUGIN_EXECUTE_COMMON)
.tap(Micrometer.observation(observationRegistry));
}

/**
Expand Down Expand Up @@ -335,6 +348,8 @@ public Mono<ActionExecutionResult> executeCommon(

Instant requestedAt = Instant.now();
return mongoOutputMono
.name(MONGO_OUTPUT_MONO)
.tap(Micrometer.observation(observationRegistry))
.onErrorMap(
MongoTimeoutException.class,
error -> new AppsmithPluginException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.mongodb.MongoCommandException;
import com.mongodb.reactivestreams.client.MongoClient;
import io.micrometer.observation.ObservationRegistry;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -60,7 +61,7 @@
*/
@Testcontainers
public class MongoPluginDatasourceTest {
MongoPlugin.MongoPluginExecutor pluginExecutor = new MongoPlugin.MongoPluginExecutor();
MongoPlugin.MongoPluginExecutor pluginExecutor = new MongoPlugin.MongoPluginExecutor(ObservationRegistry.NOOP);

private static String address;
private static Integer port;
Expand Down Expand Up @@ -196,7 +197,8 @@ public void testDatasourceWithUnauthorizedException() {
* - On calling testDatasource(...) -> call the real method.
* - On calling datasourceCreate(...) -> throw the mock exception defined above.
*/
MongoPlugin.MongoPluginExecutor mongoPluginExecutor = new MongoPlugin.MongoPluginExecutor();
MongoPlugin.MongoPluginExecutor mongoPluginExecutor =
new MongoPlugin.MongoPluginExecutor(ObservationRegistry.NOOP);
MongoPlugin.MongoPluginExecutor spyMongoPluginExecutor = spy(mongoPluginExecutor);
/* Please check this out before modifying this line: https://stackoverflow
* .com/questions/11620103/mockito-trying-to-spy-on-method-is-calling-the-original-method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.mongodb.reactivestreams.client.ListCollectionNamesPublisher;
import com.mongodb.reactivestreams.client.MongoClient;
import com.mongodb.reactivestreams.client.MongoDatabase;
import io.micrometer.observation.ObservationRegistry;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.reactivestreams.Subscriber;
Expand Down Expand Up @@ -68,7 +69,7 @@
*/
@Testcontainers
public class MongoPluginErrorsTest {
MongoPlugin.MongoPluginExecutor pluginExecutor = new MongoPlugin.MongoPluginExecutor();
MongoPlugin.MongoPluginExecutor pluginExecutor = new MongoPlugin.MongoPluginExecutor(ObservationRegistry.NOOP);

private static String address;
private static Integer port;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.mongodb.reactivestreams.client.MongoClient;
import com.mongodb.reactivestreams.client.MongoClients;
import com.mongodb.reactivestreams.client.MongoCollection;
import io.micrometer.observation.ObservationRegistry;
import org.bson.Document;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -64,7 +65,7 @@
*/
@Testcontainers
public class MongoPluginFormsTest {
MongoPlugin.MongoPluginExecutor pluginExecutor = new MongoPlugin.MongoPluginExecutor();
MongoPlugin.MongoPluginExecutor pluginExecutor = new MongoPlugin.MongoPluginExecutor(ObservationRegistry.NOOP);

private static String address;
private static Integer port;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.mongodb.reactivestreams.client.MongoClient;
import io.micrometer.observation.ObservationRegistry;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.MongoDBContainer;
Expand Down Expand Up @@ -65,7 +66,7 @@
*/
@Testcontainers
public class MongoPluginQueriesTest {
MongoPlugin.MongoPluginExecutor pluginExecutor = new MongoPlugin.MongoPluginExecutor();
MongoPlugin.MongoPluginExecutor pluginExecutor = new MongoPlugin.MongoPluginExecutor(ObservationRegistry.NOOP);

private static String address;
private static Integer port;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.appsmith.external.models.SSLDetails;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.mongodb.reactivestreams.client.MongoClient;
import io.micrometer.observation.ObservationRegistry;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.MongoDBContainer;
Expand Down Expand Up @@ -38,7 +39,7 @@
*/
@Testcontainers
public class MongoPluginRegexTest {
MongoPlugin.MongoPluginExecutor pluginExecutor = new MongoPlugin.MongoPluginExecutor();
MongoPlugin.MongoPluginExecutor pluginExecutor = new MongoPlugin.MongoPluginExecutor(ObservationRegistry.NOOP);

private static String address;
private static Integer port;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.mongodb.reactivestreams.client.ListCollectionNamesPublisher;
import com.mongodb.reactivestreams.client.MongoClient;
import com.mongodb.reactivestreams.client.MongoDatabase;
import io.micrometer.observation.ObservationRegistry;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.reactivestreams.Subscriber;
Expand Down Expand Up @@ -44,7 +45,7 @@
*/
@Testcontainers
public class MongoPluginStaleConnTest {
MongoPlugin.MongoPluginExecutor pluginExecutor = new MongoPlugin.MongoPluginExecutor();
MongoPlugin.MongoPluginExecutor pluginExecutor = new MongoPlugin.MongoPluginExecutor(ObservationRegistry.NOOP);

private static String address;
private static Integer port;
Expand Down
Loading