<#3276 Add `connection` as first-class construct i...
# meltano-repo-activity
g
#3276 Add
connection
as first-class construct in
meltano.yml
Issue created by MeltyBot Migrated from GitLab: https://gitlab.com/meltano/meltano/-/issues/3353 Originally created by @kgpayne on 2022-03-28 164045 --- Problem to solve As a user of Meltano, I would like a place in
meltano.yml
to specify
Connection
config objects that can be referenced and reused in all of the plugins I add to my Meltano Project. Target audience Engineers/developers using Meltano with tools that themselves have native constructs for connections, such as dbt, Airflow, Great Expectations and Superset. Further details Connections are a ubiquitous construct across the tools of the data platform, and yet in Meltano these details must still be expressed individually for each plugin as plain config or environment variables. This is not only extra work for users of Meltano, it also adds unnecessary human action in the integration path between plugins accessing the same resources (databases, warehouses, SaaS endpoints etc.). For example, in the case of Snowflake: • Official Snowflake Python Connector parameters (used under the hood by many python-based tools) • Airflow Snowflake Connection • dbt Snowflake Profile • Superset Snowflake Datasource connection string • Great Expectations Datasource connection string From the above it is clear that configuration is commonly expressed in two forms, with tools supporting either or both formats (examples from Airflows connection docs): • yaml/json: snowflake_example_connection: conn_type: snowflake login: user password: password host: snowflake.example schema: db-schema extra: account: account database: snow-db region: us-east warehouse: snow-warehouse • URI
Copy code
snowflake://user:password@snowflake.example/db-schema?account=account&database=snow-db&region=us-east&warehouse=snow-warehouse
Whilst it is common for tools to support the specification of a 'default' connection, the richness of User/Role/Group functionalities in databases and warehouses for controlling access and for cost management (e.g. monitoring Snowflake credit consumption based on per-tool or per-pipeline User/Role definitions) mean that most tools will define or consume several connections based on the execution context. This means a single Project will typically have many more connection definitions than base warehouse and database resources. Interestingly we already handle connections via a
ConnectionService
in
meltano.core
(for use in the older Model functionality), however (as noted in the comments) this has too detailed an understanding of the expected format of each connection type. Proposal Expected outcomes: • Allow users to specify and manage connection information via the CLI (including a default connection per type), without the need to explicitly reference that information when adding new compatible plugins. • Allow users to specify a named connection on a per-plugin and per-run basis, or override individual settings from the default connection. To achieve these two outcomes, we could: 1. Support connection definitions in
discovery.yml
. # discovery.yaml connections: - name: snowflake variant: meltano # for cases where there really is a wide variety in ways to configure a particular system, multiple variants could possibly be used? dialect: snowflake # as already exists for loaders https://gitlab.com/meltano/meltano/-/blob/master/schema/meltano.schema.json#L421 settings: # supporting all the values listed in the Snowflake docs, # with descriptions and kinds (omitted for brevity) # https://docs.snowflake.com/en/user-guide/python-connector-api.html#connect - name: user - name: password - name: host - name: port - name: database - name: account - name: warehouse ... - name: postgres variant: meltano dialect: postgres settings: # supporting all the values listed in the Postgres/sqlalchemy docs, # with descriptions and kinds (omitted for brevity) - name: user - name: password - name: host - name: port - name: database 1. Support configuration of connections, including a
default
per connection dialect. The default could be implied I guess, in cases with only one connection? # meltano.yml version: 1 plugins: connections: - name: postgres default: true config: user: meltano password: ${POSTGRES_MELTANO_PASSWORD} host: db.example.com port: 5432 database: meltano - name: snowflake default: true config: user: "MELTANO" password: ${SNOWFLAKE_MELTANO_PASSWORD} host: snowflake.example account: account_name database: snow-db ... - name: snowflake-dbt inherits_from: snowflake config: user: "DBT" password: ${SNOWFLAKE_DBT_PASSWORD} # custom settings still supported as normal wacky_auth_setting: smoke_signals # becomes CONNECTION_SNOWFLAKE_WACKY_AUTH_SETTING extractors: - name: tap-postgres loaders: - name: target-snowflake transformers: - name: dbt-snowflake 1. Support the injection of connection details, without requiring the user to specify them explicitly via refs, using either
env_aliases
,
aliases
or the default
value
field in
discovery.yml
with env var of the form
CONNECTION_<dialect>_<setting name>
. E.g.: # discovery.yml extractors: - name: tap-postgres label: PostgreSQL description: PostgreSQL database extractor namespace: tap_postgres variants: - name: transferwise docs: https://hub.meltano.com/extractors/postgres.html repo: https://github.com/transferwise/pipelinewise-tap-postgres pip_url: pipelinewise-tap-postgres capabilities: - catalog - discover - state settings_group_validation: - ['host', 'port', 'user', 'password', 'dbname'] settings: - name: host value: localhost description: PostgreSQL host env_aliases: [CONNECTION_POSTGRES_HOST] - name: port kind: integer value: 5432 description: PostgreSQL port env_aliases: [CONNECTION_POSTGRES_PORT] - name: user description: PostgreSQL user env_aliases: [CONNECTION_POSTGRES_USER] - name: password kind: password description: PostgreSQL password env_aliases: [CONNECTION_POSTGRES_PASSWORD] - name: dbname description: PostgreSQL database name env_aliases: [CONNECTION_POSTGRES_DATABASE] ... loaders: - name: target-snowflake label: Snowflake description: Snowflake database loader namespace: target_snowflake dialect: snowflake # I did not know this already existed 😅 target_schema: $TARGET_SNOWFLAKE_SCHEMA variants: - name: transferwise docs: https://hub.meltano.com/loaders/snowflake.html repo: https://github.com/transferwise/pipelinewise-target-snowflake … meltano/meltano