better_fx 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 55b10acd6ff246c5c3079d2a7b758489b39bd724
4
+ data.tar.gz: e047c129bde742ccbb1912e3caac85ac5f9dbad1
5
+ SHA512:
6
+ metadata.gz: 8de14bee27628714f05d675d0686df71a9d7cfca13cee16ea0258bc9f61af0c4a3dd3252ff8fa747eebcf5d3fd517a3bcb8ce9134d79360440a039621ccd557f
7
+ data.tar.gz: d234b348ef4051e3c373f63f4a3ea25cd32fe4a8598bead1cb0f8fdbd5c4233349b49f3f43e85fca7139013e05b5ea7e95a041e0db01e8a1a5ba94347eb5add8
data/.gitignore ADDED
@@ -0,0 +1,39 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
37
+ .idea
38
+ .idea/
39
+ .idea/*
data/.rubocop.yml ADDED
@@ -0,0 +1,75 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ Lint/UselessAssignment:
4
+ Enabled: true
5
+
6
+ Lint/UnusedMethodArgument:
7
+ Enabled: true
8
+
9
+ Lint/UnusedBlockArgument:
10
+ Enabled: true
11
+
12
+ Metrics/AbcSize:
13
+ Exclude:
14
+ - spec/**/*
15
+
16
+ Style/DotPosition:
17
+ Enabled: true
18
+ EnforcedStyle: trailing
19
+
20
+ Style/PercentLiteralDelimiters:
21
+ PreferredDelimiters:
22
+ '%': () # interpolated String
23
+ '%i': '[]' # Array of symbols
24
+ '%q': () # Single quoted string
25
+ '%Q': () # Double quoted string
26
+ '%r': '{}' # Regex
27
+ '%s': () # Symbol
28
+ '%w': '[]' # Array of strings
29
+ '%W': '[]' # Array of strings, interpolated
30
+ '%x': () # shell command
31
+
32
+ Style/StringLiterals:
33
+ EnforcedStyle: double_quotes
34
+
35
+ Style/CollectionMethods:
36
+ Enabled: true
37
+ # Mapping from undesired method to desired_method
38
+ # e.g. use `detect` over `find`:
39
+ PreferredMethods:
40
+ find: 'detect'
41
+ find_all: 'select'
42
+
43
+ Style/AlignHash:
44
+ EnforcedHashRocketStyle: table
45
+ EnforcedColonStyle: table
46
+
47
+ Style/AndOr:
48
+ # Whether `and` and `or` are banned only in conditionals (conditionals)
49
+ # or completely (always).
50
+ EnforcedStyle: conditionals # and/or are sometimes used for flow control.
51
+
52
+ Style/BlockDelimiters:
53
+ EnforcedStyle: semantic
54
+
55
+ Style/HashSyntax:
56
+ EnforcedStyle: ruby19_no_mixed_keys
57
+
58
+ Style/NumericLiterals:
59
+ MinDigits: 5
60
+
61
+ Style/SpaceBeforeFirstArg:
62
+ Enabled: false
63
+
64
+ # Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
65
+ Style/TrailingCommaInLiteral:
66
+ EnforcedStyleForMultiline: comma
67
+
68
+ Style/SingleLineBlockParams:
69
+ Enabled: false
70
+
71
+ Style/EachWithObject:
72
+ Enabled: false
73
+
74
+ Style/Lambda:
75
+ Enabled: false
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,32 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-05-18 01:05:05 +0000 using RuboCop version 0.40.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ Metrics/AbcSize:
11
+ Max: 17
12
+
13
+ # Offense count: 23
14
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
15
+ # URISchemes: http, https
16
+ Metrics/LineLength:
17
+ Max: 173
18
+
19
+ # Offense count: 2
20
+ Style/Documentation:
21
+ Exclude:
22
+ - 'spec/**/*'
23
+ - 'test/**/*'
24
+ - 'lib/better_fx.rb'
25
+ - 'lib/better_fx/client.rb'
26
+
27
+ # Offense count: 1
28
+ # Cop supports --auto-correct.
29
+ # Configuration parameters: PreferredDelimiters.
30
+ Style/PercentLiteralDelimiters:
31
+ Exclude:
32
+ - 'better_fx.gemspec'
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # BetterFx
2
+ Making it _easier_ for you to quickly interact with SignalFx in an idiomatic fashion.
3
+
4
+ ## Usage
5
+
6
+ Usually you just want to indicate that something occurred
7
+
8
+ ```ruby
9
+ require "better_fx"
10
+ bfx = BetterFx::Client.new
11
+ # This will send the value 1 to the SignalFx counter metric named "beans"
12
+ #with the current unix timestamp and vanilla metadata dimensions
13
+ bfx.increment_counter :beans
14
+ ```
15
+
16
+ ## Configuration
17
+
18
+ To use BetterFx with the least amount of code, just set the environment variable
19
+ `SIGNALFX_API_TOKEN` equal to your token.
20
+
21
+ If you want to configure it imperatively then
22
+
23
+ ```ruby
24
+ require "better_fx"
25
+ BetterFx.configure do |c|
26
+ # The SignalFx api token you want to use when transmitting to SignalFx
27
+ c.signalfx_api_token = "ABCD12345"
28
+ # The list of environments for which you want to allow transmission of data to
29
+ # SignalFx (if the current environment is not in this list then transmissions are
30
+ # skipped).
31
+ # Defaults to `[:production, :prod, "production", "prod"]`
32
+ c.supported_environments = [:local, :prod]
33
+ # The current environment
34
+ # Defaults to `ENV["APP_ENV"] || :production`
35
+ c.current_environment = :local
36
+ end
37
+ ```
data/better_fx.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "better_fx"
3
+ s.version = "0.1.1"
4
+ s.license = "MIT"
5
+ s.date = "2016-05-17"
6
+ s.summary = "A more idiomatic interface to SignalFx."
7
+ s.description = "A convenient gem for developers to interact with SignalFx with a trivial amount of effort"
8
+ s.authors = ["Courtland Caldwell"]
9
+ s.email = "engineering@mattermark.com"
10
+ s.files = `git ls-files`.split("\n") - %w(Gemfile Gemfile.lock)
11
+ s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
12
+ s.homepage =
13
+ "https://github.com/Referly/better_fx"
14
+ s.add_runtime_dependency "signalfx", "~> 0.1" # Apache2 - @link https://github.com/signalfx/signalfx-ruby
15
+ s.add_development_dependency "rspec", "~> 3.2" # MIT - @link https://github.com/rspec/rspec/blob/master/License.txt
16
+ s.add_development_dependency "byebug", "~> 3.5" # BSD (content is BSD) https://github.com/deivid-rodriguez/byebug/blob/master/LICENSE
17
+ s.add_development_dependency "simplecov", "~> 0.10" # MIT - @link https://github.com/colszowka/simplecov/blob/master/MIT-LICENSE
18
+ s.add_development_dependency "rubocop", "~> 0.31" # Create Commons Attribution-NonCommerical https://github.com/bbatsov/rubocop/blob/master/LICENSE.txt
19
+ s.add_development_dependency "rspec_junit_formatter", "~> 0.2" # MIT https://github.com/sj26/rspec_junit_formatter/blob/master/LICENSE
20
+ end
data/circle.yml ADDED
@@ -0,0 +1,15 @@
1
+ machine:
2
+
3
+ timezone:
4
+ America/Los_Angeles # Set the timezone
5
+
6
+ # Version of ruby to use
7
+ ruby:
8
+ version:
9
+ 2.1.3
10
+
11
+ test:
12
+ override:
13
+ - bundle exec rubocop
14
+ - mkdir -p $CIRCLE_TEST_REPORTS/rspec
15
+ - bundle exec rspec --format RspecJunitFormatter --out $CIRCLE_TEST_REPORTS/rspec/rspec.xml spec --format progress
@@ -0,0 +1,38 @@
1
+ require "signalfx"
2
+ module BetterFx
3
+ class Client
4
+ def initialize
5
+ # if BetterFx has not been configured then run the default configuration
6
+ BetterFx.configure unless BetterFx.configured?
7
+ end
8
+
9
+ # Increment a SignalFx counter (if the current environment is a supports using SignalFx)
10
+ #
11
+ # @params counter_name [Symbol, String] the name of the counter to be incremented
12
+ # @params value [Fixnum] what the incremental amount should be (default of 1)
13
+ # @params timestamp [Fixnum, String] the timestamp, in milliseconds since the unix epoch (defaults to the timestamp
14
+ # on the host running your code)
15
+ # @params dimensions [Array<Hash>] the metadata dimensions to be associated with the counter
16
+ def increment_counter(counter_name, value: 1, timestamp: nil, dimensions: [])
17
+ return unless configuration.supported_environments.include? configuration.current_environment
18
+ timestamp ||= 1000 * Time.now.to_i
19
+ dimensions << { env: configuration.current_environment } if dimensions.empty?
20
+ signalfx_client.bf_xmit(counters: [
21
+ metric: counter_name.to_s,
22
+ value: value,
23
+ timestamp: timestamp.to_s,
24
+ dimensions: dimensions,
25
+ ])
26
+ end
27
+
28
+ private
29
+
30
+ def signalfx_client
31
+ SignalFx.new configuration.signalfx_api_token
32
+ end
33
+
34
+ def configuration
35
+ BetterFx.configuration
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,14 @@
1
+ module BetterFx
2
+ # Provides configuration management for the BetterFx gem
3
+ class Configuration
4
+ attr_accessor :signalfx_api_token,
5
+ :supported_environments,
6
+ :current_environment
7
+
8
+ def initialize
9
+ @signalfx_api_token = ENV["SIGNALFX_API_TOKEN"]
10
+ @supported_environments = [:production, :prod, "production", "prod"]
11
+ @current_environment = ENV["APP_ENV"] || :production
12
+ end
13
+ end
14
+ end
data/lib/better_fx.rb ADDED
@@ -0,0 +1,33 @@
1
+ require "signalfx"
2
+ # Monkey patch the SignalFxClient to alias the #send method to as #bf_xmit
3
+ SignalFxClient.send :alias_method, :bf_xmit, :send
4
+ require_relative "better_fx/configuration"
5
+ require_relative "better_fx/client"
6
+ module BetterFx
7
+ class << self
8
+ # Allows the user to set configuration options
9
+ # by yielding the configuration block
10
+ #
11
+ # @param opts [Hash] an optional hash of options, supported options are `reset: true`
12
+ # @return [Configuration] the current configuration object
13
+ def configure(opts = {})
14
+ @configuration = nil if opts.key?(:reset) && opts[:reset]
15
+ yield(configuration) if block_given?
16
+ configuration
17
+ end
18
+
19
+ # Returns the singleton class's configuration object
20
+ #
21
+ # @return [Configuration] the current configuration object
22
+ def configuration
23
+ @configuration ||= Configuration.new
24
+ end
25
+
26
+ # Returns true if BetterFx has been configured, false otherwise
27
+ #
28
+ # @return [Bool] true if BetterFx is configured, false otherwise
29
+ def configured?
30
+ !@configuration.nil?
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,79 @@
1
+ require "spec_helper"
2
+
3
+ describe BetterFx::Client do
4
+ subject { described_class.new }
5
+
6
+ describe "#increment_counter" do
7
+ let(:value) { 1 }
8
+ let(:timestamp) { 12_345 }
9
+ let(:dimensions) { [{ env: BetterFx.configuration.current_environment }] }
10
+ let(:mock_fx_client) { FxMocks::MockFxClient.new }
11
+
12
+ before do
13
+ allow(SignalFx).to receive(:new).and_return mock_fx_client
14
+ end
15
+
16
+ it "sends the default incremental value to SignalFx for the specified counter" do
17
+ expect(mock_fx_client).
18
+ to receive(:bf_xmit).
19
+ with(counters: [
20
+ hash_including(
21
+ metric: "sample_counter",
22
+ value: value
23
+ ),
24
+ ])
25
+
26
+ subject.increment_counter :sample_counter
27
+ end
28
+
29
+ describe "specifying the incremental value" do
30
+ let(:value) { 25 }
31
+ it "sends the user specified incremental value" do
32
+ expect(mock_fx_client).
33
+ to receive(:bf_xmit).
34
+ with(counters: [
35
+ hash_including(
36
+ metric: "sample_counter",
37
+ value: value
38
+ ),
39
+ ])
40
+
41
+ subject.increment_counter :sample_counter, value: 25
42
+ end
43
+ end
44
+
45
+ describe "specifying the timestamp" do
46
+ let(:timestamp) { 1111 }
47
+ it "sends the user specified timestamp as a string" do
48
+ expect(mock_fx_client).
49
+ to receive(:bf_xmit).
50
+ with(counters: [
51
+ hash_including(
52
+ metric: "sample_counter",
53
+ value: value,
54
+ timestamp: timestamp.to_s
55
+ ),
56
+ ])
57
+
58
+ subject.increment_counter :sample_counter, timestamp: timestamp
59
+ end
60
+ end
61
+
62
+ describe "specifying dimensional metadata" do
63
+ let(:dimensions) { [{ size: "Large" }] }
64
+ it "sends the user specified dimensional metadata" do
65
+ expect(mock_fx_client).
66
+ to receive(:bf_xmit).
67
+ with(counters: [
68
+ hash_including(
69
+ metric: "sample_counter",
70
+ value: value,
71
+ dimensions: dimensions
72
+ ),
73
+ ])
74
+
75
+ subject.increment_counter :sample_counter, dimensions: dimensions
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,77 @@
1
+ require "spec_helper"
2
+
3
+ describe BetterFx do
4
+ describe "configuring BetterFx" do
5
+ describe ".configure" do
6
+ it "yields an instance of BetterFx::Configuration to the provided configuration block" do
7
+ expect { |b| BetterFx.configure(&b) }.to yield_with_args BetterFx::Configuration
8
+ end
9
+ describe "configurable attributes" do
10
+ {
11
+ signalfx_api_token: "123sdfss",
12
+ supported_environments: [:production, :staging],
13
+ current_environment: :development,
14
+ }.each do |k, v|
15
+ describe k.to_s do
16
+ let(:key) { k }
17
+ let(:value) { v }
18
+
19
+ let(:configure_block) do
20
+ proc do |config|
21
+ config.send "#{key}=", value
22
+ end
23
+ end
24
+
25
+ it "is configurable" do
26
+ described_class.configure(&configure_block)
27
+
28
+ expect(described_class.configuration.public_send(k)).to eq v
29
+ end
30
+ end
31
+ end
32
+ end
33
+ it "allows the configuration to be reset" do
34
+ described_class.configure do |c|
35
+ c.signalfx_api_token = "original_api_token"
36
+ end
37
+ first_configuration = described_class.configuration
38
+
39
+ described_class.configure(reset: true) do |c|
40
+ c.current_environment = :staging
41
+ end
42
+
43
+ expect(described_class.configuration).not_to eq first_configuration
44
+ expect(described_class.configuration.signalfx_api_token).not_to eq "original_api_token"
45
+ expect(described_class.configuration.current_environment).to eq :staging
46
+ end
47
+ end
48
+ end
49
+
50
+ describe "accessing the current BetterFx configuration" do
51
+ describe ".configuration" do
52
+ context "when the BetterFx has been previously configured" do
53
+ before do
54
+ described_class.configure
55
+ end
56
+
57
+ it "is the current configuration of the BetterFx" do
58
+ expected_configuration = described_class.instance_variable_get :@configuration
59
+
60
+ expect(described_class.configuration).to eq expected_configuration
61
+ end
62
+ end
63
+
64
+ context "when the BetterFx has not been previously configured" do
65
+ it "sets the current configuration to a new instance of Configuration" do
66
+ described_class.configuration
67
+
68
+ expect(described_class.instance_variable_get(:@configuration)).to be_a BetterFx::Configuration
69
+ end
70
+
71
+ it "returns the new Configuration instance" do
72
+ expect(described_class.configuration).to eq described_class.instance_variable_get :@configuration
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,4 @@
1
+ require "simplecov"
2
+ SimpleCov.profiles.define "better_fx" do
3
+ add_filter "/spec"
4
+ end
@@ -0,0 +1,5 @@
1
+ require_relative "simplecov_custom_profile"
2
+ SimpleCov.start "better_fx"
3
+ require "better_fx"
4
+ require "byebug"
5
+ require_relative "support/mocks"
@@ -0,0 +1,6 @@
1
+ module FxMocks
2
+ class MockFxClient
3
+ def bf_xmit(opts = {})
4
+ end
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: better_fx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Courtland Caldwell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: signalfx
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.31'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.31'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec_junit_formatter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '0.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '0.2'
97
+ description: A convenient gem for developers to interact with SignalFx with a trivial
98
+ amount of effort
99
+ email: engineering@mattermark.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .rubocop.yml
106
+ - .rubocop_todo.yml
107
+ - README.md
108
+ - better_fx.gemspec
109
+ - circle.yml
110
+ - lib/better_fx.rb
111
+ - lib/better_fx/client.rb
112
+ - lib/better_fx/configuration.rb
113
+ - spec/better_fx/client_spec.rb
114
+ - spec/better_fx_spec.rb
115
+ - spec/simplecov_custom_profile.rb
116
+ - spec/spec_helper.rb
117
+ - spec/support/mocks.rb
118
+ homepage: https://github.com/Referly/better_fx
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.4.2
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: A more idiomatic interface to SignalFx.
142
+ test_files:
143
+ - spec/better_fx/client_spec.rb
144
+ - spec/better_fx_spec.rb
145
+ - spec/simplecov_custom_profile.rb
146
+ - spec/spec_helper.rb
147
+ - spec/support/mocks.rb
148
+ has_rdoc: