Skip to content

Commit

Permalink
Merge branch 'reorg' of github.com:nzoschke/ferret into pr/1
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Fode authored and Eric Fode committed Dec 11, 2012
2 parents 9664878 + 1c4d8f0 commit 5e71cd5
Show file tree
Hide file tree
Showing 36 changed files with 575 additions and 196 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
.anvil/
.env
tmp/
2 changes: 1 addition & 1 deletion .profile
@@ -1,5 +1,4 @@
#!/bin/bash

[ -n "$APP" ] || { echo "error: APP required"; exit 1; }
[ -n "$HEROKU_API_KEY" ] || { echo "error: HEROKU_API_KEY required"; exit 1; }

Expand All @@ -18,3 +17,4 @@ if [ ! -f $HOME/.ssh/id_rsa ]; then
heroku keys:add --app $APP
heroku config:set --app $APP SSH_PRIVATE_KEY="$(< $HOME/.ssh/id_rsa)" SSH_PUBLIC_KEY="$(< $HOME/.ssh/id_rsa.pub)"
fi

2 changes: 1 addition & 1 deletion .slugignore
@@ -1 +1 @@
app/*
tmp/
3 changes: 0 additions & 3 deletions Gemfile

This file was deleted.

18 changes: 0 additions & 18 deletions Gemfile.lock

This file was deleted.

13 changes: 1 addition & 12 deletions Procfile
@@ -1,12 +1 @@
exec_converge: bin/loop test/exec_converge
exec_run: bin/loop test/exec_run
git_clone: bin/loop test/git_clone
git_clone_bamboo: bin/loop test/git_clone_bamboo
git_clone_elb: bin/loop test/git_clone_elb
librato: bin/loop test/librato
perf_cpu: bin/loop test/perf_cpu
perf_disk: bin/loop test/perf_disk
perf_network: bin/loop test/perf_network
ssh_fingerprint: bin/loop test/ssh_fingerprint
ssh_path: bin/loop test/ssh_path
ssh_tcp_receive: bin/loop test/ssh_tcp_receive
tester: tests/http_recurl
9 changes: 9 additions & 0 deletions Rakefile
@@ -0,0 +1,9 @@
#!/usr/bin/env rake

require "rake/testtask"

task default: :test

Rake::TestTask.new :test do |t|
t.pattern = "./tests/unit/test_*.rb"
end
81 changes: 28 additions & 53 deletions Readme.md
@@ -1,5 +1,19 @@
# Ferret




To deploy a test to the platform run
```sh
deploy.sh filename
```

To run a test locally run
```sh
foreman run filename
```


Ferret is a framework to set up canary apps and test processes:

```
Expand All @@ -14,57 +28,31 @@ Heroku Org ferret
The Control App test process logs are drained to l2met, where service availability and service time can be calculated and visualized via Librato
Metrics.

## Control App Setup
## Development Control App Setup

Get a HEROKU_API_KEY for an unpriveledged $GMAIL_USER, and an [L2Met drain](https://www.l2met.net/) for a personal Librato account.

NOTE: You can bypass this by joining $ORG.
Copy `env.sample` to `.env`, and fill in APP, HEROKU_API_KEY and L2MET_URL, then run the setup script via Foreman.

```sh
# Create an unpriveledged GMail account, sign up for Heroku, and save the keys
$ export \
UNPRIVILEGED_HEROKU_API_KEY=deadbeef87a9b10d49ab5036216c41b7f8cc3633 \
UNPRIVILEGED_GMAIL_USER=heroku.ferret@gmail.com:deadbeef84c277fa

# Create an app and add the API keys
$ export APP=ferretapp
$ heroku create $APP
$ heroku config:set \
APP=$APP \
GMAIL_USER=$UNPRIVILEGED_GMAIL_USER \
HEROKU_API_KEY=$UNPRIVILEGED_HEROKU_API_KEY

# Add the account and transfer the app to the "ferret" Heroku Manager org
$ export ORG=ferret
$ heroku manager:add_user \
--org $ORG --user ${UNPRIVILEGED_GMAIL_USER%:*} --role admin
$ heroku manager:transfer --to $ORG

# Build and release the code, then run the tests
$ heroku build -b https://github.com/nzoschke/buildpack-ferret.git -r $APP
$ heroku run "test/ferret; test/ferret_online"

# Send metrics to Librato via https://www.l2met.net/

$ heroku sudo passes:add logplex-beta-program
$ heroku drains:add https://drain.l2met.net/consumers/36f8e609-df04-4da2-8630-86a959f41c68/logs
cp env.sample .env
foreman run bin/setup.sh
```

## Local Run

```sh
$ test/git_clone
app=ferret.git_clone xid=40ff7bbd fn=heroku_info_create i=0 at=enter
app=ferret.git_clone xid=40ff7bbd fn=heroku_info_create i=0 status=0 measure=heroku_info_create.success
app=ferret.git_clone xid=40ff7bbd fn=heroku_info_create i=0 at=return val=6.515912 unit=s measure=heroku_info_create.time
app=ferret.git_clone xid=40ff7bbd fn=clone i=0 at=enter
app=ferret.git_clone xid=40ff7bbd fn=clone i=0 status=0 measure=clone.success
app=ferret.git_clone xid=40ff7bbd fn=clone i=0 at=return val=12.826495 unit=s measure=clone.time
app=ferret.git_clone xid=40ff7bbd fn=exit
2012-12-05T01:08:52+00:00 app[http_recurl.1]: app=ferret-dev-fode xid=49eab42b source=http_recurl fn=consider_restart i=0 at=enter
2012-12-05T01:08:53+00:00 app[http_recurl.1]: app=ferret-dev-fode xid=49eab42b source=http_recurl fn=consider_restart i=0 status=0 measure=success
2012-12-05T01:08:53+00:00 app[http_recurl.1]: app=ferret-dev-fode xid=49eab42b source=http_recurl fn=consider_restart i=0 val=100 measure=uptime
2012-12-05T01:08:53+00:00 app[http_recurl.1]: app=ferret-dev-fode xid=49eab42b source=http_recurl fn=consider_restart i=0 at=return val=0.629225798 measure=time

```

## Platform Run

```sh
$ heroku run git_clone
$ heroku run tests/git_clone

# OR

Expand All @@ -78,21 +66,6 @@ Ferret is a simple framework for applying the canary pattern for Heroku kernel s
Ferret *does not* implement complex platform integration tests, though these
would be easy to build with the framework.

## Test App Development

Simple test processes follow a pattern. See `test/exec_run` as an example.

First, test if the $TARGET_APP already exists, and if not create it and
transfer it to the $ORG (:setup, using `heroku info || heroku create`).

Next perform some tests on the $TARGET_APP (:run, using `heroku run true`).

The `bash` helper will automatically log a counter for success or failure, as
well as a value for the time if successful, or logs if a failure. Environment
variables for $ORG, $TARGET_APP, etc. are pre-set for convenience.

Tests are not limited to `bash` however. See `test/librato` for "tests"
performed in Ruby, logging custom measurements.

## Platform Features

Expand All @@ -113,6 +86,8 @@ discoverable, configuration free, and maintenance free:

* HTTP canaries
* Build canaries
* OAuth canary
* Tooling around Heroku setup/teardown
* Tooling around Librato configuration
* Warning / Alerting
* Measure l2met / librato delay
5 changes: 0 additions & 5 deletions bin/loop

This file was deleted.

37 changes: 37 additions & 0 deletions deploy.sh
@@ -0,0 +1,37 @@
#!/bin/bash

L2MET_URL=https://drain.l2met.net/consumers/6f65d7cc-5443-4a99-9545-8bec7a301941/logs
TARGET_APP_PATH=$1
APP=$(whoami)
ORG=ferret-dev
UNPRIVILEGED_USER=heroku.ferret.dev@gmail.com
TARGET_APP_NAME=$(echo $TARGET_APP_PATH | sed 's:[/._]:-:g')
APP=$APP-$TARGET_APP_NAME
echo "Setting up ${TARGET_APP_NAME} from path ${TARGET_APP_PATH}"
echo "Cleaning Procfile"
#cleanup procfile so that we can make the target app the tester proc
rm Procfile
touch Procfile
echo "tester: ${TARGET_APP_PATH}" >> Procfile

echo "Getting unprivileged api key from ${UNPRIVILEGED_USER}"
#someday we get to use oauth tokens instead of this hack
UNPRIVILEGED_HEROKU_API_KEY=$(heroku sudo user:info -x \
--user ${UNPRIVILEGED_USER} \
| awk '/Api Key:/ {print $3;}' \
| head -1)
echo "Cleaning up old deploy of $APP"

heroku sudo --user ${UNPRIVILEGED_USER} apps:delete $APP --confirm $APP


heroku apps:create $APP
heroku manager:transfer --to $ORG --app ${APP}
heroku config:set --app ${APP} \
APP=$APP \
HEROKU_API_KEY=$UNPRIVILEGED_HEROKU_API_KEY \
APP_PREFIX=ferret-$(whoami) \
ORG=$ORG
heroku build -b https://github.com/nzoschke/buildpack-ferret.git -r $APP
heroku scale tester=1 --app ${APP}
heroku drains:add --app ${APP} ${L2MET_URL}
6 changes: 2 additions & 4 deletions env.sample
@@ -1,4 +1,2 @@
APP=ferretapp
GMAIL_USER=heroku.ferret@gmail.com:deadbeef84c277fa
HEROKU_API_KEY=deadbeef87a9b10d49ab5036216c41b7f8cc3633
LIBRATO_API_URL=https://heroku.ferret%40gmail.com:deadbeef01baaa502bd80fcc1039ff6cd2eee2f6@metrics-api.librato.com/
APP_PREFIX=ferret-fode
ORG=ferret-dev

0 comments on commit 5e71cd5

Please sign in to comment.