Skip to content

Deploy dbt-docs with Metabase references (exposures) #3803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

erikamov
Copy link
Contributor

@erikamov erikamov commented Mar 28, 2025

Description

There is always a question about where dbt models have been used in Metabase. When working on synchronizing Metabase, @ohrite and I learned about "exposures" in dbt-metabase.

This PR creates a workflow that extracts exposures from Metabase and generate dbt-docs to be visualized in Cal-ITP dbt docs.

The workflow runs every Monday at 8am UTC (1am PST) or when there is any changes on model merged to the main branch.

image

image

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation

How has this been tested?

It was tested running locally and then through the workflow.

Post-merge follow-ups

  • No action required
  • Actions required (specified below)

@erikamov erikamov force-pushed the mov/metabase-exposures branch 3 times, most recently from 8da8493 to 71b1f07 Compare March 28, 2025 20:42
@vevetron
Copy link
Contributor

vevetron commented Mar 29, 2025

Can we update the pyproject.toml to use dbt-metabase=1.5.0. My install was using 0.10.3 and throwing errors.

Also, how do we authenticate?
I'm getting an error:

INFO     2025-03-28 18:35:48 -0700 — Metabase session established                                                           metabase.py:61
ERROR    2025-03-28 18:35:49 -0700 — HTTP request failed: Unauthenticated                                                   metabase.py:88
Traceback (most recent call last):
  File "/Users/vivek/Library/Caches/pypoetry/virtualenvs/calitp-warehouse-1QJyB9-Z-py3.11/bin/dbt-metabase", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/Users/vivek/Library/Caches/pypoetry/virtualenvs/calitp-warehouse-1QJyB9-Z-py3.11/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/vivek/Library/Caches/pypoetry/virtualenvs/calitp-warehouse-1QJyB9-Z-py3.11/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/vivek/Library/Caches/pypoetry/virtualenvs/calitp-warehouse-1QJyB9-Z-py3.11/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/vivek/Library/Caches/pypoetry/virtualenvs/calitp-warehouse-1QJyB9-Z-py3.11/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/vivek/Library/Caches/pypoetry/virtualenvs/calitp-warehouse-1QJyB9-Z-py3.11/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/vivek/Library/Caches/pypoetry/virtualenvs/calitp-warehouse-1QJyB9-Z-py3.11/lib/python3.11/site-packages/dbtmetabase/__main__.py", line 189, in wrapper
    return func(
           ^^^^^
  File "/Users/vivek/Library/Caches/pypoetry/virtualenvs/calitp-warehouse-1QJyB9-Z-py3.11/lib/python3.11/site-packages/dbtmetabase/__main__.py", line 398, in exposures
    core.extract_exposures(
  File "/Users/vivek/Library/Caches/pypoetry/virtualenvs/calitp-warehouse-1QJyB9-Z-py3.11/lib/python3.11/site-packages/dbtmetabase/_exposures.py", line 94, in extract_exposures
    d["id"]: dbname(d["details"]) for d in self.metabase.get_databases()
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/vivek/Library/Caches/pypoetry/virtualenvs/calitp-warehouse-1QJyB9-Z-py3.11/lib/python3.11/site-packages/dbtmetabase/metabase.py", line 100, in get_databases
    return list(self._api("get", "/api/database"))
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/vivek/Library/Caches/pypoetry/virtualenvs/calitp-warehouse-1QJyB9-Z-py3.11/lib/python3.11/site-packages/dbtmetabase/metabase.py", line 86, in _api
    response.raise_for_status()
  File "/Users/vivek/Library/Caches/pypoetry/virtualenvs/calitp-warehouse-1QJyB9-Z-py3.11/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://dashboards.calitp.org/api/database

@erikamov
Copy link
Contributor Author

erikamov commented Apr 9, 2025

@vevetron You need a metabase API key. Evan has access to it.

@ohrite ohrite force-pushed the mov/metabase-exposures branch from 71b1f07 to 9a70fc2 Compare April 21, 2025 21:29
@erikamov erikamov force-pushed the mov/metabase-exposures branch 2 times, most recently from 65c8abb to 7a4d99d Compare April 23, 2025 19:48
@ohrite ohrite force-pushed the mov/metabase-exposures branch 3 times, most recently from 1032154 to 7924797 Compare April 24, 2025 21:12
@erikamov erikamov force-pushed the mov/metabase-exposures branch 2 times, most recently from 9b1e847 to 3469430 Compare May 19, 2025 16:45
@erikamov erikamov force-pushed the mov/metabase-exposures branch 8 times, most recently from db29d75 to 142a58d Compare May 19, 2025 21:19
@erikamov erikamov force-pushed the mov/metabase-exposures branch 10 times, most recently from 2e00a5b to db07ce0 Compare May 23, 2025 19:11
@erikamov erikamov force-pushed the mov/metabase-exposures branch 13 times, most recently from e994296 to eba4cfd Compare June 2, 2025 18:48
@erikamov erikamov changed the title Extract references to models in Metabase to dbt documentation Deploy dbt-docs with Metabase references (exposures) Jun 2, 2025
@ohrite ohrite force-pushed the mov/metabase-exposures branch 2 times, most recently from 0e0b692 to f9b0531 Compare June 4, 2025 19:05
erikamov added 3 commits June 11, 2025 10:35
remove matrix
add model changed, sync metabase and upload
@ohrite ohrite force-pushed the mov/metabase-exposures branch from f9b0531 to 0c64589 Compare June 11, 2025 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants