Skip to content

Commit

Permalink
consistent normalization of line styles
Browse files Browse the repository at this point in the history
Updates the normalization behavior so that expressions that
use the default line style or `:line` explicitly will be
the same after normalization. For other line styles use the
simple name rather than `:ls` as it is more familiar to users.
  • Loading branch information
brharrington committed Dec 13, 2023
1 parent 794b325 commit 0bf89fa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ case class StyleExpr(expr: TimeSeriesExpr, settings: Map[String, String]) extend
// updates to the object.
val vs = settings.toList.sortWith(_._1 > _._1).map {
case ("sed", v) => v
case ("ls", v) => s":$v"
case (k, v) => s"$v,:$k"
}
if (vs.isEmpty) expr.toString else s"$expr,${vs.mkString(",")}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,12 @@ object ExprApi {
val rewritten = normalizeStat(expr).rewrite {
case q: Query => sort(q)
}
// Remove explicit :const, it can be determined from implicit conversion
// and adds visual clutter
rewritten.toString.replace(",:const", "")
// Remove explicit :const and :line, it can be determined from implicit conversion
// and add visual clutter
rewritten
.toString
.replace(",:const", "")
.replace(",:line", "")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,27 @@ class ExprApiSuite extends MUnitRouteSuite {
val expected = "name,cpuUser,:eq,:sum,foo$(name)$(abc) bar$(def)baz,:legend"
assertEquals(normalize(expr), List(expected))
}

test("normalize :line") {
val expr = "app,foo,:eq,name,cpuUser,:eq,:and,:sum,(,stack,),:by"
assertEquals(normalize(expr), List(expr))
assertEquals(normalize(s"$expr,:line"), List(expr))
}

test("normalize :stack") {
val expr = "app,foo,:eq,name,cpuUser,:eq,:and,:sum,(,stack,),:by,:stack"
assertEquals(normalize(expr), List(expr))
}

test("normalize :area") {
val expr = "app,foo,:eq,name,cpuUser,:eq,:and,:sum,(,stack,),:by,:area"
assertEquals(normalize(expr), List(expr))
}

test("normalize :vspan") {
val expr = "app,foo,:eq,name,cpuUser,:eq,:and,:sum,(,stack,),:by,:vspan"
assertEquals(normalize(expr), List(expr))
}
}

object ExprApiSuite {
Expand Down

0 comments on commit 0bf89fa

Please sign in to comment.