未验证 提交 f56d98dc 编写于 作者: D Daming 提交者: GitHub

[BugFix]Escape '/' on InfluxDB query (#4589)

* Escape '/' on InfluxDB

* fix checkstyle
上级 4474907f
...@@ -46,6 +46,8 @@ import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.select; ...@@ -46,6 +46,8 @@ import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.select;
*/ */
public class InfluxMetadataQueryDAO extends H2MetadataQueryDAO { public class InfluxMetadataQueryDAO extends H2MetadataQueryDAO {
private InfluxClient client; private InfluxClient client;
// 'name' is InfluxDB keyword, so escapes it
private static final String ENDPOINT_NAME = '\"' + EndpointTraffic.NAME + '\"';
public InfluxMetadataQueryDAO(final InfluxClient client, final JDBCHikariCPClient h2Client, public InfluxMetadataQueryDAO(final InfluxClient client, final JDBCHikariCPClient h2Client,
final int metadataQueryMaxSize) { final int metadataQueryMaxSize) {
...@@ -75,17 +77,15 @@ public class InfluxMetadataQueryDAO extends H2MetadataQueryDAO { ...@@ -75,17 +77,15 @@ public class InfluxMetadataQueryDAO extends H2MetadataQueryDAO {
public List<Endpoint> searchEndpoint(final String keyword, public List<Endpoint> searchEndpoint(final String keyword,
final int serviceId, final int serviceId,
final int limit) throws IOException { final int limit) throws IOException {
final String endpointName = '\"' + EndpointTraffic.NAME + '\"';
WhereQueryImpl<SelectQueryImpl> endpointQuery = select() WhereQueryImpl<SelectQueryImpl> endpointQuery = select()
.column(EndpointTraffic.SERVICE_ID) .column(EndpointTraffic.SERVICE_ID)
.column(endpointName) .column(ENDPOINT_NAME)
.column(EndpointTraffic.DETECT_POINT) .column(EndpointTraffic.DETECT_POINT)
.from(client.getDatabase(), EndpointTraffic.INDEX_NAME) .from(client.getDatabase(), EndpointTraffic.INDEX_NAME)
.where(); .where();
endpointQuery.where(eq(MetricsDAO.TAG_ENDPOINT_OWNER_SERVICE, String.valueOf(serviceId))); endpointQuery.where(eq(MetricsDAO.TAG_ENDPOINT_OWNER_SERVICE, String.valueOf(serviceId)));
if (!Strings.isNullOrEmpty(keyword)) { if (!Strings.isNullOrEmpty(keyword)) {
endpointQuery.where(contains(MetricsDAO.TAG_ENDPOINT_NAME, keyword.replaceAll("/", "////"))); endpointQuery.where(contains(MetricsDAO.TAG_ENDPOINT_NAME, keyword.replaceAll("/", "\\\\/")));
} }
endpointQuery.limit(limit); endpointQuery.limit(limit);
......
...@@ -98,7 +98,7 @@ public class TraceQuery implements ITraceQueryDAO { ...@@ -98,7 +98,7 @@ public class TraceQuery implements ITraceQueryDAO {
recallQuery.and(lte(SegmentRecord.LATENCY, maxDuration)); recallQuery.and(lte(SegmentRecord.LATENCY, maxDuration));
} }
if (!Strings.isNullOrEmpty(endpointName)) { if (!Strings.isNullOrEmpty(endpointName)) {
recallQuery.and(contains(SegmentRecord.ENDPOINT_NAME, endpointName)); recallQuery.and(contains(SegmentRecord.ENDPOINT_NAME, endpointName.replaceAll("/", "\\\\/")));
} }
if (serviceId != 0) { if (serviceId != 0) {
recallQuery.and(eq(RecordDAO.TAG_SERVICE_ID, String.valueOf(serviceId))); recallQuery.and(eq(RecordDAO.TAG_SERVICE_ID, String.valueOf(serviceId)));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册