Skip to content

Commit

Permalink
added more tappings
Browse files Browse the repository at this point in the history
  • Loading branch information
sondermanish committed Apr 8, 2024
1 parent 2f423f5 commit 54080a4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

public class GitSpansCE {

public static String FILE_SYSTEM_CLONE_REPO = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "file_system_clone_repo";
public static final String FILE_SYSTEM_CLONE_REPO =
APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "file_system_clone_repo";
public static final String FILE_SYSTEM_STATUS = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "file_system_status";
public static final String FILE_SYSTEM_PULL = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "file_system_pull";
public static final String FILE_SYSTEM_BRANCH_TRACK =
Expand All @@ -29,4 +30,12 @@ public class GitSpansCE {
APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "file_system_fetch_remote";
public static final String STATUS = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "status";
public static final String COMMIT = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "commit";
public static final String PUSH = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "push";
public static final String PULL = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "pull";
public static final String CREATE_BRANCH = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "create_branch";
public static final String CHECKOUT_BRANCH = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "checkout_branch";
public static final String DELETE_BRANCH = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "delete_branch";
public static final String FETCH_REMOTE = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "fetch_remote";
public static final String DETACH_REMOTE = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "detach_remote";
public static final String DISCARD_CHANGES = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "discard_changes";
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.appsmith.external.dtos.GitStatusDTO;
import com.appsmith.external.dtos.MergeStatusDTO;
import com.appsmith.external.git.GitExecutor;
import com.appsmith.external.git.constants.GitConstants;
import com.appsmith.external.git.constants.GitSpans;
import com.appsmith.external.models.Datasource;
import com.appsmith.external.models.DatasourceStorage;
Expand Down Expand Up @@ -116,6 +117,7 @@
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.FALSE;
import static java.lang.Boolean.TRUE;
import static org.apache.commons.lang.ObjectUtils.defaultIfNull;

Expand Down Expand Up @@ -219,10 +221,10 @@ public Mono<Map<String, GitProfile>> updateOrCreateGitProfileForCurrentUser(
// 2. Updating or creating repo specific profile and user want to use repo specific profile but provided empty
// values for authorName and email

if ((DEFAULT.equals(defaultApplicationId) || Boolean.FALSE.equals(gitProfile.getUseGlobalProfile()))
if ((DEFAULT.equals(defaultApplicationId) || FALSE.equals(gitProfile.getUseGlobalProfile()))
&& StringUtils.isEmptyOrNull(gitProfile.getAuthorName())) {
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, "Author Name"));
} else if ((DEFAULT.equals(defaultApplicationId) || Boolean.FALSE.equals(gitProfile.getUseGlobalProfile()))
} else if ((DEFAULT.equals(defaultApplicationId) || FALSE.equals(gitProfile.getUseGlobalProfile()))
&& StringUtils.isEmptyOrNull(gitProfile.getAuthorEmail())) {
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, "Author Email"));
} else if (StringUtils.isEmptyOrNull(defaultApplicationId)) {
Expand All @@ -232,7 +234,7 @@ public Mono<Map<String, GitProfile>> updateOrCreateGitProfileForCurrentUser(
if (DEFAULT.equals(defaultApplicationId)) {
gitProfile.setUseGlobalProfile(null);
} else if (!TRUE.equals(gitProfile.getUseGlobalProfile())) {
gitProfile.setUseGlobalProfile(Boolean.FALSE);
gitProfile.setUseGlobalProfile(FALSE);
}

return sessionUserService
Expand Down Expand Up @@ -458,7 +460,7 @@ private Mono<String> commitApplication(
.flatMap(application ->
gitPrivateRepoHelper.isRepoLimitReached(workspaceId, false))
.flatMap(isRepoLimitReached -> {
if (Boolean.FALSE.equals(isRepoLimitReached)) {
if (FALSE.equals(isRepoLimitReached)) {
return Mono.just(defaultApplication);
}
throw new AppsmithException(AppsmithError.GIT_APPLICATION_LIMIT_ERROR);
Expand Down Expand Up @@ -738,7 +740,7 @@ public Mono<Application> connectApplicationToGit(
return gitPrivateRepoHelper
.isRepoLimitReached(application.getWorkspaceId(), true)
.flatMap(isRepoLimitReached -> {
if (Boolean.FALSE.equals(isRepoLimitReached)) {
if (FALSE.equals(isRepoLimitReached)) {
return Mono.just(application);
}
return addAnalyticsForGitOperation(
Expand Down Expand Up @@ -1092,7 +1094,9 @@ private Mono<String> pushApplication(String applicationId, boolean doPublish, bo
application,
application.getGitApplicationMetadata().getIsRepoPrivate())
.thenReturn(pushStatus);
});
})
.name(GitSpans.PUSH)
.tap(Micrometer.observation(observationRegistry));

return Mono.create(sink -> pushStatusMono.subscribe(sink::success, sink::error, null, sink.currentContext()));
}
Expand Down Expand Up @@ -1236,7 +1240,9 @@ public Mono<Application> detachRemote(String defaultApplicationId) {
.collectList()
.flatMapMany(actionCollectionService::saveAll))
.then(addAnalyticsForGitOperation(AnalyticsEvents.GIT_DISCONNECT, application, false))
.map(responseUtils::updateApplicationWithDefaultResources));
.map(responseUtils::updateApplicationWithDefaultResources))
.name(GitSpans.DETACH_REMOTE)
.tap(Micrometer.observation(observationRegistry));

return Mono.create(sink -> disconnectMono.subscribe(sink::success, sink::error, null, sink.currentContext()));
}
Expand Down Expand Up @@ -1377,7 +1383,9 @@ public Mono<Application> createBranch(String defaultApplicationId, GitBranchDTO
AnalyticsEvents.GIT_CREATE_BRANCH,
application,
application.getGitApplicationMetadata().getIsRepoPrivate())))
.map(responseUtils::updateApplicationWithDefaultResources);
.map(responseUtils::updateApplicationWithDefaultResources)
.name(GitSpans.CREATE_BRANCH)
.tap(Micrometer.observation(observationRegistry));

return Mono.create(sink -> createBranchMono.subscribe(sink::success, sink::error, null, sink.currentContext()));
}
Expand Down Expand Up @@ -1447,6 +1455,9 @@ public Mono<Application> checkoutBranch(String defaultApplicationId, String bran
}
return Mono.just(result);
})
.tag(GitConstants.GitMetricConstants.CHECKOUT_REMOTE, FALSE.toString())
.name(GitSpans.CHECKOUT_BRANCH)
.tap(Micrometer.observation(observationRegistry))
.onErrorResume(throwable -> {
return Mono.error(throwable);
});
Expand Down Expand Up @@ -1559,7 +1570,10 @@ private Mono<Application> checkoutRemoteBranch(String defaultApplicationId, Stri
.map(responseUtils::updateApplicationWithDefaultResources)
.flatMap(application1 ->
releaseFileLock(defaultApplicationId).then(Mono.just(application1)));
});
})
.tag(GitConstants.GitMetricConstants.CHECKOUT_REMOTE, TRUE.toString())
.name(GitSpans.CHECKOUT_BRANCH)
.tap(Micrometer.observation(observationRegistry));

return Mono.create(
sink -> checkoutRemoteBranchMono.subscribe(sink::success, sink::error, null, sink.currentContext()));
Expand Down Expand Up @@ -1648,7 +1662,9 @@ public Mono<GitPullDTO> pullApplication(String defaultApplicationId, String bran
// Release file lock after the pull operation
.flatMap(gitPullDTO ->
releaseFileLock(defaultApplicationId).then(Mono.just(gitPullDTO)));
});
})
.name(GitSpans.PULL)
.tap(Micrometer.observation(observationRegistry));

return Mono.create(sink -> pullMono.subscribe(sink::success, sink::error, null, sink.currentContext()));
}
Expand Down Expand Up @@ -1857,7 +1873,7 @@ private Mono<List<GitBranchDTO>> getBranchListWithDefaultBranchName(
}
return branchDTOList;
})
.flatMap(gitBranchDTOList -> Boolean.FALSE.equals(pruneBranches)
.flatMap(gitBranchDTOList -> FALSE.equals(pruneBranches)
? Mono.just(gitBranchDTOList)
: addAnalyticsForGitOperation(
AnalyticsEvents.GIT_PRUNE,
Expand Down Expand Up @@ -2134,7 +2150,9 @@ public Mono<BranchTrackingStatus> fetchRemoteChanges(
return sendUnitExecutionTimeAnalyticsEvent(
AnalyticsEvents.GIT_FETCH.getEventName(), elapsedTime, currentUser, app)
.thenReturn(branchTrackingStatus);
});
})
.name(GitSpans.FETCH_REMOTE)
.tap(Micrometer.observation(observationRegistry));

return Mono.create(sink -> {
fetchRemoteStatusMono.subscribe(sink::success, sink::error, null, sink.currentContext());
Expand Down Expand Up @@ -2572,7 +2590,7 @@ public Mono<ApplicationImportDTO> importApplicationFromGit(String workspaceId, G
return gitPrivateRepoHelper
.isRepoLimitReached(workspaceId, true)
.flatMap(isRepoLimitReached -> {
if (Boolean.FALSE.equals(isRepoLimitReached)) {
if (FALSE.equals(isRepoLimitReached)) {
return Mono.just(gitAuth).zipWith(applicationMono);
}
return addAnalyticsForGitOperation(
Expand Down Expand Up @@ -2853,7 +2871,7 @@ public Mono<Application> deleteBranch(String defaultApplicationId, String branch
.flatMap(isBranchDeleted ->
releaseFileLock(defaultApplicationId).map(status -> isBranchDeleted))
.flatMap(isBranchDeleted -> {
if (Boolean.FALSE.equals(isBranchDeleted)) {
if (FALSE.equals(isBranchDeleted)) {
return Mono.error(new AppsmithException(
AppsmithError.GIT_ACTION_FAILED,
" delete branch. Branch does not exists in the repo"));
Expand Down Expand Up @@ -2889,7 +2907,9 @@ public Mono<Application> deleteBranch(String defaultApplicationId, String branch
AnalyticsEvents.GIT_DELETE_BRANCH,
application,
application.getGitApplicationMetadata().getIsRepoPrivate()))
.map(responseUtils::updateApplicationWithDefaultResources);
.map(responseUtils::updateApplicationWithDefaultResources)
.name(GitSpans.DELETE_BRANCH)
.tap(Micrometer.observation(observationRegistry));

return Mono.create(sink -> deleteBranchMono.subscribe(sink::success, sink::error, null, sink.currentContext()));
}
Expand Down Expand Up @@ -2952,7 +2972,9 @@ public Mono<Application> discardChanges(String defaultApplicationId, String bran
})
.flatMap(application -> releaseFileLock(defaultApplicationId)
.then(this.addAnalyticsForGitOperation(AnalyticsEvents.GIT_DISCARD_CHANGES, application, null)))
.map(responseUtils::updateApplicationWithDefaultResources);
.map(responseUtils::updateApplicationWithDefaultResources)
.name(GitSpans.DISCARD_CHANGES)
.tap(Micrometer.observation(observationRegistry));

return Mono.create(
sink -> discardChangeMono.subscribe(sink::success, sink::error, null, sink.currentContext()));
Expand Down Expand Up @@ -3364,7 +3386,7 @@ public Mono<Boolean> toggleAutoCommitEnabled(String defaultApplicationId) {

AutoCommitConfig autoCommitConfig = gitArtifactMetadata.getAutoCommitConfig();
if (autoCommitConfig.getEnabled()) {
autoCommitConfig.setEnabled(Boolean.FALSE);
autoCommitConfig.setEnabled(FALSE);
} else {
autoCommitConfig.setEnabled(TRUE);
}
Expand Down

0 comments on commit 54080a4

Please sign in to comment.