DEV: add frozen_string_literal

This helps avoid uneeded string allocations

Also:

- Add rubocop to travis
- Bump version
This commit is contained in:
Sam Saffron 2019-05-15 11:56:50 +10:00
parent e3c7820eb1
commit 5d6d777635
38 changed files with 82 additions and 6 deletions

View File

@ -7,3 +7,4 @@ rvm:
- 2.5
- 2.6
- jruby
script: bach -c "bundle exec rubocop && bundle exec rake"

View File

@ -1,3 +1,8 @@
0.4.11 - 15-05-2019
- Fix: Handle stopping nil worker_threads in Client
- Dev: add frozen string literals
0.4.10 - 29-04-2019
- Fix: Custom label support for puma collector

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
guard :minitest do
# with Minitest::Unit
watch(%r{^test/(.*)\/?(.*)_test\.rb$})

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "bundler/gem_tasks"
require "rake/testtask"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_relative '../lib/prometheus_exporter'
require_relative '../lib/prometheus_exporter/client'
require_relative '../lib/prometheus_exporter/server'

View File

@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'optparse'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class MyCustomCollector < PrometheusExporter::Server::Collector
def initialize
@gauge1 = PrometheusExporter::Metric::Gauge.new("thing1", "I am thing 1")

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_relative "prometheus_exporter/version"
require "json"
require "thread"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_relative "instrumentation/process"
require_relative "instrumentation/method_profiler"
require_relative "instrumentation/sidekiq"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module PrometheusExporter::Instrumentation
class DelayedJob
JOB_CLASS_REGEXP = %r{job_class: (\w+:{0,2})+}.freeze

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# see https://samsaffron.com/archive/2017/10/18/fastest-way-to-profile-a-method-in-ruby
module PrometheusExporter::Instrumentation; end

View File

@ -1,4 +1,6 @@
require 'json'
# frozen_string_literal: true
require "json"
# collects stats from puma
module PrometheusExporter::Instrumentation
@ -30,7 +32,7 @@ module PrometheusExporter::Instrumentation
def collect_puma_stats(metric)
stats = JSON.parse(::Puma.stats)
if stats.key? 'workers'
if stats.key?("workers")
metric[:phase] = stats["phase"]
metric[:workers_total] = stats["workers"]
metric[:booted_workers_total] = stats["booted_workers"]

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
begin
require 'raindrops'
rescue LoadError

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_relative "metric/base"
require_relative "metric/counter"
require_relative "metric/gauge"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_relative "metric"
require_relative "server/type_collector"
require_relative "server/web_collector"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module PrometheusExporter::Server
# minimal interface to implement a customer collector

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module PrometheusExporter::Server
class DelayedJobCollector < TypeCollector

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module PrometheusExporter::Server
class HutchCollector < TypeCollector

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module PrometheusExporter::Server
class PumaCollector < TypeCollector
PUMA_GAUGES = {

View File

@ -1,10 +1,11 @@
# frozen_string_literal: true
require 'prometheus_exporter/client'
require_relative '../instrumentation/unicorn'
module PrometheusExporter::Server
class RunnerException < StandardError; end;
class WrongInheritance < RunnerException; end;
class RunnerException < StandardError; end
class WrongInheritance < RunnerException; end
class Runner
def initialize(options = {})

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module PrometheusExporter::Server
class SidekiqCollector < TypeCollector

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module PrometheusExporter::Server
class TypeCollector
def type

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module PrometheusExporter
VERSION = "0.4.10"
VERSION = "0.4.11"
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class CustomTypeCollector < PrometheusExporter::Server::TypeCollector
def type
"custom1"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'test_helper'
require 'prometheus_exporter/metric'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'test_helper'
require 'prometheus_exporter/metric'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'test_helper'
require 'prometheus_exporter/metric'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'test_helper'
require 'prometheus_exporter/metric'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'test_helper'
require 'prometheus_exporter/metric'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "test_helper"
require 'rack/test'
require 'prometheus_exporter/middleware'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "test_helper"
class PrometheusExporterTest < Minitest::Test

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'test_helper'
require 'mini_racer'
require 'prometheus_exporter/server'
@ -283,7 +285,7 @@ class PrometheusCollectorTest < Minitest::Test
def test_it_can_collect_puma_metrics
collector = PrometheusExporter::Server::Collector.new
client = PipedClient.new(collector, custom_labels: { service: 'service1' } )
client = PipedClient.new(collector, custom_labels: { service: 'service1' })
mock_puma = Minitest::Mock.new
mock_puma.expect(

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'test_helper'
require 'prometheus_exporter/server'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'test_helper'
require 'mini_racer'
require 'prometheus_exporter/server'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'test_helper'
require 'mini_racer'
require 'prometheus_exporter/server'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'test_helper'
require 'prometheus_exporter/server'
require 'prometheus_exporter/client'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
require "prometheus_exporter"