From eb9d8e596edbf3c7eb092ffc77bd044dc56689af Mon Sep 17 00:00:00 2001 From: Mario de la Ossa Date: Fri, 18 Aug 2023 14:08:11 -0600 Subject: [PATCH] Support influxdbv2 in custom metric drain --- README.md | 1 + lib/aptible/cli/subcommands/metric_drain.rb | 29 +++++++++++++++++++ .../cli/subcommands/metric_drain_spec.rb | 28 +++++++++++++++++- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d38dfae..ec869b99 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ Commands: aptible metric_drain:create:datadog HANDLE --api_key DATADOG_API_KEY --site DATADOG_SITE --environment ENVIRONMENT # Create a Datadog Metric Drain aptible metric_drain:create:influxdb HANDLE --db DATABASE_HANDLE --environment ENVIRONMENT # Create an InfluxDB Metric Drain aptible metric_drain:create:influxdb:custom HANDLE --username USERNAME --password PASSWORD --url URL_INCLUDING_PORT --db INFLUX_DATABASE_NAME --environment ENVIRONMENT # Create an InfluxDB Metric Drain + aptible metric_drain:create:influxdb:customv2 HANDLE --org ORGANIZATION --token INFLUX_TOKEN --url URL_INCLUDING_PORT --bucket INFLUX_BUCKET_NAME --environment ENVIRONMENT # Create an InfluxDB v2 Metric Drain aptible metric_drain:deprovision HANDLE --environment ENVIRONMENT # Deprovisions a Metric Drain aptible metric_drain:list # List all Metric Drains aptible operation:cancel OPERATION_ID # Cancel a running operation diff --git a/lib/aptible/cli/subcommands/metric_drain.rb b/lib/aptible/cli/subcommands/metric_drain.rb index 940b068c..f8a8653b 100644 --- a/lib/aptible/cli/subcommands/metric_drain.rb +++ b/lib/aptible/cli/subcommands/metric_drain.rb @@ -85,6 +85,35 @@ def self.included(thor) create_metric_drain(account, opts) end + desc 'metric_drain:create:influxdb:customv2 HANDLE '\ + '--org ORGANIZATION --token INFLUX_TOKEN ' \ + '--url URL_INCLUDING_PORT ' \ + '--bucket INFLUX_BUCKET_NAME ' \ + '--environment ENVIRONMENT', + 'Create an InfluxDB v2 Metric Drain' + option :bucket, type: :string + option :org, type: :string + option :token, type: :string + option :url, type: :string + option :environment + define_method 'metric_drain:create:influxdb:customv2' do |handle| + account = ensure_environment(options) + + config = { + address: options[:url], + org: options[:org], + authToken: options[:token], + bucket: options[:bucket] + } + opts = { + handle: handle, + drain_configuration: config, + drain_type: :influxdb2 + } + + create_metric_drain(account, opts) + end + desc 'metric_drain:create:datadog HANDLE '\ '--api_key DATADOG_API_KEY '\ '--site DATADOG_SITE ' \ diff --git a/spec/aptible/cli/subcommands/metric_drain_spec.rb b/spec/aptible/cli/subcommands/metric_drain_spec.rb index fe771e0e..d13903e1 100644 --- a/spec/aptible/cli/subcommands/metric_drain_spec.rb +++ b/spec/aptible/cli/subcommands/metric_drain_spec.rb @@ -86,7 +86,7 @@ def expect_provision_metric_drain(create_opts, provision_opts = {}) end context 'influxdb:custom' do - it 'creates a new InfluxDB metric drain' do + it 'creates a new InfluxDB v1 metric drain' do opts = { handle: 'test-influxdb-custom', drain_type: :influxdb, @@ -111,6 +111,32 @@ def expect_provision_metric_drain(create_opts, provision_opts = {}) end end + context 'influxdb:customv2' do + it 'creates a new InfluxDB v2 metric drain' do + opts = { + handle: 'test-influxdb2-custom', + drain_type: :influxdb2, + drain_configuration: { + address: 'https://test.foo.com:443', + org: 'foobar', + authToken: 'bar', + bucket: 'foo' + } + } + expect_provision_metric_drain(opts) + + subject.options = { + environment: account.handle, + bucket: 'foo', + token: 'bar', + org: 'foobar', + url: 'https://test.foo.com:443' + } + subject.send('metric_drain:create:influxdb:customv2', + 'test-influxdb2-custom') + end + end + context 'datadog' do it 'creates a new Datadog metric drain' do opts = {