WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit bd4ab98

Browse files
p-datadogp
andauthored
Transports: remove Spec, non-core Instance classes (#5142)
Co-authored-by: Oleg Pudeyev <[email protected]>
1 parent 42de5d9 commit bd4ab98

File tree

53 files changed

+274
-820
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+274
-820
lines changed

lib/datadog/core/remote/transport/http.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def root(
4040
headers: nil
4141
)
4242
Core::Transport::HTTP.build(
43-
api_instance_class: API::Instance,
4443
agent_settings: agent_settings,
4544
logger: logger,
4645
api_version: api_version,
@@ -64,7 +63,6 @@ def v7(
6463
headers: nil
6564
)
6665
Core::Transport::HTTP.build(
67-
api_instance_class: API::Instance,
6866
agent_settings: agent_settings,
6967
logger: logger,
7068
api_version: api_version,

lib/datadog/core/remote/transport/http/api.rb

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# frozen_string_literal: true
22

33
require_relative '../../../encoding'
4+
require_relative '../../../transport/http/api/endpoint'
45
require_relative '../../../transport/http/api/map'
5-
require_relative '../../../transport/http/api/instance'
6-
require_relative '../../../transport/http/api/spec'
76
require_relative 'negotiation'
87
require_relative 'config'
98

@@ -22,29 +21,15 @@ module API
2221

2322
def defaults
2423
Core::Transport::HTTP::API::Map[
25-
ROOT => Spec.new do |s|
26-
s.info = Negotiation::API::Endpoint.new(
27-
'/info',
28-
)
29-
end,
30-
V7 => Spec.new do |s|
31-
s.config = Config::API::Endpoint.new(
32-
'/v0.7/config',
33-
Core::Encoding::JSONEncoder,
34-
)
35-
end,
24+
ROOT => Negotiation::API::Endpoint.new(
25+
'/info',
26+
),
27+
V7 => Config::API::Endpoint.new(
28+
'/v0.7/config',
29+
Core::Encoding::JSONEncoder,
30+
),
3631
]
3732
end
38-
39-
class Instance < Core::Transport::HTTP::API::Instance
40-
include Config::API::Instance
41-
include Negotiation::API::Instance
42-
end
43-
44-
class Spec < Core::Transport::HTTP::API::Spec
45-
include Config::API::Spec
46-
include Negotiation::API::Spec
47-
end
4833
end
4934
end
5035
end

lib/datadog/core/remote/transport/http/config.rb

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
require 'json'
44

5-
require_relative '../../../transport/http/client'
5+
require_relative '../../../transport/http/api/endpoint'
6+
require_relative '../../../transport/http/response'
67
require_relative '../../../utils/base64'
78
require_relative '../../../utils/truncation'
8-
require_relative '../../../transport/http/response'
9-
require_relative '../../../transport/http/api/endpoint'
109

1110
module Datadog
1211
module Core
@@ -17,7 +16,7 @@ module HTTP
1716
module Config
1817
# Response from HTTP transport for remote configuration
1918
class Response
20-
include Datadog::Core::Transport::HTTP::Response
19+
include Core::Transport::HTTP::Response
2120

2221
def initialize(http_response, options = {}) # standard:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
2322
super(http_response)
@@ -179,36 +178,6 @@ def initialize(key, value)
179178
end
180179

181180
module API
182-
# Extensions for HTTP API Spec
183-
module Spec
184-
attr_reader :config
185-
186-
def config=(endpoint)
187-
@config = endpoint
188-
end
189-
190-
def send_config(env, &block)
191-
raise Core::Transport::HTTP::API::Spec::EndpointNotDefinedError.new('config', self) if config.nil?
192-
193-
config.call(env, &block)
194-
end
195-
end
196-
197-
# Extensions for HTTP API Instance
198-
module Instance
199-
def send_config(env)
200-
unless spec.is_a?(Config::API::Spec)
201-
raise Core::Transport::HTTP::API::Instance::EndpointNotSupportedError.new(
202-
'config', self
203-
)
204-
end
205-
206-
spec.send_config(env) do |request_env|
207-
call(request_env)
208-
end
209-
end
210-
end
211-
212181
# Endpoint for remote configuration
213182
class Endpoint < Datadog::Core::Transport::HTTP::API::Endpoint
214183
HEADER_CONTENT_TYPE = 'Content-Type'

lib/datadog/core/remote/transport/http/negotiation.rb

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,36 +44,6 @@ def initialize(http_response, options = {})
4444
end
4545

4646
module API
47-
# Extensions for HTTP API Spec
48-
module Spec
49-
attr_reader :info
50-
51-
def info=(endpoint)
52-
@info = endpoint
53-
end
54-
55-
def send_info(env, &block)
56-
raise Core::Transport::HTTP::API::Spec::EndpointNotDefinedError.new('info', self) if info.nil?
57-
58-
info.call(env, &block)
59-
end
60-
end
61-
62-
# Extensions for HTTP API Instance
63-
module Instance
64-
def send_info(env)
65-
unless spec.is_a?(Negotiation::API::Spec)
66-
raise Core::Transport::HTTP::API::Instance::EndpointNotSupportedError.new(
67-
'info', self
68-
)
69-
end
70-
71-
spec.send_info(env) do |request_env|
72-
call(request_env)
73-
end
74-
end
75-
end
76-
7747
# Endpoint for negotiation
7848
class Endpoint < Datadog::Core::Transport::HTTP::API::Endpoint
7949
def initialize(path)

lib/datadog/core/telemetry/transport/http.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ def agentless_telemetry(
2121
api_version: nil,
2222
headers: nil
2323
)
24-
Core::Transport::HTTP.build(api_instance_class: Telemetry::API::Instance,
24+
Core::Transport::HTTP.build(
2525
logger: logger,
2626
agent_settings: agent_settings,
2727
api_version: api_version,
28-
headers: headers) do |transport|
28+
headers: headers
29+
) do |transport|
2930
apis = API.defaults
3031

3132
transport.api API::AGENTLESS_TELEMETRY, apis[API::AGENTLESS_TELEMETRY]
@@ -45,9 +46,10 @@ def agent_telemetry(
4546
api_version: nil,
4647
headers: nil
4748
)
48-
Core::Transport::HTTP.build(api_instance_class: Telemetry::API::Instance,
49+
Core::Transport::HTTP.build(
4950
logger: logger,
50-
agent_settings: agent_settings, api_version: api_version, headers: headers) do |transport|
51+
agent_settings: agent_settings, api_version: api_version, headers: headers
52+
) do |transport|
5153
apis = API.defaults
5254

5355
transport.api API::AGENT_TELEMETRY, apis[API::AGENT_TELEMETRY]

lib/datadog/core/telemetry/transport/http/api.rb

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# frozen_string_literal: true
22

33
require_relative '../../../encoding'
4+
require_relative '../../../transport/http/api/endpoint'
45
require_relative '../../../transport/http/api/map'
5-
require_relative '../../../transport/http/api/instance'
6-
require_relative '../../../transport/http/api/spec'
76
require_relative 'telemetry'
87

98
module Datadog
@@ -21,18 +20,14 @@ module API
2120

2221
def defaults
2322
Datadog::Core::Transport::HTTP::API::Map[
24-
AGENT_TELEMETRY => Telemetry::API::Spec.new do |s|
25-
s.telemetry = Telemetry::API::Endpoint.new(
26-
'/telemetry/proxy/api/v2/apmtelemetry',
27-
Core::Encoding::JSONEncoder,
28-
)
29-
end,
30-
AGENTLESS_TELEMETRY => Telemetry::API::Spec.new do |s|
31-
s.telemetry = Telemetry::API::Endpoint.new(
32-
'/api/v2/apmtelemetry',
33-
Core::Encoding::JSONEncoder,
34-
)
35-
end,
23+
AGENT_TELEMETRY => Telemetry::API::Endpoint.new(
24+
'/telemetry/proxy/api/v2/apmtelemetry',
25+
Core::Encoding::JSONEncoder,
26+
),
27+
AGENTLESS_TELEMETRY => Telemetry::API::Endpoint.new(
28+
'/api/v2/apmtelemetry',
29+
Core::Encoding::JSONEncoder,
30+
),
3631
]
3732
end
3833
end

lib/datadog/core/telemetry/transport/http/telemetry.rb

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
require_relative '../../../transport/http/api/endpoint'
44
require_relative '../../../transport/http/api/instance'
5-
require_relative '../../../transport/http/api/spec'
65
require_relative '../../../transport/http/client'
76
require_relative '../../../transport/request'
87

@@ -13,26 +12,6 @@ module Transport
1312
module HTTP
1413
module Telemetry
1514
module API
16-
class Instance < Core::Transport::HTTP::API::Instance
17-
def send_telemetry(env)
18-
raise Core::Transport::HTTP::API::Instance::EndpointNotSupportedError.new('telemetry', self) unless spec.is_a?(Telemetry::API::Spec)
19-
20-
spec.send_telemetry(env) do |request_env|
21-
call(request_env)
22-
end
23-
end
24-
end
25-
26-
class Spec < Core::Transport::HTTP::API::Spec
27-
attr_accessor :telemetry
28-
29-
def send_telemetry(env, &block)
30-
raise Core::Transport::HTTP::API::Spec::EndpointNotDefinedError.new('telemetry', self) if telemetry.nil?
31-
32-
telemetry.call(env, &block)
33-
end
34-
end
35-
3615
class Endpoint < Datadog::Core::Transport::HTTP::API::Endpoint
3716
HEADER_CONTENT_TYPE = 'Content-Type'
3817

lib/datadog/core/transport/http.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ module HTTP
2929
# Helper function that delegates to Builder.new
3030
# but is under HTTP namespace so that client code requires this file
3131
# to get the adapters configured, and not the builder directly.
32-
def build(api_instance_class:, agent_settings:, logger: Datadog.logger, api_version: nil, headers: nil, &block)
33-
Builder.new(api_instance_class: api_instance_class, logger: logger) do |transport|
32+
def build(
33+
agent_settings:,
34+
logger: Datadog.logger,
35+
api_version: nil,
36+
headers: nil,
37+
&block
38+
)
39+
Builder.new(logger: logger) do |transport|
3440
transport.adapter(agent_settings)
3541
transport.headers(default_headers)
3642

lib/datadog/core/transport/http/api/instance.rb

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,19 @@ module HTTP
77
module API
88
# An API configured with adapter and routes
99
class Instance
10-
# Raised when an endpoint is invoked on an API that is not the
11-
# of expected API class for that endpoint.
12-
class EndpointNotSupportedError < StandardError
13-
attr_reader :spec, :endpoint_name
14-
15-
def initialize(endpoint_name, spec)
16-
@spec = spec
17-
@endpoint_name = endpoint_name
18-
19-
super(message)
20-
end
21-
22-
def message
23-
"#{endpoint_name} not supported for this API!"
24-
end
25-
end
26-
2710
attr_reader \
2811
:adapter,
2912
:headers,
30-
:spec
13+
:endpoint
3114

32-
def initialize(spec, adapter, options = {})
33-
@spec = spec
15+
def initialize(endpoint, adapter, options = {})
16+
@endpoint = endpoint
3417
@adapter = adapter
3518
@headers = options.fetch(:headers, {})
3619
end
3720

3821
def encoder
39-
spec.encoder
22+
endpoint.encoder
4023
end
4124

4225
def call(env)

lib/datadog/core/transport/http/api/spec.rb

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)