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

* Escape '/' on InfluxDB

* fix checkstyle
This commit is contained in:
Daming 2020-03-30 14:49:55 +08:00 committed by GitHub
parent 4474907fef
commit f56d98dc94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -46,6 +46,8 @@ import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.select;
*/
public class InfluxMetadataQueryDAO extends H2MetadataQueryDAO {
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,
final int metadataQueryMaxSize) {
@ -75,17 +77,15 @@ public class InfluxMetadataQueryDAO extends H2MetadataQueryDAO {
public List<Endpoint> searchEndpoint(final String keyword,
final int serviceId,
final int limit) throws IOException {
final String endpointName = '\"' + EndpointTraffic.NAME + '\"';
WhereQueryImpl<SelectQueryImpl> endpointQuery = select()
.column(EndpointTraffic.SERVICE_ID)
.column(endpointName)
.column(ENDPOINT_NAME)
.column(EndpointTraffic.DETECT_POINT)
.from(client.getDatabase(), EndpointTraffic.INDEX_NAME)
.where();
endpointQuery.where(eq(MetricsDAO.TAG_ENDPOINT_OWNER_SERVICE, String.valueOf(serviceId)));
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);

View File

@ -98,7 +98,7 @@ public class TraceQuery implements ITraceQueryDAO {
recallQuery.and(lte(SegmentRecord.LATENCY, maxDuration));
}
if (!Strings.isNullOrEmpty(endpointName)) {
recallQuery.and(contains(SegmentRecord.ENDPOINT_NAME, endpointName));
recallQuery.and(contains(SegmentRecord.ENDPOINT_NAME, endpointName.replaceAll("/", "\\\\/")));
}
if (serviceId != 0) {
recallQuery.and(eq(RecordDAO.TAG_SERVICE_ID, String.valueOf(serviceId)));