Skip to main content

Storage and database adapters available in project Thoth

Project description

This library provides a library called thoth-storages used in project Thoth. The library exposes core queries and methods for Dgraph database as well as adapters for manipulating with Ceph via its S3 compatible API.

Installation and Usage

The library can be installed via pip or Pipenv from PyPI:

pipenv install thoth-storages

The library does not provide any CLI, it is rather a low level library supporting other parts of Thoth.

You can run prepared testsuite via the following command:

pipenv install --dev
pipenv run python3 setup.py test

# To generate docs:
pipenv run python3 setup.py build_sphinx

Automatically generate schema for Graph database

To automatically generate schema for the graph database from models defined in this module, run:

PYTHONPATH=. pipenv run python3 ./create_schema.py --output thoth/storages/graph/schema.rdf

After running this command, the RDF file describing schema will be updated based on changes in model.

from thoth.storages import GraphDatabase

# Also provide configuration if needed.
graph = GraphDatabase()
graph.connect()
graph.initialize_schema()

Running Dgraph locally

You can use docker-compose present in this repository to run a local Dgraph instance. It does not use TLS certificates (so you must not to provide GRAPH_TLS_PATH environment variable).

$ docker-compose up

After running the command above (make sure your big fat daemon is up using systemctl start docker), you should be able to access a local Dgraph instance at localhost:9080. This is also the default configuration for Dgraph’s adapter - you don’t need to provide GRAPH_SERVICE_HOST explicitly.

The provided docker-compose has also Ratel enabled for to have an UI for graph database content. To access it visit http://localhost:8000/.

The provided docker-compose uses volume mounted from /tmp. After you computer restart, the content will not be available anymore.

If you would like to experiment with Dgraph programatically, you can use the following code snippet as a starting point:

from thoth.storages import GraphDatabase

graph = GraphDatabase()
graph.connect()
# To clear database:
# graph.drop_all()
# To initialize schema in the graph database:
# graph.initialize_schema()

Schema adjustment in deployment

It’s possible to perform adjustments of schema in a deployemnt. It’s important that there are no open transactions (simply retry schema creation until it succeeds). You can use relevant endpoint on Management API for this purpose.

If there are changes in types, Dgraph tries to automatically perform conversion from an old type to the new one as described in the new schema (e.g. a float to string). Invalid schema changes (e.g. parsing string into a float, but the string cannot be parsed as a float) result in schema change errors. These errors need to be handled programatically by deployment administrator (ideally avoid such conversions).

Creating own performance indicators

You can create your own performance indicators. To create own performance indicator, create a script which tests desired functionality of a library. An example can be matrix multiplication script present in performance repository. This script can be supplied to Dependency Monkey to validate certain combination of libraries in desired runtime and buildtime environment or directly on Amun API which will run the given script using desired software and hardware configuration. Please follow instructions on how to create a performance script shown in the README of performance repo.

To create relevant models, adjust thoth/storages/graph/performance.py file and add your model. Describe parameters (reported in @parameters section of performance indicator result) and result (reported in @result). The name of class should match name which is reported by performance indicator run.

@attr.s(slots=True)
class PiMatmul(PerformanceIndicatorBase):
    """A class for representing a matrix multiplication micro-performance test."""

    SCHEMA_PARAMETERS = Schema({
        Required("matrix_size"): int,
        Required("dtype"): str,
        Required("reps"): int,
        Required("device"): str,
    })

    SCHEMA_RESULT = Schema({
        Required("elapsed"): float,
        Required("rate"): float,
    })

    # Device used during performance indicator run - CPU/GPU/TPU/...
    device = model_property(type=str, index="exact")
    matrix_size = model_property(type=int, index="int")
    dtype = model_property(type=str, index="exact")
    reps = model_property(type=int, index="int")
    elapsed = model_property(type=float)
    rate = model_property(type=float)

After you have created relevant model, register your model to ALL_PERFORMANCE_MODELS and re-generate graph database schema (as discussed above).

Online debugging of queries done to Dgraph

You can print to logger all the queries that are performed to a Dgraph instance. To do so, set the following environment variables:

export THOTH_LOG_STORAGES=DEBUG
export THOTH_STORAGES_DEBUG_QUERIES=1

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

thoth-storages-0.18.1.tar.gz (40.5 kB view details)

Uploaded Source

Built Distribution

thoth_storages-0.18.1-py3-none-any.whl (63.5 kB view details)

Uploaded Python 3

File details

Details for the file thoth-storages-0.18.1.tar.gz.

File metadata

  • Download URL: thoth-storages-0.18.1.tar.gz
  • Upload date:
  • Size: 40.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/36.5.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.3

File hashes

Hashes for thoth-storages-0.18.1.tar.gz
Algorithm Hash digest
SHA256 6569e1ffbc681078f267956025fd9cbb5a93d32012f881beab252df03b81ba9e
MD5 ba1541f4ff5ef0609126775bd30d844d
BLAKE2b-256 0b0f0a01b0f23a6fbaa966b2dee1ad4c1a52f4ee020fb04f67c15c97626c650a

See more details on using hashes here.

File details

Details for the file thoth_storages-0.18.1-py3-none-any.whl.

File metadata

  • Download URL: thoth_storages-0.18.1-py3-none-any.whl
  • Upload date:
  • Size: 63.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/36.5.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.3

File hashes

Hashes for thoth_storages-0.18.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7b3af21d09e7d2e869859002e956b2ef464d307f0bdc0415245c746bbd8cf0a3
MD5 522418f77f9c93fcb8d8ba4aa6d5a718
BLAKE2b-256 c78626e357209e4bcc987c121f07625cd3f1f5f922dc4007b6f7c8136cd3000c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page