Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Premium feature is sufficient for complexity scoring (#74222)

Chris Truterb0feafc6bbdc
diff --git a/enterprise/backend/src/metabase_enterprise/data_complexity_score/settings.clj b/enterprise/backend/src/metabase_enterprise/data_complexity_score/settings.clj
index a784b0faf80..17d1b80f77a 100644
--- a/enterprise/backend/src/metabase_enterprise/data_complexity_score/settings.clj
+++ b/enterprise/backend/src/metabase_enterprise/data_complexity_score/settings.clj
@@ -1,18 +1,35 @@
(ns metabase-enterprise.data-complexity-score.settings
"Settings for the data-complexity-score module."
(:require
+ [metabase.premium-features.core :as premium-features]
[metabase.settings.core :refer [defsetting]]
[metabase.util.i18n :refer [deferred-tru]]))
-(defsetting data-complexity-scoring-enabled
- (deferred-tru "Run the scheduled Data Complexity Score job (one node per cluster, daily).")
+(defsetting ^:deprecated data-complexity-scoring-enabled
+ (deferred-tru
+ (str "Deprecated: the :data-complexity-score premium feature token is the authoritative gate "
+ "for the scheduled scoring job. Retained as a read-only fallback so existing overrides "
+ "keep working — values from the MB_DATA_COMPLEXITY_SCORING_ENABLED env var or previously "
+ "persisted DB rows are still honored, but the setting can no longer be changed at runtime."))
:encryption :no
- :visibility :admin
- :default false
+ :visibility :internal
+ :setter :none
+ :deprecated "0.61.0"
:type :boolean
:export? false
:doc false)
+(defn scoring-active?
+ "Whether the scheduled Data Complexity Score runner is permitted to execute on this instance.
+ The `:data-complexity-score` premium feature token is authoritative; the deprecated
+ [[data-complexity-scoring-enabled]] setting is honored as a backward-compatible fallback so
+ existing self-hosted overrides keep working until the setting is removed."
+ []
+ (boolean (or (premium-features/enable-data-complexity-score?)
+ ;; Intentional call to the deprecated env-var-only fallback (see docstring above).
+ #_{:clj-kondo/ignore [:deprecated-var]}
+ (data-complexity-scoring-enabled))))
+
(defsetting data-complexity-scoring-last-fingerprint
(deferred-tru "Internal bookkeeping: Fingerprint of last successful run, to prevent needless re-calculations.")
:encryption :no
diff --git a/enterprise/backend/src/metabase_enterprise/data_complexity_score/task/complexity_score.clj b/enterprise/backend/src/metabase_enterprise/data_complexity_score/task/complexity_score.clj
index 6c053062d6e..6130af978bd 100644
--- a/enterprise/backend/src/metabase_enterprise/data_complexity_score/task/complexity_score.clj
+++ b/enterprise/backend/src/metabase_enterprise/data_complexity_score/task/complexity_score.clj
@@ -50,8 +50,9 @@
(log/warn "Data Complexity Score: Snowplow publish failed; leaving fingerprint unchanged so the next boot or cron retries")))
(defn- run-scoring!
- "One scoring pass. Gated by [[settings/data-complexity-scoring-enabled]] so admins can silence
- scoring without unscheduling the job.
+ "One scoring pass. Gated by [[settings/scoring-active?]] — the `:data-complexity-score` premium
+ feature token is authoritative, with the deprecated `data-complexity-scoring-enabled` setting as
+ a backward-compatible fallback — so the job can be silenced without unscheduling.
`claim-fingerprint` is the fingerprint carried on the scoring claim that authorized this run.
Using it (rather than re-sampling [[current-fingerprint]] at commit time) means a config change
@@ -62,7 +63,7 @@
other outcome leaves it untouched so the next boot or cron retries and telemetry doesn't
silently stall behind a transient publish failure."
[claim-fingerprint]
- (if (settings/data-complexity-scoring-enabled)
+ (if (settings/scoring-active?)
(try
(let [result (complexity/complexity-scores
(assoc (synonym-source/complexity-scores-opts)
@@ -76,7 +77,7 @@
(catch Throwable t
(log/warn t "Data Complexity Score run failed")
nil))
- (log/debug "Data Complexity Score run skipped — data-complexity-scoring-enabled is off")))
+ (log/debug "Data Complexity Score run skipped — scoring-active? is false")))
;; Long enough that any realistic scoring run finishes well inside it, short enough that a crashed
;; claimant unblocks the next tick's retry without operator intervention.
@@ -135,7 +136,7 @@
:timeout-seconds 10}
(binding [config/*disable-setting-cache* true]
(let [current (current-fingerprint)]
- (when (and (settings/data-complexity-scoring-enabled)
+ (when (and (settings/scoring-active?)
(or (not require-fingerprint-change?)
(not= current (settings/data-complexity-scoring-last-fingerprint)))
(not (scoring-claim-active?
diff --git a/enterprise/backend/test/metabase_enterprise/data_complexity_score/complexity_test.clj b/enterprise/backend/test/metabase_enterprise/data_complexity_score/complexity_test.clj
index 3a0d5d66cd3..626fd5e024b 100644
--- a/enterprise/backend/test/metabase_enterprise/data_complexity_score/complexity_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/data_complexity_score/complexity_test.clj
@@ -1051,6 +1051,38 @@
(is (= "stale" (settings/data-complexity-scoring-last-fingerprint))
"fingerprint preserved — next boot / cron will retry the emission")))))))
+(deftest ^:sequential scoring-gate-matrix-test
+ (testing "scoring runs iff :data-complexity-score premium feature OR deprecated setting is on"
+ (mt/with-dynamic-fn-redefs [metabot-scope/internal-metabot-scope (constantly {})]
+ (doseq [[label premium-features setting-value should-run?]
+ [["both gates on → run" #{:data-complexity-score} true true]
+ ["feature on, setting off → run" #{:data-complexity-score} false true]
+ ["feature off, setting on → run" #{} true true]
+ ["both gates off → skip" #{} false false]]]
+ (testing label
+ (mt/with-premium-features premium-features
+ (mt/with-temporary-setting-values [data-complexity-scoring-enabled setting-value
+ data-complexity-scoring-last-fingerprint "stale"
+ data-complexity-scoring-claim ""]
+ (testing "run-scoring! direct path"
+ (let [scoring-ran? (atom false)]
+ (mt/with-dynamic-fn-redefs [complexity/complexity-scores
+ (fn [& _]
+ (reset! scoring-ran? true)
+ (stub-result true))]
+ (#'task.complexity-score/run-scoring! "gate-matrix-test-fp")
+ (is (= should-run? @scoring-ran?)
+ (format "run-scoring! should %sinvoke complexity-scores for [%s]"
+ (if should-run? "" "NOT ") label)))))
+ (testing "with-scoring-claim! cron/boot path"
+ (let [inner-ran? (atom false)]
+ (#'task.complexity-score/with-scoring-claim!
+ {}
+ (fn [_fp] (reset! inner-ran? true)))
+ (is (= should-run? @inner-ran?)
+ (format "with-scoring-claim! should %sacquire a claim for [%s]"
+ (if should-run? "" "NOT ") label)))))))))))
+
(deftest ^:sequential run-scoring-keeps-fingerprint-stale-when-persistence-fails-test
(testing "persistence is part of a successful run now — if the cache write fails we must retry"
(mt/with-dynamic-fn-redefs [metabot-scope/internal-metabot-scope (constantly {})]