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
Allow specifying athena hostname (#62438)
Riley Thompson65e2a389ca7b
diff --git a/modules/drivers/athena/resources/metabase-plugin.yaml b/modules/drivers/athena/resources/metabase-plugin.yamlindex bb537ec3ee3..45e19c0a06f 100644--- a/modules/drivers/athena/resources/metabase-plugin.yaml+++ b/modules/drivers/athena/resources/metabase-plugin.yaml@@ -36,9 +36,15 @@ driver:- name: secret_keydisplay-name: Secret keyhelper-text: Leave this empty to authorize using AWS Credentials Provider Chain (Instance Profiles or IAM Roles for Tasks)+ - name: hostname+ display-name: Full hostname+ placeholder: "Optional"+ helper-text: "This is useful when Metabase is deployed on a VPC or AWS Secret Cloud."+ required: false- name: dbnamedisplay-name: Specific databasehelper-text: Specify a single database to enable features like DB routing+ required: false- advanced-options-start- merge:- additional-optionsdiff --git a/modules/drivers/athena/src/metabase/driver/athena.clj b/modules/drivers/athena/src/metabase/driver/athena.cljindex 0c230bfa93d..dfdb67420da 100644--- a/modules/drivers/athena/src/metabase/driver/athena.clj+++ b/modules/drivers/athena/src/metabase/driver/athena.clj@@ -60,19 +60,19 @@;;; ---------------------------------------------- sql-jdbc.connection ------------------------------------------------(defn endpoint-for-region+(defn- endpoint-for-region"Returns the endpoint URL for a specific region"[region]- (cond- (str/starts-with? region "cn-") ".amazonaws.com.cn"- :else ".amazonaws.com"))+ (str "//athena." region ".amazonaws.com" (when (str/starts-with? region "cn-") ".cn") ":443"))(defmethod sql-jdbc.conn/connection-details->spec :athena- [_driver {:keys [region access_key secret_key s3_staging_dir workgroup catalog dbname], :as details}]+ [_driver {:keys [region access_key secret_key s3_staging_dir workgroup catalog dbname hostname], :as details}](-> (merge{:classname "com.amazon.athena.jdbc.AthenaDriver":subprotocol "athena"- :subname (str "//athena." region (endpoint-for-region region) ":443")+ :subname (if (str/blank? hostname)+ (endpoint-for-region region)+ (str "//" hostname ":443")):User access_key:Password secret_key:OutputLocation s3_staging_dir@@ -88,7 +88,7 @@(dissoc details;; Remove 2.x jdbc driver version options from details.;; They are mapped to appropriate 3.x keys on preceding lines- :db :dbname :catalog :region :access_key :secret_key :s3_staging_dir :workgroup))+ :db :dbname :catalog :region :access_key :secret_key :s3_staging_dir :workgroup :hostname))(sql-jdbc.common/handle-additional-options details, :seperator-style :semicolon)))(defmethod sql-jdbc.conn/data-source-name :athenadiff --git a/modules/drivers/athena/test/metabase/driver/athena_test.clj b/modules/drivers/athena/test/metabase/driver/athena_test.cljindex c0c79a8b82d..100eb485084 100644--- a/modules/drivers/athena/test/metabase/driver/athena_test.clj+++ b/modules/drivers/athena/test/metabase/driver/athena_test.clj@@ -62,11 +62,35 @@(deftest ^:parallel endpoint-test(testing "AWS Endpoint URL"(are [region endpoint] (= endpoint- (athena/endpoint-for-region region))- "us-east-1" ".amazonaws.com"- "us-west-2" ".amazonaws.com"- "cn-north-1" ".amazonaws.com.cn"- "cn-northwest-1" ".amazonaws.com.cn")))+ (#'athena/endpoint-for-region region))+ "us-east-1" "//athena.us-east-1.amazonaws.com:443"+ "us-west-2" "//athena.us-west-2.amazonaws.com:443"+ "cn-north-1" "//athena.cn-north-1.amazonaws.com.cn:443"+ "cn-northwest-1" "//athena.cn-northwest-1.amazonaws.com.cn:443")))++(deftest ^:parallel athena-subname-uses-hostname-test+ (mt/test-driver :athena+ (doseq [[test-desc details exp-subname]+ [["the subname uses the region when the hostname is missing"+ {:region "us-east-1"}+ "//athena.us-east-1.amazonaws.com:443"]+ ["the subname uses the region when the hostname is nil"+ {:region "us-east-1" :hostname nil}+ "//athena.us-east-1.amazonaws.com:443"]+ ["the subname uses the region when the hostname is empty"+ {:region "us-east-1" :hostname ""}+ "//athena.us-east-1.amazonaws.com:443"]+ ["the subname uses the hostname as is when it is provided"+ {:region "us-east-1" :hostname "athena.us-west-1.amazonaws.com"}+ "//athena.us-west-1.amazonaws.com:443"]+ ["the subname uses cn when the region is in china"+ {:region "cn-north-1"}+ "//athena.cn-north-1.amazonaws.com.cn:443"]]]+ (testing test-desc+ (is (= exp-subname+ (->> details+ (sql-jdbc.conn/connection-details->spec driver/*driver*)+ :subname)))))))(deftest ^:parallel data-source-name-test(are [details expected] (= expected