redash-stmo/README.rst

277 строки
9.9 KiB
ReStructuredText
Исходник Обычный вид История

2018-02-27 00:31:35 +03:00
Redash-STMO
===========
2019-02-26 13:56:11 +03:00
`Redash <https://redash.io>`_ extensions for
`sql.telemetry.mozilla.org <https://sql.telemetry.mozilla.org/>`_.
2019-02-18 20:28:38 +03:00
2019-02-26 13:56:11 +03:00
Or as it should have been called: *St. Moredash* ;)
2019-02-18 20:29:58 +03:00
2019-02-26 13:56:11 +03:00
.. image:: https://circleci.com/gh/mozilla/redash-stmo.svg?style=svg
:target: https://circleci.com/gh/mozilla/redash-stmo
2019-02-18 20:28:38 +03:00
2021-02-03 23:17:52 +03:00
.. image:: https://codecov.io/gh/mozilla/redash-stmo/branch/main/graph/badge.svg
2019-02-26 13:56:11 +03:00
:target: https://codecov.io/gh/mozilla/redash-stmo
2019-02-18 20:28:38 +03:00
2019-03-27 16:50:10 +03:00
.. image:: https://img.shields.io/badge/calver-YYYY.M.PATCH-22bfda.svg
2019-02-26 13:56:11 +03:00
:target: https://calver.org/
:alt: CalVer - Timely Software Versioning
2018-02-27 00:31:35 +03:00
Overview
--------
2018-02-27 00:31:35 +03:00
Inherits Redash's Docker setup
redash-stmo is using Redash's own Docker image for development to implement a
close development/production parity and extends it in various ways, e.g.
an own docker-compose configuration, an own docker-entrypoint script.
2018-02-27 00:31:35 +03:00
Specifically it uses Mozilla's "rc" tagged version of the Redash Docker
image, which includes (at the time of writing this, 2019-06-13) many
customizations from Mozilla's pseudo-temporary and regularly updated Redash
fork. The "rc" tagged Docker image is updated every time a "rebase" from
upstream Redash happens and is put to testing in the "release" Redash
environment on Mozilla's server.
2018-02-27 00:31:35 +03:00
Please review the `Redash Docker installation guidelines <https://redash.io/help/open-source/dev-guide/docker>`_ before continuing. It's important to know
those basics since many decisions for redash-stmo were derived from it.
Thank you.
2019-03-07 00:58:20 +03:00
Is mounted under /extension
The current working directory (the directory with this ``README.rst``) is
mounted under the path ``/extension`` by docker-compose inside the Docker
container.
Runs with Redash in /app
Since it reuses the Redash Docker image, you can find all the Redash setup
under the ``/app`` directory inside the Docker container.
Uses Redash's "entrypoints" for discovery
The way Redash finds new extensions is by using the so called "entrypoints"
of Python packages, metadata that is specified and distributed in
Python packages, that is read out by Redash at runtime to find the filesystem
locations for Redash extensions.
That's true for three kinds of entrypoints:
``redash.extensions``
Python callables to be used to extend the Redash Flask app, e.g.
``redash_stmo.data_sources.health:extension``.
``redash.bundles``
Python packages that contain additional front-end files for the
webpack build process, e.g. ``redash_stmo.data_sources.link``.
``redash.scheduled_jobs``
Python callables that return parameters for scheduled RQ jobs,
e.g. ``redash_stmo.data_sources.health:scheduled_job``.
Hooks into Webpack
Since Redash extensions like redash-stmo can also provide additional Webpack
bundles, the development setup runs Redash's `bundle-extension script <https://github.com/getredash/redash/blob/master/bin/bundle-extensions>`_ periodically
to copy the files from redash-stmo to the right place for webpack to pick
them up (``/app/client/app/extensions``).
See the section about the webpack development server below for more
information.
Development workflow
--------------------
We provide some convenience Make tasks to be run from your host machine
(not inside the Docker container) to ease this non-trivial application setup:
Build and update the local Docker image
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Many of the helpers below will implicitely run docker-compose to start the
Redash containers and in effect automatically build the local Docker image
as well if it doesn't exist.
If you'd like to build the local Docker image separately or if you'd like to
fetch the latest version of the base Redash Docker image (or its child
image of the Mozilla Redash fork), e.g. in the event of a new rebase by
Mozilla staff, please run the following::
make build
2019-06-13 20:29:50 +03:00
Behind the scenes
This will run ``docker-compose build --pull`` which will pull updates to
the Docker images used by the docker-compose setup, including the Redash,
Redis and Postgres images.
2019-03-11 14:43:03 +03:00
2019-03-11 18:29:43 +03:00
Create the database
~~~~~~~~~~~~~~~~~~~
On you command line run this **ONCE** to create the database for
Redash/redash-stmo setup:
::
2019-03-11 14:43:03 +03:00
2019-03-11 18:23:10 +03:00
make database
2019-03-11 14:43:03 +03:00
This uses Redash's own ability and redash-stmo is just set up to reuse it.
2019-06-13 20:29:50 +03:00
Behind the scenes
This will run docker-compose to create the server container that is
running the Redash Python server and in effect the Redis and Postgres
containers, too.
2019-06-13 20:29:50 +03:00
It will then initialize the Postgres tables needed for Redash.
Install npm modules
2019-03-11 18:29:43 +03:00
~~~~~~~~~~~~~~~~~~~
Then we'll install the Redash npm modules inside the server container::
2019-03-11 18:29:43 +03:00
make node_modules
2019-06-13 20:29:50 +03:00
Behind the scenes
This will run ``npm install`` inside the server in the ``/app`` directory,
which is the directory with Redash's code from the Redash Docker base
image.
2019-06-13 20:29:50 +03:00
NOTE, the redash-stmo development setup mounts the ``/app/node_modules``
directory as a separate Docker volume, that will be maintained by Docker
and won't show up in or transfer to the host machine where Docker is
running.
2019-03-11 18:29:43 +03:00
Start the containers
~~~~~~~~~~~~~~~~~~~~
To start the whole set of Docker containers for a working environment
(Redash server, RQ workers, Redis, Postgres) all you need to run is this::
2019-03-07 00:58:20 +03:00
2019-03-11 18:22:47 +03:00
make up
2019-03-07 00:58:20 +03:00
2019-06-13 20:29:50 +03:00
Behind the scenes
This is pretty simply running ``docker-compose up``, to launch all
containers of the redash-stmo Docker setup.
2019-06-13 20:29:50 +03:00
NOTE: This **requires** first installing npm modules inside the container
above and creating the database as well!
2019-03-11 18:29:43 +03:00
Run webpack devserver
~~~~~~~~~~~~~~~~~~~~~
If you're developing a Redash extension that includes an additional webpack
bundle (which will need to be included in Redash's webpack build process
to be shipped in the client application bundle) you'll want to use the webpack
development server.
It automatically compiles the Redash client application bundle on files
changes and proxies requests for the Redash server via a proxy running
on port 8080 (instead of the usual Redash port of 5000).
After starting the containers using the description in the above step,
open a second terminal and **additionally run**::
2019-03-07 00:58:20 +03:00
2019-03-11 18:23:10 +03:00
make devserver
2019-03-07 00:58:20 +03:00
2019-06-13 20:29:50 +03:00
Behind the scenes
This will run the webpack devserver in another instance of the server
container (not the same as when running ``make up``) and runs a script
that listens for files changes to ``.js`` and ``.jsx`` files in the
``/extension`` directory.
2019-06-13 20:29:50 +03:00
When changes are detected, it'll automatically run Redash's
``bundle-extensions`` script that does the heavy lifting of copying
the changed extension files into the ``/app/client/app/extensions``
directory, which triggers the webpack devserver to recompile the
client application bundle.
2019-06-13 20:29:50 +03:00
NOTE: This **requires** opening the Redash instance via
http://localhost:8080/ instead of http://localhost:5000/ to go through
the webpack devserver.
2019-03-11 18:29:43 +03:00
Start shell
~~~~~~~~~~~
In case you need to do any debugging or file system checks inside the
server container, you can create a bash shell by running::
2019-03-07 00:58:20 +03:00
2019-03-11 18:22:47 +03:00
make bash
2019-03-07 00:58:20 +03:00
2019-06-13 20:29:50 +03:00
Behind the scenes
Any changes you make here outside the ``/extension`` directory
(which is mounted as a Docker volume with the current working directory on
the Docker host machine) and the following directores are not persisted.
2019-06-13 20:29:50 +03:00
List of directories inside the container that are mounted as Docker volumes:
2019-06-13 20:29:50 +03:00
``/extension``
Maps the current working directory (where this README.rst is located)
on the host machine for developing the extension.
2019-06-13 20:29:50 +03:00
``/home/redash/.cache``
Used by pip and other scripts,
2019-06-13 20:29:50 +03:00
``/app/client/dist``
Directory to retain webpack build results, so webpack builds don't take
as long on consecutive runs.
2019-06-13 20:29:50 +03:00
``/home/redash/.local``
Directory for "user-installed" Python packages. If you'd like you can
easily install additonal Python packages with the Docker container user
Redash using ``pip install --user <package>``. Installed scripts from
those packages will be found under ``/home/redash/.local/bin`` but
are also automatically added to ``PATH``.
2019-06-13 20:29:50 +03:00
``/app/node_modules``
Directory for npm modules, that are installed when running ``npm install``
inside of ``/app`` in the container. Retained to make use of native npm
caching between consecutive runs.
2019-03-11 18:29:43 +03:00
Run tests
~~~~~~~~~
2019-03-11 14:43:03 +03:00
Running the Python based tests requires first creating a separate database
(implemented by the ``test_database`` Make task) and then running the test
runner inside the container. The test database is not the same as the
databse in use for regular development (e.g. to not overwrite development
data).
Frontend or integration tests are currently not supported.
2019-03-11 18:22:47 +03:00
To run the tests (from the host machine) run::
2019-03-07 00:58:20 +03:00
2019-03-11 18:22:47 +03:00
make test
2019-03-07 00:58:20 +03:00
This will automatically run the ``test_database`` Make task before running
the tests.
2019-06-13 20:29:50 +03:00
Behind the scenes
When launching the tests runner it'll the regular server container,
but also set the ``REDASH_DATABASE_URL`` environment variable to the
test database to prevent overwriting any data that you added to the
database the regular Redash interface (e.g. data sources, queries etc).
2019-06-13 20:29:50 +03:00
By default it uses `pytest <https://docs.pytest.org/>`_ to run
the Python tests in ``/extension``, with a number of parameters as
defined in the ``pytest.ini``.
2019-06-13 20:29:50 +03:00
If you'd like to add additional parameters to pytest simply appened the
command line arguments in ``pytest.ini``.
2019-06-13 20:29:50 +03:00
Alternatively, e.g. if you'd like to use `pdb <https://docs.python.org/3/library/pdb.html>`_ to debug a test, do this:
2019-06-13 20:29:50 +03:00
create the test database from the host machine
``make test_database``
2019-06-13 20:29:50 +03:00
start a Bash shell in the container
``make bash``
2019-06-13 20:29:50 +03:00
set the ``REDASH_DATABASE_URL`` env var in the container
``export REDASH_DATABASE_URL="postgresql://postgres@postgres/tests"``
2019-06-13 20:29:50 +03:00
change direcotry to extensio code
``cd /extension``
2019-06-13 20:29:50 +03:00
run the tests with whatever parameter
``pytest -vvv --pdb``
2018-02-27 00:31:35 +03:00
Issues & questions
------------------
2018-02-28 23:05:41 +03:00
See the `issue tracker on GitHub <https://github.com/mozilla/redash-stmo/issues>`_
2018-02-27 00:31:35 +03:00
to open tickets if you have issues or questions about Redash-STMO.