Service API to retrieve telemetry schemas and validate them against incoming json.
Перейти к файлу
Mark Reid 3bcbe5a7c3
Merge pull request #14 from mozilla/mreid-moz-patch-1
Update README.md
2018-12-14 10:26:12 -04:00
app Fixing home page 404 2016-08-12 16:33:02 -07:00
bin Various changes to Dockerfile 2016-08-09 14:46:52 -07:00
tests Review fixes 8/1. 2016-08-01 08:43:11 -07:00
.gitignore fixing review changes mozschemas_cli.py and gitignoring pycharm fiels 2016-07-07 13:17:02 -07:00
Dockerfile Various changes to Dockerfile 2016-08-09 14:46:52 -07:00
LICENSE Adding LICENSE and License headers 2016-07-13 08:00:24 -07:00
README.md Update README.md 2018-12-14 10:25:16 -04:00
circle.yml Change circle.yml to follow svcops best practices 2016-08-05 09:41:17 -07:00
requirements.txt Reverting back to one requirements.txt. Broke CircleCI 2016-08-01 09:20:28 -07:00
version.json Make version.json a stub 2016-08-05 13:24:51 -07:00

README.md

telemetry-schema-service

CircleCI

Note This repository is archived. More details can be found in the mozilla-pipeline-schemas repository.

Service API to retrieve telemetry schemas and validate them against incoming json.

Building and Running the service standalone

The service is a Flask app that runs in a Gunicorn WSGI http server.

  1. Clone the repository and cd in

    git clone https://github.com/purukaushik/telemetry-schema-service.git
    cd telemetry-schema-service    
    
  2. Install python dependencies :

    pip install -r requirements.txt
    
  3. Set git checkout path in os_dir in git_config.json

  4. Run nose tests

    nose2
    
  5. Run Gunicorn

    gunicorn -w 4 -b 0.0.0.0:8080 mozschemas_service:app
    

Building the service into a Docker image

The app is built into a docker container and hence the only prerequisite is docker, installed and running on your system.

  1. Clone the repository and cd in

    git clone https://github.com/purukaushik/telemetry-schema-service.git
    cd telemetry-schema-service    
    
  2. Set git checkout path in 'os_dir' in git_config.json

  3. Docker build in /telemetry-schema-service:

    docker build -t telemetry-schema-service .
    

Running the service in Docker container##

The default logging is directed to stdout. In order to use docker logs run with:

docker run --log-driver=json-file -p 8080:8080 telemetry-schema-service & 

API

Once the flask app is up and running, either in Gunicorn or in the Docker container, the schemas can be requested.

Schemas are retrieved from this github repo.

In general, the uri <-> schema name mapping is: <namespace>/<doctype>/<version> translates to namespace/doctype.version.schema.json

e.g telemetry/main/4 refers to the main.4.schema.json located in telemetry/ folder.

  • Retrieve a schema: To retrieve a schema version, say - telemetry/main.4.schema.json (from the github repo):

    $ curl -i http://localhost:8080/schema/telemetry/main/4
    

    To retrieve a schema version with minification of json:

    $ curl -i http://localhost:8080/schema/telemetry/main/4?minify=true
    
  • Validate a JSON payload via POST:

    • To validate a JSON payload with a particular version schema, send a POST with same uri as the schema GET request:

    $ curl -iH "Content-type: application/json" -X POST http://localhost:8080/validate/telemetry/main/4 --data @sample_v4_ping.json

    • To use the file upload utility:

      http://localhost:8080/validate/telemetry/main/4
      

      will pull up the file upload screen.

    On clicking 'upload and validate' the service will POST the uploaded json and validate it with the schema specified in the uri.

CLI version

To run the schema retrieval as a CLI program from terminal, the following will be useful:

./app/mozschemas_cli.py [(-n <namespace>)]
./app/mozschemas_cli.py [(-n <namespace>  -d <doctype>)]
./app/mozschemas_cli.py [(-n <namespace>  -d <doctype> -v <version>)]
./app/mozschemas_cli.py (-h | --help)
Options:
-h --help       Show this screen.
-n namespace    List all docTypes under namespace
-n namespace -d doctype List versions under namespace and docType
-n namespace -d doctype -v version Show schema @ namespace/docType/version