Skip to content

Commit

Permalink
Added support for logs pipelines CRUD methods (#252)
Browse files Browse the repository at this point in the history
* feat(dogapi): add logs pipeline resource and CRUD methods

* Try to pin crack to 0.4.4

* Typo in crack version

* Try hard lock

* Update lib/dogapi/v1/logs_pipeline.rb

Co-authored-by: Hippolyte HENRY <zippolyte@users.noreply.github.com>
  • Loading branch information
hi-artem and zippolyte authored Jan 25, 2021
1 parent 9f9c158 commit 52808a8
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 0 deletions.
1 change: 1 addition & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ Style/AccessorMethodName:
- 'lib/dogapi/v1/dash.rb'
- 'lib/dogapi/v1/dashboard.rb'
- 'lib/dogapi/v1/embed.rb'
- 'lib/dogapi/v1/logs_pipeline.rb'
- 'lib/dogapi/v1/screenboard.rb'
- 'lib/dogapi/v1/synthetics.rb'
- 'lib/dogapi/v1/user.rb'
Expand Down
25 changes: 25 additions & 0 deletions lib/dogapi/facade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def initialize(api_key, application_key=nil, host=nil, device=nil, silent=true,
@gcp_integration_svc = Dogapi::V1::GcpIntegrationService.new(@api_key, @application_key, silent, timeout, @datadog_host, skip_ssl_validation)
@service_level_objective_svc = Dogapi::V1::ServiceLevelObjectiveService.new(@api_key, @application_key, silent,
timeout, @datadog_host, skip_ssl_validation)
@logs_pipeline_svc = Dogapi::V1::LogsPipelineService.new(@api_key, @application_key, silent, timeout, @datadog_host, skip_ssl_validation)

# Support for Dashboard List API v2.
@v2 = Dogapi::ClientV2.new(@api_key, @application_key, true, true, @datadog_host, skip_ssl_validation)
Expand Down Expand Up @@ -717,6 +718,30 @@ def delete_timeframes_service_level_objective(ops)
@service_level_objective_svc.delete_timeframes_service_level_objective(ops)
end

#
# LOGS PIPELINES
#

def create_logs_pipeline(name, filter, options = {})
@logs_pipeline_svc.create_logs_pipeline(name, filter, options)
end

def get_logs_pipeline(pipeline_id)
@logs_pipeline_svc.get_logs_pipeline(pipeline_id)
end

def get_all_logs_pipelines
@logs_pipeline_svc.get_all_logs_pipelines
end

def update_logs_pipeline(pipeline_id, name, filter, options = {})
@logs_pipeline_svc.update_logs_pipeline(pipeline_id, name, filter, options)
end

def delete_logs_pipeline(pipeline_id)
@logs_pipeline_svc.delete_logs_pipeline(pipeline_id)
end

#
# SERVICE CHECKS
#
Expand Down
1 change: 1 addition & 0 deletions lib/dogapi/v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require 'dogapi/v1/dashboard_list'
require 'dogapi/v1/embed'
require 'dogapi/v1/event'
require 'dogapi/v1/logs_pipeline'
require 'dogapi/v1/metadata'
require 'dogapi/v1/metric'
require 'dogapi/v1/monitor'
Expand Down
41 changes: 41 additions & 0 deletions lib/dogapi/v1/logs_pipeline.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Unless explicitly stated otherwise all files in this repository are licensed under the BSD-3-Clause License.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2011-Present Datadog, Inc.

module Dogapi
class V1 # for namespacing
class LogsPipelineService < Dogapi::APIService
API_VERSION = 'v1'

def create_logs_pipeline(name, filter, options = {})
body = {
'name' => name,
'filter' => filter
}.merge options

request(Net::HTTP::Post, "/api/#{API_VERSION}/logs/config/pipelines", nil, body, true)
end

def get_logs_pipeline(pipeline_id)
request(Net::HTTP::Get, "/api/#{API_VERSION}/logs/config/pipelines/#{pipeline_id}", nil, nil, false)
end

def get_all_logs_pipelines
request(Net::HTTP::Get, "/api/#{API_VERSION}/logs/config/pipelines", nil, nil, false)
end

def update_logs_pipeline(pipeline_id, name, filter, options = {})
body = {
'name' => name,
'filter' => filter
}.merge options

request(Net::HTTP::Put, "/api/#{API_VERSION}/logs/config/pipelines/#{pipeline_id}", nil, body, true)
end

def delete_logs_pipeline(pipeline_id)
request(Net::HTTP::Delete, "/api/#{API_VERSION}/logs/config/pipelines/#{pipeline_id}", nil, nil, false)
end
end
end
end
43 changes: 43 additions & 0 deletions spec/integration/logs_pipeline_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Unless explicitly stated otherwise all files in this repository are licensed under the BSD-3-Clause License.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2011-Present Datadog, Inc.

require_relative '../spec_helper'

describe Dogapi::Client do
LOGS_PIPELINE_ID = '42'
LOGS_PIPELINE_NAME = 'my logs pipeline'.freeze
LOGS_PIPELINE_FILTER = { 'query' => 'source:my-app' }.freeze

describe '#create_logs_pipeline' do
it_behaves_like 'an api method with options',
:create_logs_pipeline, [LOGS_PIPELINE_NAME, LOGS_PIPELINE_FILTER],
:post, '/logs/config/pipelines', 'name' => LOGS_PIPELINE_NAME,
'filter' => LOGS_PIPELINE_FILTER
end

describe '#get_logs_pipeline' do
it_behaves_like 'an api method',
:get_logs_pipeline, [LOGS_PIPELINE_ID],
:get, "/logs/config/pipelines/#{LOGS_PIPELINE_ID}"
end

describe '#get_all_logs_pipelines' do
it_behaves_like 'an api method',
:get_all_logs_pipelines, [],
:get, '/logs/config/pipelines'
end

describe '#update_logs_pipeline' do
it_behaves_like 'an api method with options',
:update_logs_pipeline, [LOGS_PIPELINE_ID, LOGS_PIPELINE_NAME, LOGS_PIPELINE_FILTER],
:put, "/logs/config/pipelines/#{LOGS_PIPELINE_ID}", 'name' => LOGS_PIPELINE_NAME,
'filter' => LOGS_PIPELINE_FILTER
end

describe '#delete_logs_pipeline' do
it_behaves_like 'an api method',
:delete_logs_pipeline, [LOGS_PIPELINE_ID],
:delete, "/logs/config/pipelines/#{LOGS_PIPELINE_ID}"
end
end

0 comments on commit 52808a8

Please sign in to comment.