Skip to content

Commit

Permalink
Merge pull request #19 from qzhello/main
Browse files Browse the repository at this point in the history
fix: metadata config loaded without checking ck data source
  • Loading branch information
qzhello authored Feb 4, 2024
2 parents 14678c2 + de2dba2 commit fed984b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,11 @@ public void refreshConfig() {
JSONObject hitObj = searchResultObj.getJSONObject("hits");
JSONArray hitsDataObjArray = hitObj.getJSONArray("hits");
if (hitsDataObjArray.isEmpty()) {
initConfig();
log.warn("no config in {}. set to default configuration. [\n{}\n]", getSettingsIndexName(), JSON.toJSONString(proxyConfig));
if (StringUtils.isNotBlank(kibanaPropertyOriginalString) || kibanaPropertyOriginalString == null) {
log.warn("no config in {}. set to default configuration. [\n{}\n]", getSettingsIndexName(), JSON.toJSONString(proxyConfig));
initConfig();
}
kibanaPropertyOriginalString = "";
return;
}
JSONObject data = (JSONObject) hitsDataObjArray.get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ public boolean supports(Object handler) {
@Override
public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
try {
String ipAddress = request.getHeader("X-Forwarded-For");
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("Proxy-Client-IP");
}
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("WL-Proxy-Client-IP");
}
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getRemoteAddr();
}
log.warn("[{}] uri: {}", request.getMethod(), request.getRequestURI());
((BaseHandler) handler).handle(request, response);
} catch (Exception e) {
log.error(e.getMessage(), e);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/ly/ckibana/model/request/ProxyConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ProxyConfig(KibanaItemProperty kibanaItemProperty) {

public String getCkDatabase() {
if (kibanaItemProperty.getCk() == null) {
throw new DataSourceEmptyException("clickhouse数据源为空,请检查配置proxy.ck");
return null;
}
return kibanaItemProperty.getCk().getDefaultCkDatabase();
}
Expand Down Expand Up @@ -133,6 +133,9 @@ public IndexPattern buildIndexPattern(String originIndex) {
public IndexPattern buildIndexPattern(String uiIndex, String index) {
IndexPattern indexPattern = new IndexPattern();
String database = getCkDatabase();
if (database == null) {
throw new DataSourceEmptyException("clickhouse数据源为空,请检查配置proxy.ck");
}
indexPattern.setUiIndex(uiIndex);
indexPattern.setIndex(index);
indexPattern.setDatabase(database);
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/ly/ckibana/service/CkService.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ public List<String> queryTables(ProxyConfig proxyConfig, List<String> tablePrefi
}

private List<String> queryTablesWithCondition(ProxyConfig proxyConfig, String tableCondition) throws Exception {
String sql = String.format("SELECT name FROM system.tables WHERE database = '%s' ", proxyConfig.getCkDatabase());
String ckDatabase = proxyConfig.getCkDatabase();
if (ckDatabase == null) {
throw new DataSourceEmptyException("clickhouse数据源为空,请检查配置proxy.ck");
}
String sql = String.format("SELECT name FROM system.tables WHERE database = '%s' ", ckDatabase);
if (StringUtils.isNotEmpty(tableCondition)) {
sql = String.format("%s AND %s ", sql, tableCondition);
}
Expand Down

0 comments on commit fed984b

Please sign in to comment.