Skip to content

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

fix metabot token count query (#63556)

Oleksandr Solovyovb0299c474d26
diff --git a/enterprise/backend/src/metabase_enterprise/metabot_v3/core.clj b/enterprise/backend/src/metabase_enterprise/metabot_v3/core.clj
index 4afd8c16441..8d2373d8c12 100644
--- a/enterprise/backend/src/metabase_enterprise/metabot_v3/core.clj
+++ b/enterprise/backend/src/metabase_enterprise/metabot_v3/core.clj
@@ -6,6 +6,7 @@
[metabase-enterprise.metabot-v3.client]
[metabase-enterprise.metabot-v3.table-utils]
[metabase-enterprise.metabot-v3.util]
+ [metabase.premium-features.core :refer [defenterprise]]
[potemkin :as p]
[toucan2.core :as t2]))
@@ -22,12 +23,13 @@
used-tables
schema-sample])
-(defn metabot-stats
+(defenterprise metabot-stats
"Calculate total Metabot token usage over a window of the the previous UTC day 00:00-23:59"
+ :feature :metabot-v3
[]
(let [yesterday-utc (t/minus (t/offset-date-time (t/zone-offset "+00")) (t/days 1))]
{:metabot-tokens (t2/select-one-fn :sum
- [:model/MetabotMessage [:%sum.total :sum]]
+ [:model/MetabotMessage [:%sum.total_tokens :sum]]
{:where [:= [:cast :created_at :date] [:cast yesterday-utc :date]]})
:metabot-queries (t2/select-one-fn :cnt
[:model/MetabotMessage [:%count.id :cnt]]
diff --git a/src/metabase/premium_features/token_check.clj b/src/metabase/premium_features/token_check.clj
index 87461fe961b..1bbf18ac9f5 100644
--- a/src/metabase/premium_features/token_check.clj
+++ b/src/metabase/premium_features/token_check.clj
@@ -101,7 +101,9 @@
"Stats for Metabot"
metabase-enterprise.metabot-v3.core
[]
- {:metabot-tokens 0})
+ {:metabot-tokens 0
+ :metabot-queries 0
+ :metabot-users 0})
(defn- stats-for-token-request
[]