From 52808a84825704f2666ed3855bc4354898cc40e5 Mon Sep 17 00:00:00 2001 From: Artem A <67011886+hi-artem@users.noreply.github.com> Date: Mon, 25 Jan 2021 07:43:44 -0800 Subject: [PATCH] Added support for logs pipelines CRUD methods (#252) * 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 --- .rubocop_todo.yml | 1 + lib/dogapi/facade.rb | 25 +++++++++++++++ lib/dogapi/v1.rb | 1 + lib/dogapi/v1/logs_pipeline.rb | 41 ++++++++++++++++++++++++ spec/integration/logs_pipeline_spec.rb | 43 ++++++++++++++++++++++++++ 5 files changed, 111 insertions(+) create mode 100644 lib/dogapi/v1/logs_pipeline.rb create mode 100644 spec/integration/logs_pipeline_spec.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4300f369..57cc2784 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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' diff --git a/lib/dogapi/facade.rb b/lib/dogapi/facade.rb index d10a62f6..6e9bf852 100644 --- a/lib/dogapi/facade.rb +++ b/lib/dogapi/facade.rb @@ -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) @@ -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 # diff --git a/lib/dogapi/v1.rb b/lib/dogapi/v1.rb index 34fbb231..d5ae278e 100644 --- a/lib/dogapi/v1.rb +++ b/lib/dogapi/v1.rb @@ -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' diff --git a/lib/dogapi/v1/logs_pipeline.rb b/lib/dogapi/v1/logs_pipeline.rb new file mode 100644 index 00000000..24d30c47 --- /dev/null +++ b/lib/dogapi/v1/logs_pipeline.rb @@ -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 diff --git a/spec/integration/logs_pipeline_spec.rb b/spec/integration/logs_pipeline_spec.rb new file mode 100644 index 00000000..e3468192 --- /dev/null +++ b/spec/integration/logs_pipeline_spec.rb @@ -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