-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Re-add service level objectives support #224
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
require 'dogapi' | ||
|
||
module Dogapi | ||
class V1 # for namespacing | ||
|
||
# Implements Service Level Objectives endpoints | ||
class ServiceLevelObjectiveService < Dogapi::APIService | ||
|
||
API_VERSION = 'v1' | ||
|
||
def create_service_level_objective(type, slo_name, thresholds, options = {}) | ||
body = { | ||
type: type, | ||
name: slo_name, | ||
thresholds: thresholds | ||
} | ||
|
||
symbolized_options = Dogapi.symbolized_access(options) | ||
if type.to_s == 'metric' | ||
body[:query] = { | ||
numerator: symbolized_options[:numerator], | ||
denominator: symbolized_options[:denominator] | ||
} | ||
else | ||
body[:monitor_search] = symbolized_options[:monitor_search] if symbolized_options[:monitor_search] | ||
body[:monitor_ids] = symbolized_options[:monitor_ids] if symbolized_options[:monitor_ids] | ||
body[:groups] = symbolized_options[:groups] if symbolized_options[:groups] | ||
end | ||
body[:tags] = symbolized_options[:tags] if symbolized_options[:tags] | ||
body[:description] = symbolized_options[:description] if symbolized_options[:description] | ||
|
||
request(Net::HTTP::Post, "/api/#{API_VERSION}/slo", nil, body, true) | ||
end | ||
|
||
def update_service_level_objective(slo_id, type, options = {}) | ||
body = { | ||
type: type | ||
} | ||
|
||
symbolized_options = Dogapi.symbolized_access(options) | ||
if type == 'metric' | ||
if symbolized_options[:numerator] && symbolized_options[:denominator] | ||
body[:query] = { | ||
numerator: symbolized_options[:numerator], | ||
denominator: symbolized_options[:denominator] | ||
} | ||
end | ||
else | ||
body[:monitor_search] = symbolized_options[:monitor_search] if symbolized_options[:monitor_search] | ||
body[:monitor_ids] = symbolized_options[:monitor_ids] if symbolized_options[:monitor_ids] | ||
body[:groups] = symbolized_options[:groups] if symbolized_options[:groups] | ||
end | ||
[:name, :thresholds, :tags, :description].each do |a| | ||
body[a] = symbolized_options[a] if symbolized_options[a] | ||
end | ||
|
||
request(Net::HTTP::Put, "/api/#{API_VERSION}/slo/#{slo_id}", nil, body, true) | ||
end | ||
|
||
def get_service_level_objective(slo_id) | ||
request(Net::HTTP::Get, "/api/#{API_VERSION}/slo/#{slo_id}", nil, nil, false) | ||
end | ||
|
||
def search_service_level_objective(slo_ids, query, offset, limit) | ||
params = {} | ||
params[:offset] = offset unless offset.nil? | ||
params[:limit] = limit unless limit.nil? | ||
if !slo_ids.nil? | ||
params[:ids] = slo_ids.join(',') | ||
else | ||
params[:query] = query | ||
end | ||
|
||
request(Net::HTTP::Get, "/api/#{API_VERSION}/slo/", params, nil, false) | ||
end | ||
|
||
def delete_service_level_objective(slo_id) | ||
request(Net::HTTP::Delete, "/api/#{API_VERSION}/slo/#{slo_id}", nil, nil, false) | ||
end | ||
|
||
def delete_many_service_level_objective(slo_ids) | ||
body = { | ||
ids: slo_ids | ||
} | ||
request(Net::HTTP::Delete, "/api/#{API_VERSION}/slo/", nil, body, true) | ||
end | ||
|
||
def delete_timeframes_service_level_objective(ops) | ||
# ops is a hash of slo_id: [<timeframe>] to delete | ||
request(Net::HTTP::Post, "/api/#{API_VERSION}/slo/bulk_delete", nil, ops, true) | ||
end | ||
|
||
def get_service_level_objective_history(slo_id, from_ts, to_ts) | ||
params = { | ||
from_ts: from_ts, | ||
to_ts: to_ts | ||
} | ||
request(Net::HTTP::Get, "/api/#{API_VERSION}/slo/#{slo_id}/history", params, nil, false) | ||
end | ||
|
||
def can_delete_service_level_objective(slo_ids) | ||
params = {} | ||
params[:ids] = if slo_ids.is_a? Array | ||
slo_ids.join(',') | ||
else | ||
slo_ids | ||
end | ||
request(Net::HTTP::Get, "/api/#{API_VERSION}/slo/can_delete", params, nil, false) | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
require_relative '../spec_helper' | ||
|
||
describe Dogapi::Client do | ||
SLO_ID = '42424242424242424242424242424242'.freeze | ||
SLO_TYPE = 'metric'.freeze | ||
SLO_NAME = 'test slo'.freeze | ||
SLO_DESCRIPTION = 'test slo description'.freeze | ||
SLO_QUERY_NUMERATOR = 'sum:test.metric.metric{type:good}.as_count()'.freeze | ||
SLO_QUERY_DENOMINATOR = 'sum:test.metric.metric{*}.as_count()'.freeze | ||
SLO_TAGS = ['type:test'].freeze | ||
SLO_THRESHOLDS = [{ timeframe: '7d', target: 90 }, { timeframe: '30d', target: 95 }].freeze | ||
|
||
describe '#create_service_level_objective' do | ||
it_behaves_like 'an api method', | ||
:create_service_level_objective, [SLO_TYPE, SLO_NAME, SLO_THRESHOLDS, { | ||
description: SLO_DESCRIPTION, | ||
tags: SLO_TAGS, | ||
numerator: SLO_QUERY_NUMERATOR, | ||
denominator: SLO_QUERY_DENOMINATOR | ||
}], | ||
:post, '/slo', 'type' => SLO_TYPE, 'name' => SLO_NAME, 'thresholds' => SLO_THRESHOLDS, | ||
'query' => { numerator: SLO_QUERY_NUMERATOR, denominator: SLO_QUERY_DENOMINATOR }, | ||
'tags' => SLO_TAGS, 'description' => SLO_DESCRIPTION | ||
end | ||
|
||
describe '#update_service_level_objective' do | ||
it_behaves_like 'an api method', | ||
:update_service_level_objective, [SLO_ID, SLO_TYPE, { name: SLO_NAME }], | ||
:put, "/slo/#{SLO_ID}", 'type' => SLO_TYPE, 'name' => SLO_NAME | ||
end | ||
|
||
describe '#get_service_level_objective' do | ||
it_behaves_like 'an api method', | ||
:get_service_level_objective, [SLO_ID], | ||
:get, "/slo/#{SLO_ID}" | ||
end | ||
|
||
describe '#get_service_level_objective_history' do | ||
it_behaves_like 'an api method with params', | ||
:get_service_level_objective_history, [SLO_ID], | ||
:get, "/slo/#{SLO_ID}/history", 'from_ts' => 0, 'to_ts' => 1_000_000 | ||
end | ||
|
||
describe '#can_delete_service_level_objective' do | ||
it_behaves_like 'an api method with params', | ||
:can_delete_service_level_objective, [], | ||
:get, '/slo/can_delete', 'ids' => [SLO_ID] | ||
end | ||
|
||
describe '#search_service_level_objective' do | ||
it_behaves_like 'an api method with optional params', | ||
:search_service_level_objective, [[SLO_ID]], | ||
:get, '/slo/', 'ids' => SLO_ID | ||
end | ||
|
||
describe '#delete_service_level_objective' do | ||
it_behaves_like 'an api method', | ||
:delete_service_level_objective, [SLO_ID], | ||
:delete, "/slo/#{SLO_ID}" | ||
end | ||
|
||
describe '#delete_many_service_level_objective' do | ||
it_behaves_like 'an api method', | ||
:delete_many_service_level_objective, [[SLO_ID]], | ||
:delete, '/slo/', 'ids' => [SLO_ID] | ||
end | ||
|
||
describe '#delete_timeframes_service_level_objective' do | ||
it_behaves_like 'an api method', | ||
:delete_timeframes_service_level_objective, [{ SLO_ID => ['7d'] }], | ||
:post, '/slo/bulk_delete', SLO_ID => ['7d'] | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reasoning behind this one ?
We already have a few endpoints that use a hash for options, but aren't using this symbolized access.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking across the other usages, all of the other
options
are merged into thebody
without modification. In a few cases here we construct a deeper object in the body based on the flat options passed in.