grape-librato 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +10 -0
- data/LICENSE +22 -0
- data/README.md +66 -0
- data/Rakefile +20 -0
- data/grape-librato.gemspec +22 -0
- data/lib/grape-librato.rb +2 -0
- data/lib/grape-librato/middleware.rb +20 -0
- data/lib/grape-librato/version.rb +5 -0
- data/spec/grape-librato/middleware_spec.rb +26 -0
- data/spec/grape-librato/version_spec.rb +7 -0
- data/spec/spec_helper.rb +11 -0
- metadata +95 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012-2013 Richard Huang, Sean Moon
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Libarto::Grape
|
2
|
+
|
3
|
+
Librato tracking for [Grape][0], based on code from [this NewRelic
|
4
|
+
gem][1], using [librato-rack][2]
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'grape-librato'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install grape-librato
|
19
|
+
|
20
|
+
Include it in your Grape API like this
|
21
|
+
|
22
|
+
class TestAPI < Grape::API
|
23
|
+
use Librato::Grape::Middleware
|
24
|
+
|
25
|
+
get 'hello' do
|
26
|
+
"Hello World"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
*Make sure you are also using the librato-rack middleware*
|
31
|
+
|
32
|
+
Here's an example `config.ru`
|
33
|
+
|
34
|
+
require 'grape'
|
35
|
+
require 'librato-rack'
|
36
|
+
require 'grape-librato'
|
37
|
+
|
38
|
+
LIBRATO_CONFIGURATION = Librato::Rack::Configuration.new
|
39
|
+
LIBRATO_CONFIGURATION.user = ENV['LIBRATO_USER']
|
40
|
+
LIBRATO_CONFIGURATION.token = ENV['LIBRATO_TOKEN']
|
41
|
+
LIBRATO_CONFIGURATION.source = ENV['LIBRATO_SOURCE'] || 'localhost'
|
42
|
+
|
43
|
+
class API < Grape::API
|
44
|
+
use Librato::Grape::Middleware
|
45
|
+
get 'hello' do
|
46
|
+
"Hello World"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
use Librato::Rack, config: LIBRATO_CONFIGURATION
|
51
|
+
run API
|
52
|
+
|
53
|
+
See how to set up the `Librato::Rack` object in the [librato-rack][2]
|
54
|
+
documentation.
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
1. Fork it
|
59
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
60
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
61
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
62
|
+
5. Make a pull request
|
63
|
+
|
64
|
+
[0]: https://github.com/intridea/grape
|
65
|
+
[1]: https://github.com/flyerhzm/newrelic-grape
|
66
|
+
[2]: https://github.com/librato/librato-rack
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'rake'
|
12
|
+
|
13
|
+
require 'rspec/core'
|
14
|
+
require 'rspec/core/rake_task'
|
15
|
+
|
16
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
17
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
18
|
+
end
|
19
|
+
|
20
|
+
task :default => :spec
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'grape-librato/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "grape-librato"
|
8
|
+
gem.version = Librato::Grape::VERSION
|
9
|
+
gem.authors = ["Sean Moon"]
|
10
|
+
gem.email = ["ssamoon@ucla.edu"]
|
11
|
+
gem.description = %q{librato metrics for grape}
|
12
|
+
gem.summary = %q{librato metrics for grape}
|
13
|
+
gem.homepage = "https://github.com/seanmoon/grape-librato"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(spec)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency(%q<grape>)
|
21
|
+
gem.add_runtime_dependency(%q<librato-rack>)
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'grape'
|
2
|
+
require 'librato-rack'
|
3
|
+
|
4
|
+
module Librato
|
5
|
+
module Grape
|
6
|
+
class Middleware < ::Grape::Middleware::Base
|
7
|
+
def initialize(app)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
req = ::Rack::Request.new(env)
|
13
|
+
request_path = env['api.endpoint'].routes.first.route_path[1..-1].gsub("/", ".").sub(/\(\.:format\)\z/, "")
|
14
|
+
Librato.timing "#{req.request_method}.#{request_path}" do
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Librato::Grape::Middleware do
|
4
|
+
|
5
|
+
class TestAPI < Grape::API
|
6
|
+
use Librato::Grape::Middleware
|
7
|
+
get 'hello' do
|
8
|
+
"Hello World"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
subject { TestAPI }
|
13
|
+
|
14
|
+
def app
|
15
|
+
subject
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should send a timing event for each request" do
|
19
|
+
Librato.should_receive(:timing).and_yield
|
20
|
+
get "/hello"
|
21
|
+
last_response.status.should == 200
|
22
|
+
last_response.body.should == "Hello World"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: grape-librato
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sean Moon
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: grape
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: librato-rack
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: librato metrics for grape
|
47
|
+
email:
|
48
|
+
- ssamoon@ucla.edu
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- .rspec
|
55
|
+
- CHANGELOG.md
|
56
|
+
- Gemfile
|
57
|
+
- LICENSE
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- grape-librato.gemspec
|
61
|
+
- lib/grape-librato.rb
|
62
|
+
- lib/grape-librato/middleware.rb
|
63
|
+
- lib/grape-librato/version.rb
|
64
|
+
- spec/grape-librato/middleware_spec.rb
|
65
|
+
- spec/grape-librato/version_spec.rb
|
66
|
+
- spec/spec_helper.rb
|
67
|
+
homepage: https://github.com/seanmoon/grape-librato
|
68
|
+
licenses: []
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.8.25
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: librato metrics for grape
|
91
|
+
test_files:
|
92
|
+
- spec/grape-librato/middleware_spec.rb
|
93
|
+
- spec/grape-librato/version_spec.rb
|
94
|
+
- spec/spec_helper.rb
|
95
|
+
has_rdoc:
|