Skip to content

Commit

Permalink
misc(query): make match[] parameter optional for LabelNames queries (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sherali42 authored Nov 3, 2023
1 parent 6e8d9b9 commit b927aac
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
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

0 comments on commit b927aac

Please sign in to comment.