Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed error with single timestamp filter query on prometheus datasource #1244

Merged
merged 1 commit into from
Jan 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public static String build(String metricName, Expression filterCondition) {
SeriesSelectionExpressionNodeVisitor seriesSelectionExpressionNodeVisitor
= new SeriesSelectionExpressionNodeVisitor();
String selectorQuery = filterCondition.accept(seriesSelectionExpressionNodeVisitor, null);
return metricName + "{" + selectorQuery + "}";
if (selectorQuery != null) {
return metricName + "{" + selectorQuery + "}";
}
}
return metricName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ void testTimeRangeResolverWithOutEndTimeInFilter() {
new PrometheusMetricTable(client, "prometheus_http_total_requests");


//Both endTime and startTime are set.
//Only endTime is set.
List<NamedExpression> finalProjectList = new ArrayList<>();
finalProjectList.add(DSL.named(VALUE, DSL.ref(VALUE, STRING)));
finalProjectList.add(DSL.named(TIMESTAMP, DSL.ref(TIMESTAMP, ExprCoreType.TIMESTAMP)));
Expand Down Expand Up @@ -724,6 +724,35 @@ void testImplementWithRelationAndFilter() {
assertEquals(List.of(VALUE, TIMESTAMP), outputFields);
}

@Test
void testImplementWithRelationAndTimestampFilter() {
List<NamedExpression> finalProjectList = new ArrayList<>();
finalProjectList.add(DSL.named(VALUE, DSL.ref(VALUE, STRING)));
finalProjectList.add(DSL.named(TIMESTAMP, DSL.ref(TIMESTAMP, ExprCoreType.TIMESTAMP)));
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Long endTime = new Date(System.currentTimeMillis()).getTime();
PrometheusMetricTable prometheusMetricTable =
new PrometheusMetricTable(client, "prometheus_http_total_requests");
LogicalPlan logicalPlan = project(indexScan("prometheus_http_total_requests",
DSL.lte(DSL.ref("@timestamp", ExprCoreType.TIMESTAMP),
DSL.literal(
fromObjectValue(dateFormat.format(new Date(endTime)),
ExprCoreType.TIMESTAMP)))
), finalProjectList, null);
PhysicalPlan physicalPlan = prometheusMetricTable.implement(logicalPlan);
assertTrue(physicalPlan instanceof ProjectOperator);
assertTrue(((ProjectOperator) physicalPlan).getInput() instanceof PrometheusMetricScan);
PrometheusQueryRequest request
= ((PrometheusMetricScan) ((ProjectOperator) physicalPlan).getInput()).getRequest();
assertEquals((3600 / 250) + "s", request.getStep());
assertEquals("prometheus_http_total_requests",
request.getPromQl());
List<NamedExpression> projectList = ((ProjectOperator) physicalPlan).getProjectList();
List<String> outputFields
= projectList.stream().map(NamedExpression::getName).collect(Collectors.toList());
assertEquals(List.of(VALUE, TIMESTAMP), outputFields);
}

@Test
void testOptimize() {
PrometheusQueryRequest prometheusQueryRequest = new PrometheusQueryRequest();
Expand Down