Code Monkey home page Code Monkey logo

dashdotdb's Introduction

Dash.DB

The AppSRE Dashboards Database is a repository of metrics and statistics about the services we run.

The Dash.DB is a service created to implement the Database Model and to read/write data from/to the Database.

It's a building block - and a central part - in the architecture created to extract information from multiples sources, place them into the Database and expose the relevant insights via Grafana Dashboards and monthly reports.

Quickstart

Docker-compose

You can quickly run the app locally with docker-compose

docker-compose up

Test data can be generated via

make test-data

Manual

Run a PostgreSQL instance:

docker run --rm -it -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres

Open a new terminal. Install the package:

python -m venv venv
source venv/bin/activate
python setup.py develop

Export the FLASK_APP and the DASHDOTDB_DATABASE_URL:

export FLASK_APP=dashdotdb
export DASHDOTDB_DATABASE_URL=postgresql://postgres:[email protected]:5432/postgres

Initialize the Database:

$ FLASK_APP=dashdotdb flask db upgrade
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade  -> c4f641d56546, Initial migration.

Run the service:

flask run --debugger --port 8080

Using the app

Open a new terminal. Get a token:

TOKEN=$(curl --silent localhost:8080/api/v1/token?scope=imagemanifestvuln | sed 's/"//g')

Apply imagemanifestvuln example data:

$ curl --request POST \
--header "Content-Type: application/json" \
--header "X-Auth: $TOKEN" \
--data @examples/imagemanifestvuln.json \
localhost:8080/api/v1/imagemanifestvuln/app-sre-prod-01

Or, if you already have a live cluster:

$ oc get imagemanifestvuln <object_name> -o json | $ curl --request POST \
--header "Content-Type: application/json" \
--header "X-Auth: $TOKEN" \
--data @- \
"localhost:8080/api/v1/imagemanifestvuln/app-sre-prod-01"
...

(Note: Data that is uploaded to dashdotDB is not actually available for query until the token that was used to upload it is deleted. The only data available for query at any given moment is that which was uploaded using the most recently deleted token.)

Close the token (to make the latest data queryable):

curl --request DELETE "localhost:8080/api/v1/token/$TOKEN?scope=imagemanifestvuln"

Query vulnerabilities:

$ curl "localhost:8080/api/v1/imagemanifestvuln?cluster=app-sre-prod-01&namespace=cso"
[
  {
    "affected_pods": 3,
    "current_version": "9.0.3-15.el8",
    "fixed_in_version": "0:9.0.3-16.el8",
    "link": "https://access.redhat.com/errata/RHSA-2020:1916",
    "manifest": "sha256:9e0c275",
    "name": "centos:8",
    "package": "platform-python-pip",
    "repository": "quay.io/app-sre/centos",
    "severity": "Medium",
    "vulnerability": "RHSA-2020:1916"
  },
  {
    "affected_pods": 3,
    "current_version": "8.3.1-4.5.el8",
    "fixed_in_version": "0:8.3.1-5.el8",
    "link": "https://access.redhat.com/errata/RHSA-2020:1864",
    "manifest": "sha256:9e0c275",
    "name": "centos:8",
    "package": "libstdc++",
    "repository": "quay.io/app-sre/centos",
    "severity": "Medium",
    "vulnerability": "RHSA-2020:1864"
  },
...

Prometheus metrics endpoint:

$ curl "localhost:8080/api/v1/imagemanifestvuln/metrics"
...
# HELP imagemanifestvuln_total Vulnerabilities total per severity
# TYPE imagemanifestvuln_total counter
imagemanifestvuln_total{cluster="app-sre-prod-01",namespace="cso",severity="Medium"} 86.0
imagemanifestvuln_total{cluster="app-sre-prod-01",namespace="cso",severity="High"} 43.0
imagemanifestvuln_total{cluster="app-sre-prod-01",namespace="cso",severity="Low"} 20.0
imagemanifestvuln_total{cluster="app-sre-prod-01",namespace="cso",severity="Unknown"} 5.0
imagemanifestvuln_total{cluster="app-sre-prod-01",namespace="cso",severity="Critical"} 4.0
...

Changing the Database Model

The current Entity Relationship Diagram looks like this:

ERD

To change the database, start by editing the ERD ".dia" file using Gnome Dia.

The Dia application is known to have issues running on Mac OS. It may launch fine the first time, and then never again. Following these directions should help fix that.

Model

Reflect the changes to the ERD in the database model, either by updating an existing model or by creating new ones. Models are placed here.

DB Upgrade

Create the upgrade routine executing the command:

make db

That will create a new migration file in the migrations directory.

NOTE: Any change to a Enum type will need to be done manually. See this issue and an example.

For the deployed environments, the entrypoint.sh will execute the migration before running the service. To execute the migration on your own database instance, run:

FLASK_APP=dashdotdb flask db upgrade

SQLAlchemy Debug

To enable verbose SQLAlchemy logging, which will output the compiled queries add to the app.config object:

app.config['SQLALCHEMY_ECHO'] = True

dashdotdb's People

Contributors

apahim avatar fishi0x01 avatar bkez322 avatar bumblefeng avatar xyntrix avatar rporres avatar geoberle avatar jmelis avatar jfchevrette avatar tgpski avatar maorfr avatar janboll avatar kwilczynski avatar violetyao avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.