Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Git spans changed from enum to string #32454

Merged
merged 7 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -7,7 +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.GitSpans;
import com.appsmith.external.git.constants.GitSpan;
import com.appsmith.external.helpers.Stopwatch;
import com.appsmith.git.configurations.GitServiceConfig;
import com.appsmith.git.constants.AppsmithBotAsset;
Expand Down Expand Up @@ -139,7 +139,7 @@ public Mono<String> commitArtifact(
}
})
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
.name(GitSpans.FILE_SYSTEM_COMMIT.getEventName())
.name(GitSpan.FS_COMMIT)
.tap(Micrometer.observation(observationRegistry))
.subscribeOn(scheduler);
}
Expand Down Expand Up @@ -243,7 +243,7 @@ public Mono<String> pushApplication(
}
})
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
.name(GitSpans.FILE_SYSTEM_PUSH.getEventName())
.name(GitSpan.FS_PUSH)
.tap(Micrometer.observation(observationRegistry))
.subscribeOn(scheduler);
}
Expand Down Expand Up @@ -285,7 +285,7 @@ public Mono<String> cloneRemoteIntoArtifactRepo(
return branchName;
})
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
.name(GitSpans.FILE_SYSTEM_CLONE_REPO.getEventName())
.name(GitSpan.FS_CLONE_REPO)
.tap(Micrometer.observation(observationRegistry))
.subscribeOn(scheduler);
}
Expand Down Expand Up @@ -315,7 +315,7 @@ public Mono<String> createAndCheckoutToBranch(Path repoSuffix, String branchName
}
})
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
.name(GitSpans.FILE_SYSTEM_CREATE_BRANCH.getEventName())
.name(GitSpan.FS_CREATE_BRANCH)
.tap(Micrometer.observation(observationRegistry))
.subscribeOn(scheduler);
}
Expand Down Expand Up @@ -345,7 +345,7 @@ public Mono<Boolean> deleteBranch(Path repoSuffix, String branchName) {
}
})
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
.name(GitSpans.FILE_SYSTEM_DELETE_BRANCH.getEventName())
.name(GitSpan.FS_DELETE_BRANCH)
.tap(Micrometer.observation(observationRegistry))
.subscribeOn(scheduler);
}
Expand Down Expand Up @@ -381,7 +381,7 @@ public Mono<Boolean> checkoutToBranch(Path repoSuffix, String branchName) {
})
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
.tag(CHECKOUT_REMOTE, FALSE.toString())
.name(GitSpans.FILE_SYSTEM_CHECKOUT_BRANCH.getEventName())
.name(GitSpan.FS_CHECKOUT_BRANCH)
.tap(Micrometer.observation(observationRegistry))
.subscribeOn(scheduler);
}
Expand Down Expand Up @@ -443,7 +443,7 @@ public Mono<MergeStatusDTO> pullApplication(
}
})
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
.name(GitSpans.FILE_SYSTEM_PULL.getEventName())
.name(GitSpan.FS_PULL)
.tap(Micrometer.observation(observationRegistry))
.subscribeOn(scheduler);
}
Expand Down Expand Up @@ -560,7 +560,7 @@ public Mono<GitStatusDTO> getStatus(Path repoPath, String branchName) {
})
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
.flatMap(response -> response)
.name(GitSpans.FILE_SYSTEM_STATUS.getEventName())
.name(GitSpan.FS_STATUS)
.tap(Micrometer.observation(observationRegistry))
.subscribeOn(scheduler);
}
Expand Down Expand Up @@ -682,7 +682,7 @@ public Mono<String> mergeBranch(Path repoSuffix, String sourceBranch, String des
}
})
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
.name(GitSpans.FILE_SYSTEM_MERGE.getEventName())
.name(GitSpan.FS_MERGE)
.tap(Micrometer.observation(observationRegistry))
.subscribeOn(scheduler);
}
Expand Down Expand Up @@ -727,7 +727,7 @@ public Mono<String> fetchRemote(
return Mono.error(error);
})
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
.name(GitSpans.FILE_SYSTEM_FETCH_REMOTE.getEventName())
.name(GitSpan.FS_FETCH_REMOTE)
.tap(Micrometer.observation(observationRegistry))
.subscribeOn(scheduler);
}
Expand Down Expand Up @@ -838,7 +838,7 @@ public Mono<String> checkoutRemoteBranch(Path repoSuffix, String branchName) {
})
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
.tag(CHECKOUT_REMOTE, TRUE.toString())
.name(GitSpans.FILE_SYSTEM_CHECKOUT_BRANCH.getEventName())
.name(GitSpan.FS_CHECKOUT_BRANCH)
.tap(Micrometer.observation(observationRegistry))
.subscribeOn(scheduler);
}
Expand Down Expand Up @@ -873,7 +873,7 @@ private Mono<Ref> resetToLastCommit(Git git) throws GitAPIException {
})
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
.tag(HARD_RESET, Boolean.FALSE.toString())
.name(GitSpans.FILE_SYSTEM_RESET.getEventName())
.name(GitSpan.FS_RESET)
.tap(Micrometer.observation(observationRegistry))
.subscribeOn(scheduler);
}
Expand Down Expand Up @@ -909,7 +909,7 @@ public Mono<Boolean> resetHard(Path repoSuffix, String branchName) {
})
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
.tag(HARD_RESET, TRUE.toString())
.name(GitSpans.FILE_SYSTEM_RESET.getEventName())
.name(GitSpan.FS_RESET)
.tap(Micrometer.observation(observationRegistry))
.subscribeOn(scheduler);
}
Expand Down Expand Up @@ -940,7 +940,7 @@ public Mono<Boolean> rebaseBranch(Path repoSuffix, String branchName) {
}
})
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
.name(GitSpans.FILE_SYSTEM_REBASE.getEventName())
.name(GitSpan.FS_REBASE)
.tap(Micrometer.observation(observationRegistry))
.subscribeOn(scheduler);
}
Expand All @@ -953,7 +953,7 @@ public Mono<BranchTrackingStatus> getBranchTrackingStatus(Path repoPath, String
}
})
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
.name(GitSpans.FILE_SYSTEM_BRANCH_TRACK.getEventName())
.name(GitSpan.FS_BRANCH_TRACK)
.tap(Micrometer.observation(observationRegistry))
.subscribeOn(scheduler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public class BaseSpan {
* This prefix is for all the git flows
*/
public static final String GIT_SPAN_PREFIX = "git.";

public static final String APPLICATION_SPAN_PREFIX = "application.";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.appsmith.external.git.constants;

import com.appsmith.external.git.constants.ce.GitSpanCE;

public class GitSpan extends GitSpanCE {}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.appsmith.external.git.constants.ce;

import static com.appsmith.external.constants.spans.BaseSpan.APPSMITH_SPAN_PREFIX;
import static com.appsmith.external.constants.spans.BaseSpan.GIT_SPAN_PREFIX;

public class GitSpanCE {

public static final String FS_CLONE_REPO = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "fs_clone_repo";
public static final String FS_STATUS = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "fs_status";
public static final String FS_PULL = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "fs_pull";
public static final String FS_BRANCH_TRACK = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "fs_branch_track";
public static final String ADD_FILE_LOCK = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "add_file_lock";
public static final String RELEASE_FILE_LOCK = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "release_file_lock";
public static final String FS_COMMIT = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "fs_commit";
public static final String FS_CHECKOUT_BRANCH = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "fs_checkout_branch";
public static final String FS_CREATE_BRANCH = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "fs_create_branch";
public static final String FS_DELETE_BRANCH = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "fs_delete_branch";
public static final String FS_CREATE_REPO = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "fs_create_repo";
public static final String FS_RESET = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "fs_reset";
public static final String FS_MERGE = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "fs_merge";
public static final String FS_REBASE = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "fs_rebase";
public static final String FS_PUSH = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "fs_push";
public static final String FS_FETCH_REMOTE = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "fs_fetch_remote";
public static final String OPS_STATUS = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "ops_status";
public static final String OPS_COMMIT = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "ops_commit";
public static final String OPS_PUSH = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "ops_push";
public static final String OPS_PULL = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "ops_pull";
public static final String OPS_CREATE_BRANCH = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "ops_create_branch";
public static final String OPS_CHECKOUT_BRANCH = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "ops_checkout_branch";
public static final String OPS_DELETE_BRANCH = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "ops_delete_branch";
public static final String OPS_FETCH_REMOTE = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "ops_fetch_remote";
public static final String OPS_DETACH_REMOTE = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "ops_detach_remote";
public static final String OPS_DISCARD_CHANGES = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX + "ops_discard_changes";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.appsmith.external.git;

import com.appsmith.external.git.constants.ce.GitSpanCE;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Field;

import static com.appsmith.external.constants.spans.BaseSpan.APPSMITH_SPAN_PREFIX;
import static com.appsmith.external.constants.spans.BaseSpan.GIT_SPAN_PREFIX;
import static org.assertj.core.api.Assertions.assertThat;

@Slf4j
public class GitSpansTest {

@Test
public void enforceCorrectNameUsage_InGitSpansCE() throws IllegalAccessException {
Class<?> gitSpansClass = GitSpanCE.class;
Field[] fields = gitSpansClass.getDeclaredFields();
for (Field field : fields) {
if (java.lang.reflect.Modifier.isStatic(field.getModifiers())) {
// Allow access to private fields
field.setAccessible(true);
String prefix = APPSMITH_SPAN_PREFIX + GIT_SPAN_PREFIX;
String propertyName = field.getName();
String propertyValue = (String) field.get(null);
assertThat(propertyValue).isEqualTo(prefix + propertyName.toLowerCase());
}
}
}
}
Loading
Loading