continuous (production) integration: ruby on rails application monitoring with cucumber

81
Feature: Ruby on Rails Application Monitoring with Cucumber In order to ensure continuous application availability A developer should be able to assert the behavior of production apps From the outside in Without using antiquated monitoring tools To protect revenue

Upload: jnewland

Post on 28-Jan-2015

113 views

Category:

Technology


0 download

DESCRIPTION

Feature: Ruby on Rails Application Monitoring with Cucumber 
 In order to ensure continuous application availability
 A developer should be able to assert the behavior of production apps
 From the outside in
 Without using antiquated monitoring tools 
 To protect revenue

TRANSCRIPT

Page 1: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Feature: Ruby on Rails Application Monitoring with Cucumber

In order to ensure continuous application availability A developer should be able to assert the behavior of production apps From the outside in Without using antiquated monitoring tools To protect revenue

Page 2: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

VP of Research & Developmentrailsmachine.com

[email protected]@jnewland

github.com/jnewland

About me:

I get to hack on Ruby tools to manage large Rails deployments all day long. Not a bad job, eh?

Page 3: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Before we get into monitoring or cucumber, let’s talk about testing.

In my career as a dev, my testing habits have evolved over time, largely inspired by available tools.

I’m sure some of you have shared a similar journey - let’s take a quick look back.

Page 4: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

NomoreclickingaroundSave in your editor / refresh in your browser / lather / rinse repeat.

Occasional human preformed quality assurance

Broken by design

Page 5: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

I then made the jump to unit testing using Ruby’s Test::Unit - specifically the generated Model and Controller tests Rails generated.

This was nice, but it was often devalued by stakeholders due to poor communication of the business value of this work on my part.

Page 6: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

R

Enter Rspec and the BDD movement.

Rspec helped me, and I’m sure a lot of others, associate the business value with writing tests / specs.

Stakeholder-digestable code if you’re really good, stakeholder-digestable output if you’re doing things right.

Page 7: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

CUCUMBER

Basically, BDD nirvana. Stakeholder-*writable* if you’re crazy.

Page 8: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.For those of you that aren’t familiar with Cuke

Page 9: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

TATFT!The most important part of the evolution of these tools is that they make it easy and - legitimately - fun to test first and test all of the time as you’re developing your application.

Page 10: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

ProductionMonitoring

But what about production? We’re testing all the time in development, while we’re developing the that’s going to create revenue. But in production...

Page 11: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

RevenuePreservation

...there’s actually revenue being earned. Why not test with the same veracity in production?

Page 12: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

CurrentMonitoringLandscape

Quiz:

* Raise your hand if you are at least partially responsible for the continuous operation of a business critical production rails app* If you have ZERO monitoring of the site’s uptime - meaning your customers or boss would be the one to tell you that the homepage was down - put your hand down* If your monitoring solution runs on your server itself - monit or god, for example - put your hand down* If your external monitoring solution only hits one URL on the site, put your hand down

Some sites are monitored very closely, but I’ve found that in most cases, the monitoring of many production apps is rather slim.

I generally evaluate monitoring solutions on two axes:

Page 13: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

What’s being monitored - what URLs, metrics, system statistics, etc are being watched

Page 14: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

How closely areyou lookingatit?We’ll call this one the crazy monkey test - How frequently these URLs / metrics are being queried, what values are acceptable, etc.

Page 15: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

It seems that in many situations, the home page of an application is the only thing checked closely

Page 16: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

The crazy monkey has laser focus

Page 17: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

but if the crazy monkey is that focused

Page 18: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber
Page 19: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Bad things can happen when he’s not looking.

For example, in Rails apps, I see this happen all the time with...

Page 20: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Search is a part of many applications that I’ve seen go unmonitored. I’m not singling out sphinx here - this is just a sweet picture - the same thing happens to Solr, etc

Page 21: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Search can fail when the rest of a site works fine due to many reasons:

* search daemon may go down* the indicies may be corrupt* or things may fail in a more interesting kind of way...

Page 22: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

0 results for “beer”

Wherein no results are returned when they obviously should be.

Page 23: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

TATFT?So are we really testing all the time?

Page 24: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

TATFT**except in production

It doesn’t seem so

Page 25: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

_why?

But why? Why are we testing so....ferociously in development, but so weakly in production?

Page 26: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

OldBroken

ToolsI’m largely convinced it’s because the tools that are presented to us for use in the monitoring space are largely old and broken.

Page 27: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

How many of your recognize this? Oh, nagios.

Page 28: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

It’s the industry standard tool for infra monitoring. I haven’t met a single person that’s used nagios that’s been an honest fan. The most widely despised part of nagios

Page 29: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

is the noise. Unless masterly configured, Nagios is a noisy beast. This leads to “boy cries wolf” type scenarios, wherein alerts are improperly categorized as noise and discarded.

Page 30: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

EVIL

Because of the noise, and the piece of crap interface, esoteric configuration language, and for years and years of waking me up for false positives, I’m going to paint this all in black and white and just call nagios evil.

Page 31: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Pingdom’s a relatively new tool that’s gained a good bit of traction. It’s a hosted monitoring service, that can test HTTP and many other types of services from a network of computers around the world.

Page 32: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

✔Nagios and pingdom pass the crazy monkey intense focus test

Page 33: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

but in their default configuration generally only monitor a snapshot of what’s neccessary.

Page 34: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

A recent entry into the space that’s doesn’t get a quick EVIL stamp from me is watchmouse

Page 35: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Twitter uses watchmouse to provide a public API status page, hitting many different API endpoints and watching for outages and service problems

Page 36: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Twitter’s use of Watchmouse passes the “what are you looking at test”

Page 37: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

BusinessValueDisconnect

However, one thing that all of these tools are missing is a clear link between the business value of the things they’re checking and the alerts they’re sending out

Page 38: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Hey, I know something that does that well!

Page 39: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.Cucumber’s served well for me in my experience in bringing stakeholders and developers together.

Page 40: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid - all rolled into one format.But with a couple quick edits

Page 41: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Cucumber also lets operations teams describe how infrastructure should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, monitoring and deployment-aid - all rolled into one format.We have a tool that can help us bring together developers, operations, *and* stakeholders

Page 42: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

#devops

Some of you following the twitterz may have noticed some people in the ops and development space talking about the ‘devops movement’

Page 43: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

devs

ops

working togetherWhile calling this a movement is pretty wild - a hashtag does not a movement make - the ideas surrounding this ‘movement’ are things that I believe in personally, and things we’re working on everyday at Rails Machine - blurring the line between development and ops, and the line between the infrastructure and the application.

Page 44: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Cucumber also lets #devops teams describe how applications should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, monitoring and deployment-aid - all rolled into one format.Using cucumber in production embodies everything that is devops, and can blur those lines even more

Page 45: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

kumbaya

And thus result in a big happy #devops family

Page 46: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

ExampleProductionCucumberFeatures

Page 47: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Benchmarking

Page 48: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Feature: slashdot.com To keep the geek masses satisfied Slashdot must be responsive Scenario: Cached pages are super quick Given I am benchmarking When I go to http://slashdot.org/ Then the elapsed time should be less than 500 milliseconds When I follow "Login" Then the elapsed time should be less than 500 milliseconds When I follow "Contact" Then the elapsed time should be less than 500 milliseconds

Page 49: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Email Deliverability

Page 50: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Feature: Signup Emails In order to prevent bots from taking over the site A new user should receive a verification email upon signup

Scenario: New User signup Given I visit "http://example.com" And I follow "Signup!" When I signup with a random email address and password And I press "Go" And I wait 10 seconds # an unfortunate reality Then I should have one email in my inbox And the email subject should match "^Welcome" And the email body should match "http:\/\/example.com\/v\/\w+"

https://github.com/technicalpickles/mailinator-spec

Page 51: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

ExistingMetrics

Page 52: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Feature: Response Time As a impatient user Our web server should be in tip-top shape So our app can be super fast

Background: Given my Scout account name is 'railsmachine' And my Scout email and password are '[email protected]' and 'sekret'

Scenario: Passenger Queue When I get the metrics from the 'Passenger' plugin on 'example.com' Then the 'passenger_queue_depth' should be 0

Scenatiro: CPU usage is low When I get the metrics from the 'Server Overview' plugin on 'example.com' Then 'cpu_last_minute' should be less than 1

http://github.com/jnewland/cucumber-scout/

Page 53: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Feature: Response Time As a impatient user Our app should be super fast

Background: Given my NewRelic license key is 'omgwtfbbq'

Scenario: Average Response time Given that my application is being monitored by New Relic Then my application's 'response time' should be less than 500 milliseconds

Scenario: Apdex Given that my application is being monitored by New Relic Then my application's 'apdex' should be 1

http://github.com/jnewland/cucumber-newrelic

Page 54: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

SEO

Page 55: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Feature: Cucumber wiki discoverability In order to learn more about Cucumber As an uninformed developer I should be able easily find the GitHub wiki

Scenario: Searching for Cucumber on Google When I go to http://www.google.com/ And I fill in "q" with "cucumber" And I press "Google Search" Then I should see "BDD that talks to domain experts first and code second"

Page 56: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Security

Page 57: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Feature: example.org ssh logins As a user of example.org I need to login remotely

Scenario: Login with a key Given I have the following public keys: | keyfile | | /home/jnewland/.ssh/id_dsa | Then I can ssh to the following hosts with these credentials: | hostname | username | | example.org | jnewland | | mail.example.org | jnewland |

Scenario: Checking /etc/passwd When I ssh to "example.org" with the following credentials: | username | password | keyfile | | jnewland | | /home/jnewland/.ssh/id_dsa | And I run "cat /etc/passwd" Then I should see "jnewland" in the output And I should not see "that_dude_we_just_fired" in the output

http://github.com/auxesis/cucumber-nagios

Page 58: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Infrastructure

Page 59: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Feature: RAID To ensure optimal server operation And guarantee data is stored redundantly The RAID array should be in a good state

Scenario: RAID Array status When I check the raid array status Then controller "1" should have a status of "optimal" And controller "2" should have a status of "optimal" And controller "1" should have "1" logical device with a status of "optimal" And controller "1" should have "4" drives in "online" state And controller "2" should have "1" logical device with a status of "optimal" And controller "2" should have "4" drives in "online" state

http://github.com/auxesis/cucumber-nagios

Page 60: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

DNS

Page 61: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Feature: rubygems.org As a member of the Ruby community I should be able to easily install Ruby gems

Scenario: DNS When I lookup "rubygems.org" Then the name should resolve an IP

http://github.com/auxesis/cucumber-nagios

Page 62: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Possibilities

Page 63: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

CreditCardTransactions

Page 64: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

SSL

Page 65: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

ExceptionRate

Page 66: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Runningfeatures

in production

Page 67: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

$ gem install cucumber-json cucumber-newrelic \ cucumber-scout cucumber-nagios$ cd RAILS_ROOT$ mkdir -p production_features/step_definitions$ mkdir -p production_features/support$ vi config/cucumber.yml

production: production_features -f Cucumber::Formatter::JSON --out tmp/cuke.json

$ vi production_features/support/env.rb

require 'cucumber/nagios/steps'require 'cucumber/newrelic'require 'cucumber/scout'# etc

$ # hack on features$ cucumber -p production # doesn’t load the Rails env, just the defined steps$ # profit!

Sorta Quick Setup Generatorcomingsoon!

Page 68: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber
Page 69: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Cucumber Scout Plugin

Page 71: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Cucumber Scout Plugin

Page 72: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Cucumber Scout PluginZOMG!

Page 73: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Cucumber Scout Plugin

Sent via email

Page 74: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Powertomonitoranythingandeverything

Page 75: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

ClearlyDefinedBusinessValue

Page 76: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

IN

RUBY

Page 77: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

24/7/365

Page 78: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Know before your customers do

Page 79: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Thanks!Any questions?

Page 80: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Get in touch:

Jesse [email protected]

@jnewlandgithub.com/jnewland

Page 81: Continuous (Production) Integration: Ruby on Rails Application Monitoring with Cucumber

Flickr Creative Commons Photos

http://flic.kr/p/4EjsDJhttp://flic.kr/p/c1UTfhttp://flic.kr/p/5BGJMuhttp://flic.kr/p/5iTuuahttp://flic.kr/p/77oAy2http://flic.kr/p/CdYo8http://flic.kr/p/k2LCmhttp://flic.kr/p/71vxY6http://flic.kr/p/5aZYkPhttp://flic.kr/p/79ikH2http://flic.kr/p/6rhqadhttp://flic.kr/p/4MdrW8http://flic.kr/p/5WuXzMhttp://flic.kr/p/3jzrJhttp://flic.kr/p/5B4TaFhttp://flic.kr/p/4FAf2Rhttp://flic.kr/p/39poLPhttp://flic.kr/p/6nq52Ehttp://flic.kr/p/yQuMGhttp://flic.kr/p/jZ5Aehttp://flic.kr/p/4yhzz

http://flic.kr/p/nxAqthttp://flic.kr/p/4VWY5Fhttp://flic.kr/p/EKbuFhttp://flic.kr/p/5xitHhhttp://flic.kr/p/4uE9Wzhttp://flic.kr/p/65KZaJhttp://flic.kr/p/7JKj5Hhttp://flic.kr/p/79HLb5http://flic.kr/p/xiYnyhttp://flic.kr/p/68vjKVhttp://flic.kr/p/rvc1http://flic.kr/p/6y7EfXhttp://flic.kr/p/2Mxkhphttp://flic.kr/p/5t7h5http://flic.kr/p/29qc7http://flic.kr/p/JBajhttp://flic.kr/p/smfabhttp://flic.kr/p/4t5Qf9http://flic.kr/p/M8kdvhttp://flic.kr/p/z3eWmhttp://flic.kr/p/4XAQs7