Skip to content

Commit

Permalink
Add counter stat to track the number of batch files processed when de…
Browse files Browse the repository at this point in the history
…lta pull is enabled
  • Loading branch information
maallen committed Aug 14, 2023
1 parent 2c4075f commit 436141f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import javax.persistence.Index;
import javax.persistence.PreUpdate;
import javax.persistence.Table;
import org.hibernate.annotations.Type;
import org.joda.time.DateTime;

/** Entity that stores the checksum of a translated file downloaded via a third party sync. */
Expand All @@ -19,17 +18,13 @@
columnList = "repository_id, locale_id, file_name",
unique = true),
})
public class ThirdPartyFileChecksum extends SettableAuditableEntity {
public class ThirdPartyFileChecksum extends AuditableEntity {

@Embedded private ThirdPartyFileChecksumCompositeId thirdPartyFileChecksumCompositeId;

@Column(name = "md5")
private String md5;

@Column(name = "last_modified_date")
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime lastModifiedDate;

public ThirdPartyFileChecksum() {}

public ThirdPartyFileChecksum(
Expand Down Expand Up @@ -71,12 +66,4 @@ public Repository getRepository() {
public String getFileName() {
return thirdPartyFileChecksumCompositeId.getFileName();
}

public DateTime getLastModifiedDate() {
return lastModifiedDate;
}

public void setLastModifiedDate(DateTime lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -536,12 +536,18 @@ public void pull(
String skipAssetsWithPathPattern,
List<String> optionList) {

SmartlingOptions options = SmartlingOptions.parseList(optionList);

meterRegistry
.timer("SmartlingSync.pull", Tags.of("repository", repository.getName()))
.timer(
"SmartlingSync.pull",
Tags.of(
"repository",
repository.getName(),
"deltaPull",
Boolean.toString(options.isDeltaPull())))
.record(
() -> {
SmartlingOptions options = SmartlingOptions.parseList(optionList);

if (options.isJsonSync()) {
thirdPartyTMSSmartlingWithJson.pull(
repository, projectId, localeMapping, options.isDeltaPull());
Expand Down Expand Up @@ -610,7 +616,12 @@ private void processPullBatch(
.timer(
"SmartlingSync.processPullBatch",
Tags.of(
"repository", repository.getName(), "locale", locale.getLocale().getBcp47Tag()))
"repository",
repository.getName(),
"locale",
locale.getLocale().getBcp47Tag(),
"deltaPull",
Boolean.toString(options.isDeltaPull())))
.record(
() -> {
String localeTag = locale.getLocale().getBcp47Tag();
Expand Down Expand Up @@ -662,7 +673,8 @@ && isFileEqualToPreviousRun(
repository,
locale.getLocale(),
fileName,
fileContent)) {
fileContent,
meterRegistry)) {
logger.info(
"Checksum match for "
+ fileName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ && isFileEqualToPreviousRun(
repository,
repositoryLocale.getLocale(),
file.getFileUri(),
localizedFileContent)) {
localizedFileContent,
meterRegistry)) {
logger.info(
"Checksum match for "
+ file.getFileUri()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import com.box.l10n.mojito.entity.Repository;
import com.box.l10n.mojito.entity.ThirdPartyFileChecksum;
import com.box.l10n.mojito.entity.ThirdPartyFileChecksumCompositeId;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tags;
import java.util.Optional;
import org.apache.commons.codec.digest.DigestUtils;
import org.joda.time.DateTime;

public class ThirdPartyTMSUtils {

Expand All @@ -14,7 +17,10 @@ public static boolean isFileEqualToPreviousRun(
Repository repository,
Locale locale,
String fileName,
String fileContent) {
String fileContent,
MeterRegistry meterRegistry) {

boolean isChecksumEqual = false;

String currentChecksum = DigestUtils.md5Hex(fileContent);
ThirdPartyFileChecksumCompositeId thirdPartyFileChecksumCompositeId =
Expand All @@ -25,16 +31,31 @@ public static boolean isFileEqualToPreviousRun(
thirdPartyFileChecksumCompositeId);
if (thirdPartyFileChecksumOpt.isPresent()
&& thirdPartyFileChecksumOpt.get().getMd5().equals(currentChecksum)) {
return true;
isChecksumEqual = true;
} else if (thirdPartyFileChecksumOpt.isPresent()) {
ThirdPartyFileChecksum thirdPartyFileChecksum = thirdPartyFileChecksumOpt.get();
thirdPartyFileChecksum.setMd5(currentChecksum);
thirdPartyFileChecksum.setLastModifiedDate(new DateTime());
thirdPartyFileChecksumRepository.save(thirdPartyFileChecksum);
} else {
thirdPartyFileChecksumRepository.save(
new ThirdPartyFileChecksum(thirdPartyFileChecksumCompositeId, currentChecksum));
}

return false;
meterRegistry
.counter(
"ThirdPartyTMSUtils.deltaPullFilesProcessed",
Tags.of(
"repository",
repository.getName(),
"locale",
locale.getBcp47Tag(),
"fileName",
fileName,
"shortCircuited",
Boolean.toString(isChecksumEqual)))
.increment();

return isChecksumEqual;
}
}

0 comments on commit 436141f

Please sign in to comment.