From d0162013f6a78bbda170f56e4c5fd90751a774a3 Mon Sep 17 00:00:00 2001 From: Manish Kumar <107841575+sondermanish@users.noreply.github.com> Date: Tue, 2 Apr 2024 20:55:19 +0530 Subject: [PATCH] chore: analytics for GIT FS (#32302) --- .../git/helpers/ce/FileUtilsCEImpl.java | 10 +-- .../appsmith/git/service/GitExecutorImpl.java | 5 +- .../git/service/ce/GitExecutorCEImpl.java | 59 +++++++++++++++--- .../external/constants/GitConstants.java | 5 -- .../external/constants/spans/BaseSpan.java | 5 ++ .../external/git/constants/GitConstants.java | 8 +++ .../external/git/constants/GitSpans.java | 36 +++++++++++ .../constants/ce/GitConstantsCE.java | 7 ++- ...tionCollectionExportableServiceCEImpl.java | 2 +- .../git/ApplicationGitFileUtilsCE.java | 2 +- .../server/helpers/ce/GitFileUtilsCE.java | 2 +- .../NewActionExportableServiceCEImpl.java | 2 +- .../services/ce/CommonGitServiceCEImpl.java | 8 +-- .../server/services/ce/GitServiceCEImpl.java | 61 +++++++++++-------- .../ce/AutoCommitEventHandlerCEImpl.java | 2 +- .../exports/internal/ExportServiceTests.java | 2 +- .../server/helpers/GitFileUtilsTest.java | 2 +- .../imports/internal/ImportServiceTests.java | 2 +- 18 files changed, 160 insertions(+), 60 deletions(-) delete mode 100644 app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/GitConstants.java create mode 100644 app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/constants/GitConstants.java create mode 100644 app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/constants/GitSpans.java rename app/server/appsmith-interfaces/src/main/java/com/appsmith/external/{ => git}/constants/ce/GitConstantsCE.java (86%) diff --git a/app/server/appsmith-git/src/main/java/com/appsmith/git/helpers/ce/FileUtilsCEImpl.java b/app/server/appsmith-git/src/main/java/com/appsmith/git/helpers/ce/FileUtilsCEImpl.java index 34d32365cc..36c55e45ee 100644 --- a/app/server/appsmith-git/src/main/java/com/appsmith/git/helpers/ce/FileUtilsCEImpl.java +++ b/app/server/appsmith-git/src/main/java/com/appsmith/git/helpers/ce/FileUtilsCEImpl.java @@ -64,11 +64,11 @@ import java.util.Set; import java.util.regex.Pattern; import java.util.stream.Stream; -import static com.appsmith.external.constants.GitConstants.ACTION_COLLECTION_LIST; -import static com.appsmith.external.constants.GitConstants.ACTION_LIST; -import static com.appsmith.external.constants.GitConstants.CUSTOM_JS_LIB_LIST; -import static com.appsmith.external.constants.GitConstants.NAME_SEPARATOR; -import static com.appsmith.external.constants.GitConstants.PAGE_LIST; +import static com.appsmith.external.git.constants.GitConstants.ACTION_COLLECTION_LIST; +import static com.appsmith.external.git.constants.GitConstants.ACTION_LIST; +import static com.appsmith.external.git.constants.GitConstants.CUSTOM_JS_LIB_LIST; +import static com.appsmith.external.git.constants.GitConstants.NAME_SEPARATOR; +import static com.appsmith.external.git.constants.GitConstants.PAGE_LIST; import static com.appsmith.git.constants.GitDirectories.ACTION_COLLECTION_DIRECTORY; import static com.appsmith.git.constants.GitDirectories.ACTION_DIRECTORY; import static com.appsmith.git.constants.GitDirectories.DATASOURCE_DIRECTORY; diff --git a/app/server/appsmith-git/src/main/java/com/appsmith/git/service/GitExecutorImpl.java b/app/server/appsmith-git/src/main/java/com/appsmith/git/service/GitExecutorImpl.java index f4309bff23..f4ec6a4ecf 100644 --- a/app/server/appsmith-git/src/main/java/com/appsmith/git/service/GitExecutorImpl.java +++ b/app/server/appsmith-git/src/main/java/com/appsmith/git/service/GitExecutorImpl.java @@ -3,6 +3,7 @@ package com.appsmith.git.service; import com.appsmith.external.git.GitExecutor; import com.appsmith.git.configurations.GitServiceConfig; import com.appsmith.git.service.ce.GitExecutorCEImpl; +import io.micrometer.observation.ObservationRegistry; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -10,7 +11,7 @@ import org.springframework.stereotype.Component; @Slf4j public class GitExecutorImpl extends GitExecutorCEImpl implements GitExecutor { - public GitExecutorImpl(GitServiceConfig gitServiceConfig) { - super(gitServiceConfig); + public GitExecutorImpl(GitServiceConfig gitServiceConfig, ObservationRegistry observationRegistry) { + super(gitServiceConfig, observationRegistry); } } diff --git a/app/server/appsmith-git/src/main/java/com/appsmith/git/service/ce/GitExecutorCEImpl.java b/app/server/appsmith-git/src/main/java/com/appsmith/git/service/ce/GitExecutorCEImpl.java index cad61d82de..4ff073d07c 100644 --- a/app/server/appsmith-git/src/main/java/com/appsmith/git/service/ce/GitExecutorCEImpl.java +++ b/app/server/appsmith-git/src/main/java/com/appsmith/git/service/ce/GitExecutorCEImpl.java @@ -7,6 +7,7 @@ import com.appsmith.external.dtos.GitLogDTO; import com.appsmith.external.dtos.GitStatusDTO; import com.appsmith.external.dtos.MergeStatusDTO; import com.appsmith.external.git.GitExecutor; +import com.appsmith.external.git.constants.GitSpans; import com.appsmith.external.helpers.Stopwatch; import com.appsmith.git.configurations.GitServiceConfig; import com.appsmith.git.constants.AppsmithBotAsset; @@ -16,6 +17,7 @@ import com.appsmith.git.constants.GitDirectories; import com.appsmith.git.helpers.RepositoryHelper; import com.appsmith.git.helpers.SshTransportConfigCallback; import com.appsmith.git.helpers.StopwatchHelpers; +import io.micrometer.observation.ObservationRegistry; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.eclipse.jgit.api.CreateBranchCommand; @@ -40,6 +42,7 @@ import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.util.StringUtils; import org.springframework.stereotype.Component; import org.springframework.util.FileSystemUtils; +import reactor.core.observability.micrometer.Micrometer; import reactor.core.publisher.Mono; import reactor.core.scheduler.Scheduler; import reactor.core.scheduler.Schedulers; @@ -60,7 +63,11 @@ import java.util.List; import java.util.Optional; import java.util.Set; +import static com.appsmith.external.git.constants.GitConstants.GitMetricConstants.CHECKOUT_REMOTE; +import static com.appsmith.external.git.constants.GitConstants.GitMetricConstants.HARD_RESET; import static com.appsmith.git.constants.CommonConstants.FILE_MIGRATION_MESSAGE; +import static java.lang.Boolean.FALSE; +import static java.lang.Boolean.TRUE; @RequiredArgsConstructor @Component @@ -71,6 +78,8 @@ public class GitExecutorCEImpl implements GitExecutor { private final GitServiceConfig gitServiceConfig; + protected final ObservationRegistry observationRegistry; + public static final DateTimeFormatter ISO_FORMATTER = DateTimeFormatter.ISO_INSTANT.withZone(ZoneId.from(ZoneOffset.UTC)); @@ -104,7 +113,7 @@ public class GitExecutorCEImpl implements GitExecutor { return Mono.fromCallable(() -> { log.debug("Trying to commit to local repo path, {}", path); Path repoPath = path; - if (Boolean.TRUE.equals(isSuffixedPath)) { + if (TRUE.equals(isSuffixedPath)) { repoPath = createRepoPath(repoPath); } Stopwatch processStopwatch = @@ -130,6 +139,8 @@ public class GitExecutorCEImpl implements GitExecutor { } }) .timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS)) + .name(GitSpans.FILE_SYSTEM_COMMIT.getEventName()) + .tap(Micrometer.observation(observationRegistry)) .subscribeOn(scheduler); } @@ -232,6 +243,8 @@ public class GitExecutorCEImpl implements GitExecutor { } }) .timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS)) + .name(GitSpans.FILE_SYSTEM_PUSH.getEventName()) + .tap(Micrometer.observation(observationRegistry)) .subscribeOn(scheduler); } @@ -272,6 +285,8 @@ public class GitExecutorCEImpl implements GitExecutor { return branchName; }) .timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS)) + .name(GitSpans.FILE_SYSTEM_CLONE_REPO.getEventName()) + .tap(Micrometer.observation(observationRegistry)) .subscribeOn(scheduler); } @@ -289,7 +304,7 @@ public class GitExecutorCEImpl implements GitExecutor { try (Git git = Git.open(baseRepoPath.toFile())) { // Create and checkout to new branch git.checkout() - .setCreateBranch(Boolean.TRUE) + .setCreateBranch(TRUE) .setName(branchName) .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK) .call(); @@ -300,6 +315,8 @@ public class GitExecutorCEImpl implements GitExecutor { } }) .timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS)) + .name(GitSpans.FILE_SYSTEM_CREATE_BRANCH.getEventName()) + .tap(Micrometer.observation(observationRegistry)) .subscribeOn(scheduler); } @@ -318,16 +335,18 @@ public class GitExecutorCEImpl implements GitExecutor { // Create and checkout to new branch List deleteBranchList = git.branchDelete() .setBranchNames(branchName) - .setForce(Boolean.TRUE) + .setForce(TRUE) .call(); processStopwatch.stopAndLogTimeInMillis(); if (deleteBranchList.isEmpty()) { return Boolean.FALSE; } - return Boolean.TRUE; + return TRUE; } }) .timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS)) + .name(GitSpans.FILE_SYSTEM_DELETE_BRANCH.getEventName()) + .tap(Micrometer.observation(observationRegistry)) .subscribeOn(scheduler); } @@ -345,7 +364,7 @@ public class GitExecutorCEImpl implements GitExecutor { try (Git git = Git.open(baseRepoPath.toFile())) { if (StringUtils.equalsIgnoreCase( branchName, git.getRepository().getBranch())) { - return Boolean.TRUE; + return TRUE; } // Create and checkout to new branch String checkedOutBranch = git.checkout() @@ -361,6 +380,9 @@ public class GitExecutorCEImpl implements GitExecutor { } }) .timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS)) + .tag(CHECKOUT_REMOTE, FALSE.toString()) + .name(GitSpans.FILE_SYSTEM_CHECKOUT_BRANCH.getEventName()) + .tap(Micrometer.observation(observationRegistry)) .subscribeOn(scheduler); } @@ -421,6 +443,8 @@ public class GitExecutorCEImpl implements GitExecutor { } }) .timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS)) + .name(GitSpans.FILE_SYSTEM_PULL.getEventName()) + .tap(Micrometer.observation(observationRegistry)) .subscribeOn(scheduler); } } @@ -536,6 +560,8 @@ public class GitExecutorCEImpl implements GitExecutor { }) .timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS)) .flatMap(response -> response) + .name(GitSpans.FILE_SYSTEM_STATUS.getEventName()) + .tap(Micrometer.observation(observationRegistry)) .subscribeOn(scheduler); } @@ -656,6 +682,8 @@ public class GitExecutorCEImpl implements GitExecutor { } }) .timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS)) + .name(GitSpans.FILE_SYSTEM_MERGE.getEventName()) + .tap(Micrometer.observation(observationRegistry)) .subscribeOn(scheduler); } @@ -669,12 +697,12 @@ public class GitExecutorCEImpl implements GitExecutor { boolean isFetchAll) { Stopwatch processStopwatch = StopwatchHelpers.startStopwatch(repoSuffix, AnalyticsEvents.GIT_FETCH.getEventName()); - Path repoPath = Boolean.TRUE.equals(isRepoPath) ? repoSuffix : createRepoPath(repoSuffix); + Path repoPath = TRUE.equals(isRepoPath) ? repoSuffix : createRepoPath(repoSuffix); return Mono.fromCallable(() -> { TransportConfigCallback config = new SshTransportConfigCallback(privateKey, publicKey); try (Git git = Git.open(repoPath.toFile())) { String fetchMessages; - if (Boolean.TRUE.equals(isFetchAll)) { + if (TRUE.equals(isFetchAll)) { fetchMessages = git.fetch() .setRemoveDeletedRefs(true) .setTransportConfigCallback(config) @@ -699,6 +727,8 @@ public class GitExecutorCEImpl implements GitExecutor { return Mono.error(error); }) .timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS)) + .name(GitSpans.FILE_SYSTEM_FETCH_REMOTE.getEventName()) + .tap(Micrometer.observation(observationRegistry)) .subscribeOn(scheduler); } @@ -793,7 +823,7 @@ public class GitExecutorCEImpl implements GitExecutor { try (Git git = Git.open(baseRepoPath.toFile())) { // Create and checkout to new branch git.checkout() - .setCreateBranch(Boolean.TRUE) + .setCreateBranch(TRUE) .setName(branchName) .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK) .setStartPoint("origin/" + branchName) @@ -807,6 +837,9 @@ public class GitExecutorCEImpl implements GitExecutor { } }) .timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS)) + .tag(CHECKOUT_REMOTE, TRUE.toString()) + .name(GitSpans.FILE_SYSTEM_CHECKOUT_BRANCH.getEventName()) + .tap(Micrometer.observation(observationRegistry)) .subscribeOn(scheduler); } @@ -839,6 +872,9 @@ public class GitExecutorCEImpl implements GitExecutor { return ref; }) .timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS)) + .tag(HARD_RESET, Boolean.FALSE.toString()) + .name(GitSpans.FILE_SYSTEM_RESET.getEventName()) + .tap(Micrometer.observation(observationRegistry)) .subscribeOn(scheduler); } @@ -872,6 +908,9 @@ public class GitExecutorCEImpl implements GitExecutor { return Mono.just(false); }) .timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS)) + .tag(HARD_RESET, TRUE.toString()) + .name(GitSpans.FILE_SYSTEM_RESET.getEventName()) + .tap(Micrometer.observation(observationRegistry)) .subscribeOn(scheduler); } @@ -901,6 +940,8 @@ public class GitExecutorCEImpl implements GitExecutor { } }) .timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS)) + .name(GitSpans.FILE_SYSTEM_REBASE.getEventName()) + .tap(Micrometer.observation(observationRegistry)) .subscribeOn(scheduler); } @@ -912,6 +953,8 @@ public class GitExecutorCEImpl implements GitExecutor { } }) .timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS)) + .name(GitSpans.FILE_SYSTEM_BRANCH_TRACK.getEventName()) + .tap(Micrometer.observation(observationRegistry)) .subscribeOn(scheduler); } } diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/GitConstants.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/GitConstants.java deleted file mode 100644 index cc2fbb64bb..0000000000 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/GitConstants.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.appsmith.external.constants; - -import com.appsmith.external.constants.ce.GitConstantsCE; - -public class GitConstants extends GitConstantsCE {} 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 index 5da675c7cf..392f7586b0 100644 --- 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 @@ -2,4 +2,9 @@ package com.appsmith.external.constants.spans; public class BaseSpan { public static final String APPSMITH_SPAN_PREFIX = "appsmith."; + + /** + * This prefix is for all the git flows + */ + public static final String GIT_SPAN_PREFIX = "git."; } diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/constants/GitConstants.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/constants/GitConstants.java new file mode 100644 index 0000000000..c26ec3c2a2 --- /dev/null +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/constants/GitConstants.java @@ -0,0 +1,8 @@ +package com.appsmith.external.git.constants; + +import com.appsmith.external.git.constants.ce.GitConstantsCE; + +public class GitConstants extends GitConstantsCE { + + public class GitMetricConstants extends GitMetricConstantsCE {} +} diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/constants/GitSpans.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/constants/GitSpans.java new file mode 100644 index 0000000000..20fe0cb7f3 --- /dev/null +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/constants/GitSpans.java @@ -0,0 +1,36 @@ +package com.appsmith.external.git.constants; + +import java.util.Locale; + +import static com.appsmith.external.constants.spans.BaseSpan.APPSMITH_SPAN_PREFIX; +import static com.appsmith.external.constants.spans.BaseSpan.GIT_SPAN_PREFIX; + +public enum GitSpans { + FILE_SYSTEM_CLONE_REPO, + FILE_SYSTEM_STATUS, + FILE_SYSTEM_PULL, + FILE_SYSTEM_BRANCH_TRACK, + ADD_FILE_LOCK, + RELEASE_FILE_LOCK, + FILE_SYSTEM_COMMIT, + FILE_SYSTEM_CHECKOUT_BRANCH, + FILE_SYSTEM_CREATE_BRANCH, + FILE_SYSTEM_DELETE_BRANCH, + FILE_SYSTEM_CREATE_REPO, + FILE_SYSTEM_RESET, + FILE_SYSTEM_MERGE, + FILE_SYSTEM_REBASE, + FILE_SYSTEM_PUSH, + FILE_SYSTEM_FETCH_REMOTE, + STATUS, + COMMIT; + private final String eventName; + + GitSpans() { + this.eventName = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + name().toLowerCase(Locale.ROOT); + } + + public String getEventName() { + return this.eventName; + } +} diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/ce/GitConstantsCE.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/constants/ce/GitConstantsCE.java similarity index 86% rename from app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/ce/GitConstantsCE.java rename to app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/constants/ce/GitConstantsCE.java index 467375d976..ab0199164d 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/ce/GitConstantsCE.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/constants/ce/GitConstantsCE.java @@ -1,4 +1,4 @@ -package com.appsmith.external.constants.ce; +package com.appsmith.external.git.constants.ce; public class GitConstantsCE { // This will be used as a key separator for action and jsobjects name @@ -21,4 +21,9 @@ public class GitConstantsCE { public static final String GIT_PROFILE_ERROR = "Unable to find git author configuration for logged-in user. You can" + " set up a git profile from the user profile section."; + + public class GitMetricConstantsCE { + public static final String CHECKOUT_REMOTE = "checkout-remote"; + public static final String HARD_RESET = "hard-reset"; + } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/exportable/ActionCollectionExportableServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/exportable/ActionCollectionExportableServiceCEImpl.java index 6bfa6e9fc7..34f46f26e3 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/exportable/ActionCollectionExportableServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/exportable/ActionCollectionExportableServiceCEImpl.java @@ -22,7 +22,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import static com.appsmith.external.constants.GitConstants.NAME_SEPARATOR; +import static com.appsmith.external.git.constants.GitConstants.NAME_SEPARATOR; import static com.appsmith.server.constants.ResourceModes.EDIT; import static com.appsmith.server.constants.ResourceModes.VIEW; diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/ApplicationGitFileUtilsCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/ApplicationGitFileUtilsCE.java index 2557cabc42..034ac9503b 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/ApplicationGitFileUtilsCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/ApplicationGitFileUtilsCE.java @@ -27,7 +27,7 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; -import static com.appsmith.external.constants.ce.GitConstantsCE.NAME_SEPARATOR; +import static com.appsmith.external.git.constants.GitConstants.NAME_SEPARATOR; import static com.appsmith.external.helpers.AppsmithBeanUtils.copyProperties; import static com.appsmith.server.constants.ce.FieldNameCE.ACTION_COLLECTION_LIST; import static com.appsmith.server.constants.ce.FieldNameCE.ACTION_LIST; diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/GitFileUtilsCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/GitFileUtilsCE.java index 5804776a14..3f6d60639b 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/GitFileUtilsCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/GitFileUtilsCE.java @@ -57,7 +57,7 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; -import static com.appsmith.external.constants.GitConstants.NAME_SEPARATOR; +import static com.appsmith.external.git.constants.GitConstants.NAME_SEPARATOR; import static com.appsmith.external.helpers.AppsmithBeanUtils.copyNestedNonNullProperties; import static com.appsmith.external.helpers.AppsmithBeanUtils.copyProperties; import static com.appsmith.server.constants.FieldName.ACTION_COLLECTION_LIST; diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/exportable/NewActionExportableServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/exportable/NewActionExportableServiceCEImpl.java index 6583b97b4c..0a315b05af 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/exportable/NewActionExportableServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/exportable/NewActionExportableServiceCEImpl.java @@ -22,7 +22,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import static com.appsmith.external.constants.GitConstants.NAME_SEPARATOR; +import static com.appsmith.external.git.constants.GitConstants.NAME_SEPARATOR; import static com.appsmith.server.constants.ResourceModes.EDIT; import static com.appsmith.server.constants.ResourceModes.VIEW; import static com.appsmith.server.helpers.ImportExportUtils.sanitizeDatasourceInActionDTO; diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/CommonGitServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/CommonGitServiceCEImpl.java index d89379b2a0..92cb22f6db 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/CommonGitServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/CommonGitServiceCEImpl.java @@ -62,10 +62,10 @@ import java.util.Optional; import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; -import static com.appsmith.external.constants.ce.GitConstantsCE.DEFAULT_COMMIT_MESSAGE; -import static com.appsmith.external.constants.ce.GitConstantsCE.EMPTY_COMMIT_ERROR_MESSAGE; -import static com.appsmith.external.constants.ce.GitConstantsCE.GIT_CONFIG_ERROR; -import static com.appsmith.external.constants.ce.GitConstantsCE.GIT_PROFILE_ERROR; +import static com.appsmith.external.git.constants.GitConstants.DEFAULT_COMMIT_MESSAGE; +import static com.appsmith.external.git.constants.GitConstants.EMPTY_COMMIT_ERROR_MESSAGE; +import static com.appsmith.external.git.constants.GitConstants.GIT_CONFIG_ERROR; +import static com.appsmith.external.git.constants.GitConstants.GIT_PROFILE_ERROR; import static com.appsmith.server.constants.ArtifactType.APPLICATION; import static com.appsmith.server.constants.SerialiseArtifactObjective.VERSION_CONTROL; import static com.appsmith.server.constants.ce.FieldNameCE.DEFAULT; diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java index 75b1cdf365..7295514b89 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java @@ -7,6 +7,7 @@ import com.appsmith.external.dtos.GitLogDTO; import com.appsmith.external.dtos.GitStatusDTO; import com.appsmith.external.dtos.MergeStatusDTO; import com.appsmith.external.git.GitExecutor; +import com.appsmith.external.git.constants.GitSpans; import com.appsmith.external.models.Datasource; import com.appsmith.external.models.DatasourceStorage; import com.appsmith.git.service.GitExecutorImpl; @@ -100,12 +101,14 @@ import java.util.stream.Collectors; import static com.appsmith.external.constants.AnalyticsEvents.GIT_ADD_PROTECTED_BRANCH; import static com.appsmith.external.constants.AnalyticsEvents.GIT_REMOVE_PROTECTED_BRANCH; -import static com.appsmith.external.constants.GitConstants.CONFLICTED_SUCCESS_MESSAGE; -import static com.appsmith.external.constants.GitConstants.DEFAULT_COMMIT_MESSAGE; -import static com.appsmith.external.constants.GitConstants.EMPTY_COMMIT_ERROR_MESSAGE; -import static com.appsmith.external.constants.GitConstants.GIT_CONFIG_ERROR; -import static com.appsmith.external.constants.GitConstants.GIT_PROFILE_ERROR; -import static com.appsmith.external.constants.GitConstants.MERGE_CONFLICT_BRANCH_NAME; +import static com.appsmith.external.git.constants.GitConstants.CONFLICTED_SUCCESS_MESSAGE; +import static com.appsmith.external.git.constants.GitConstants.DEFAULT_COMMIT_MESSAGE; +import static com.appsmith.external.git.constants.GitConstants.EMPTY_COMMIT_ERROR_MESSAGE; +import static com.appsmith.external.git.constants.GitConstants.GIT_CONFIG_ERROR; +import static com.appsmith.external.git.constants.GitConstants.GIT_PROFILE_ERROR; +import static com.appsmith.external.git.constants.GitConstants.MERGE_CONFLICT_BRANCH_NAME; +import static com.appsmith.external.git.constants.GitSpans.COMMIT; +import static com.appsmith.external.git.constants.GitSpans.STATUS; import static com.appsmith.git.constants.AppsmithBotAsset.APPSMITH_BOT_USERNAME; import static com.appsmith.server.constants.ArtifactType.APPLICATION; import static com.appsmith.server.constants.FieldName.DEFAULT; @@ -113,6 +116,7 @@ import static com.appsmith.server.constants.SerialiseArtifactObjective.VERSION_C import static com.appsmith.server.helpers.DefaultResourcesUtils.createDefaultIdsOrUpdateWithGivenResourceIds; import static com.appsmith.server.helpers.GitUtils.MAX_RETRIES; import static com.appsmith.server.helpers.GitUtils.RETRY_DELAY; +import static java.lang.Boolean.TRUE; import static org.apache.commons.lang.ObjectUtils.defaultIfNull; /** @@ -227,7 +231,7 @@ public class GitServiceCEImpl implements GitServiceCE { if (DEFAULT.equals(defaultApplicationId)) { gitProfile.setUseGlobalProfile(null); - } else if (!Boolean.TRUE.equals(gitProfile.getUseGlobalProfile())) { + } else if (!TRUE.equals(gitProfile.getUseGlobalProfile())) { gitProfile.setUseGlobalProfile(Boolean.FALSE); } @@ -427,7 +431,7 @@ public class GitServiceCEImpl implements GitServiceCE { }) .flatMap(application -> { GitArtifactMetadata gitData = application.getGitApplicationMetadata(); - if (Boolean.TRUE.equals(isFileLock)) { + if (TRUE.equals(isFileLock)) { return addFileLock(gitData.getDefaultApplicationId()).then(Mono.just(application)); } return Mono.just(application); @@ -445,7 +449,7 @@ public class GitServiceCEImpl implements GitServiceCE { .flatMap(isPrivate -> { // Check the repo limit if the visibility status is updated, or it is private if (!isPrivate.equals(defaultGitMetadata.getIsRepoPrivate()) - || isPrivate.equals(Boolean.TRUE)) { + || isPrivate.equals(TRUE)) { defaultGitMetadata.setIsRepoPrivate(isPrivate); defaultApplication.setGitApplicationMetadata(defaultGitMetadata); return applicationService @@ -574,7 +578,7 @@ public class GitServiceCEImpl implements GitServiceCE { String commitStatus = tuple.getT1(); result.append(commitStatus); - if (Boolean.TRUE.equals(commitDTO.getDoPush())) { + if (TRUE.equals(commitDTO.getDoPush())) { // Push flow result.append(".\nPush Result : "); return pushApplication(childApplication.getId(), false, false) @@ -606,7 +610,7 @@ public class GitServiceCEImpl implements GitServiceCE { .update(childApplication.getId(), update) // Release the file lock on git repo .flatMap(application -> { - if (Boolean.TRUE.equals(isFileLock)) { + if (TRUE.equals(isFileLock)) { return releaseFileLock(childApplication .getGitApplicationMetadata() .getDefaultApplicationId()); @@ -621,8 +625,7 @@ public class GitServiceCEImpl implements GitServiceCE { childApplication.getGitApplicationMetadata().getIsRepoPrivate(), isSystemGenerated)) .thenReturn(status) - .tag("gitCommit", defaultApplicationId) - .name(AnalyticsEvents.GIT_COMMIT.getEventName()) + .name(COMMIT.getEventName()) .tap(Micrometer.observation(observationRegistry)); }); @@ -872,7 +875,7 @@ public class GitServiceCEImpl implements GitServiceCE { if (!application.getPages().isEmpty()) { defaultPageId = application.getPages().stream() .filter(applicationPage -> - applicationPage.getIsDefault().equals(Boolean.TRUE)) + applicationPage.getIsDefault().equals(TRUE)) .collect(Collectors.toList()) .get(0) .getId(); @@ -906,7 +909,7 @@ public class GitServiceCEImpl implements GitServiceCE { GitProfile profile = userData.getGitProfileByKey(defaultApplicationId); if (profile == null || StringUtils.isEmptyOrNull(profile.getAuthorName()) - || Boolean.TRUE.equals(profile.getUseGlobalProfile())) { + || TRUE.equals(profile.getUseGlobalProfile())) { profile = userData.getGitProfileByKey(DEFAULT); } @@ -1009,7 +1012,7 @@ public class GitServiceCEImpl implements GitServiceCE { }); }) .flatMap(application -> { - if (Boolean.TRUE.equals(isFileLock)) { + if (TRUE.equals(isFileLock)) { return addFileLock( application.getGitApplicationMetadata().getDefaultApplicationId()) .map(status -> application); @@ -1069,7 +1072,7 @@ public class GitServiceCEImpl implements GitServiceCE { .flatMap(tuple -> { String pushStatus = tuple.getT1(); Application application = tuple.getT2(); - if (Boolean.TRUE.equals(isFileLock)) { + if (TRUE.equals(isFileLock)) { return releaseFileLock( application.getGitApplicationMetadata().getDefaultApplicationId()) .map(status -> tuple); @@ -1545,7 +1548,7 @@ public class GitServiceCEImpl implements GitServiceCE { .flatMap(application1 -> addAnalyticsForGitOperation( AnalyticsEvents.GIT_CHECKOUT_REMOTE_BRANCH, application1, - Boolean.TRUE.equals(application1 + TRUE.equals(application1 .getGitApplicationMetadata() .getIsRepoPrivate()))) .map(responseUtils::updateApplicationWithDefaultResources) @@ -1558,7 +1561,7 @@ public class GitServiceCEImpl implements GitServiceCE { } private Mono publishAndOrGetApplication(String applicationId, boolean publish) { - if (Boolean.TRUE.equals(publish)) { + if (TRUE.equals(publish)) { return applicationPageService .publish(applicationId, true) // Get application here to decrypt the git private key if present @@ -1779,7 +1782,7 @@ public class GitServiceCEImpl implements GitServiceCE { .flatMap(rootApplication -> { Path repoPath = getRepoPath(rootApplication); Mono defaultBranchMono; - if (Boolean.TRUE.equals(pruneBranches) && syncDefaultBranchWithRemote) { + if (TRUE.equals(pruneBranches) && syncDefaultBranchWithRemote) { defaultBranchMono = syncDefaultBranchNameFromRemote(repoPath, rootApplication); } else { defaultBranchMono = @@ -1825,7 +1828,7 @@ public class GitServiceCEImpl implements GitServiceCE { .flatMap(objects -> { GitArtifactMetadata gitArtifactMetadata = rootApp.getGitApplicationMetadata(); - if (Boolean.TRUE.equals(pruneBranches)) { + if (TRUE.equals(pruneBranches)) { return gitExecutor .fetchRemote( repoPath, @@ -1992,8 +1995,7 @@ public class GitServiceCEImpl implements GitServiceCE { throwable); return Mono.error(new AppsmithException(AppsmithError.GIT_GENERIC_ERROR, throwable.getMessage())); }) - .tag("gitStatus", defaultApplicationId) - .name(AnalyticsEvents.GIT_STATUS.getEventName()) + .name(STATUS.getEventName()) .tap(Micrometer.observation(observationRegistry)); return Mono.zip(statusMono, sessionUserService.getCurrentUser(), branchedAppMono) @@ -2261,7 +2263,7 @@ public class GitServiceCEImpl implements GitServiceCE { ApplicationJson applicationJson = tuple.getT3(); MergeStatusDTO mergeStatusDTO = new MergeStatusDTO(); mergeStatusDTO.setStatus(tuple.getT1()); - mergeStatusDTO.setMergeAble(Boolean.TRUE); + mergeStatusDTO.setMergeAble(TRUE); // 4. Get the latest application mono with all the changes return importService @@ -3271,11 +3273,16 @@ public class GitServiceCEImpl implements GitServiceCE { .retryWhen(Retry.fixedDelay(MAX_RETRIES, RETRY_DELAY) .onRetryExhaustedThrow((retryBackoffSpec, retrySignal) -> { throw new AppsmithException(AppsmithError.GIT_FILE_IN_USE); - })); + })) + .name(GitSpans.ADD_FILE_LOCK.getEventName()) + .tap(Micrometer.observation(observationRegistry)); } private Mono releaseFileLock(String defaultApplicationId) { - return redisUtils.releaseFileLock(defaultApplicationId); + return redisUtils + .releaseFileLock(defaultApplicationId) + .name(GitSpans.RELEASE_FILE_LOCK.getEventName()) + .tap(Micrometer.observation(observationRegistry)); } @Override @@ -3354,7 +3361,7 @@ public class GitServiceCEImpl implements GitServiceCE { if (autoCommitConfig.getEnabled()) { autoCommitConfig.setEnabled(Boolean.FALSE); } else { - autoCommitConfig.setEnabled(Boolean.TRUE); + autoCommitConfig.setEnabled(TRUE); } // need to call the setter because getter returns a default config if attribute is null application.getGitApplicationMetadata().setAutoCommitConfig(autoCommitConfig); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/AutoCommitEventHandlerCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/AutoCommitEventHandlerCEImpl.java index ccfbe4bb6d..ef28b86593 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/AutoCommitEventHandlerCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/AutoCommitEventHandlerCEImpl.java @@ -35,7 +35,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import static com.appsmith.external.constants.GitConstants.PAGE_LIST; +import static com.appsmith.external.git.constants.GitConstants.PAGE_LIST; import static com.appsmith.server.helpers.GitUtils.MAX_RETRIES; import static com.appsmith.server.helpers.GitUtils.RETRY_DELAY; diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/exports/internal/ExportServiceTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/exports/internal/ExportServiceTests.java index d495250ae9..d2a55752eb 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/exports/internal/ExportServiceTests.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/exports/internal/ExportServiceTests.java @@ -95,7 +95,7 @@ import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; -import static com.appsmith.external.constants.GitConstants.NAME_SEPARATOR; +import static com.appsmith.external.git.constants.GitConstants.NAME_SEPARATOR; import static com.appsmith.server.acl.AclPermission.MANAGE_APPLICATIONS; import static com.appsmith.server.acl.AclPermission.MANAGE_PAGES; import static com.appsmith.server.acl.AclPermission.READ_ACTIONS; diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/GitFileUtilsTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/GitFileUtilsTest.java index cdbde52d05..f8742b85c4 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/GitFileUtilsTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/GitFileUtilsTest.java @@ -37,7 +37,7 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import static com.appsmith.external.constants.GitConstants.NAME_SEPARATOR; +import static com.appsmith.external.git.constants.GitConstants.NAME_SEPARATOR; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(SpringExtension.class) diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java index d20ca90e7c..563bb9acf5 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java @@ -124,7 +124,7 @@ import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; -import static com.appsmith.external.constants.ce.GitConstantsCE.NAME_SEPARATOR; +import static com.appsmith.external.git.constants.ce.GitConstantsCE.NAME_SEPARATOR; import static com.appsmith.server.acl.AclPermission.MANAGE_ACTIONS; import static com.appsmith.server.acl.AclPermission.MANAGE_APPLICATIONS; import static com.appsmith.server.acl.AclPermission.MANAGE_DATASOURCES;