Installing as a Heroku App

The filter node can be installed as a Heroku App.

The functionality of the filter node installed as a Heroku App is completely identical to the functionality of the other deployment options.

See also the Heroku buildpack in the Wallarm public repository.

Features

  • L2met friendly NGINX log format.
  • Heroku request IDs embedded in NGINX logs.
  • Crashes dyno if a NGINX or an app server crashes. Safety first.
  • Language/App Server agnostic.
  • Customizable NGINX configuration.
  • Application coordinated dyno starts.

Prerequisites

  • You have a Wallarm account with the Administrator role.
  • Your webserver listens to the socket at /tmp/nginx.socket.
  • You touch /tmp/app-initialized when you are ready for traffic.
  • You can start your web server with a shell command.

Language/App Server Agnostic

The Wallarm Node buildpack provides the wallarm/bin/start-wallarm command. This command takes another command as an argument. You must pass your app server's startup command to start-wallarm.

For example, to get Wallarm Node and Unicorn up and running:

$ cat Procfile
web: wallarm/bin/start-wallarm bundle exec unicorn -c config/unicorn.rb

Environment variables

You can use the following environment variables:

  • WALLARM_USER - The user at my.wallarm.com that has rights to add new nodes.
  • WALLARM_PASSWORD - The user password.
  • WALLARM_MODE - The request handling mode: off, monitoring (default), blocking.
  • WALLARM_TARANTOOL_MEMORY - The amount of memory in gigabytes allocated to postanalytics; 0.5 of total memory by default.

For example, to set your WALLARM_MODE to the blocking mode:

$ heroku config:set WALLARM_MODE=block

Customizable NGINX configuration

You can provide your own NGINX configuration by creating a file named nginx.conf.erb in the directory wallarm/etc. Start by copying the buildpack's default configuration file.

Application/Dyno coordination

The buildpack will not start NGINX with the Wallarm module until a file is written to /tmp/app-initialized. Since NGINX binds to the dyno's $PORT and since $PORT determines if the app can receive traffic, you can delay NGINX accepting traffic until your application is ready to handle it. The examples below show how/when you should write the file when working with Unicorn.

Setup

Here are two setup examples. One example is for a new app; another one is for an existing app. In both cases, we are using Ruby & Unicorn. Keep in mind that this buildpack is not Ruby specific.

Existing App

Update the buildpacks:

$ heroku buildpacks:add https://github.com/wallarm/heroku-buildpack-wallarm-node.git

Update Procfile:

web: wallarm/bin/start-wallarm bundle exec unicorn -c config/unicorn.rb
$ git add Procfile
$ git commit -m 'Update procfile for Wallarm Node buildpack'

Update Unicorn configuration:

require 'fileutils'
listen '/tmp/nginx.socket'
before_fork do |server,worker|
  FileUtils.touch('/tmp/app-initialized')
end
$ git add config/unicorn.rb
$ git commit -m 'Update unicorn config to listen on NGINX socket.'

Connect to the Wallarm cloud:

heroku config:set WALLARM_USER=<your email>
heroku config:set WALLARM_PASSWORD=<your password>

Deploy the changes:

$ git push heroku master

New App

We are using Ruby & Unicorn. Keep in mind that this buildpack is not Ruby specific. These are the components you need to have installed on your system for the following instructions to work: gcc, heroku cli, bundler

Create a directory for the app:

$ mkdir myapp; cd myapp
$ git init

Gemfile:

source 'https://rubygems.org'
gem 'unicorn'

config.ru:

run Proc.new {[200,{'Content-Type' => 'text/plain'}, ["hello world"]]}

config/unicorn.rb:

require 'fileutils'
preload_app true
timeout 5
worker_processes 4
listen '/tmp/nginx.socket', backlog: 1024

before_fork do |server,worker|
  FileUtils.touch('/tmp/app-initialized')
end

Install Gems:

$ bundle install

Create Procfile:

web: wallarm/bin/start-wallarm bundle exec unicorn -c config/unicorn.rb

Create & push the Heroku app:

$ heroku create
$ heroku buildpacks:add heroku/ruby
$ heroku buildpacks:add https://github.com/wallarm/heroku-buildpack-wallarm-node.git
$ heroku config:set WALLARM_USER=<your email>
$ heroku config:set WALLARM_PASSWORD=<your password>
$ git add .
$ git commit -am "init"
$ git push heroku master
$ heroku logs -t

Check the app:

$ heroku open

results matching ""

    No results matching ""