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

core: add extractors for trace queries #1613

Merged
merged 1 commit into from
Feb 27, 2024
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 @@ -103,4 +103,32 @@ object ModelExtractors {
case _ => None
}
}

case object TraceFilterType {

def unapply(value: Any): Option[TraceQuery.SpanFilter] = value match {
case q: TraceQuery => Some(toFilter(q))
case q: Query => Some(toFilter(TraceQuery.Simple(q)))
case f: TraceQuery.SpanFilter => Some(f)
case _ => None
}

private def toFilter(q: TraceQuery): TraceQuery.SpanFilter = {
TraceQuery.SpanFilter(q, Query.True)
}
}

case object TraceTimeSeriesType {

def unapply(value: Any): Option[TraceQuery.SpanTimeSeries] = value match {
case q: TraceQuery => Some(toTimeSeries(q))
case q: Query => Some(toTimeSeries(TraceQuery.Simple(q)))
case t: TraceQuery.SpanTimeSeries => Some(t)
case _ => None
}

private def toTimeSeries(q: TraceQuery): TraceQuery.SpanTimeSeries = {
TraceQuery.SpanTimeSeries(q, StyleExpr(DataExpr.Sum(Query.True), Map.empty))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,87 @@ class ModelExtractorsSuite extends FunSuite {
completionTest("name,sps,:eq", 21)
completionTest("name,sps,:eq,app,foo,:eq", 42)
completionTest("name,sps,:eq,app,foo,:eq,:and,(,asg,)", 12)

test("TraceQueryType: implicit from Query") {
val value = Query.Equal("name", "sps")
value match {
case ModelExtractors.TraceQueryType(t) =>
assertEquals(t, TraceQuery.Simple(value))
case _ =>
fail(s"did not match value: $value")
}
}

test("TraceQueryType: explicit TraceQuery") {
val value = TraceQuery.Simple(Query.Equal("name", "sps"))
value match {
case ModelExtractors.TraceQueryType(t) =>
assertEquals(t, value)
case _ =>
fail(s"did not match value: $value")
}
}

test("TraceFilterType: implicit from Query") {
val value = Query.Equal("name", "sps")
value match {
case ModelExtractors.TraceFilterType(t) =>
assertEquals(t, TraceQuery.SpanFilter(TraceQuery.Simple(value), Query.True))
case _ =>
fail(s"did not match value: $value")
}
}

test("TraceFilterType: implicit from TraceQuery") {
val value = TraceQuery.Simple(Query.Equal("name", "sps"))
value match {
case ModelExtractors.TraceFilterType(t) =>
assertEquals(t, TraceQuery.SpanFilter(value, Query.True))
case _ =>
fail(s"did not match value: $value")
}
}

test("TraceFilterType: explicit TraceQuery.SpanFilter") {
val value = TraceQuery.SpanFilter(TraceQuery.Simple(Query.Equal("name", "sps")), Query.True)
value match {
case ModelExtractors.TraceFilterType(t) =>
assertEquals(t, value)
case _ =>
fail(s"did not match value: $value")
}
}

test("TraceTimeSeriesType: implicit from Query") {
val expr = StyleExpr(DataExpr.Sum(Query.True), Map.empty)
val value = Query.Equal("name", "sps")
value match {
case ModelExtractors.TraceTimeSeriesType(t) =>
assertEquals(t, TraceQuery.SpanTimeSeries(TraceQuery.Simple(value), expr))
case _ =>
fail(s"did not match value: $value")
}
}

test("TraceTimeSeriesType: implicit from TraceQuery") {
val expr = StyleExpr(DataExpr.Sum(Query.True), Map.empty)
val value = TraceQuery.Simple(Query.Equal("name", "sps"))
value match {
case ModelExtractors.TraceTimeSeriesType(t) =>
assertEquals(t, TraceQuery.SpanTimeSeries(value, expr))
case _ =>
fail(s"did not match value: $value")
}
}

test("TraceTimeSeriesType: explicit TraceQuery.SpanFilter") {
val expr = StyleExpr(DataExpr.Sum(Query.True), Map.empty)
val value = TraceQuery.SpanTimeSeries(TraceQuery.Simple(Query.Equal("name", "sps")), expr)
value match {
case ModelExtractors.TraceTimeSeriesType(t) =>
assertEquals(t, value)
case _ =>
fail(s"did not match value: $value")
}
}
}
Loading