Skip to content

Commit

Permalink
Refactored: Datadog::Diagnostics::Health::Metrics --> Datadog::Core::…
Browse files Browse the repository at this point in the history
…Diagnostics::Health::Metrics
  • Loading branch information
delner committed Jan 25, 2022
1 parent 91c49a3 commit 086163b
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 132 deletions.
40 changes: 40 additions & 0 deletions lib/datadog/core/diagnostics/ext.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# typed: true
module Datadog
module Core
module Diagnostics
# @public_api
module Ext
DD_TRACE_STARTUP_LOGS = 'DD_TRACE_STARTUP_LOGS'.freeze
DD_TRACE_DEBUG = 'DD_TRACE_DEBUG'.freeze
DD_TRACE_ENABLED = 'DD_TRACE_ENABLED'.freeze
# Health
module Health
# Metrics
module Metrics
ENV_ENABLED = 'DD_HEALTH_METRICS_ENABLED'.freeze

METRIC_API_ERRORS = 'datadog.tracer.api.errors'.freeze
METRIC_API_REQUESTS = 'datadog.tracer.api.requests'.freeze
METRIC_API_RESPONSES = 'datadog.tracer.api.responses'.freeze
METRIC_ERROR_CONTEXT_OVERFLOW = 'datadog.tracer.error.context_overflow'.freeze
METRIC_ERROR_INSTRUMENTATION_PATCH = 'datadog.tracer.error.instrumentation_patch'.freeze
METRIC_ERROR_SPAN_FINISH = 'datadog.tracer.error.span_finish'.freeze
METRIC_ERROR_UNFINISHED_SPANS = 'datadog.tracer.error.unfinished_spans'.freeze
METRIC_INSTRUMENTATION_PATCHED = 'datadog.tracer.instrumentation_patched'.freeze
METRIC_QUEUE_ACCEPTED = 'datadog.tracer.queue.accepted'.freeze
METRIC_QUEUE_ACCEPTED_LENGTHS = 'datadog.tracer.queue.accepted_lengths'.freeze
METRIC_QUEUE_DROPPED = 'datadog.tracer.queue.dropped'.freeze
METRIC_QUEUE_LENGTH = 'datadog.tracer.queue.length'.freeze
METRIC_QUEUE_MAX_LENGTH = 'datadog.tracer.queue.max_length'.freeze
METRIC_QUEUE_SPANS = 'datadog.tracer.queue.spans'.freeze
METRIC_SAMPLING_SERVICE_CACHE_LENGTH = 'datadog.tracer.sampling.service_cache_length'.freeze
METRIC_TRACES_FILTERED = 'datadog.tracer.traces.filtered'.freeze
METRIC_TRANSPORT_CHUNKED = 'datadog.tracer.transport.chunked'.freeze
METRIC_TRANSPORT_TRACE_TOO_LARGE = 'datadog.tracer.transport.trace_too_large'.freeze
METRIC_WRITER_CPU_TIME = 'datadog.tracer.writer.cpu_time'.freeze
end
end
end
end
end
end
36 changes: 36 additions & 0 deletions lib/datadog/core/diagnostics/health.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# typed: false
require 'datadog/core/metrics/client'
require 'datadog/core/diagnostics/ext'

module Datadog
module Core
module Diagnostics
# Health-related diagnostics
module Health
# Health metrics for diagnostics
class Metrics < ::Datadog::Core::Metrics::Client
count :api_errors, Ext::Health::Metrics::METRIC_API_ERRORS
count :api_requests, Ext::Health::Metrics::METRIC_API_REQUESTS
count :api_responses, Ext::Health::Metrics::METRIC_API_RESPONSES
count :error_context_overflow, Ext::Health::Metrics::METRIC_ERROR_CONTEXT_OVERFLOW
count :error_instrumentation_patch, Ext::Health::Metrics::METRIC_ERROR_INSTRUMENTATION_PATCH
count :error_span_finish, Ext::Health::Metrics::METRIC_ERROR_SPAN_FINISH
count :error_unfinished_spans, Ext::Health::Metrics::METRIC_ERROR_UNFINISHED_SPANS
count :instrumentation_patched, Ext::Health::Metrics::METRIC_INSTRUMENTATION_PATCHED
count :queue_accepted, Ext::Health::Metrics::METRIC_QUEUE_ACCEPTED
count :queue_accepted_lengths, Ext::Health::Metrics::METRIC_QUEUE_ACCEPTED_LENGTHS
count :queue_dropped, Ext::Health::Metrics::METRIC_QUEUE_DROPPED
count :traces_filtered, Ext::Health::Metrics::METRIC_TRACES_FILTERED
count :transport_trace_too_large, Ext::Health::Metrics::METRIC_TRANSPORT_TRACE_TOO_LARGE
count :transport_chunked, Ext::Health::Metrics::METRIC_TRANSPORT_CHUNKED
count :writer_cpu_time, Ext::Health::Metrics::METRIC_WRITER_CPU_TIME

gauge :queue_length, Ext::Health::Metrics::METRIC_QUEUE_LENGTH
gauge :queue_max_length, Ext::Health::Metrics::METRIC_QUEUE_MAX_LENGTH
gauge :queue_spans, Ext::Health::Metrics::METRIC_QUEUE_SPANS
gauge :sampling_service_cache_length, Ext::Health::Metrics::METRIC_SAMPLING_SERVICE_CACHE_LENGTH
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/ddtrace/buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'datadog/core/buffer/thread_safe'
require 'datadog/core/buffer/cruby'

require 'ddtrace/diagnostics/health'
require 'datadog/core/diagnostics/health'

module Datadog
# Health metrics for trace buffers.
Expand Down
4 changes: 2 additions & 2 deletions lib/ddtrace/configuration/components.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# typed: false
require 'ddtrace/configuration/agent_settings_resolver'
require 'ddtrace/diagnostics/health'
require 'datadog/core/diagnostics/health'
require 'datadog/core/logger'
require 'ddtrace/profiling'
require 'ddtrace/runtime/metrics'
Expand All @@ -21,7 +21,7 @@ def build_health_metrics(settings)
options = { enabled: settings.enabled }
options[:statsd] = settings.statsd unless settings.statsd.nil?

Datadog::Diagnostics::Health::Metrics.new(**options)
Datadog::Core::Diagnostics::Health::Metrics.new(**options)
end

def build_logger(settings)
Expand Down
10 changes: 5 additions & 5 deletions lib/ddtrace/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def initialize(*_)
# @default `DD_TRACE_DEBUG` environment variable, otherwise `false`
# @return [Boolean]
option :debug do |o|
o.default { env_to_bool(Datadog::Ext::Diagnostics::DD_TRACE_DEBUG, false) }
o.default { env_to_bool(Core::Diagnostics::Ext::DD_TRACE_DEBUG, false) }
o.lazy
o.on_set do |enabled|
# Enable rich debug print statements.
Expand All @@ -100,15 +100,15 @@ def initialize(*_)

# Internal {Datadog::Statsd} metrics collection.
#
# The list of metrics collected can be found in {Datadog::Ext::Diagnostics::Health::Metrics}.
# The list of metrics collected can be found in {Datadog::Core::Diagnostics::Ext::Health::Metrics}.
# @public_api
settings :health_metrics do
# Enable health metrics collection.
#
# @default `DD_HEALTH_METRICS_ENABLED` environment variable, otherwise `false`
# @return [Boolean]
option :enabled do |o|
o.default { env_to_bool(Datadog::Ext::Diagnostics::Health::Metrics::ENV_ENABLED, false) }
o.default { env_to_bool(Core::Diagnostics::Ext::Health::Metrics::ENV_ENABLED, false) }
o.lazy
end

Expand All @@ -134,7 +134,7 @@ def initialize(*_)
# @return [Boolean,nil]
option :enabled do |o|
# Defaults to nil as we want to know when the default value is being used
o.default { env_to_bool(Datadog::Ext::Diagnostics::DD_TRACE_STARTUP_LOGS, nil) }
o.default { env_to_bool(Core::Diagnostics::Ext::DD_TRACE_STARTUP_LOGS, nil) }
o.lazy
end
end
Expand Down Expand Up @@ -497,7 +497,7 @@ def initialize(*_)
# @default `DD_TRACE_ENABLED` environment variable, otherwise `true`
# @return [Boolean]
option :enabled do |o|
o.default { env_to_bool(Datadog::Ext::Diagnostics::DD_TRACE_ENABLED, true) }
o.default { env_to_bool(Core::Diagnostics::Ext::DD_TRACE_ENABLED, true) }
o.lazy
end

Expand Down
34 changes: 0 additions & 34 deletions lib/ddtrace/diagnostics/health.rb

This file was deleted.

38 changes: 0 additions & 38 deletions lib/ddtrace/ext/diagnostics.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/ddtrace/sampler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

require 'ddtrace/ext/priority'
require 'ddtrace/ext/sampling'
require 'ddtrace/diagnostics/health'
require 'datadog/core/diagnostics/health'

module Datadog
# Interface for client-side trace sampling.
Expand Down
2 changes: 1 addition & 1 deletion lib/ddtrace/transport/statistics.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# typed: true
require 'datadog/core/metrics/metric'
require 'ddtrace/diagnostics/health'
require 'datadog/core/diagnostics/health'

module Datadog
module Transport
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# typed: false
require 'spec_helper'
require 'ddtrace'
require 'ddtrace/diagnostics/health'
require 'datadog/core/diagnostics/health'

RSpec.describe Datadog::Diagnostics::Health::Metrics do
RSpec.describe Datadog::Core::Diagnostics::Health::Metrics do
subject(:health_metrics) { described_class.new }

shared_examples_for 'a health metric' do |type, name, stat|
Expand All @@ -23,22 +23,23 @@
end

# rubocop:disable Layout/LineLength
it_behaves_like 'a health metric', :count, :api_errors, Datadog::Ext::Diagnostics::Health::Metrics::METRIC_API_ERRORS
it_behaves_like 'a health metric', :count, :api_requests, Datadog::Ext::Diagnostics::Health::Metrics::METRIC_API_REQUESTS
it_behaves_like 'a health metric', :count, :api_responses, Datadog::Ext::Diagnostics::Health::Metrics::METRIC_API_RESPONSES
it_behaves_like 'a health metric', :count, :error_context_overflow, Datadog::Ext::Diagnostics::Health::Metrics::METRIC_ERROR_CONTEXT_OVERFLOW
it_behaves_like 'a health metric', :count, :error_instrumentation_patch, Datadog::Ext::Diagnostics::Health::Metrics::METRIC_ERROR_INSTRUMENTATION_PATCH
it_behaves_like 'a health metric', :count, :error_span_finish, Datadog::Ext::Diagnostics::Health::Metrics::METRIC_ERROR_SPAN_FINISH
it_behaves_like 'a health metric', :count, :error_unfinished_spans, Datadog::Ext::Diagnostics::Health::Metrics::METRIC_ERROR_UNFINISHED_SPANS
it_behaves_like 'a health metric', :count, :instrumentation_patched, Datadog::Ext::Diagnostics::Health::Metrics::METRIC_INSTRUMENTATION_PATCHED
it_behaves_like 'a health metric', :count, :queue_accepted, Datadog::Ext::Diagnostics::Health::Metrics::METRIC_QUEUE_ACCEPTED
it_behaves_like 'a health metric', :count, :queue_accepted_lengths, Datadog::Ext::Diagnostics::Health::Metrics::METRIC_QUEUE_ACCEPTED_LENGTHS
it_behaves_like 'a health metric', :count, :queue_dropped, Datadog::Ext::Diagnostics::Health::Metrics::METRIC_QUEUE_DROPPED
it_behaves_like 'a health metric', :count, :traces_filtered, Datadog::Ext::Diagnostics::Health::Metrics::METRIC_TRACES_FILTERED
it_behaves_like 'a health metric', :count, :writer_cpu_time, Datadog::Ext::Diagnostics::Health::Metrics::METRIC_WRITER_CPU_TIME
it_behaves_like 'a health metric', :count, :api_errors, Datadog::Core::Diagnostics::Ext::Health::Metrics::METRIC_API_ERRORS
it_behaves_like 'a health metric', :count, :api_requests, Datadog::Core::Diagnostics::Ext::Health::Metrics::METRIC_API_REQUESTS
it_behaves_like 'a health metric', :count, :api_responses, Datadog::Core::Diagnostics::Ext::Health::Metrics::METRIC_API_RESPONSES
it_behaves_like 'a health metric', :count, :error_context_overflow, Datadog::Core::Diagnostics::Ext::Health::Metrics::METRIC_ERROR_CONTEXT_OVERFLOW
it_behaves_like 'a health metric', :count, :error_instrumentation_patch, Datadog::Core::Diagnostics::Ext::Health::Metrics::METRIC_ERROR_INSTRUMENTATION_PATCH
it_behaves_like 'a health metric', :count, :error_span_finish, Datadog::Core::Diagnostics::Ext::Health::Metrics::METRIC_ERROR_SPAN_FINISH
it_behaves_like 'a health metric', :count, :error_unfinished_spans, Datadog::Core::Diagnostics::Ext::Health::Metrics::METRIC_ERROR_UNFINISHED_SPANS
it_behaves_like 'a health metric', :count, :instrumentation_patched, Datadog::Core::Diagnostics::Ext::Health::Metrics::METRIC_INSTRUMENTATION_PATCHED
it_behaves_like 'a health metric', :count, :queue_accepted, Datadog::Core::Diagnostics::Ext::Health::Metrics::METRIC_QUEUE_ACCEPTED
it_behaves_like 'a health metric', :count, :queue_accepted_lengths, Datadog::Core::Diagnostics::Ext::Health::Metrics::METRIC_QUEUE_ACCEPTED_LENGTHS
it_behaves_like 'a health metric', :count, :queue_dropped, Datadog::Core::Diagnostics::Ext::Health::Metrics::METRIC_QUEUE_DROPPED
it_behaves_like 'a health metric', :count, :traces_filtered, Datadog::Core::Diagnostics::Ext::Health::Metrics::METRIC_TRACES_FILTERED
it_behaves_like 'a health metric', :count, :writer_cpu_time, Datadog::Core::Diagnostics::Ext::Health::Metrics::METRIC_WRITER_CPU_TIME

it_behaves_like 'a health metric', :gauge, :queue_length, Datadog::Ext::Diagnostics::Health::Metrics::METRIC_QUEUE_LENGTH
it_behaves_like 'a health metric', :gauge, :queue_max_length, Datadog::Ext::Diagnostics::Health::Metrics::METRIC_QUEUE_MAX_LENGTH
it_behaves_like 'a health metric', :gauge, :queue_spans, Datadog::Ext::Diagnostics::Health::Metrics::METRIC_QUEUE_SPANS
it_behaves_like 'a health metric', :gauge, :sampling_service_cache_length, Datadog::Ext::Diagnostics::Health::Metrics::METRIC_SAMPLING_SERVICE_CACHE_LENGTH
it_behaves_like 'a health metric', :gauge, :queue_length, Datadog::Core::Diagnostics::Ext::Health::Metrics::METRIC_QUEUE_LENGTH
it_behaves_like 'a health metric', :gauge, :queue_max_length, Datadog::Core::Diagnostics::Ext::Health::Metrics::METRIC_QUEUE_MAX_LENGTH
it_behaves_like 'a health metric', :gauge, :queue_spans, Datadog::Core::Diagnostics::Ext::Health::Metrics::METRIC_QUEUE_SPANS
it_behaves_like 'a health metric', :gauge, :sampling_service_cache_length, Datadog::Core::Diagnostics::Ext::Health::Metrics::METRIC_SAMPLING_SERVICE_CACHE_LENGTH
# rubocop:enable Layout/LineLength
end
8 changes: 4 additions & 4 deletions spec/ddtrace/configuration/components_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
let(:tracer) { instance_double(Datadog::Tracer) }
let(:profiler) { Datadog::Profiling.supported? ? instance_double(Datadog::Profiler) : nil }
let(:runtime_metrics) { instance_double(Datadog::Core::Workers::RuntimeMetrics) }
let(:health_metrics) { instance_double(Datadog::Diagnostics::Health::Metrics) }
let(:health_metrics) { instance_double(Datadog::Core::Diagnostics::Health::Metrics) }

before do
expect(described_class).to receive(:build_logger)
Expand Down Expand Up @@ -62,12 +62,12 @@

context 'given settings' do
shared_examples_for 'new health metrics' do
let(:health_metrics) { instance_double(Datadog::Diagnostics::Health::Metrics) }
let(:health_metrics) { instance_double(Datadog::Core::Diagnostics::Health::Metrics) }
let(:default_options) { { enabled: settings.diagnostics.health_metrics.enabled } }
let(:options) { {} }

before do
expect(Datadog::Diagnostics::Health::Metrics).to receive(:new)
expect(Datadog::Core::Diagnostics::Health::Metrics).to receive(:new)
.with(default_options.merge(options))
.and_return(health_metrics)
end
Expand Down Expand Up @@ -1124,7 +1124,7 @@
let(:profiler) { Datadog::Profiling.supported? ? instance_double(Datadog::Profiler) : nil }
let(:runtime_metrics_worker) { instance_double(Datadog::Core::Workers::RuntimeMetrics, metrics: runtime_metrics) }
let(:runtime_metrics) { instance_double(Datadog::Core::Runtime::Metrics, statsd: statsd) }
let(:health_metrics) { instance_double(Datadog::Diagnostics::Health::Metrics, statsd: statsd) }
let(:health_metrics) { instance_double(Datadog::Core::Diagnostics::Health::Metrics, statsd: statsd) }
let(:statsd) { instance_double(::Datadog::Statsd) }

before do
Expand Down
12 changes: 6 additions & 6 deletions spec/ddtrace/configuration/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@

it { is_expected.to be false }

context "when #{Datadog::Ext::Diagnostics::DD_TRACE_DEBUG}" do
context "when #{Datadog::Core::Diagnostics::Ext::DD_TRACE_DEBUG}" do
around do |example|
ClimateControl.modify(Datadog::Ext::Diagnostics::DD_TRACE_DEBUG => environment) do
ClimateControl.modify(Datadog::Core::Diagnostics::Ext::DD_TRACE_DEBUG => environment) do
example.run
end
end
Expand Down Expand Up @@ -146,9 +146,9 @@
describe '#enabled' do
subject(:enabled) { settings.diagnostics.health_metrics.enabled }

context "when #{Datadog::Ext::Diagnostics::Health::Metrics::ENV_ENABLED}" do
context "when #{Datadog::Core::Diagnostics::Ext::Health::Metrics::ENV_ENABLED}" do
around do |example|
ClimateControl.modify(Datadog::Ext::Diagnostics::Health::Metrics::ENV_ENABLED => environment) do
ClimateControl.modify(Datadog::Core::Diagnostics::Ext::Health::Metrics::ENV_ENABLED => environment) do
example.run
end
end
Expand Down Expand Up @@ -1119,9 +1119,9 @@

it { is_expected.to be true }

context "when #{Datadog::Ext::Diagnostics::DD_TRACE_ENABLED}" do
context "when #{Datadog::Core::Diagnostics::Ext::DD_TRACE_ENABLED}" do
around do |example|
ClimateControl.modify(Datadog::Ext::Diagnostics::DD_TRACE_ENABLED => enable) do
ClimateControl.modify(Datadog::Core::Diagnostics::Ext::DD_TRACE_ENABLED => enable) do
example.run
end
end
Expand Down
Loading

0 comments on commit 086163b

Please sign in to comment.