Skip to content

Instantly share code, notes, and snippets.

@therealcisse
Last active July 31, 2018 00:22
Show Gist options
  • Save therealcisse/c3da8a94da9ef323f527fb517ef7a059 to your computer and use it in GitHub Desktop.
Save therealcisse/c3da8a94da9ef323f527fb517ef7a059 to your computer and use it in GitHub Desktop.

Restoo

Restaurant stock management app.

Getting started

Database

I'm using an in-memory h2 database. The database will be automatically created via a migration using Flyway

Running the app

$ sbt run

Open http://localhost:8080 in your browser to access the swagger UI page.

By default, the app will start listening on localhost port 8080. You can change this behavoir by setting any of the ENV variables RESTOO_SERVER_ADDRESS or RESTOO_SERVER_PORT.

The following command will start the server on localhost port 9009:

$ RESTOO_SERVER_PORT=9009 sbt run

Swagger also defaults to localhost:8080 when making requests. So if you change the default host or port, you should set SWAGGER_URL accordingly.

E. g:

$ SWAGGER_URL="localhost:9009" RESTOO_SERVER_PORT=9009 sbt run

REST endpoints

See the swagger UI.

Tracing

Logging and zipkin backends are supported but disabled by default.

To enable logging, execute:

$ RESTOO_ENABLE_TRACING_LOGGIN=true sbt run

To enable zipkin, make sure there is an instance of zipkin running on localhost on port 9411 then execute:

$ RESTOO_ENABLE_TRACING_ZIPKIN=true sbt run

If zipkin is on a remote host, you can use the ENV variable RESTOO_ZIPKIN_URL.

e. g:

$ RESTOO_ENABLE_TRACING_ZIPKIN=true RESTOO_ZIPKIN_URL="http://zipkinhost/api/v2/spans" sbt run

By default, only a few requests are traced (0.01%). You can change this behavior by setting RESTOO_TRACE_SAMPLING_PROBABILITY

The following will trace all requests.

$ RESTOO_ENABLE_TRACING_ZIPKIN=true RESTOO_TRACE_SAMPLING_PROBABILITY=1.0 sbt run

Monitoring

Monitoring is on by default via the builtin http4s-server-prometheus module. All metrics are exported by the /metrics endpoint.

To configure prometheus to scrape for metrics, add the following to your prometheus.yml scrape_configs config section assuming you are running on localhost port 8080:

  - job_name: 'restoo'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:8080']

Execute some requests and you should see some metrics variables in prometheus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment