Skip to content

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

BOT-2052: stop reading six Metabot settings from the environment (#81217)

Andrei Simionescu9c04238b1614
diff --git a/docs/configuring-metabase/config-template.md b/docs/configuring-metabase/config-template.md
index febdba6a3e8..39b88070751 100644
--- a/docs/configuring-metabase/config-template.md
+++ b/docs/configuring-metabase/config-template.md
@@ -381,6 +381,7 @@ config:
usage-metadata-retention-days: 90
usage-metadata-schedule: 0 0 2 * * ? *
use-native-pivot-tables: false
+ use-tenants: false
user-visibility: all
warehouse-allowed-networks: null
```
diff --git a/docs/configuring-metabase/environment-variables.md b/docs/configuring-metabase/environment-variables.md
index 2ad115432f9..54a0d50a2de 100644
--- a/docs/configuring-metabase/environment-variables.md
+++ b/docs/configuring-metabase/environment-variables.md
@@ -1786,17 +1786,6 @@ Popular MCP clients enabled for CORS, stored as CSV client keys (e.g. claude, vs
Whether the AI feature access admin page shows granular, per-tool group permissions instead of a single on/off toggle per group.
-### `MB_METABOT_CHAT_SYSTEM_PROMPT`
-
-> Only available on Metabase [Pro](https://www.metabase.com/product/pro) and [Enterprise](https://www.metabase.com/product/enterprise) plans.
-
-- Type: string
-- Default: ``
-- [Exported as](../installation-and-operation/serialization.md): `metabot-chat-system-prompt`.
-- [Configuration file name](./config-file.md): `metabot-chat-system-prompt`
-
-Custom instructions appended to Metabot's system prompt for the chat experience (the AI sidebar and embedded Metabot).
-
### `MB_METABOT_ENABLED`
- Type: boolean
@@ -1817,28 +1806,6 @@ Whether Metabot is enabled for regular usage.
The icon for Metabot. Set to `metabot` for the default icon, or a data URI for a custom uploaded image (up to 1MB).
-### `MB_METABOT_LIMIT_RESET_RATE`
-
-> Only available on Metabase [Pro](https://www.metabase.com/product/pro) and [Enterprise](https://www.metabase.com/product/enterprise) plans.
-
-- Type: keyword
-- Default: `monthly`
-- [Exported as](../installation-and-operation/serialization.md): `metabot-limit-reset-rate`.
-- [Configuration file name](./config-file.md): `metabot-limit-reset-rate`
-
-How often Metabot usage limits reset: `daily`, `weekly`, or `monthly`.
-
-### `MB_METABOT_LIMIT_UNIT`
-
-> Only available on Metabase [Pro](https://www.metabase.com/product/pro) and [Enterprise](https://www.metabase.com/product/enterprise) plans.
-
-- Type: keyword
-- Default: `tokens`
-- [Exported as](../installation-and-operation/serialization.md): `metabot-limit-unit`.
-- [Configuration file name](./config-file.md): `metabot-limit-unit`
-
-The unit used for Metabot usage limits: `tokens` or `messages`.
-
### `MB_METABOT_NAME`
> Only available on Metabase [Pro](https://www.metabase.com/product/pro) and [Enterprise](https://www.metabase.com/product/enterprise) plans.
@@ -1850,28 +1817,6 @@ The unit used for Metabot usage limits: `tokens` or `messages`.
The display name for Metabot, shown throughout the Metabase UI.
-### `MB_METABOT_NLQ_SYSTEM_PROMPT`
-
-> Only available on Metabase [Pro](https://www.metabase.com/product/pro) and [Enterprise](https://www.metabase.com/product/enterprise) plans.
-
-- Type: string
-- Default: ``
-- [Exported as](../installation-and-operation/serialization.md): `metabot-nlq-system-prompt`.
-- [Configuration file name](./config-file.md): `metabot-nlq-system-prompt`
-
-Custom instructions appended to Metabot's system prompt for the natural language query (AI exploration) experience.
-
-### `MB_METABOT_QUOTA_REACHED_MESSAGE`
-
-> Only available on Metabase [Pro](https://www.metabase.com/product/pro) and [Enterprise](https://www.metabase.com/product/enterprise) plans.
-
-- Type: string
-- Default: `You have reached your AI usage limit for the current period. Please contact your administrator.`
-- [Exported as](../installation-and-operation/serialization.md): `metabot-quota-reached-message`.
-- [Configuration file name](./config-file.md): `metabot-quota-reached-message`
-
-The message shown to users when they reach their usage quota.
-
### `MB_METABOT_RECENT_VIEWS_ENABLED`
- Type: boolean
@@ -1898,17 +1843,6 @@ Whether to show Metabot illustrations in the UI.
Signing secret for verifying requests from the Metabot Slack app.
-### `MB_METABOT_SQL_SYSTEM_PROMPT`
-
-> Only available on Metabase [Pro](https://www.metabase.com/product/pro) and [Enterprise](https://www.metabase.com/product/enterprise) plans.
-
-- Type: string
-- Default: ``
-- [Exported as](../installation-and-operation/serialization.md): `metabot-sql-system-prompt`.
-- [Configuration file name](./config-file.md): `metabot-sql-system-prompt`
-
-Custom instructions appended to Metabot's system prompt for the SQL generation experience.
-
### `MB_MFA_CHALLENGE_SIGNING_KEY`
- Type: string
diff --git a/e2e/test/scenarios/monitor/tools/tools.cy.spec.ts b/e2e/test/scenarios/monitor/tools/tools.cy.spec.ts
index 5637720c603..3f5da30c7b1 100644
--- a/e2e/test/scenarios/monitor/tools/tools.cy.spec.ts
+++ b/e2e/test/scenarios/monitor/tools/tools.cy.spec.ts
@@ -31,6 +31,42 @@ describe("issue 14636", () => {
).as(alias);
}
+ function stubFilteredResponse({
+ status,
+ task,
+ data,
+ alias,
+ }: {
+ status?: string;
+ task?: string;
+ data: ReturnType<typeof createMockTask>[];
+ alias: string;
+ }) {
+ cy.intercept(
+ {
+ method: "GET",
+ pathname: "/api/task",
+ query: {
+ limit: String(limit),
+ offset: "0",
+ sort_column: "started_at",
+ sort_direction: "desc",
+ ...(status ? { status } : {}),
+ ...(task ? { task } : {}),
+ },
+ },
+ {
+ statusCode: 200,
+ body: {
+ data,
+ limit,
+ offset: 0,
+ total: data.length,
+ },
+ },
+ ).as(alias);
+ }
+
/**
* @typedef {Object} Row
*
@@ -130,12 +166,38 @@ describe("issue 14636", () => {
it("filtering should work", () => {
const total = 57;
+ const task = "field values scanning";
+ const filteredTask = createMockTask({ task });
+
+ // Keep this test independent of background tasks created asynchronously by H.restore().
+ // Register the less-specific routes first because Cypress matches intercepts in reverse order.
+ stubFilteredResponse({
+ status: "success",
+ data: [filteredTask],
+ alias: "successfulTasks",
+ });
+ stubFilteredResponse({
+ task,
+ data: [filteredTask],
+ alias: "filteredTasks",
+ });
+ stubFilteredResponse({
+ status: "failed",
+ task,
+ data: [],
+ alias: "failedFilteredTasks",
+ });
+ stubFilteredResponse({
+ status: "success",
+ task,
+ data: [filteredTask],
+ alias: "successfulFilteredTasks",
+ });
+
cy.visit("/monitor/tasks/list?status=success&task=field+values+scanning");
+ cy.wait("@successfulFilteredTasks");
- cy.findByPlaceholderText("Filter by task").should(
- "have.value",
- "field values scanning",
- );
+ cy.findByPlaceholderText("Filter by task").should("have.value", task);
getFilterByStatus().should("have.value", "Success");
cy.findAllByTestId("task").should("have.length", 1);
cy.findByTestId("task")
@@ -145,6 +207,7 @@ describe("issue 14636", () => {
getFilterByStatus().click();
H.popover().findByText("Failed").click();
+ cy.wait("@failedFilteredTasks");
cy.location("search").should(
"eq",
"?status=failed&task=field+values+scanning",
@@ -153,6 +216,7 @@ describe("issue 14636", () => {
cy.findByTestId("monitor-main").should("contain.text", "No results");
getFilterByStatus().parent().findByLabelText("Clear").click();
+ cy.wait("@filteredTasks");
cy.location("search").should("eq", "?task=field+values+scanning");
getFilterByStatus().should("have.value", "");
cy.findAllByTestId("task").should("have.length", 1);
@@ -169,6 +233,7 @@ describe("issue 14636", () => {
cy.wait("@first");
cy.findByLabelText("pagination").findByText("1 - 50").should("be.visible");
cy.visit("/monitor/tasks/list?page=1");
+ cy.wait("@second");
cy.findByLabelText("pagination")
.findByText(`51 - ${total}`)
.should("be.visible");
@@ -176,10 +241,12 @@ describe("issue 14636", () => {
cy.log("should reset pagination when changing filters");
getFilterByStatus().click();
H.popover().findByText("Success").click();
+ cy.wait("@successfulTasks");
cy.location("search").should("eq", "?status=success");
cy.log("should remove invalid query params");
cy.visit("/monitor/tasks/list?status=foobar");
+ cy.wait("@first");
cy.location("search").should("eq", "");
getFilterByStatus().should("have.value", "");
});
diff --git a/enterprise/backend/src/metabase_enterprise/metabot/settings.clj b/enterprise/backend/src/metabase_enterprise/metabot/settings.clj
index c41e0d06273..e1de3d2e3cb 100644
--- a/enterprise/backend/src/metabase_enterprise/metabot/settings.clj
+++ b/enterprise/backend/src/metabase_enterprise/metabot/settings.clj
@@ -14,6 +14,7 @@
:encryption :no
:export? true
:feature :ai-controls
+ :can-read-from-env? false
:setter (fn [new-value]
(let [v (some-> new-value keyword)]
(when (and v (not (contains? valid-limit-units v)))
@@ -32,6 +33,7 @@
:encryption :no
:export? true
:feature :ai-controls
+ :can-read-from-env? false
:setter (fn [new-value]
(let [v (some-> new-value keyword)]
(when (and v (not (contains? valid-reset-rates v)))
@@ -47,7 +49,8 @@
:visibility :settings-manager
:encryption :no
:export? true
- :feature :ai-controls)
+ :feature :ai-controls
+ :can-read-from-env? false)
(defsetting metabot-advanced-permissions
(deferred-tru "Whether the AI feature access admin page shows granular, per-tool group permissions instead of a single on/off toggle per group.")
diff --git a/src/metabase/cmd/env_var_dox.clj b/src/metabase/cmd/env_var_dox.clj
index be538d723d4..fe437658eda 100644
--- a/src/metabase/cmd/env_var_dox.clj
+++ b/src/metabase/cmd/env_var_dox.clj
@@ -168,7 +168,6 @@
"Used to filter out environment variables with high foot-gun indices."
[env-var]
(or (false? (:doc env-var))
- (false? (:can-read-from-env? env-var))
;; Ideally, we'd move off of this list completely,
;; but not all environment variables are defsettings.
(contains? env-vars-not-to-mess-with (format-prefix env-var))))
@@ -198,9 +197,14 @@
(remove setter-none?)))
(defn format-env-var-docs
- "Preps relevant environment variable docs as a Markdown string."
+ "Preps relevant environment variable docs as a Markdown string. A setting that ignores its environment variable has
+ none to document, but it is still settable in a config file, so that filter belongs here rather than in
+ [[remove-env-vars-we-should-not-document]], which the config file template shares."
[settings]
- (map format-env-var-entry (remove-env-vars-we-should-not-document settings)))
+ (->> settings
+ remove-env-vars-we-should-not-document
+ (remove (comp false? :can-read-from-env?))
+ (map format-env-var-entry)))
(defn- format-intro
"Exists just so we can write the intro in Markdown."
diff --git a/src/metabase/metabot/settings.clj b/src/metabase/metabot/settings.clj
index ef6ddb5ad11..84bb5124031 100644
--- a/src/metabase/metabot/settings.clj
+++ b/src/metabase/metabot/settings.clj
@@ -60,7 +60,8 @@
:visibility :admin
:encryption :when-encryption-key-set
:export? true
- :feature :ai-controls)
+ :feature :ai-controls
+ :can-read-from-env? false)
(defsetting metabot-nlq-system-prompt
(deferred-tru "Custom instructions appended to Metabot''s system prompt for the natural language query (AI exploration) experience.")
@@ -69,7 +70,8 @@
:visibility :admin
:encryption :when-encryption-key-set
:export? true
- :feature :ai-controls)
+ :feature :ai-controls
+ :can-read-from-env? false)
(defsetting metabot-sql-system-prompt
(deferred-tru "Custom instructions appended to Metabot''s system prompt for the SQL generation experience.")
@@ -78,7 +80,8 @@
:visibility :admin
:encryption :when-encryption-key-set
:export? true
- :feature :ai-controls)
+ :feature :ai-controls
+ :can-read-from-env? false)
(defsetting embedded-metabot-enabled?
(deferred-tru "Whether Metabot is enabled for embedding.")
diff --git a/src/metabase/transforms/settings.clj b/src/metabase/transforms/settings.clj
index ac0f3e5b8c6..71e49b93d23 100644
--- a/src/metabase/transforms/settings.clj
+++ b/src/metabase/transforms/settings.clj
@@ -70,6 +70,7 @@
:visibility :authenticated
:export? false
:audit :getter
+ :setter :none
:can-read-from-env? false
:getter (fn []
;; if the setting is set (whether true or false), then setup is complete. otherwise, check the token feature for cloud
diff --git a/test/metabase/cmd/config_file_gen_test.clj b/test/metabase/cmd/config_file_gen_test.clj
index 4190af50e0f..ca48655d176 100644
--- a/test/metabase/cmd/config_file_gen_test.clj
+++ b/test/metabase/cmd/config_file_gen_test.clj
@@ -134,3 +134,36 @@
(testing "and settable settings are still included"
(is (contains? names "admin-email"))
(is (contains? names "aggregated-query-row-limit"))))))
+
+(def ^:private setting-without-env-var
+ "A setting with `:can-read-from-env? false`, like the Metabot system prompts. It has no environment
+ variable to document, but a config file can still set it."
+ {:database-local :never,
+ :cache? true,
+ :user-local :never,
+ :init nil,
+ :default "",
+ :name :metabot-chat-system-prompt,
+ :export? true,
+ :type :string,
+ :enabled? nil,
+ :encryption :no,
+ :deprecated nil,
+ :audit :no-value,
+ :sensitive? false,
+ :tag java.lang.String,
+ :on-change nil,
+ :can-read-from-env? false,
+ :doc nil,
+ :feature :ai-controls,
+ :namespace 'metabase.metabot.settings,
+ :munged-name "metabot-chat-system-prompt",
+ :visibility :admin})
+
+(deftest config-file-settings-includes-settings-without-env-vars-test
+ (testing "Settings that ignore their environment variable are still offered in the config file template"
+ (let [names (->> (conj (vec example-settings) setting-without-env-var)
+ config-file-settings
+ (map :munged-name)
+ set)]
+ (is (contains? names "metabot-chat-system-prompt")))))
diff --git a/test/metabase/cmd/env_var_dox_test.clj b/test/metabase/cmd/env_var_dox_test.clj
index 25c725c9e19..b4b1a53de9b 100644
--- a/test/metabase/cmd/env_var_dox_test.clj
+++ b/test/metabase/cmd/env_var_dox_test.clj
@@ -115,3 +115,15 @@
:visibility :public}]
(is (string? (#'sut/format-env-var-entry env-var-with-false-doc)))
(is (str/includes? (#'sut/format-env-var-entry env-var-with-false-doc) "MB_TEST_SETTING")))))
+
+(deftest ^:parallel env-var-docs-exclude-settings-that-ignore-env-vars-test
+ (let [setting {:name :metabot-chat-system-prompt
+ :munged-name "metabot-chat-system-prompt"
+ :type :string
+ :default ""
+ :description (constantly "Custom instructions appended to Metabot's system prompt.")
+ :visibility :admin}]
+ (testing "A setting that ignores its environment variable gets no entry in the env var docs"
+ (is (empty? (sut/format-env-var-docs [(assoc setting :can-read-from-env? false)]))))
+ (testing "and a setting that reads its environment variable gets one"
+ (is (= 1 (count (sut/format-env-var-docs [setting])))))))