|
| 1 | +# Superset Asset Management |
| 2 | + |
| 3 | +This directory contains version-controlled Superset assets (dashboards, charts, datasets, databases) that can be synchronized between QA and Production environments. |
| 4 | + |
| 5 | +📖 **See [WORKFLOWS.md](./WORKFLOWS.md) for detailed workflow diagrams and comparisons** |
| 6 | + |
| 7 | +## Supported Workflows |
| 8 | + |
| 9 | +### 🔄 Primary Workflow: QA → Production (Recommended) |
| 10 | +Develop and test in QA, then promote to production: |
| 11 | + |
| 12 | +1. **Edit** dashboards in QA Superset UI |
| 13 | +2. **Export** from QA → version control |
| 14 | +3. **Review & Commit** changes |
| 15 | +4. **Promote** to production |
| 16 | + |
| 17 | +### 🔄 Alternative Workflow: Production → QA |
| 18 | +Mirror production assets to QA for testing: |
| 19 | + |
| 20 | +1. **Export** from production → version control |
| 21 | +2. **Review & Commit** changes |
| 22 | +3. **Deploy** to QA for testing |
| 23 | + |
| 24 | +## Directory Structure |
| 25 | + |
| 26 | +``` |
| 27 | +src/ol_superset/ |
| 28 | +├── README.md # This file |
| 29 | +├── sync_config.yml # Configuration for syncing to QA |
| 30 | +├── assets/ # All Superset assets (auto-generated) |
| 31 | +│ ├── dashboards/ # Dashboard YAML definitions |
| 32 | +│ ├── charts/ # Chart YAML definitions |
| 33 | +│ ├── datasets/ # Dataset YAML definitions |
| 34 | +│ └── databases/ # Database connection configs |
| 35 | +└── scripts/ # Automation scripts |
| 36 | + ├── export_all.sh # Export from production |
| 37 | + ├── export_from_qa.sh # Export from QA (for promotion) |
| 38 | + ├── promote_to_production.sh # Promote QA → Production |
| 39 | + ├── sync_to_qa.sh # Deploy Production → QA |
| 40 | + └── validate_assets.sh # Validate asset definitions |
| 41 | +``` |
| 42 | + |
| 43 | +## Prerequisites |
| 44 | + |
| 45 | +1. **Install sup CLI**: Already available at `/home/tmacey/.local/bin/sup` |
| 46 | +2. **Configure authentication**: `sup config` (already configured for production/QA) |
| 47 | +3. **Set active instance**: `sup instance use superset-production` |
| 48 | + |
| 49 | +## Common Workflows |
| 50 | + |
| 51 | +### Workflow 1: QA → Production (Primary/Recommended) |
| 52 | + |
| 53 | +**Use case**: Developing new dashboards or modifying existing ones |
| 54 | + |
| 55 | +```bash |
| 56 | +cd src/ol_superset |
| 57 | + |
| 58 | +# 1. Make changes in QA Superset UI |
| 59 | +# https://bi-qa.ol.mit.edu |
| 60 | + |
| 61 | +# 2. Export latest from QA |
| 62 | +./scripts/export_from_qa.sh |
| 63 | + |
| 64 | +# 3. Validate changes |
| 65 | +./scripts/validate_assets.sh |
| 66 | + |
| 67 | +# 4. Review what changed |
| 68 | +git diff assets/ |
| 69 | + |
| 70 | +# 5. Commit changes with descriptive message |
| 71 | +git add assets/ |
| 72 | +git commit -m "Add new enrollment dashboard with demographic filters" |
| 73 | +git push |
| 74 | + |
| 75 | +# 6. Promote to production (automated with sup dashboard push) |
| 76 | +./scripts/promote_to_production.sh |
| 77 | + |
| 78 | +# 7. Verify in production UI |
| 79 | +# https://bi.ol.mit.edu/dashboard/list/ |
| 80 | +``` |
| 81 | + |
| 82 | +### Workflow 2: Production → QA (Mirroring) |
| 83 | + |
| 84 | +**Use case**: Copying production dashboards to QA for testing changes |
| 85 | + |
| 86 | +```bash |
| 87 | +cd src/ol_superset |
| 88 | + |
| 89 | +# 1. Export from production |
| 90 | +./scripts/export_all.sh |
| 91 | + |
| 92 | +# 2. Review and commit |
| 93 | +git diff assets/ |
| 94 | +git add assets/ && git commit -m "Mirror production dashboards" |
| 95 | + |
| 96 | +# 3. Deploy to QA (automated with sup dashboard push) |
| 97 | +./scripts/sync_to_qa.sh |
| 98 | +``` |
| 99 | + |
| 100 | +### Workflow 3: Regular Backups |
| 101 | + |
| 102 | +**Use case**: Periodic snapshots of production for disaster recovery |
| 103 | + |
| 104 | +```bash |
| 105 | +cd src/ol_superset |
| 106 | + |
| 107 | +# Export and commit (weekly via cron or GitHub Actions) |
| 108 | +./scripts/export_all.sh |
| 109 | +git add assets/ |
| 110 | +git commit -m "Backup: Production assets - $(date +%Y-%m-%d)" |
| 111 | +git push |
| 112 | +``` |
| 113 | + |
| 114 | +## Common Workflows (Detailed Steps) |
| 115 | + |
| 116 | +Export all dashboards, charts, datasets, and databases: |
| 117 | + |
| 118 | +```bash |
| 119 | +cd src/ol_superset |
| 120 | +./scripts/export_all.sh |
| 121 | +``` |
| 122 | + |
| 123 | +This pulls all published dashboards along with their dependencies (charts, datasets, databases). |
| 124 | + |
| 125 | +### 2. Export Specific Dashboard |
| 126 | + |
| 127 | +To export a single dashboard with dependencies: |
| 128 | + |
| 129 | +```bash |
| 130 | +cd src/ol_superset |
| 131 | +sup dashboard pull assets/ --id=52 |
| 132 | +``` |
| 133 | + |
| 134 | +### 3. Sync Assets to QA (Dry Run) |
| 135 | + |
| 136 | +Preview what changes would be applied to QA: |
| 137 | + |
| 138 | +```bash |
| 139 | +cd src/ol_superset |
| 140 | +sup sync run . --dry-run |
| 141 | +``` |
| 142 | + |
| 143 | +### 4. Deploy to QA |
| 144 | + |
| 145 | +### Deploy to QA (from production) |
| 146 | + |
| 147 | +Execute the sync to push production assets to QA for testing: |
| 148 | + |
| 149 | +```bash |
| 150 | +cd src/ol_superset |
| 151 | +./scripts/sync_to_qa.sh |
| 152 | +``` |
| 153 | + |
| 154 | +### Validate Assets |
| 155 | + |
| 156 | +Check that all asset files are valid: |
| 157 | + |
| 158 | +```bash |
| 159 | +cd src/ol_superset |
| 160 | +./scripts/validate_assets.sh |
| 161 | +``` |
| 162 | + |
| 163 | +## Working with Assets |
| 164 | + |
| 165 | +### Pull Commands |
| 166 | + |
| 167 | +```bash |
| 168 | +# Pull all dashboards + dependencies (charts, datasets, databases) |
| 169 | +sup dashboard pull assets/ |
| 170 | + |
| 171 | +# Pull only published dashboards |
| 172 | +sup dashboard pull assets/ --search="status:published" |
| 173 | + |
| 174 | +# Pull specific dashboard by ID |
| 175 | +sup dashboard pull assets/ --id=52 |
| 176 | + |
| 177 | +# Pull multiple dashboards |
| 178 | +sup dashboard pull assets/ --ids=52,58,14 |
| 179 | + |
| 180 | +# Pull only dashboards you own |
| 181 | +sup dashboard pull assets/ --mine |
| 182 | + |
| 183 | +# Pull without dependencies (dashboards only) |
| 184 | +sup dashboard pull assets/ --skip-dependencies |
| 185 | +``` |
| 186 | + |
| 187 | +### Push Commands |
| 188 | + |
| 189 | +```bash |
| 190 | +# Push charts to QA or production instance |
| 191 | +sup instance use superset-qa |
| 192 | +sup chart push assets/ --overwrite --force |
| 193 | + |
| 194 | +# Push with automatic database UUID mapping (recommended for cross-environment) |
| 195 | +sup chart push assets/ --auto-map-databases --overwrite --force |
| 196 | + |
| 197 | +# Push dashboards (includes charts, datasets, databases as dependencies) |
| 198 | +sup instance use superset-production |
| 199 | +sup dashboard push assets/ --overwrite --force |
| 200 | + |
| 201 | +# Push with automatic database mapping by name |
| 202 | +sup dashboard push assets/ --auto-map-databases --overwrite --force |
| 203 | + |
| 204 | +# Push to specific instance without changing context |
| 205 | +sup dashboard push assets/ --instance superset-qa --overwrite |
| 206 | + |
| 207 | +# Push with specific database UUID (all assets use this database) |
| 208 | +sup dashboard push assets/ --database-uuid "abc-123-def" --overwrite |
| 209 | + |
| 210 | +# Push with database name lookup (fetches UUID from target) |
| 211 | +sup dashboard push assets/ --database-name "Trino" --overwrite |
| 212 | + |
| 213 | +# Push with template variables |
| 214 | +sup dashboard push assets/ --option ENV=production --option REGION=us-east |
| 215 | + |
| 216 | +# Continue on error (useful for batch imports) |
| 217 | +sup dashboard push assets/ --continue-on-error --force |
| 218 | +``` |
| 219 | + |
| 220 | +#### Database UUID Transformation |
| 221 | + |
| 222 | +When importing assets from one environment to another (e.g., production → QA), database UUIDs often don't match. Use these options to automatically transform database references: |
| 223 | + |
| 224 | +- `--auto-map-databases`: **Recommended**. Automatically matches databases by name between source and target. Best for environments with similarly named databases. |
| 225 | +- `--database-name "Name"`: Use a specific database from the target by name. All assets will reference this database. |
| 226 | +- `--database-uuid "uuid"`: Use a specific UUID. All assets will reference this database UUID. |
| 227 | + |
| 228 | +**Example**: Syncing production assets to QA with auto-mapped databases: |
| 229 | +```bash |
| 230 | +sup instance use superset-qa |
| 231 | +sup dashboard push assets/ --auto-map-databases --overwrite --force |
| 232 | +``` |
| 233 | + |
| 234 | +**Note**: Both `chart push` and `dashboard push` automatically import all dependencies (datasets, databases) so you don't need to push them separately. Database transformation is applied before import to ensure compatibility with the target environment. |
| 235 | + |
| 236 | +## Sync Configuration |
| 237 | + |
| 238 | +The `sync_config.yml` file defines: |
| 239 | +- **Source**: superset-production instance |
| 240 | +- **Targets**: superset-qa instance (can add more) |
| 241 | +- **Variables**: Environment-specific values (database connections, schema names) |
| 242 | +- **Filters**: Which assets to sync |
| 243 | + |
| 244 | +### Jinja2 Templating |
| 245 | + |
| 246 | +Assets support Jinja2 variables for environment-specific customization: |
| 247 | + |
| 248 | +```yaml |
| 249 | +# In asset files |
| 250 | +database_name: "{{ database }}" |
| 251 | +schema: "ol_warehouse_{{ environment }}_mart" |
| 252 | +``` |
| 253 | +
|
| 254 | +Variables are defined in `sync_config.yml`: |
| 255 | + |
| 256 | +```yaml |
| 257 | +variables: |
| 258 | + production: |
| 259 | + environment: "production" |
| 260 | + database: "Trino Production" |
| 261 | + qa: |
| 262 | + environment: "qa" |
| 263 | + database: "Trino QA" |
| 264 | +``` |
| 265 | + |
| 266 | +## Security Notes |
| 267 | + |
| 268 | +⚠️ **Never commit secrets to version control** |
| 269 | + |
| 270 | +- Database passwords are excluded from exports |
| 271 | +- API tokens should be managed via environment variables or Vault |
| 272 | +- The `.gitignore` prevents accidental secret commits |
| 273 | +- Use Jinja2 variables for environment-specific credentials |
| 274 | + |
| 275 | +## Maintenance |
| 276 | + |
| 277 | +### Regular Export Cadence |
| 278 | + |
| 279 | +Establish a regular schedule for exporting production assets: |
| 280 | + |
| 281 | +```bash |
| 282 | +# Weekly export (suggested cron job or GitHub Action) |
| 283 | +cd /home/tmacey/code/mit/data/ol-data-platform/src/ol_superset |
| 284 | +./scripts/export_all.sh |
| 285 | +git add assets/ |
| 286 | +git commit -m "Update Superset assets from production - $(date +%Y-%m-%d)" |
| 287 | +git push |
| 288 | +``` |
| 289 | + |
| 290 | +### After Making Changes in Superset UI |
| 291 | + |
| 292 | +**For QA → Production flow** (recommended): |
| 293 | + |
| 294 | +1. Export from QA: `./scripts/export_from_qa.sh` |
| 295 | +2. Review changes: `git diff assets/` |
| 296 | +3. Commit: `git add assets/ && git commit -m "Description of changes"` |
| 297 | +4. Promote: `./scripts/promote_to_production.sh` |
| 298 | + |
| 299 | +**For Production → QA flow** (mirroring): |
| 300 | + |
| 301 | +1. Export from production: `./scripts/export_all.sh` |
| 302 | +2. Review changes: `git diff assets/` |
| 303 | +3. Commit: `git add -p && git commit -m "Update from production"` |
| 304 | +4. Deploy to QA: `./scripts/sync_to_qa.sh` |
| 305 | + |
| 306 | +## Troubleshooting |
| 307 | + |
| 308 | +### Authentication Issues |
| 309 | + |
| 310 | +```bash |
| 311 | +# Re-authenticate |
| 312 | +sup config |
| 313 | +
|
| 314 | +# Verify current instance |
| 315 | +sup instance list |
| 316 | +``` |
| 317 | + |
| 318 | +### Asset Conflicts |
| 319 | + |
| 320 | +If sync encounters conflicts: |
| 321 | +1. Use `--dry-run` to preview changes |
| 322 | +2. Use `--overwrite` flag to force updates |
| 323 | +3. Review diffs before applying |
| 324 | + |
| 325 | +### Dependencies Not Pulled |
| 326 | + |
| 327 | +Ensure you're not using `--skip-dependencies` flag when pulling dashboards. |
| 328 | + |
| 329 | +## References |
| 330 | + |
| 331 | +- [sup CLI Documentation](https://github.com/preset-io/backend-sdk) |
| 332 | +- [Superset Documentation](https://superset.apache.org/) |
| 333 | +- Internal: `dg_projects/lakehouse/lakehouse/assets/superset.py` - Dagster asset integration |
0 commit comments