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

misc(query): make match[] parameter optional for LabelNames queries #1687

Merged
merged 1 commit into from
Nov 3, 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 @@ -1337,6 +1337,29 @@ class MultiPartitionPlannerSpec extends AnyFunSpec with Matchers with PlanValida
.children(0).asInstanceOf[LabelNamesExec].endMs shouldEqual (endSeconds * 1000)
}

it("should materialize LabelNames with empty query correctly") {
val (startSeconds: Int, endSeconds: Int, engine: MultiPartitionPlanner) = getPlannerForMetadataQueryTests

val promQl = """"""
val lv = Parser.labelNamesQueryToLogicalPlan(promQl, TimeStepParams(startSeconds, step, endSeconds))

val promQlQueryParams = PromQlQueryParams(promQl, startSeconds, step, endSeconds, Some("/api/v2/labels/name"))
val execPlan = engine.materialize(lv, QueryContext(origQueryParams = promQlQueryParams, plannerParams =
PlannerParams(processMultiPartition = true)))

execPlan.isInstanceOf[LabelNamesDistConcatExec] shouldEqual true
execPlan.children.size shouldEqual 2

val expectedUrlParams = Map("match[]" -> "{}")
execPlan.children(1).asInstanceOf[MetadataRemoteExec].urlParams shouldEqual (expectedUrlParams)
execPlan.children(1).asInstanceOf[MetadataRemoteExec].queryContext.origQueryParams.asInstanceOf[PromQlQueryParams].
endSecs shouldEqual (localPartitionStart - 1)
execPlan.children(0).asInstanceOf[LabelNamesDistConcatExec]
.children(0).asInstanceOf[LabelNamesExec].startMs shouldEqual (localPartitionStart * 1000)
execPlan.children(0).asInstanceOf[LabelNamesDistConcatExec]
.children(0).asInstanceOf[LabelNamesExec].endMs shouldEqual (endSeconds * 1000)
}

it ("should generate correct plan for multipartition BinaryJoin with instant function") {
def partitions(timeRange: TimeRange): List[PartitionAssignment] = List(PartitionAssignment("remote", "remote-url",
TimeRange(timeRange.startMs, timeRange.endMs)))
Expand Down
14 changes: 9 additions & 5 deletions prometheus/src/main/scala/filodb/prometheus/parse/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.typesafe.scalalogging.StrictLogging
import filodb.core.GlobalConfig
import filodb.core.query.{ColumnFilter, Filter, QueryConfig, QueryUtils}
import filodb.prometheus.ast._
import filodb.query.{LabelValues, LogicalPlan}
import filodb.query.{LabelNames, LabelValues, LogicalPlan}

/**
* Parser routes requests to LegacyParser or AntlrParser.
Expand Down Expand Up @@ -169,10 +169,14 @@ object Parser extends StrictLogging {

def labelNamesQueryToLogicalPlan(query: String,
timeParams: TimeRangeParams): LogicalPlan = {
val expression = parseQuery(query)
expression match {
case p: InstantExpression => p.toLabelNamesPlan(timeParams)
case _ => throw new UnsupportedOperationException()
if (query == null || query.isEmpty) {
LabelNames(Seq.empty, timeParams.start * 1000, timeParams.end * 1000)
} else {
val expression = parseQuery(query)
expression match {
case p: InstantExpression => p.toLabelNamesPlan(timeParams)
case _ => throw new UnsupportedOperationException()
}
}
}

Expand Down
Loading