use of com.ctrip.framework.apollo.tracer.spi.Transaction in project apollo by ctripcorp.
the class ConfigServiceWithCache method initialize.
@PostConstruct
void initialize() {
configCache = CacheBuilder.newBuilder().expireAfterAccess(DEFAULT_EXPIRED_AFTER_ACCESS_IN_MINUTES, TimeUnit.MINUTES).build(new CacheLoader<String, ConfigCacheEntry>() {
@Override
public ConfigCacheEntry load(String key) throws Exception {
List<String> namespaceInfo = STRING_SPLITTER.splitToList(key);
if (namespaceInfo.size() != 3) {
Tracer.logError(new IllegalArgumentException(String.format("Invalid cache load key %s", key)));
return nullConfigCacheEntry;
}
Transaction transaction = Tracer.newTransaction(TRACER_EVENT_CACHE_LOAD, key);
try {
ReleaseMessage latestReleaseMessage = releaseMessageService.findLatestReleaseMessageForMessages(Lists.newArrayList(key));
Release latestRelease = releaseService.findLatestActiveRelease(namespaceInfo.get(0), namespaceInfo.get(1), namespaceInfo.get(2));
transaction.setStatus(Transaction.SUCCESS);
long notificationId = latestReleaseMessage == null ? ConfigConsts.NOTIFICATION_ID_PLACEHOLDER : latestReleaseMessage.getId();
if (notificationId == ConfigConsts.NOTIFICATION_ID_PLACEHOLDER && latestRelease == null) {
return nullConfigCacheEntry;
}
return new ConfigCacheEntry(notificationId, latestRelease);
} catch (Throwable ex) {
transaction.setStatus(ex);
throw ex;
} finally {
transaction.complete();
}
}
});
configIdCache = CacheBuilder.newBuilder().expireAfterAccess(DEFAULT_EXPIRED_AFTER_ACCESS_IN_MINUTES, TimeUnit.MINUTES).build(new CacheLoader<Long, Optional<Release>>() {
@Override
public Optional<Release> load(Long key) throws Exception {
Transaction transaction = Tracer.newTransaction(TRACER_EVENT_CACHE_LOAD_ID, String.valueOf(key));
try {
Release release = releaseService.findActiveOne(key);
transaction.setStatus(Transaction.SUCCESS);
return Optional.ofNullable(release);
} catch (Throwable ex) {
transaction.setStatus(ex);
throw ex;
} finally {
transaction.complete();
}
}
});
}
use of com.ctrip.framework.apollo.tracer.spi.Transaction in project apollo by ctripcorp.
the class AccessKeyServiceWithCache method scanNewAndUpdatedAccessKeys.
private void scanNewAndUpdatedAccessKeys() {
Transaction transaction = Tracer.newTransaction("Apollo.AccessKeyServiceWithCache", "scanNewAndUpdatedAccessKeys");
try {
loadNewAndUpdatedAccessKeys();
transaction.setStatus(Transaction.SUCCESS);
} catch (Throwable ex) {
transaction.setStatus(ex);
logger.error("Load new/updated app access keys failed", ex);
} finally {
transaction.complete();
}
}
use of com.ctrip.framework.apollo.tracer.spi.Transaction in project apollo by ctripcorp.
the class ReleaseMessageServiceWithCache method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
populateDataBaseInterval();
// block the startup process until load finished
// this should happen before ReleaseMessageScanner due to autowire
loadReleaseMessages(0);
executorService.submit(() -> {
while (doScan.get() && !Thread.currentThread().isInterrupted()) {
Transaction transaction = Tracer.newTransaction("Apollo.ReleaseMessageServiceWithCache", "scanNewReleaseMessages");
try {
loadReleaseMessages(maxIdScanned);
transaction.setStatus(Transaction.SUCCESS);
} catch (Throwable ex) {
transaction.setStatus(ex);
logger.error("Scan new release messages failed", ex);
} finally {
transaction.complete();
}
try {
scanIntervalTimeUnit.sleep(scanInterval);
} catch (InterruptedException e) {
// ignore
}
}
});
}
use of com.ctrip.framework.apollo.tracer.spi.Transaction in project apollo by ctripcorp.
the class RepositoryAspect method invokeWithCatTransaction.
@Around("anyRepositoryMethod()")
public Object invokeWithCatTransaction(ProceedingJoinPoint joinPoint) throws Throwable {
String name = joinPoint.getSignature().getDeclaringType().getSimpleName() + "." + joinPoint.getSignature().getName();
Transaction catTransaction = Tracer.newTransaction("SQL", name);
try {
Object result = joinPoint.proceed();
catTransaction.setStatus(Transaction.SUCCESS);
return result;
} catch (Throwable ex) {
catTransaction.setStatus(ex);
throw ex;
} finally {
catTransaction.complete();
}
}
use of com.ctrip.framework.apollo.tracer.spi.Transaction in project apollo by ctripcorp.
the class RetryableRestTemplate method exchangeGet.
private <T> ResponseEntity<T> exchangeGet(Env env, String path, ParameterizedTypeReference<T> reference, Object... uriVariables) {
if (path.startsWith("/")) {
path = path.substring(1);
}
String uri = uriTemplateHandler.expand(path, uriVariables).getPath();
Transaction ct = Tracer.newTransaction("AdminAPI", uri);
ct.addData("Env", env);
List<ServiceDTO> services = getAdminServices(env, ct);
HttpEntity<Void> entity = new HttpEntity<>(assembleExtraHeaders(env));
for (ServiceDTO serviceDTO : services) {
try {
ResponseEntity<T> result = restTemplate.exchange(parseHost(serviceDTO) + path, HttpMethod.GET, entity, reference, uriVariables);
ct.setStatus(Transaction.SUCCESS);
ct.complete();
return result;
} catch (Throwable t) {
logger.error("Http request failed, uri: {}, method: {}", uri, HttpMethod.GET, t);
Tracer.logError(t);
if (canRetry(t, HttpMethod.GET)) {
Tracer.logEvent(TracerEventType.API_RETRY, uri);
} else {
// biz exception rethrow
ct.setStatus(t);
ct.complete();
throw t;
}
}
}
// all admin server down
ServiceException e = new ServiceException(String.format("Admin servers are unresponsive. meta server address: %s, admin servers: %s", portalMetaDomainService.getDomain(env), services));
ct.setStatus(e);
ct.complete();
throw e;
}
Aggregations