Skip to content

Commit

Permalink
optimize log (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkPotato777 committed Sep 15, 2023
1 parent d03626b commit 2df68eb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttp
ODCRestContext odcRestContext = OdcRestTemplate.get();
Verify.notNull(odcRestContext, "odcRestContext");
odcRestContext.setRealUrl(request.getURI().toString());
log.info("start call rest {} , method:{} , URL:{}", odcRestContext.getApiName(), request.getMethod(),
log.debug("start call rest {} , method:{} , URL:{}", odcRestContext.getApiName(), request.getMethod(),
request.getURI());
return execution.execute(request, body);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,18 @@ protected <T> T doExecute(URI url, @Nullable HttpMethod method, @Nullable Reques
T res = super.doExecute(url, method, requestCallback, responseExtractor);
ODCRestContext context = API_CALL_LOG_PREFIX.get();
if (context.getLogResponseEnabled()) {
log.info("success call rest {}, url={}, response={}, cost={}ms", context.getApiName(),
log.debug("success call rest {}, url={}, response={}, cost={}ms", context.getApiName(),
context.getRealUrl(), res,
context.getExecTime());
} else {
log.info("success call rest {}, url={}, cost={}ms", context.getApiName(),
log.debug("success call rest {}, url={}, cost={}ms", context.getApiName(),
context.getRealUrl(),
context.getExecTime());
}
return res;
} catch (Exception e) {
ODCRestContext context = API_CALL_LOG_PREFIX.get();
log.error("failed call rest {}, URL:{}, cost={} ms ", context.getApiName(), context.getRealUrl(),
log.debug("failed call rest {}, URL:{}, cost={} ms ", context.getApiName(), context.getRealUrl(),
context.getExecTime(), e);
throw new UnexpectedException("Internal service call failed, please contact support team");
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public void syncDatabases() {
try {
SecurityContextUtils.setCurrentUser(connection.getCreatorId(), connection.getOrganizationId(), null);
databaseSyncManager.syncDataSource(connection.getId());
log.info("sync datasource successfully, connectionId={}", connection.getId());
log.debug("sync datasource successfully, connectionId={}", connection.getId());
} catch (Exception ex) {
log.warn("sync datasource failed, datasourceId={}", connection.getId(), ex);
log.debug("sync datasource failed, datasourceId={}", connection.getId(), ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -60,6 +61,8 @@
import com.oceanbase.odc.core.shared.exception.BadRequestException;
import com.oceanbase.odc.core.shared.exception.ConflictException;
import com.oceanbase.odc.core.shared.exception.NotFoundException;
import com.oceanbase.odc.metadb.connection.ConnectionConfigRepository;
import com.oceanbase.odc.metadb.connection.ConnectionEntity;
import com.oceanbase.odc.metadb.connection.DatabaseEntity;
import com.oceanbase.odc.metadb.connection.DatabaseRepository;
import com.oceanbase.odc.metadb.connection.DatabaseSpecs;
Expand Down Expand Up @@ -133,6 +136,9 @@ public class DatabaseService {
@Autowired
private HorizontalDataPermissionValidator horizontalDataPermissionValidator;

@Autowired
private ConnectionConfigRepository connectionConfigRepository;

@Transactional(rollbackFor = Exception.class)
@SkipAuthorize("internal authenticated")
public Database detail(@NonNull Long id) {
Expand Down Expand Up @@ -367,14 +373,17 @@ public Boolean internalSyncDataSourceSchemas(@NonNull Long dataSourceId) throws
}
ConnectionSession connectionSession = null;
try {
if (!connectionService.existsById(dataSourceId)) {
Optional<ConnectionEntity> connectionOpt = connectionConfigRepository.findById(dataSourceId);
if (!connectionOpt.isPresent()) {
return false;
}
ConnectionConfig connection = connectionService.getForConnectionSkipPermissionCheck(dataSourceId);
if (connection.getEnvironmentId().longValue() == -1L
|| connection.getVisibleScope() == ConnectionVisibleScope.PRIVATE) {
ConnectionEntity saved = connectionOpt.get();
if (saved.getEnvironmentId().longValue() == -1L
|| saved.getVisibleScope() == ConnectionVisibleScope.PRIVATE) {
return false;
}

ConnectionConfig connection = connectionService.getForConnectionSkipPermissionCheck(dataSourceId);
horizontalDataPermissionValidator.checkCurrentOrganization(connection);
DefaultConnectSessionFactory factory = new DefaultConnectSessionFactory(connection);
connectionSession = factory.generateSession();
Expand Down

0 comments on commit 2df68eb

Please sign in to comment.