Skip to content

Commit

Permalink
Add metric metadata endpoint
Browse files Browse the repository at this point in the history
+ a few more gitignores.
  • Loading branch information
degemer committed Feb 14, 2017
1 parent afad205 commit 0c6e4a0
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ coverage
doc/
pkg/
.idea
vendor/
.bundle/
*.gem
2 changes: 1 addition & 1 deletion .tailor
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Tailor.config do |config|
style.allow_invalid_ruby false, level: :warn
style.indentation_spaces 2, level: :error
style.max_code_lines_in_class 300, level: :error
style.max_code_lines_in_method 33, level: :error
style.max_code_lines_in_method 34, level: :error
style.max_line_length 160, level: :warn
style.spaces_after_comma 1, level: :error
style.spaces_after_lbrace 1, level: :error
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changes
=======

# 1.25.0 / UNRELEASED

* [FEATURE] Add Datadog endpoint for metrics metadata. See [#120][]

# 1.24.0 / 2017-01-12

* [FEATURE] Add the ability to record events per host and to filter events. See [#115][] (thanks [@hnovikov][])
Expand Down Expand Up @@ -168,6 +172,7 @@ This is the last release compatible with Ruby 1.8. ([EOL 2013-06-30](https://www
[#113]: https://github.com/DataDog/dogapi-rb/issues/113
[#114]: https://github.com/DataDog/dogapi-rb/issues/114
[#115]: https://github.com/DataDog/dogapi-rb/issues/115
[#120]: https://github.com/DataDog/dogapi-rb/issues/120
[@ArjenSchwarz]: https://github.com/ArjenSchwarz
[@Kaixiang]: https://github.com/Kaixiang
[@ansel1]: https://github.com/ansel1
Expand All @@ -181,4 +186,4 @@ This is the last release compatible with Ruby 1.8. ([EOL 2013-06-30](https://www
[@rmoriz]: https://github.com/rmoriz
[@treeder]: https://github.com/treeder
[@winebarrel]: https://github.com/winebarrel
[@yyuu]: https://github.com/yyuu
[@yyuu]: https://github.com/yyuu
27 changes: 27 additions & 0 deletions lib/dogapi/facade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def initialize(api_key, application_key=nil, host=nil, device=nil, silent=true,
@screenboard_svc = Dogapi::V1::ScreenboardService.new(@api_key, @application_key, silent, timeout, @datadog_host)
@monitor_svc = Dogapi::V1::MonitorService.new(@api_key, @application_key, silent, timeout, @datadog_host)
@service_check_svc = Dogapi::V1::ServiceCheckService.new(@api_key, @application_key, silent, timeout, @datadog_host)
@metadata_svc = Dogapi::V1::MetadataService.new(@api_key, @application_key, silent, timeout, @datadog_host)
@legacy_event_svc = Dogapi::EventService.new(@datadog_host)
end

Expand Down Expand Up @@ -467,6 +468,32 @@ def service_check(check, host, status, options= {})
@service_check_svc.service_check(check, host, status, options)
end

#
# METADATA
#

# Get metadata information on an existing Datadog metric
def get_metadata(metric)
@metadata_svc.get(metric)
end

# Update metadata fields for an existing Datadog metric.
# If the metadata does not exist for the metric it is created by
# the update.
# Optional arguments:
# :type => String, type of the metric (ex. "gauge", "rate", etc.)
# see http://docs.datadoghq.com/metrictypes/
# :description => String, description of the metric
# :short_name => String, short name of the metric
# :unit => String, unit type associated with the metric (ex. "byte", "operation")
# see http://docs.datadoghq.com/units/ for full list
# :per_unit => String, per unit type (ex. "second" as in "queries per second")
# see http://docs.datadoghq.com/units/ for full
# :statsd_interval => Integer, statsd flush interval for metric in seconds (if applicable)
def update_metadata(metric, options= {})
@metadata_svc.update(metric, options)
end

private

def override_scope(options= {})
Expand Down
17 changes: 9 additions & 8 deletions lib/dogapi/v1.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
require 'dogapi/v1/event'
require 'dogapi/v1/metric'
require 'dogapi/v1/tag'
require 'dogapi/v1/alert'
require 'dogapi/v1/comment'
require 'dogapi/v1/search'
require 'dogapi/v1/dash'
require 'dogapi/v1/alert'
require 'dogapi/v1/user'
require 'dogapi/v1/snapshot'
require 'dogapi/v1/embed'
require 'dogapi/v1/screenboard'
require 'dogapi/v1/event'
require 'dogapi/v1/metadata'
require 'dogapi/v1/metric'
require 'dogapi/v1/monitor'
require 'dogapi/v1/screenboard'
require 'dogapi/v1/search'
require 'dogapi/v1/service_check'
require 'dogapi/v1/snapshot'
require 'dogapi/v1/tag'
require 'dogapi/v1/user'
20 changes: 20 additions & 0 deletions lib/dogapi/v1/metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'dogapi'

module Dogapi
class V1

class MetadataService < Dogapi::APIService

API_VERSION = 'v1'

def get(metric_name)
request(Net::HTTP::Get, "/api/#{API_VERSION}/metrics/#{metric_name}", nil, nil, false)
end

def update(metric_name, options = {})
request(Net::HTTP::Put, "/api/#{API_VERSION}/metrics/#{metric_name}", nil, options, true)
end
end

end
end
17 changes: 17 additions & 0 deletions spec/integration/metadata_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require_relative '../spec_helper'

describe Dogapi::Client do
METRIC_NAME = 'my.metric'.freeze

describe '#get_metadata' do
it_behaves_like 'an api method',
:get_metadata, [METRIC_NAME],
:get, '/metrics/' + METRIC_NAME
end

describe '#update_metadata' do
it_behaves_like 'an api method with options',
:update_metadata, [METRIC_NAME],
:put, '/metrics/' + METRIC_NAME, {}
end
end

0 comments on commit 0c6e4a0

Please sign in to comment.