Extending the Plugin
Relevant source files
The following files were used as context for generating this wiki page:
Extending the superset-ext utility involves leveraging the Meltano Extension Developer Kit (EDK) to wrap the Apache Superset CLI. This extension provides a bridge between Meltano's lifecycle management and Superset's internal administration commands, allowing for automated configuration, initialization, and user management.
The architecture is built upon the ExtensionBase class, which handles the orchestration of subprocesses and environment configuration. By defining specific commands in a Typer-based CLI, developers can expose Superset's functionality directly to the Meltano ecosystem.
Sources: superset_ext/extension.py:27-31, superset_ext/main.py:15-20, README.md:1-5
Core Architecture and Extension Mechanism
The extension operates as a wrapper around the superset binary. It uses a dual-entry point system: one for high-level extension management and another for direct command passthrough.
Components Relationship
The following diagram illustrates how the Meltano EDK classes are utilized to implement the Superset extension.
Initialization Logic
When initialize is called, the extension performs a sequence of setup tasks to ensure the Superset environment is ready.
- Config Generation: Generates
superset_config.pyfrom environment variables. - Database Migration: Runs
superset db upgrade. - App Initialization: Runs
superset init. - Permission Setup: Executes
superset fab create-permissions.
Sources: superset_ext/extension.py:53-96
Environment and Configuration Management
The extension uses a specific prefix (SUPERSET_) to filter environment variables and transform them into Superset-compatible configuration settings.
Configuration Utilities
The system relies on superset_ext/utils.py to handle the mapping of Meltano environment variables to the Superset configuration file.
| Function | Purpose |
|---|---|
trim_prefix | Removes a specific prefix from environment keys. |
load_config_from_env | Filters and optionally trims environment variables based on a prefix. |
prepared_env | Sets default paths for SUPERSET_HOME and SQLALCHEMY_DATABASE_URI. |
write_config | Dynamically generates a Python module that sets uppercase keys as attributes. |
Sources: superset_ext/utils.py:11-105
Config Mapping Logic
The prepared_env function ensures that standard Meltano paths are mapped to Superset's expected variables:
HOME(within prefix) ->SUPERSET_HOMECONFIG_PATH->SUPERSET_CONFIG_PATH- Default DB:
sqlite:///{MELTANO_PROJECT_ROOT}/.meltano/utilities/superset/superset.db
Sources: superset_ext/utils.py:65-90
Command Implementation
The extension exposes two primary executable scripts defined in the project configuration.
CLI Entry Points
| Script Name | Target Function | Description |
|---|---|---|
superset_extension | superset_ext.main:app | Main Typer CLI for initialization and admin tasks. |
superset_invoker | superset_ext.pass_through:pass_through_cli | Direct passthrough to the underlying Superset CLI. |
Sources: pyproject.toml:50-51, superset_ext/pass_through.py:12-19
Extension Commands
The main CLI (superset_ext/main.py) implements the following commands:
- initialize: Orchestrates the setup of the config file and database.
- create-admin: Wraps
fab create-adminwith interactive Typer prompts for credentials. - invoke: Allows execution of arbitrary Superset commands via the extension's environment.
- describe: Returns metadata about the extension in various formats (text/json).
Sources: superset_ext/main.py:26-95
Passthrough Mechanism
To allow users to interact with Superset directly while maintaining the extension's managed environment, a passthrough invoker is implemented.
Summary
Extending this plugin requires implementing logic within the Superset class in extension.py and exposing it via main.py. The architecture ensures that any command executed via the extension inherits the correct environment configuration, including the dynamically generated superset_config.py. This structure allows the extension to provide a seamless management layer over the complex initialization requirements of Apache Superset within a Meltano project.
Sources: superset_ext/extension.py:27-31, superset_ext/main.py:15-20