From 4766b50a6b4a3f741d84ece0de58a9921ef9c4c4 Mon Sep 17 00:00:00 2001 From: Alex Theimer Date: Mon, 16 Oct 2023 13:49:04 -0700 Subject: [PATCH] make configurable --- core/src/main/resources/filodb-defaults.conf | 3 +++ .../src/main/scala/filodb/prometheus/ast/Vectors.scala | 6 +++++- .../main/scala/filodb/prometheus/parse/Parser.scala | 10 +++++++--- .../filodb/prometheus/query/PrometheusModel.scala | 8 +++++--- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/core/src/main/resources/filodb-defaults.conf b/core/src/main/resources/filodb-defaults.conf index 1d92e10964..d9f00f79f4 100644 --- a/core/src/main/resources/filodb-defaults.conf +++ b/core/src/main/resources/filodb-defaults.conf @@ -321,6 +321,9 @@ filodb { # If true, an exception is thrown if any ExecPlan::execute result size is greater than result-byte-limit. enforce-result-byte-limit = false + # If true, EqualsRegex filters with only the pipe special-character can have unbounded length. + relax-pipe-only-equals-regex-limit = true + # Minimum step required for a query min-step = 5 seconds diff --git a/prometheus/src/main/scala/filodb/prometheus/ast/Vectors.scala b/prometheus/src/main/scala/filodb/prometheus/ast/Vectors.scala index bd73e6d152..9124247e37 100644 --- a/prometheus/src/main/scala/filodb/prometheus/ast/Vectors.scala +++ b/prometheus/src/main/scala/filodb/prometheus/ast/Vectors.scala @@ -12,6 +12,8 @@ object Vectors { val PromMetricLabel = "__name__" val TypeLabel = "_type_" val BucketFilterLabel = "_bucket_" + val conf = GlobalConfig.systemConfig + val queryConfig = conf.getConfig("filodb.query") } object WindowConstants { @@ -268,7 +270,9 @@ sealed trait Vector extends Expression { ColumnFilter(labelMatch.label, query.Filter.NotEqualsRegex(labelValue)) case RegexMatch => // Relax the length limit only for matchers that contain at most the "|" special character. - if (!Utils.isPipeOnlyRegex(labelValue)) { + val shouldRelax = queryConfig.getBoolean("relax-pipe-only-equals-regex-limit") && + Utils.isPipeOnlyRegex(labelValue) + if (!shouldRelax) { require(labelValue.length <= Parser.REGEX_MAX_LEN, s"Regular expression filters should be <= ${Parser.REGEX_MAX_LEN} characters " + s"when non-`|` special characters are used.") diff --git a/prometheus/src/main/scala/filodb/prometheus/parse/Parser.scala b/prometheus/src/main/scala/filodb/prometheus/parse/Parser.scala index c93b059716..e638f33d2d 100644 --- a/prometheus/src/main/scala/filodb/prometheus/parse/Parser.scala +++ b/prometheus/src/main/scala/filodb/prometheus/parse/Parser.scala @@ -20,9 +20,11 @@ object Parser extends StrictLogging { case object Antlr extends Mode case object Shadow extends Mode + private val conf = GlobalConfig.systemConfig + private val queryConf = conf.getConfig("filodb.query") + val mode: Mode = { - val conf = GlobalConfig.systemConfig - val queryConfig = QueryConfig(conf.getConfig("filodb.query")) + val queryConfig = QueryConfig(queryConf) val parser = queryConfig.parser logger.info(s"Query parser mode: $parser") parser match { @@ -141,7 +143,9 @@ object Parser extends StrictLogging { ColumnFilter(l.label, Filter.NotEqualsRegex(l.value)) case RegexMatch => // Relax the length limit only for matchers that contain at most the "|" special character. - if (!Utils.isPipeOnlyRegex(l.value)) { + val shouldRelax = queryConf.getBoolean("relax-pipe-only-equals-regex-limit") && + Utils.isPipeOnlyRegex(l.value) + if (!shouldRelax) { require(l.value.length <= Parser.REGEX_MAX_LEN, s"Regular expression filters should be <= ${Parser.REGEX_MAX_LEN} characters " + s"when non-`|` special characters are used.") diff --git a/prometheus/src/main/scala/filodb/prometheus/query/PrometheusModel.scala b/prometheus/src/main/scala/filodb/prometheus/query/PrometheusModel.scala index 0435caf894..28b9eb54da 100644 --- a/prometheus/src/main/scala/filodb/prometheus/query/PrometheusModel.scala +++ b/prometheus/src/main/scala/filodb/prometheus/query/PrometheusModel.scala @@ -15,8 +15,8 @@ import filodb.query.exec.{ExecPlan, HistToPromSeriesMapper} object PrometheusModel { import com.softwaremill.quicklens._ - val conf = GlobalConfig.defaultsFromUrl - val queryConfig = conf.getConfig("filodb.query") + private val conf = GlobalConfig.systemConfig + private val queryConfig = conf.getConfig("filodb.query") /** * If the result contains Histograms, automatically convert them to Prometheus vector-per-bucket output @@ -44,7 +44,9 @@ object PrometheusModel { case MatchType.NOT_EQUAL => Filter.NotEquals(m.getValue) case MatchType.REGEX_MATCH => // Relax the length limit only for matchers that contain at most the "|" special character. - if (!Utils.isPipeOnlyRegex(m.getValue)) { + val shouldRelax = queryConfig.getBoolean("relax-pipe-only-equals-regex-limit") && + Utils.isPipeOnlyRegex(m.getValue) + if (!shouldRelax) { require(m.getValue.length <= REGEX_MAX_LEN, s"Regular expression filters should be <= ${REGEX_MAX_LEN} characters " + s"when non-`|` special characters are used.")