Skip to content

Commit

Permalink
Doggy v2
Browse files Browse the repository at this point in the history
  • Loading branch information
bai committed Oct 5, 2015
1 parent 64fddc2 commit 34f22fd
Show file tree
Hide file tree
Showing 43 changed files with 664 additions and 961 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: ruby
rvm:
- 2.2.2
before_install: gem install bundler -v 1.10.6
13 changes: 13 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Contributor Code of Conduct

As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.

We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.

Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.

This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in doggy.gemspec
gemspec
37 changes: 26 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
PATH
remote: .
specs:
doggy (0.2.0)
dogapi (~> 1.17)
ejson (~> 1.0)
thor (~> 0.19)
thread (~> 0.2)
doggy (2.0.0)
json (~> 1.8.3)
parallel (~> 1.6.1)
thor (~> 0.19.1)
virtus (~> 1.0.5)

GEM
remote: https://rubygems.org/
specs:
dogapi (1.20.0)
multi_json
ejson (1.0.0)
multi_json (1.11.2)
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
equalizer (0.0.11)
ice_nine (0.11.1)
json (1.8.3)
minitest (5.8.0)
parallel (1.6.1)
rake (10.4.2)
thor (0.19.1)
thread (0.2.2)
thread_safe (0.3.5)
virtus (1.0.5)
axiom-types (~> 0.1)
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
equalizer (~> 0.0, >= 0.0.9)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.9)
bundler (~> 1.10)
doggy!
minitest
rake (~> 10.0)

BUNDLED WITH
Expand Down
7 changes: 4 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
require "bundler/gem_tasks"
require "rake/testtask"

Rake::TestTask.new do |t|
t.libs << 'test'
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList['test/**/*_test.rb']
end

desc "Run tests"
task :default => :test
8 changes: 8 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@

require "bundler/setup"
require "doggy"

# 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.

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start

require "irb"
IRB.start
2 changes: 2 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ set -euo pipefail
IFS=$'\n\t'

bundle install

# Do any other automated setup that you need to do here
24 changes: 17 additions & 7 deletions doggy.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,33 @@ require 'doggy/version'
Gem::Specification.new do |spec|
spec.name = "doggy"
spec.version = Doggy::VERSION
spec.authors = ["Vlad Gorodetsky"]
spec.email = ["[email protected]"]
spec.authors = ["Vlad Gorodetsky", "Andre Medeiros"]
spec.email = ["[email protected]", "[email protected]"]

spec.summary = %q{Syncs DataDog dashboards, alerts, screenboards, and monitors.}
spec.description = %q{Syncs DataDog dashboards, alerts, screenboards, and monitors.}
spec.homepage = "http://github.com/bai/doggy"
spec.license = "MIT"

# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
# delete this section to allow pushing this gem to any host.
if spec.respond_to?(:metadata)
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
else
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
end

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", "~> 1.9"
spec.add_dependency "json", "~> 1.8.3"
spec.add_dependency "parallel", "~> 1.6.1"
spec.add_dependency "thor", "~> 0.19.1"
spec.add_dependency "virtus", "~> 1.0.5"

spec.add_development_dependency "bundler", "~> 1.10"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_dependency "thor", "~> 0.19"
spec.add_dependency "dogapi", "~> 1.17"
spec.add_dependency "thread", "~> 0.2"
spec.add_dependency "ejson", "~> 1.0"
spec.add_development_dependency "minitest"
end
14 changes: 0 additions & 14 deletions examples/my-monitor.rb

This file was deleted.

12 changes: 2 additions & 10 deletions exe/doggy
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
#!/usr/bin/env ruby

# Exit cleanly from an early interrupt
Signal.trap('INT') { exit 1 }

require 'bundler/setup'
require 'doggy/friendly_errors'

Doggy.with_friendly_errors do
require 'doggy/cli'
Doggy::CLI.start(ARGV, :debug => true)
end
require "doggy"
Doggy::CLI.start(ARGV)
134 changes: 47 additions & 87 deletions lib/doggy.rb
Original file line number Diff line number Diff line change
@@ -1,103 +1,63 @@
require 'fileutils'
require 'pathname'
require 'json'
require 'yaml'
require 'dogapi'

require 'doggy/friendly_errors'

require 'doggy/version'
require 'doggy/errors'
require 'doggy/shared_helpers'
require 'doggy/client'
require 'doggy/worker'
require 'doggy/definition'
require 'doggy/dsl'
require 'doggy/serializer/json'
require 'doggy/serializer/yaml'
require 'doggy/model/dash'
require 'doggy/model/monitor'
require 'doggy/model/screen'
require "pathname"
require "net/http"

require "doggy/cli"
require "doggy/cli/edit"
require "doggy/cli/mute"
require "doggy/cli/pull"
require "doggy/cli/push"
require "doggy/cli/unmute"
require "doggy/model"
require "doggy/models/dashboard"
require "doggy/models/monitor"
require "doggy/models/screen"
require "doggy/version"

module Doggy
DOG_SKIP_REGEX = /😱|:scream:/i.freeze
MANAGED_BY_DOGGY_REGEX = /🐶|\:dog\:/i.freeze
DEFAULT_SERIALIZER_CLASS = Doggy::Serializer::Json
DOG_SKIP_REGEX = /\xF0\x9F\x98\xB1|:scream:/i.freeze
MANAGED_BY_DOGGY_REGEX = /\xF0\x9F\x90\xB6|:dog:/i.freeze

class << self
# @option arguments [Constant] :serializer A specific serializer class to use, will be initialized by doggy and passed the object instance
def serializer(options = {})
@serializer ||= options[:serializer] ? options[:serializer] : DEFAULT_SERIALIZER_CLASS
end
extend self

def client
Doggy::Client.new
end
def ui
(defined?(@ui) && @ui) || (self.ui = Thor::Shell::Color.new)
end

def objects_path
@objects_path ||= Pathname.new('objects').expand_path(SharedHelpers.find_root).expand_path.tap { |path| FileUtils.mkdir_p(path) }
end
def ui=(ui)
@ui = ui
end

def load_item(f)
item = case File.extname(f)
when '.yaml', '.yml' then Doggy::Serializer::Yaml.load(File.read(f))
when '.json' then Doggy::Serializer::Json.load(File.read(f))
when '.rb' then Doggy::Dsl.evaluate(f).obj
else raise InvalidItemType
end
def object_root
@object_root ||= Pathname.new('objects').expand_path(repo_root)
end

# Hackery to support legacy dash format
{
[
determine_type(item), item['id'] || item['dash']['id']
] => item['dash'] ? item['dash'] : item
}
end
def repo_root
# TODO: Raise error when root can't be found
current_dir = Dir.pwd

def edit(id_or_filename)
if id_or_filename =~ /json|yml|yaml/
item_from_filename = Doggy.load_item(Doggy.objects_path.join(id_or_filename))
id = item_from_filename.keys[0][1]
while current_dir != '/' do
if File.exists?(File.join(current_dir, 'Gemfile')) then
return Pathname.new(current_dir)
else
id = id_or_filename
current_dir = File.expand_path('../', current_dir)
end

object = (item_from_filename || all_local_items).detect { |(type, object_id), object| object_id.to_s == id.to_s }
if object && object[0] && object[0][0] && type = object[0][0].sub(/^[a-z\d]*/) { $&.capitalize }
Object.const_get("Doggy::#{type}").edit(id)
end
end

def determine_type(item)
return 'dash' if item['graphs'] || item['dash']
return 'monitor' if item['message']
return 'screen' if item['board_title']
raise InvalidItemType
end
end

def emit_shipit_deployment
Doggy.client.dog.emit_event(
Dogapi::Event.new(ENV['REVISION'], msg_title: "ShipIt Deployment by #{ENV['USER']}", tags: %w(audit shipit), source_type_name: 'shipit')
)
rescue => e
puts "Exception: #{e.message}"
end
def api_key
ENV['DATADOG_API_KEY'] || secrets['datadog_api_key']
end

def current_sha
now = Time.now.to_i
month_ago = now - 3600 * 24 * 30
events = Doggy.client.dog.stream(month_ago, now, tags: %w(audit shipit))[1]['events']
def application_key
ENV['DATADOG_APP_KEY'] || secrets['datadog_app_key']
end

events[0]['text'] # most recetly deployed SHA
rescue => e
puts "Exception: #{e.message}"
end
protected

def all_local_items
@all_local_items ||= Dir[Doggy.objects_path.join('**/*')].inject({}) do |memo, file|
next if File.directory?(file)
memo.merge!(load_item(file))
end
end
def secrets
@secrets ||= begin
raw = File.read(repo_root.join('secrets.json'))
JSON.parse(raw)
end
end
end
end # Doggy
Loading

0 comments on commit 34f22fd

Please sign in to comment.