From 1677c6d56777e79fd636a601e62a5d83b4c08036 Mon Sep 17 00:00:00 2001 From: brharrington Date: Fri, 9 Feb 2024 12:07:17 -0600 Subject: [PATCH] eval: support simple legends for streaming data (#1607) To make streaming data more consistent with the backends allow simple legends to be used. Defaults to true, but can be disabled if needed. --- atlas-eval/src/main/resources/reference.conf | 5 +++++ .../com/netflix/atlas/eval/graph/SimpleLegends.scala | 2 +- .../com/netflix/atlas/eval/stream/ExprInterpreter.scala | 8 +++++++- atlas-eval/src/test/resources/application.conf | 4 ++++ .../scala/com/netflix/atlas/eval/stream/TestContext.scala | 2 ++ 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/atlas-eval/src/main/resources/reference.conf b/atlas-eval/src/main/resources/reference.conf index e0bbf789f..9e51d0e18 100644 --- a/atlas-eval/src/main/resources/reference.conf +++ b/atlas-eval/src/main/resources/reference.conf @@ -32,6 +32,11 @@ atlas.eval { // Which version of the LWC server API to use lwcapi-version = 2 + + // If set to true, then it will try to generate a simple legend for the set of expressions + // on the graph. By default the legend will just summarize the expression which is often + // long and hard to read for users. + simple-legends-enabled = true } graph { diff --git a/atlas-eval/src/main/scala/com/netflix/atlas/eval/graph/SimpleLegends.scala b/atlas-eval/src/main/scala/com/netflix/atlas/eval/graph/SimpleLegends.scala index b99a78c9d..9ca1487dc 100644 --- a/atlas-eval/src/main/scala/com/netflix/atlas/eval/graph/SimpleLegends.scala +++ b/atlas-eval/src/main/scala/com/netflix/atlas/eval/graph/SimpleLegends.scala @@ -26,7 +26,7 @@ import com.typesafe.scalalogging.StrictLogging * Helper to analyze a set of expressions and try to automatically set a reasonable * human readable legend. */ -private[graph] object SimpleLegends extends StrictLogging { +object SimpleLegends extends StrictLogging { def generate(exprs: List[StyleExpr]): List[StyleExpr] = { try { diff --git a/atlas-eval/src/main/scala/com/netflix/atlas/eval/stream/ExprInterpreter.scala b/atlas-eval/src/main/scala/com/netflix/atlas/eval/stream/ExprInterpreter.scala index a5e2b85a9..46bac73e7 100644 --- a/atlas-eval/src/main/scala/com/netflix/atlas/eval/stream/ExprInterpreter.scala +++ b/atlas-eval/src/main/scala/com/netflix/atlas/eval/stream/ExprInterpreter.scala @@ -24,6 +24,7 @@ import com.netflix.atlas.core.model.ModelExtractors import com.netflix.atlas.core.model.StatefulExpr import com.netflix.atlas.core.model.StyleExpr import com.netflix.atlas.core.stacklang.Interpreter +import com.netflix.atlas.eval.graph.SimpleLegends import com.netflix.atlas.eval.stream.Evaluator.DataSource import com.netflix.atlas.eval.stream.Evaluator.DataSources import com.netflix.atlas.eval.util.HostRewriter @@ -35,11 +36,16 @@ private[stream] class ExprInterpreter(config: Config) { private val hostRewriter = new HostRewriter(config.getConfig("atlas.eval.host-rewrite")) + // Use simple legends for expressions + private val simpleLegendsEnabled: Boolean = + config.getBoolean("atlas.eval.stream.simple-legends-enabled") + def eval(expr: String): List[StyleExpr] = { - interpreter.execute(expr).stack.map { + val exprs = interpreter.execute(expr).stack.map { case ModelExtractors.PresentationType(t) => t case v => throw new MatchError(v) } + if (simpleLegendsEnabled) SimpleLegends.generate(exprs) else exprs } def eval(uri: Uri): List[StyleExpr] = { diff --git a/atlas-eval/src/test/resources/application.conf b/atlas-eval/src/test/resources/application.conf index c6fe5cf17..b1663aba0 100644 --- a/atlas-eval/src/test/resources/application.conf +++ b/atlas-eval/src/test/resources/application.conf @@ -24,5 +24,9 @@ atlas { graph { simple-legends-enabled = false } + + stream { + simple-legends-enabled = false + } } } \ No newline at end of file diff --git a/atlas-eval/src/test/scala/com/netflix/atlas/eval/stream/TestContext.scala b/atlas-eval/src/test/scala/com/netflix/atlas/eval/stream/TestContext.scala index 56ce95590..d821715d1 100644 --- a/atlas-eval/src/test/scala/com/netflix/atlas/eval/stream/TestContext.scala +++ b/atlas-eval/src/test/scala/com/netflix/atlas/eval/stream/TestContext.scala @@ -61,6 +61,8 @@ object TestContext { | expression-limit = 50000 | | ignored-tag-keys = [] + | + | simple-legends-enabled = false |} | |atlas.eval.host-rewrite {