Commit e1e8c7a4 authored by Pablo Carranza's avatar Pablo Carranza

Rubocop auto correct pass

parent af76f6af
#!/usr/bin/env ruby
require "optparse"
require "gitlab_monitor"
......
......@@ -35,18 +35,18 @@ module GitLab
def run
validate!
::GitLab::Monitor::GitProber.new(self).
probe_pull.
probe_push.
write_to(@target)
::GitLab::Monitor::GitProber.new(self)
.probe_pull
.probe_push
.write_to(@target)
end
def options(args)
args.options do |opts|
opts.banner = "Usage: #{EXECUTABLE_NAME} #{COMMAND_NAME} [options] repository_path [target_file]"
opts.on("-l", "--labels=key=value,key2=value2", "Labels to append to the metrics") { |val|
@labels = val.split(",").map{|value| value.split("=").tap{|aa| aa[0] = aa[0].to_sym} }.to_h
}
opts.on("-l", "--labels=key=value,key2=value2", "Labels to append to the metrics") do |val|
@labels = val.split(",").map { |value| value.split("=").tap { |aa| aa[0] = aa[0].to_sym } }.to_h
end
opts
end
end
......@@ -62,7 +62,7 @@ module GitLab
end
def self.commands
[GIT].inject({}) do |commands, command_class|
[GIT].each_with_object({}) do |command_class, commands|
commands[command_class::COMMAND_NAME] = command_class
commands
end
......
......@@ -18,7 +18,7 @@ module GitLab
@tracker.track { execute "git push -q" }
end
def empty_commit(message="Beep")
def empty_commit(message = "Beep")
@tracker.track { execute("git commit --allow-empty -m '#{message}'") }
end
......
......@@ -6,18 +6,18 @@ module GitLab
end
def add(name, value, **labels)
@metrics[name] = { value: value, labels: labels, timestamp: (Time.now.to_f * 1000).to_i}
@metrics[name] = { value: value, labels: labels, timestamp: (Time.now.to_f * 1000).to_i }
self
end
def to_s
buffer = StringIO.new
@metrics.each { |name, metrics|
@metrics.each do |name, metrics|
buffer.write(name.to_s)
labels = (metrics[:labels] || {}).map { |label, value| "#{label}=\"#{value}\"" }.join(",")
buffer.write("{#{labels}}") unless labels.empty?
buffer.write(" #{metrics[:value]} #{metrics[:timestamp]}\n")
}
end
buffer.rewind
buffer.read
end
......
......@@ -15,4 +15,3 @@ module GitLab
end
end
end
module GitLab
module Monitor
VERSION = "0.0.1"
VERSION = "0.0.1".freeze
end
end
......@@ -7,18 +7,17 @@ context "An invalid repository" do
it "fails with an invalid repository" do
repo = Dir.mktmpdir
Dir.rmdir(repo)
expect{GitLab::Monitor::Git.new(repo)}.to raise_error(/Repository #{repo} does not exists/)
expect { GitLab::Monitor::Git.new(repo) }.to raise_error(/Repository #{repo} does not exists/)
end
end
end
GitProberOptions = Struct.new(:source, :labels)
context "With valid pair of repositories" do
let (:repos) { GitRepoBuilder.new }
after { repos.cleanup }
after do repos.cleanup end
describe GitLab::Monitor::Git do
it "builds with a repo folder" do
......@@ -26,11 +25,11 @@ context "With valid pair of repositories" do
end
it "pulls correctly" do
expect(GitLab::Monitor::Git.new(repos.cloned_repo).pull.time).to satisfy {|v| v >= 0}
expect(GitLab::Monitor::Git.new(repos.cloned_repo).pull.time).to satisfy { |v| v >= 0 }
end
it "pushes correctly" do
expect(GitLab::Monitor::Git.new(repos.cloned_repo).push.time).to satisfy {|v| v >= 0}
expect(GitLab::Monitor::Git.new(repos.cloned_repo).push.time).to satisfy { |v| v >= 0 }
end
end
......@@ -74,4 +73,3 @@ context "With valid pair of repositories" do
end
end
end
......@@ -11,6 +11,7 @@ describe GitLab::Monitor::PrometheusMetrics do
it "supports metrics with many labels" do
expect(subject.add("mymetric", 1.3, mylabel: "x", myotherlabel: "y").to_s).to match(
/mymetric{mylabel="x",myotherlabel="y"} 1.3 \d*$/)
/mymetric{mylabel="x",myotherlabel="y"} 1.3 \d*$/
)
end
end
......@@ -2,6 +2,6 @@ require "spec_helper"
describe GitLab::Monitor::TimeTracker do
it "tracks execution time" do
expect(subject.track { sleep 0.1 }.time).to satisfy {|v| v >= 0.1}
expect(subject.track { sleep 0.1 }.time).to satisfy { |v| v >= 0.1 }
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment