Skip to content
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

Rubocop on metrics #1683

Merged
merged 5 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 9 additions & 20 deletions exporter/otlp-metrics/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
inherit_from: ../../contrib/rubocop.yml

AllCops:
TargetRubyVersion: "3.0"
NewCops: disable
SuggestExtensions: false
Exclude:
- "lib/opentelemetry/proto/**/*"
- "vendor/**/*"

Bundler/OrderedGems:
Exclude:
- gemfiles/**/*
Lint/UnusedMethodArgument:
Enabled: false
Lint/MissingSuper:
Enabled: false
Lint/ConstantDefinitionInBlock:
Exclude:
- "test/**/*"
Style/StringConcatenation:
Exclude:
- "test/**/*"
Metrics/AbcSize:
Metrics/CyclomaticComplexity:
Enabled: false
Layout/LineLength:
Metrics/PerceivedComplexity:
Enabled: false
Metrics/MethodLength:
Max: 20
Metrics/ParameterLists:
Enabled: false
Metrics/ClassLength:
Enabled: false
Bundler/OrderedGems:
Exclude:
- gemfiles/**/*
Style/FrozenStringLiteralComment:
Exclude:
- gemfiles/**/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module OpenTelemetry
module Exporter
module OTLP
# An OpenTelemetry metrics exporter that sends metrics over HTTP as Protobuf encoded OTLP ExportMetricsServiceRequest.
class MetricsExporter < ::OpenTelemetry::SDK::Metrics::Export::MetricReader # rubocop:disable Metrics/ClassLength
class MetricsExporter < ::OpenTelemetry::SDK::Metrics::Export::MetricReader
include Util

attr_reader :metric_snapshots
Expand Down Expand Up @@ -90,7 +90,7 @@ def export(metrics, timeout: nil)
end
end

def send_bytes(bytes, timeout:) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
def send_bytes(bytes, timeout:)
return FAILURE if bytes.nil?

request = Net::HTTP::Post.new(@path)
Expand Down Expand Up @@ -184,7 +184,7 @@ def send_bytes(bytes, timeout:) # rubocop:disable Metrics/CyclomaticComplexity,
@http.write_timeout = @timeout if WRITE_TIMEOUT_SUPPORTED
end

def encode(metrics_data) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
def encode(metrics_data)
Opentelemetry::Proto::Collector::Metrics::V1::ExportMetricsServiceRequest.encode(
Opentelemetry::Proto::Collector::Metrics::V1::ExportMetricsServiceRequest.new(
resource_metrics: metrics_data
Expand Down Expand Up @@ -218,7 +218,7 @@ def encode(metrics_data) # rubocop:disable Metrics/MethodLength, Metrics/Cycloma
# current metric sdk only implements instrument: :counter -> :sum, :histogram -> :histogram
#
# metrics [MetricData]
def as_otlp_metrics(metrics) # rubocop:disable Metrics/MethodLength
def as_otlp_metrics(metrics)
case metrics.instrument_kind
when :observable_gauge
Opentelemetry::Proto::Metrics::V1::Metric.new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def parse_headers(raw)
end
end

def backoff?(retry_count:, reason:, retry_after: nil) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def backoff?(retry_count:, reason:, retry_after: nil)
return false if retry_count > RETRY_COUNT

sleep_interval = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Counter
# Values must be non-nil and (array of) string, boolean or numeric type.
# Array values must not contain nil elements and all elements must be of
# the same basic type (string, numeric, boolean).
def add(increment, attributes: nil); end
def add(increment, attributes: {}); end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Histogram
# Values must be non-nil and (array of) string, boolean or numeric type.
# Array values must not contain nil elements and all elements must be of
# the same basic type (string, numeric, boolean).
def record(amount, attributes: nil); end
def record(amount, attributes: {}); end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class UpDownCounter
# Values must be non-nil and (array of) string, boolean or numeric type.
# Array values must not contain nil elements and all elements must be of
# the same basic type (string, numeric, boolean).
def add(amount, attributes: nil); end
def add(amount, attributes: {}); end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def instrument_kind
# Values must be non-nil and (array of) string, boolean or numeric type.
# Array values must not contain nil elements and all elements must be of
# the same basic type (string, numeric, boolean).
def record(amount, attributes: nil)
def record(amount, attributes: {})
update(amount, attributes)
nil
rescue StandardError => e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def instrument_kind
# Values must be non-nil and (array of) string, boolean or numeric type.
# Array values must not contain nil elements and all elements must be of
# the same basic type (string, numeric, boolean).
def add(amount, attributes: nil)
def add(amount, attributes: {})
update(amount, attributes)
nil
rescue StandardError => e
Expand Down
Loading