From e5181702ba234cd89f6d6f9bc0364748d701cb7d Mon Sep 17 00:00:00 2001 From: Dmitry Salahutdinov Date: Tue, 17 Mar 2020 10:10:52 +0500 Subject: [PATCH] Make up --- Gemfile | 16 +++++++++++----- Rakefile | 11 ++++++++--- bin/console | 7 ++++--- lib/yabeda/http.rb | 10 +++++++--- lib/yabeda/http/sniffer.rb | 3 +++ lib/yabeda/http/version.rb | 4 +++- spec/spec_helper.rb | 9 ++++++--- spec/yabeda/http_spec.rb | 24 +++++++++++++++++++++--- yabeda-http.gemspec | 36 ++++++++++++++++++++---------------- 9 files changed, 83 insertions(+), 37 deletions(-) diff --git a/Gemfile b/Gemfile index e50a5ad..60ac2bc 100644 --- a/Gemfile +++ b/Gemfile @@ -1,9 +1,15 @@ -source "https://rubygems.org" +# frozen_string_literal: true + +source 'https://rubygems.org' gemspec -gem "rake", "~> 12.0" -gem "rspec", "~> 3.0" -gem 'sniffer', git: 'https://github.com/dsalahutdinov/sniffer', branch: 'feature/middleware' +gem 'rake', '~> 12.0' +gem 'rspec', '~> 3.0' +gem 'rubocop' + gem 'byebug' -gem 'faraday' +gem 'faraday', require: false +gem 'sniffer', + git: 'https://github.com/dsalahutdinov/sniffer', + branch: 'feature/middleware' diff --git a/Rakefile b/Rakefile index b7e9ed5..8cf332b 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,11 @@ -require "bundler/gem_tasks" -require "rspec/core/rake_task" +# frozen_string_literal: true + +require 'bundler/gem_tasks' +require 'rspec/core/rake_task' +require 'rubocop/rake_task' + +RuboCop::RakeTask.new RSpec::Core::RakeTask.new(:spec) -task :default => :spec +task default: %i[rubocop spec] diff --git a/bin/console b/bin/console index 7e86574..638c9af 100755 --- a/bin/console +++ b/bin/console @@ -1,7 +1,8 @@ #!/usr/bin/env ruby +# frozen_string_literal: true -require "bundler/setup" -require "yabeda/http" +require 'bundler/setup' +require 'yabeda/http' # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. @@ -10,5 +11,5 @@ require "yabeda/http" # require "pry" # Pry.start -require "irb" +require 'irb' IRB.start(__FILE__) diff --git a/lib/yabeda/http.rb b/lib/yabeda/http.rb index cb27a13..b45223b 100644 --- a/lib/yabeda/http.rb +++ b/lib/yabeda/http.rb @@ -1,16 +1,20 @@ -require "yabeda/http/version" +# frozen_string_literal: true + +require 'yabeda/http/version' require 'yabeda/http/sniffer' -require "yabeda" +require 'yabeda' require 'sniffer' require 'byebug' module Yabeda + # Common module module Http Yabeda.configure do group :http counter :requests_total, - comment: "A counter of the total number of external HTTP requests.", + comment: 'A counter of the total number of external HTTP \ + requests.', tags: %i[host] ::Sniffer.config do |c| diff --git a/lib/yabeda/http/sniffer.rb b/lib/yabeda/http/sniffer.rb index 2ac0126..c7bf79b 100644 --- a/lib/yabeda/http/sniffer.rb +++ b/lib/yabeda/http/sniffer.rb @@ -1,5 +1,8 @@ +# frozen_string_literal: true + module Yabeda module Http + # Middleware for sniffer gem class Sniffer def call(data_item) Yabeda.http_requests_total.increment( diff --git a/lib/yabeda/http/version.rb b/lib/yabeda/http/version.rb index feb403f..a03d659 100644 --- a/lib/yabeda/http/version.rb +++ b/lib/yabeda/http/version.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + module Yabeda module Http - VERSION = "0.1.0" + VERSION = '0.1.0' end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 407ffa9..c01223e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,9 +1,12 @@ -require "bundler/setup" -require "yabeda/http" +# frozen_string_literal: true + +require 'bundler/setup' +require 'yabeda/http' +require 'faraday' RSpec.configure do |config| # Enable flags like --only-failures and --next-failure - config.example_status_persistence_file_path = ".rspec_status" + config.example_status_persistence_file_path = '.rspec_status' # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_patching! diff --git a/spec/yabeda/http_spec.rb b/spec/yabeda/http_spec.rb index 8dc4308..8094599 100644 --- a/spec/yabeda/http_spec.rb +++ b/spec/yabeda/http_spec.rb @@ -1,9 +1,27 @@ +# frozen_string_literal: true + RSpec.describe Yabeda::Http do - it "has a version number" do + it 'has a version number' do expect(Yabeda::Http::VERSION).not_to be nil end - it "does something useful" do - expect(false).to eq(true) + context 'sdf' do + before do + Yabeda.configure! + Faraday.get 'http://sushi.com/nigiri/sake.json' + end + + it do + expect(Yabeda.http_requests_total.values).to( + eq( + { + host: 'sushi.com', + method: 'GET', + port: 80, + query: '/nigiri/sake.json' + } => 1 + ) + ) + end end end diff --git a/yabeda-http.gemspec b/yabeda-http.gemspec index 57dfc17..6fd234e 100644 --- a/yabeda-http.gemspec +++ b/yabeda-http.gemspec @@ -1,27 +1,31 @@ +# frozen_string_literal: true + require_relative 'lib/yabeda/http/version' Gem::Specification.new do |spec| - spec.name = "yabeda-http" + spec.name = 'yabeda-http' spec.version = Yabeda::Http::VERSION - spec.authors = ["Dmitry Salahutdinov"] - spec.email = ["dsalahutdinov@gmail.com"] + spec.authors = ['Dmitry Salahutdinov'] + spec.email = ['dsalahutdinov@gmail.com'] - spec.summary = %q{Monitoring of external services http/https calls} - spec.description = %q{Extends Yabeda metrics to collect external calls} - spec.homepage = "https://github.com/yabeda-rb/yabeda-http" - spec.license = "MIT" - spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0") + spec.summary = 'Monitoring of external services http/https calls' + spec.description = 'Extends Yabeda metrics to collect external calls' + spec.homepage = 'https://github.com/yabeda-rb/yabeda-http' + spec.license = 'MIT' + spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0') - spec.metadata["homepage_uri"] = spec.homepage - spec.metadata["source_code_uri"] = "https://github.com/yabeda-rb/yabeda-http" + spec.metadata['homepage_uri'] = spec.homepage + spec.metadata['source_code_uri'] = 'https://github.com/yabeda-rb/yabeda-http' - spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do - `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } + spec.files = Dir.chdir(File.expand_path(__dir__)) do + `git ls-files -z`.split("\x0").reject do |f| + f.match(%r{^(test|spec|features)/}) + end end - spec.bindir = "exe" + spec.bindir = 'exe' spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } - spec.require_paths = ["lib"] + spec.require_paths = ['lib'] - spec.add_runtime_dependency "yabeda" - spec.add_runtime_dependency "sniffer" + spec.add_runtime_dependency 'sniffer' + spec.add_runtime_dependency 'yabeda' end