The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Add transform metrics to anonymous stats ping (#67786)
Nicola Mometto75ab330328a2
diff --git a/enterprise/backend/src/metabase_enterprise/analytics/stats.clj b/enterprise/backend/src/metabase_enterprise/analytics/stats.cljindex 4d44023bbca..484d36b29fa 100644--- a/enterprise/backend/src/metabase_enterprise/analytics/stats.clj+++ b/enterprise/backend/src/metabase_enterprise/analytics/stats.clj@@ -1,5 +1,6 @@(ns metabase-enterprise.analytics.stats(:require+ [java-time.api :as t][metabase-enterprise.advanced-config.settings :as advanced-config.settings][metabase-enterprise.scim.core :as scim][metabase-enterprise.semantic-search.core :as semantic-search]@@ -32,3 +33,12 @@{:name :semantic-search:available (premium-features/enable-semantic-search?):enabled (semantic-search/supported?)}])++(defenterprise ee-transform-metrics+ "Returns transform usage metrics for the Snowplow stats ping."+ :feature :none+ []+ (let [one-day-ago (t/minus (t/offset-date-time) (t/days 1))]+ {:transforms (t2/count :model/Transform)+ :transform_runs_last_24h (t2/count :model/TransformRun+ :start_time [:>= one-day-ago])}))diff --git a/enterprise/backend/test/metabase_enterprise/analytics/stats_test.clj b/enterprise/backend/test/metabase_enterprise/analytics/stats_test.cljindex 7ddd77d8c5b..21881a6c765 100644--- a/enterprise/backend/test/metabase_enterprise/analytics/stats_test.clj+++ b/enterprise/backend/test/metabase_enterprise/analytics/stats_test.clj@@ -1,10 +1,12 @@(ns metabase-enterprise.analytics.stats-test(:require[clojure.test :refer :all]+ [java-time.api :as t][metabase-enterprise.analytics.stats :as ee-stats][metabase-enterprise.audit-app.audit :as ee-audit][metabase.analytics.stats :as stats][metabase.app-db.core :as mdb]+ [metabase.lib.core :as lib][metabase.test :as mt][toucan2.core :as t2]))@@ -36,3 +38,29 @@:public {}:embedded {}}(#'stats/dashboard-metrics)))))))++(deftest ee-transform-metrics-test+ (mt/with-temp-empty-app-db [_conn :h2]+ (mdb/setup-db! :create-sample-content? false)+ (testing "with no transforms"+ (is (=? {:transforms 0 :transform_runs_last_24h 0}+ (ee-stats/ee-transform-metrics))))+ (testing "with transforms"+ (mt/with-temp [:model/Transform transform {:target {:database (mt/id)+ :table "test_table"}+ :name "Test SQL transform"+ :source {:type "query"+ :query (lib/native-query (mt/metadata-provider) "SELECT 1")}}+ :model/TransformRun _ {:start_time (t/minus (t/offset-date-time) (t/hours 1))+ :transform_id (:id transform)}]+ (is (=? {:transforms 1 :transform_runs_last_24h 1}+ (ee-stats/ee-transform-metrics))))+ (testing "with old transform runs"+ (mt/with-temp [:model/Transform transform {:target {:database (mt/id)+ :table "test_table"}+ :name "Test SQL transform"+ :source {:type "query"+ :query (lib/native-query (mt/metadata-provider) "SELECT 1")}}+ :model/TransformRun _ {:start_time (t/minus (t/offset-date-time) (t/hours 25))+ :transform_id (:id transform)}]+ (is (zero? (:transform_runs_last_24h (ee-stats/ee-transform-metrics)))))))))diff --git a/src/metabase/analytics/stats.clj b/src/metabase/analytics/stats.cljindex dfaf055f869..ac7dbdf7b7d 100644--- a/src/metabase/analytics/stats.clj+++ b/src/metabase/analytics/stats.clj@@ -647,25 +647,39 @@:values (mapv (fn [[k v]] {:group k :value v}) eid-translations-24h):tags ["embedding"]}]))+(defn- ee-transform-metrics'+ "OSS fallback for transform metrics. Returns zeros since transforms are an enterprise feature."+ []+ {:transforms 0+ :transform_runs_last_24h 0})++(defenterprise ee-transform-metrics+ "Returns transform usage metrics for the Snowplow stats ping."+ metabase-enterprise.analytics.stats+ []+ (ee-transform-metrics'))+(defn- ->snowplow-metric-info"Collects Snowplow metrics data that is not in the legacy stats format. Also clears entity id translation count."[](let [one-day-ago (->one-day-ago)total-translation-count (:total (get-translation-count))]- {:models (t2/count :model/Card :type :model :archived false)- :new_embedded_dashboards (t2/count :model/Dashboard- :enable_embedding true- :archived false- :created_at [:>= one-day-ago])- :new_users_last_24h (t2/count :model/User- :is_active true- :date_joined [:>= one-day-ago])- :pivot_tables (t2/count :model/Card :display :pivot :archived false)- :query_executions_last_24h (t2/count :model/QueryExecution :started_at [:>= one-day-ago])- :entity_id_translations_last_24h total-translation-count- :scim_users_last_24h (t2/count :model/User :sso_source :scim- :is_active true- :date_joined [:>= one-day-ago])}))+ (merge+ {:models (t2/count :model/Card :type :model :archived false)+ :new_embedded_dashboards (t2/count :model/Dashboard+ :enable_embedding true+ :archived false+ :created_at [:>= one-day-ago])+ :new_users_last_24h (t2/count :model/User+ :is_active true+ :date_joined [:>= one-day-ago])+ :pivot_tables (t2/count :model/Card :display :pivot :archived false)+ :query_executions_last_24h (t2/count :model/QueryExecution :started_at [:>= one-day-ago])+ :entity_id_translations_last_24h total-translation-count+ :scim_users_last_24h (t2/count :model/User :sso_source :scim+ :is_active true+ :date_joined [:>= one-day-ago])}+ (ee-transform-metrics))))(mu/defn- snowplow-metrics[stats metric-info :- [:map@@ -674,7 +688,9 @@[:new_users_last_24h :int][:pivot_tables :int][:query_executions_last_24h :int]- [:entity_id_translations_last_24h :int]]]+ [:entity_id_translations_last_24h :int]+ [:transforms :int]+ [:transform_runs_last_24h :int]]](mapv(fn [[k v tags]](assert (every? string? tags) "Tags must be strings in snowplow metrics.")@@ -713,6 +729,8 @@[:questions_with_params (get-in stats [:stats :question :questions :with_params] 0) #{"questions"}][:segments (get-in stats [:stats :segment :segments] 0) #{"segments"}][:tables (get-in stats [:stats :table :tables] 0) #{"tables"}]+ [:transform_runs_last_24h (:transform_runs_last_24h metric-info 0) #{"transforms"}]+ [:transforms (:transforms metric-info 0) #{"transforms"}][:users (get-in stats [:stats :user :users :total] 0) #{"users"}]]))(defn- whitelabeling-in-use?diff --git a/test/metabase/analytics/stats_test.clj b/test/metabase/analytics/stats_test.cljindex 46e48cc86de..68f112b6ccd 100644--- a/test/metabase/analytics/stats_test.clj+++ b/test/metabase/analytics/stats_test.clj@@ -639,3 +639,9 @@(is (=? {:documents {:total 2:archived 1}}(#'stats/document-metrics)))))))++(deftest transform-metrics-test+ (testing "ee-transform-metrics should return zeros for OSS"+ (mt/with-empty-h2-app-db!+ (is (= {:transforms 0, :transform_runs_last_24h 0}+ (stats/ee-transform-metrics))))))