GithubHelp home page GithubHelp logo

datadog / dogapi-rb Goto Github PK

View Code? Open in Web Editor NEW
92.0 535.0 92.0 690 KB

Ruby client for Datadog's API

Home Page: https://www.datadoghq.com

License: BSD 3-Clause "New" or "Revised" License

Ruby 99.91% Roff 0.09%

dogapi-rb's Introduction

Ruby Client for Datadog API

<img src=“https://badge.fury.io/rb/dogapi.svg” alt=“Gem Version” /> <img src=“https://dev.azure.com/datadoghq/dogapi-rb/_apis/build/status/DataDog.dogapi-rb?branchName=master” alt=“Build Status” />

The Ruby client is a library suitable for inclusion in existing Ruby projects or for development of standalone scripts. It provides an abstraction on top of Datadog’s raw HTTP interface for reporting events and metrics.

To support all Datadog HTTP APIs, a generated library is available which will expose all the endpoints: datadog-api-client-ruby.

What’s new?

See CHANGELOG.md for details

Installation

From Source

Available at: github.com/DataDog/dogapi-rb

$ cd dogapi-rb
$ bundle
$ rake install

Using RubyGems

Gem page: rubygems.org/gems/dogapi

$ gem install dogapi

If you get a permission error, you might need to run the install process with sudo:

$ sudo gem install dogapi

If you get a LoadError, missing mkmf, you need to install the development packages for ruby.

# on ubuntu e.g.
$ sudo apt-get install ruby-dev

Usage

Supported Versions

This project currently works with Ruby versions 1.9.3+

Note Newer features and new endpoint support may no longer support EOL Ruby versions but the client should still intialize and allow metric/event submission.

How to find your API and application keys

Go to your setup page.

A word about hosts and devices

Events and metric data points can be attached to hosts to take advantage of automatic tagging with the host’s tags.

If you want to attach events and points to a specific device on a host, simply specify the device when calling emit functions.

Configure the Datadog API Url

require 'rubygems'
require 'dogapi'

api_key = "abcdef123456"
application_key = "fedcba654321"

# by default the API Url will be set to https://api.datadoghq.com
dog = Dogapi::Client.new(api_key, application_key)
p dog.datadog_host  # prints https://api.datadoghq.com

# API Url can be passed to the initializer...
dog = Dogapi::Client.new(api_key, application_key, nil, nil, nil, nil, 'https://myproxy.local')
p dog.datadog_host  # prints https://myproxy.local

# ...or set on the client instance directly
dog = Dogapi::Client.new(api_key, application_key)
dog.datadog_host = 'https://myproxy.local'
p dog.datadog_host  # prints https://myproxy.local

# in any case, contents of the DATADOG_HOST env var take precedence
ENV['DATADOG_HOST'] = https://myproxy.local
dog = Dogapi::Client.new(api_key, application_key)
p dog.datadog_host  # prints https://myproxy.local

Submit an event to Datadog

require 'rubygems'
require 'dogapi'

api_key = "abcdef123456"

# submitting events doesn't require an application_key, so we don't bother setting it
dog = Dogapi::Client.new(api_key)

dog.emit_event(Dogapi::Event.new('Testing done, FTW'), :host => "my_host")

Tag a host in Datadog

require 'rubygems'
require 'dogapi'

api_key = "abcdef123456"
application_key = "fedcba654321"

dog = Dogapi::Client.new(api_key, application_key)

dog.add_tags("my_host", ["tagA", "tagB"])

Submit a metric to Datadog

You want to track a new metric called some.metric.name and have just sampled it from my_device on my_host. Its value is 50. Here is how you submit the value to Datadog.

require 'rubygems'
require 'dogapi'

api_key = "abcdef123456"

# submitting metrics doesn't require an application_key, so we don't bother setting it
dog = Dogapi::Client.new(api_key)

dog.emit_point('some.metric.name', 50.0, :host => "my_host", :device => "my_device")

Let us now assume that you have sampled the metric multiple times and you would like to submit the results. You can use the emit_points method (instead of emit_point). Since you are submitting more than one data point you will need to pass a list of Time, float pairs, instead of a simple float value.

require 'rubygems'
require 'dogapi'

# Actual sampling takes place
t1 = Time.now
val1 = 50.0

# some time elapses
t2 = Time.now
val2 = 51.0

# some more time elapses
t3 = Time.now
val3 = -60.0

api_key = "abcdef123456"

dog = Dogapi::Client.new(api_key)

dog.emit_points('some.metric.name', [[t1, val1], [t2, val2], [t3, val3]], :host => "my_host", :device => "my_device")

If you want to specify the metric type, using the example above you can pass in a symbol key with :type and a value of a metric type such as counter, gauge or rate.

dog.emit_points('some.metric.name', [[t1, val1], [t2, val2], [t3, val3]], :host => "my_host", :device => "my_device", :type => 'counter' )

If you want to add metric tags, using the example above you can pass in a symbol key with :tags and an array of tags.

dog.emit_points('some.metric.name', [[t1, val1], [t2, val2], [t3, val3]], :host => "my_host", :device => "my_device", :tags => ['frontend', 'app:webserver'] )

Get points from a Datadog metric

require 'rubygems'
require 'dogapi'

api_key = "abcd123"
application_key = "brec1252"

dog = Dogapi::Client.new(api_key, application_key)

# get points from the last hour
from = Time.now - 3600
to = Time.now

query = 'sum:metric.count{*}.as_count()'

dog.get_points(query, from, to)

dogapi-rb's People

Contributors

alq666 avatar ansel1 avatar armcburney avatar bkabrda avatar byroot avatar clofresh avatar clutchski avatar conorbranagan avatar degemer avatar enbashi avatar ericmustin avatar gzussa avatar isaacdd avatar jirikuncar avatar martinisoft avatar masci avatar miketheman avatar mlaureb avatar nmuesch avatar pcockwell avatar remh avatar sethrosenblum avatar ssc3 avatar talwai avatar taylurre avatar therve avatar xcolour avatar yannmh avatar yyuu avatar zippolyte avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dogapi-rb's Issues

No capistrano deploy notifications seen on event stream dashboard

Viewing all (or just capistrano) event stream (https://app.datadoghq.com/event/stream), I never see any capistrano events.

I have at the very top of my Capfile

require "capistrano/datadog"
set :datadog_api_key, 'retracted'

And have the following gem versions

  • dogapi (1.25.0)
  • capistrano (3.4.0)

Debuging within lib/capistrano/datadog.rb, I can get a real cap event, and also create a test_event from your specs.

The real event does not show up, but the test one does.

# a real cap event
[17] pry(Capistrano::Datadog)> event = reporter.report.first
[18] pry(Capistrano::Datadog)> event
=> [#<Dogapi::Event:0x007ff8aacded30
  @aggregation_key="0cda32bb5db83f5e3a4b2eb31feb2f84",
  @alert_type="success",
  @date_happened=1489151435,
  @event_type="deploy",
  @msg_text="",
  @msg_title="[email protected] ran staging on  with capistrano in 1.07 secs",
  @parent=nil,
  @priority="normal",
  @source_type_name="capistrano",
  @tags=["#capistrano"]>,
 []]

# send it (cannot see it on event stream)
[19] pry(Capistrano::Datadog)> dog.emit_event event.first
=> ["202",
 {"status"=>"ok",
  "event"=>
   {"id"=>973689024792381642,
    "title"=>"[email protected] ran staging on  with capistrano in 1.07 secs",
    "text"=>"",
    "date_happened"=>1489151435,
    "handle"=>nil,
    "priority"=>"normal",
    "related_event_id"=>nil,
    "tags"=>["#capistrano"],
    "url"=>"https://app.datadoghq.com/event/event?id=973689024792381642"}}]

# test event
[23] pry(Capistrano::Datadog)> test_event
=> #<Dogapi::Event:0x007ff8aac90770
 @aggregation_key="job-123",
 @alert_type="error",
 @date_happened=1489151540,
 @event_type=nil,
 @msg_text="Uh-oh, something bad happened",
 @msg_title="Alert! Alert!",
 @parent=nil,
 @priority="normal",
 @source_type_name=nil,
 @tags=["ruby", "dogapi"]>

# send it (it shows up on the event stream)
[24] pry(Capistrano::Datadog)> dog.emit_event test_event
=> ["202",
 {"status"=>"ok",
  "event"=>
   {"id"=>973689153003286310,
    "title"=>"Alert! Alert!",
    "text"=>"Uh-oh, something bad happened",
    "date_happened"=>1489151540,
    "handle"=>nil,
    "priority"=>"normal",
    "related_event_id"=>nil,
    "tags"=>["ruby", "dogapi"],
    "url"=>"https://app.datadoghq.com/event/event?id=973689153003286310"}}]

Requiring MD5 under Digest.

The capistrano/datadog.rb you have require 'md5'. It looks like you are after the standard MD5 implementation, which is in require 'digest/md5'.

is emit_point the correct method to count page views?

I tried emit_point("foo", 1 ) and emit_point("bar", 1, { type: 'counter' } ), but it seems to not have the desired effect - I always get a graph with a flat line showing 1 as value. I'm searching for something identical to statsd.increment('foo').

screenshot 2015-08-20 12 03 33

New datadog API endpoint

Hi, following internal re-organization, we can now use the new endpoint for all API requests:

https://api.datadoghq.com/api instead of https://app.datadoghq.com/api.

response message inaccurate

when submitting a message, the 'text' shows up as nil, but the event itself in the UI looks okay (the message is there)

> dog_client = Dogapi::Client.new(api_key, app_key)
> sd = dog_client.emit_event(Dogapi::Event.new("Testing", :msg_title => 'ERROR', :alert_type => 'error'))
=> ["202",
 {"status"=>"ok",
  "event"=>
   {"priority"=>"normal",
    "date_happened"=>1382446682,
    "handle"=>nil,
    "title"=>"ERROR",
    "url"=>
     "https://app.datadoghq.com/event/jump_to?event_id=",
    "text"=>nil,
    "tags"=>[],
    "related_event_id"=>nil,
    "id"=>}}] 

capistrano datadog:submit failure...

I am getting this at the end of my deploy...

* executing `datadog:submit'
Could not submit to Datadog: #<NoMethodError: undefined method `sort' for #<Proc:0x007fd4fdb27580>>
/Users/dboyd/.rvm/gems/ruby-1.9.3-p125/gems/dogapi-1.3.3/lib/capistrano/datadog.rb:89:in `block in report'
...

The deploy does succeed, but I assume that the API call should not behaving this way.

Net::OpenTimeout exception

I'm getting an intermittent Net::OpenTimeout exception when I call emit_point when the datadog agent isn't running.

I'd expect there to be no difference in my program's functioning whether the agent is running or not.

Net::OpenTimeout: execution expired
/usr/local/Cellar/ruby/2.3.1_2/lib/ruby/2.3.0/net/http.rb:880:in initialize' /usr/local/Cellar/ruby/2.3.1_2/lib/ruby/2.3.0/net/http.rb:880:inopen'
/usr/local/Cellar/ruby/2.3.1_2/lib/ruby/2.3.0/net/http.rb:880:in block in connect' /usr/local/Cellar/ruby/2.3.1_2/lib/ruby/2.3.0/timeout.rb:101:intimeout'
/usr/local/Cellar/ruby/2.3.1_2/lib/ruby/2.3.0/net/http.rb:878:in connect' /usr/local/Cellar/ruby/2.3.1_2/lib/ruby/2.3.0/net/http.rb:863:indo_start'
/usr/local/Cellar/ruby/2.3.1_2/lib/ruby/2.3.0/net/http.rb:852:in start' /usr/local/lib/ruby/gems/2.3.0/gems/dogapi-1.23.0/lib/dogapi/common.rb:97:inconnect'
/usr/local/lib/ruby/gems/2.3.0/gems/dogapi-1.23.0/lib/dogapi/common.rb:117:in request' /usr/local/lib/ruby/gems/2.3.0/gems/dogapi-1.23.0/lib/dogapi/v1/metric.rb:24:inupload'
/usr/local/lib/ruby/gems/2.3.0/gems/dogapi-1.23.0/lib/dogapi/v1/metric.rb:29:in submit_to_api' /usr/local/lib/ruby/gems/2.3.0/gems/dogapi-1.23.0/lib/dogapi/v1/metric.rb:48:insubmit'
/usr/local/lib/ruby/gems/2.3.0/gems/dogapi-1.23.0/lib/dogapi/facade.rb:87:in `emit_points'

getting connection refused

I have a rails project that I am trying to set up to push metrics to datadog using the dogapi-rb gem
I am getting a connection refused error when I try to send data - for example from the rails console:

> dog = Dogapi::Client.new( "my-api-key" )
#<Dogapi::Client ....
> dog.emit_point('test.api.test_metric',4.0)
Connection refused - connect(2) for nil port 80
=> [-1, {}]

Compatibility with Ruby 1.8 broken

There seems to have been unnecessary use of Ruby 1.9's "symbol: value" syntax in a recent change that has broken compatibility with Ruby 1.8:

Could not autoload puppet/reports/datadog_reports: /usr/lib/ruby/gems/1.8/gems/dogapi-1.22.0/lib/dogapi/v1/metric.rb:17: syntax error, unexpected ':', expecting tASSOC
            from: from.to_i,
                 ^
/usr/lib/ruby/gems/1.8/gems/dogapi-1.22.0/lib/dogapi/v1/metric.rb:18: syntax error, unexpected ':', expecting '='
            to: to.to_i,
               ^
/usr/lib/ruby/gems/1.8/gems/dogapi-1.22.0/lib/dogapi/v1/metric.rb:19: syntax error, unexpected ':', expecting '='
            query: query
                  ^
Could not autoload puppet/reports/datadog_reports: /usr/lib/ruby/gems/1.8/gems/dogapi-1.22.0/lib/dogapi/v1/metric.rb:17: syntax error, unexpected ':', expecting tASSOC
            from: from.to_i,
                 ^
/usr/lib/ruby/gems/1.8/gems/dogapi-1.22.0/lib/dogapi/v1/metric.rb:18: syntax error, unexpected ':', expecting '='
            to: to.to_i,
               ^
/usr/lib/ruby/gems/1.8/gems/dogapi-1.22.0/lib/dogapi/v1/metric.rb:19: syntax error, unexpected ':', expecting '='
            query: query
                  ^

capistrano plugin: timeout option, new formatter

Hi,

please make the timeout configurable for capistrano events. Usually a lot of events will be sent and especially bigger payloads tend to timeout on each deployment.

Also please note that Capistrano/SSHKit again introduced new default format for colorful shell output………

There doesn't appear to be a way to turn off Datadog for test environment.

The requests can't be stubbed by webmock without deep hacks, because some service teardowns happen outside the context of an example (like after(:suite)) and datadog wants to hook into those teardowns.

I don't understand why enabled: false doesn't turn off the library, but it doesn't.

How do people use this library (or avoid it) when testing?

uninitialized constant Dogapi

Dogapi gem is installed but the error above still occurs.
~/gem install dogapi
Successfully installed dogapi-1.23.0
1 gem installed

~/gem list | grep dogapi
dogapi (1.23.0)

Code:
require 'dogapi'
api_key = "some_api_key"
$dog = Dogapi::Client.new(api_key)

Error when deploy with capistrano is finished

triggering exit callbacks
* 2018-04-09 14:37:19 executing `datadog:submit'
Could not submit to Datadog: #<NoMethodError: undefined method `round' for nil:NilClass>
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/dogapi-1.29.0/lib/capistrano/datadog.rb:112:in `block in report'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/dogapi-1.29.0/lib/capistrano/datadog.rb:100:in `map'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/dogapi-1.29.0/lib/capistrano/datadog.rb:100:in `report'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/dogapi-1.29.0/lib/capistrano/datadog.rb:29:in `submit'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/dogapi-1.29.0/lib/capistrano/datadog/v2.rb:61:in `block (3 levels) in <module:Datadog>'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/capistrano-2.15.9/lib/capistrano/configuration/execution.rb:138:in `instance_eval'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/capistrano-2.15.9/lib/capistrano/configuration/execution.rb:138:in `invoke_task_directly'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/capistrano-2.15.9/lib/capistrano/configuration/callbacks.rb:25:in `invoke_task_directly_with_callbacks'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/capistrano-2.15.9/lib/capistrano/configuration/execution.rb:89:in `execute_task'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/dogapi-1.29.0/lib/capistrano/datadog/v2.rb:27:in `block in find_and_execute_task'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/dogapi-1.29.0/lib/capistrano/datadog.rb:70:in `block in record_task'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/2.1.0/benchmark.rb:279:in `measure'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/dogapi-1.29.0/lib/capistrano/datadog.rb:69:in `record_task'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/dogapi-1.29.0/lib/capistrano/datadog/v2.rb:25:in `find_and_execute_task'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/capistrano-2.15.9/lib/capistrano/callback.rb:38:in `call'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/capistrano-2.15.9/lib/capistrano/configuration/callbacks.rb:141:in `block in trigger'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/capistrano-2.15.9/lib/capistrano/configuration/callbacks.rb:141:in `each'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/capistrano-2.15.9/lib/capistrano/configuration/callbacks.rb:141:in `trigger'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/capistrano-2.15.9/lib/capistrano/cli/execute.rb:35:in `execute!'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/capistrano-2.15.9/lib/capistrano/cli/execute.rb:14:in `execute'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/capistrano-2.15.9/bin/cap:4:in `<top (required)>'
/Users/Work/.rbenv/versions/2.1.10/bin/cap:23:in `load'
/Users/Work/.rbenv/versions/2.1.10/bin/cap:23:in `<top (required)>'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/lib/bundler/cli/exec.rb:75:in `load'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/lib/bundler/cli/exec.rb:75:in `kernel_load'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/lib/bundler/cli/exec.rb:28:in `run'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/lib/bundler/cli.rb:424:in `exec'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/lib/bundler/cli.rb:27:in `dispatch'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/lib/bundler/cli.rb:18:in `start'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/exe/bundle:30:in `block in <top (required)>'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/lib/bundler/friendly_errors.rb:122:in `with_friendly_errors'
/Users/Work/.rbenv/versions/2.1.10/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/exe/bundle:22:in `<top (required)>'
/Users/Work/.rbenv/versions/2.1.10/bin/bundle:23:in `load'
/Users/Work/.rbenv/versions/2.1.10/bin/bundle:23:in `<main>'

https://github.com/DataDog/dogapi-rb/blob/master/lib/capistrano/datadog.rb#L112

Add option to set/unset host automatically if no scope is given to a metric

Unlike the python client, this one send a nil host to the API, causing the metric to be tied to no-host on the backend. This is usually not the desired behavior so the default behavior will change to mimic the python client's.

Now that find_localhost returns the correct value, we can rely on it to implement this.

capistrano v3 not working

Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
+ bundle exec cap staging deploy
cap aborted!
undefined method `instance' for Capistrano::Configuration:Class
/Capfile:23:in `require'
/Capfile:23:in `<top (required)>'
/lib/capistrano/application.rb:22:in `load_rakefile'
/lib/capistrano/application.rb:12:in `run'
/bin/cap:3:in `<top (required)>'
(See full trace by running task with --trace)
Build step 'Execute shell' marked build as failure
Finished: FAILURE

Graph definition with template variable works in screen board but not through API

I'm having trouble passing a template variable to get_embed. I first create the embeddable graph (notice the $company_name variable).

graph_json = '{
  "viz": "query_value",
  "requests": [
    {
      "q": "sum:api.request.count{$company_name}.as_count()",
      "aggregator": "sum",
      "conditional_formats": [
        {
          "palette": "white_on_green",
          "comparator": ">=",
          "value": "0"
        },
        {
          "palette": "white_on_yellow",
          "comparator": ">=",
          "value": null
        },
        {
          "palette": "white_on_green",
          "comparator": "<",
          "value": null
        }
      ]
    }
  ],
  "autoscale": false,
  "precision": "0"
}'

timeframe = "2_days"
size = "medium"
legend = "no"
title = "Test Graph"

# # Create parameter hash
description = {
  :timeframe => timeframe,
  :size => size,
  :legend => legend,
  :title => title
}

status, result = dog.create_embed(graph_json, description)

Now I get the graph that was created and provide a value for the variable.

embed_id = result['embed_id']

get_embed_description = {
  :size => size,
  :legend => legend,
  :company_name => "us_bank"
}

status, result = dog.get_embed(embed_id, get_embed_description)

The result is just a grey square, even though the same graph definition works when I use it in a ScreenBoard through the GUI. If instead of the variable $company_name I supply the company name in the graph definition (i.e., copany_name:us_bank) it also works.

Execution expired error when using Ruby 2.1.5+

When making API requests on Ruby version 2.1.5+, getting execution expired errors. For example:

#event.rb
require 'rubygems'
require 'dogapi'

api_key='xxxxxxxx'
app_key='xxxxxxxx'

dog = Dogapi::Client.new(api_key, app_key)

event_id = 'xxxxxx'
print dog.get_event(event_id)
myhost:Desktop samanthadrago$ ruby event.rb
execution expired
[-1, {}]

Query metrics is missing?

Can you currently query metrics?

I couldn't find it in this API, unlike the Python version, or shell APIDocs.

Or have I gone mad... thanks

execution expired message

I'm getting these messages every once in a while and when it happens the metrics don't show up in Datadog.

Emitting data to Datadog..
execution expired

code:

require 'dogapi'

def emit_to_datadog(failed,pipeline_name,pipeline_url,deploy_dict,elapsed_seconds)
  puts "\n\n\tEmitting data to Datadog.."
  api_key = ENV['DD_API_KEY'] || 'xxxxx'
  begin
    dog = Dogapi::Client.new(api_key)

    result = failed ? 'Failed' : 'Success'

    dog.emit_event(Dogapi::Event.new("Result: #{result}\n#{pipeline_url}\nItems Deployed: #{deploy_dict}",
      :msg_title       => "Deployment - Pipeline: #{pipeline_name}",
      :aggregation_key => "#{pipeline_url}",
      :alert_type      => failed ? 'error' : 'success',
      :tags            => ["#{pipeline_name}"]
    ))

    dog.emit_point('deployment.duration', elapsed_seconds, :type => 'gauge')
    dog.emit_point('deployment.success', 1, :type => 'counter') if !failed
    dog.emit_point('deployment.failed', 1, :type => 'counter') if failed

  rescue Exception => e
    puts "\n\n\tGot an Error attempting to send data to DataDog: #{e}"
  rescue Timeout::Error => te
    puts "\n\n\tRescued from timeout: #{te}"
  end
end

The exception handling above is not catching the error. Any ideas?

The data being sent is fairly important so I'd like to at least be able to catch timeout type errors and re-try an emit.

Capistrano doctor raises exception on Logger

If you have require 'capistrano/datadog' in your capfile and then run cap production doctor, you get an error NoMethodError: undefined method write' for #<Logger:0x007ff793b0a940>. /usr/local/var/rbenv/versions/2.0.0-p645/lib/ruby/gems/2.0.0/gems/dogapi-1.22.0/lib/capistrano/datadog/v3.rb:33:inwrite'
/usr/local/var/rbenv/versions/2.0.0-p645/lib/ruby/gems/2.0.0/gems/sshkit-1.10.0/lib/sshkit/formatters/pretty.rb:53:in write_message' /usr/local/var/rbenv/versions/2.0.0-p645/lib/ruby/gems/2.0.0/gems/sshkit-1.10.0/lib/sshkit/formatters/pretty.rb:12:inwrite'

Test mode?

Hi, I was wondering if there are plans to introduce a testing mode for clients?

What is the recommended way to use this in dev/test?

Is there a recommended way to use this gem in development and test environment. Inside test-environment it is easy to utilize for example webmock, but when for example running an application in development and having code that sends datadog events it would be nice to have a supplied fake mode or fake client.

I can easily implement a fake-client but then the issue comes with syncing the interface and making sure it doesn't work with wrong calls.

How do you suggest it is done?

Datadog/Capistrano 3 integration broken

I'm trying to send deploys event to Datadog using the tasks included in datadog gem, unfortunately nothings happen (no errors, and I can't see the gem logging anything)

Here's what I have in my Capfile:

require 'capistrano/datadog'
set :datadog_api_key, "my-key"

I'm using Capistrano 3.2.1

Any idea?

capistrano: empty logging

We don't receive any log output in DataDog.

  • capistrano (3.3.5)
  • dogapi (1.20.0)

Since we're running capistrano headless, we're using the bundled simpletext formatter which doesn't output color codes:

set :format, :simpletext if ENV['HEADLESS']

When using the default, color-ful output, digapi-rb's capistrano plugin doesn't reliably remove color codes.

service_check should allow message

e.g. dd-agent in python allows

def service_check(self, check_name, status, tags=None, timestamp=None,
                      hostname=None, check_run_id=None, message=None):

however the Ruby version is limited to following payload:

def service_check(check, host, status, options = {})
  begin
    params = {
      :api_key => @api_key,
      :application_key => @application_key
    }

    body = {
      'check' => check,
      'host_name' => host,
      'status' => status
    }.merge options

    request(Net::HTTP::Post, "/api/#{API_VERSION}/check_run", params, body, true)
  rescue Exception => e
    suppress_error_if_silent e
  end
end

Make read_timeout configurable

Our chef integration to create data alerts sometimes fails because our API request to load all alerts times out. For now I'm monkey patching a higher timeout in Dogapi::APIService#connect, but it would be nice if I could tune the read_timeout when creating the Dogapi::Client.

#get_monitor does not accept a string for :group_states

In the documentation, it says that you should pass a string like 'all' or 'alert,warn' into the #get_monitor method if you'd like information regarding group states. This gives an exception because the method actually wants an array.

Expected:

dog.get_monitor(1234, group_states: 'all')

Actual (required at the moment)

dog.get_monitor(1234, group_states: ['all'])

Documentation of scope host vs. api host is lacking

There's been some confusion over the difference between the host specified in an event's scope and the api host. The documentation needs to clear this up and the code examples need to make the distinction clearer.

Ensure that the "tags" parameter is always a list

When the user sets the tags option with something, ensure that it is just a list of strings (not something nested), it will warn the user that the point tag set is malformed and avoid rejecting it much later in the backend.

Unable to submit events

My code:

    event_service = Dogapi::EventService.new(@host)
    self.logs.each do |log|
      event = Dogapi::Event.new(log, :event_type => 'Puppet')
      event_service.submit(API_KEY, event)
    end 

I get:
debug: Sending events for absenta.lovedthanlost.net to DataDog
/usr/lib/ruby/1.8/net/http.rb:1118:in addr_port' /usr/lib/ruby/1.8/net/http.rb:1078:inbegin_transport'
/usr/lib/ruby/1.8/net/http.rb:1048:in request' /usr/lib/ruby/gems/1.8/gems/dogapi-1.0.3/lib/dogapi/common.rb:61:inrequest'
/usr/lib/ruby/gems/1.8/gems/dogapi-1.0.3/lib/dogapi/common.rb:43:in connect' /usr/lib/ruby/1.8/net/http.rb:543:instart'
/usr/lib/ruby/gems/1.8/gems/dogapi-1.0.3/lib/dogapi/common.rb:42:in connect' /usr/lib/ruby/gems/1.8/gems/dogapi-1.0.3/lib/dogapi/common.rb:58:inrequest'
/usr/lib/ruby/gems/1.8/gems/dogapi-1.0.3/lib/dogapi/event.rb:84:in submit' /usr/local/lib/site_ruby/1.8/puppet/reports/datadog.rb:37:inprocess'
/usr/local/lib/site_ruby/1.8/puppet/reports/datadog.rb:35:in each' /usr/local/lib/site_ruby/1.8/puppet/reports/datadog.rb:35:inprocess'
/usr/local/lib/site_ruby/1.8/puppet/indirector/report/processor.rb:32:in process' /usr/local/lib/site_ruby/1.8/puppet/indirector/report/processor.rb:25:ineach'
/usr/local/lib/site_ruby/1.8/puppet/indirector/report/processor.rb:25:in process' /usr/local/lib/site_ruby/1.8/puppet/indirector/report/processor.rb:14:insave'
/usr/local/lib/site_ruby/1.8/puppet/indirector/indirection.rb:264:in save' /usr/local/lib/site_ruby/1.8/puppet/network/http/handler.rb:164:indo_save'
/usr/local/lib/site_ruby/1.8/puppet/network/http/handler.rb:68:in send' /usr/local/lib/site_ruby/1.8/puppet/network/http/handler.rb:68:inprocess'
/usr/local/lib/site_ruby/1.8/puppet/network/http/webrick/rest.rb:24:in service' /usr/lib/ruby/1.8/webrick/httpserver.rb:104:inservice'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in run' /usr/local/lib/site_ruby/1.8/puppet/network/http/webrick.rb:45:inlisten'
/usr/lib/ruby/1.8/webrick/server.rb:173:in call' /usr/lib/ruby/1.8/webrick/server.rb:173:instart_thread'
/usr/lib/ruby/1.8/webrick/server.rb:162:in start' /usr/lib/ruby/1.8/webrick/server.rb:162:instart_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in start' /usr/lib/ruby/1.8/webrick/server.rb:92:ineach'
/usr/lib/ruby/1.8/webrick/server.rb:92:in start' /usr/lib/ruby/1.8/webrick/server.rb:23:instart'
/usr/lib/ruby/1.8/webrick/server.rb:82:in start' /usr/local/lib/site_ruby/1.8/puppet/network/http/webrick.rb:42:inlisten'
/usr/local/lib/site_ruby/1.8/puppet/network/http/webrick.rb:41:in initialize' /usr/local/lib/site_ruby/1.8/puppet/network/http/webrick.rb:41:innew'
/usr/local/lib/site_ruby/1.8/puppet/network/http/webrick.rb:41:in listen' /usr/local/lib/site_ruby/1.8/puppet/network/http/webrick.rb:38:insynchronize'
/usr/local/lib/site_ruby/1.8/puppet/network/http/webrick.rb:38:in listen' /usr/local/lib/site_ruby/1.8/puppet/network/server.rb:127:inlisten'
/usr/local/lib/site_ruby/1.8/puppet/network/server.rb:142:in start' /usr/local/lib/site_ruby/1.8/puppet/daemon.rb:124:instart'
/usr/local/lib/site_ruby/1.8/puppet/application/master.rb:202:in main' /usr/local/lib/site_ruby/1.8/puppet/application/master.rb:144:inrun_command'
/usr/local/lib/site_ruby/1.8/puppet/application.rb:307:in run' /usr/local/lib/site_ruby/1.8/puppet/application.rb:411:inhook'
/usr/local/lib/site_ruby/1.8/puppet/application.rb:307:in run' /usr/local/lib/site_ruby/1.8/puppet/application.rb:402:inexit_on_fail'
/usr/local/lib/site_ruby/1.8/puppet/application.rb:307:in run' /usr/local/lib/site_ruby/1.8/puppet/util/command_line.rb:69:inexecute'
/usr/bin/puppet:4
err: Report datadog failed: undefined method `+' for nil:NilClass

More efficient API for sending many different metrics

The current metrics API only allows sending one metric at a time, which is horribly inefficient. Please create another API that allows sending multiple metrics at the same time, maybe something like

dog.emit_metrics([["my.metric.a", 50.0], ["my.metric.b", 59.9]])

Proxy Support

Does this support proxies? If so how does it like to be configured?

breaks with capistrano 2.13.5

/Users/me/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/capistrano-2.13.5/lib/capistrano/logger.rb:86:in log':
undefined method tty?' for #<Capistrano::Datadog::LogCapture:0x007f8396103b70> (NoMethodError) from /Users/russegan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/capistrano-2.13.5/lib/capistrano/logger.rb:145:in trace'
from /Users/russegan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/capistrano-2.13.5/lib/capistrano/configuration/callbacks.rb:140:in trigger' from /Users/russegan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/capistrano-2.13.5/lib/capistrano/cli/execute.rb:33:in execute!'
from /Users/russegan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/capistrano-2.13.5/lib/capistrano/cli/execute.rb:14:in execute' from /Users/russegan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/capistrano-2.13.5/bin/cap:4:in <top (required)>'
from /Users/russegan/.rbenv/versions/1.9.3-p194/bin/cap:23:in load' from /Users/russegan/.rbenv/versions/1.9.3-p194/bin/cap:23:in

'`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.