Skip to content

Commit

Permalink
Merge pull request #3707 from DataDog/anmarchenko/telemetry_type_chec…
Browse files Browse the repository at this point in the history
…king

[SDTEST-409] add signatures and enable type checking for Core::Telemetry module
  • Loading branch information
anmarchenko authored Jun 12, 2024
2 parents be93f85 + 3b3c2ac commit 66a74aa
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 51 deletions.
19 changes: 0 additions & 19 deletions Steepfile
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,6 @@ target :datadog do
ignore 'lib/datadog/core/pin.rb'
ignore 'lib/datadog/core/runtime/ext.rb'
ignore 'lib/datadog/core/runtime/metrics.rb'
ignore 'lib/datadog/core/telemetry/client.rb'
ignore 'lib/datadog/core/telemetry/collector.rb'
ignore 'lib/datadog/core/telemetry/emitter.rb'
ignore 'lib/datadog/core/telemetry/event.rb'
ignore 'lib/datadog/core/telemetry/ext.rb'
ignore 'lib/datadog/core/telemetry/heartbeat.rb'
ignore 'lib/datadog/core/telemetry/http/adapters/net.rb'
ignore 'lib/datadog/core/telemetry/http/env.rb'
ignore 'lib/datadog/core/telemetry/http/ext.rb'
ignore 'lib/datadog/core/telemetry/http/response.rb'
ignore 'lib/datadog/core/telemetry/http/transport.rb'
ignore 'lib/datadog/core/telemetry/v1/app_event.rb'
ignore 'lib/datadog/core/telemetry/v1/application.rb'
ignore 'lib/datadog/core/telemetry/v1/configuration.rb'
ignore 'lib/datadog/core/telemetry/v1/dependency.rb'
ignore 'lib/datadog/core/telemetry/v1/host.rb'
ignore 'lib/datadog/core/telemetry/v1/integration.rb'
ignore 'lib/datadog/core/telemetry/v1/product.rb'
ignore 'lib/datadog/core/telemetry/v1/telemetry_request.rb'
ignore 'lib/datadog/core/transport/ext.rb'
ignore 'lib/datadog/core/transport/http/adapters/net.rb'
ignore 'lib/datadog/core/transport/http/adapters/registry.rb'
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/core/telemetry/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def payload(seq_id)
private

def products
# @type var products: Hash[Symbol, Hash[Symbol, Object]]
products = {
appsec: {
enabled: Datadog::AppSec.enabled?,
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/core/telemetry/heartbeat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module Datadog
module Core
module Telemetry
# Periodically (every DEFAULT_INTERVAL_SECONDS) sends a heartbeat event to the telemetry API.
# Periodically sends a heartbeat event to the telemetry API.
class Heartbeat < Core::Worker
include Core::Workers::Polling

Expand Down
1 change: 1 addition & 0 deletions sig/datadog/core.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ module Datadog
end

extend Core::Configuration
extend Tracing::Contrib::Extensions::Helpers
end
20 changes: 10 additions & 10 deletions sig/datadog/core/telemetry/client.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@ module Datadog
module Core
module Telemetry
class Client
@enabled: bool
@dependency_collection: bool
@started: bool
@stopped: bool

attr_reader emitter: untyped
@emitter: Datadog::Core::Telemetry::Emitter
@unsupported: bool
@worker: Datadog::Core::Telemetry::Heartbeat

attr_reader enabled: bool

attr_reader unsupported: bool

attr_reader worker: untyped

include Core::Utils::Forking

def initialize: (heartbeat_interval_seconds: Numeric, dependency_collection: bool, enabled: bool) -> void

def disable!: () -> untyped
def disable!: () -> void

def client_configuration_change!: (Enumerable[[String, Numeric | bool | String]] changes) -> void

def started!: () -> (nil | untyped)
def started!: () -> void

def emit_closing!: () -> (nil | untyped)
def emit_closing!: () -> void

def stop!: () -> (nil | untyped)
def stop!: () -> void

def integrations_change!: () -> (nil | untyped)
def integrations_change!: () -> void

private

def heartbeat!: () -> (nil | untyped)
def heartbeat!: () -> void
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion sig/datadog/core/telemetry/emitter.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Datadog

extend Core::Utils::Forking
def initialize: (?http_transport: untyped) -> void
def request: (String request_type, data: Object?) -> Datadog::Core::Telemetry::Http::Adapters::Net::Response
def request: (Datadog::Core::Telemetry::Event::Base event) -> Datadog::Core::Telemetry::Http::Adapters::Net::Response
def self.sequence: () -> untyped
end
end
Expand Down
53 changes: 51 additions & 2 deletions sig/datadog/core/telemetry/event.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,57 @@ module Datadog
module Telemetry
class Event
class Base
def payload: (int seq_id) -> ::Hash[Symbol, Object]
def type: -> string
def payload: (int seq_id) -> Hash[Symbol, untyped]
def type: -> String?
end

class AppStarted < Base
TARGET_OPTIONS: Array[String]

@seq_id: int

private

def products: -> Hash[Symbol, untyped]

def configuration: -> Array[Hash[Symbol, untyped]]

def agent_transport: (untyped config) -> String

def conf_value: (String name, Object value, ?String origin) -> Hash[Symbol, untyped]

def to_value: (Object value) -> Object

def install_signature: -> Hash[Symbol, Object]
end

class AppDependenciesLoaded < Base
private

def dependencies: -> Array[Hash[Symbol, String]]
end

class AppIntegrationsChange < Base
private

def integrations: -> Array[Hash[Symbol, string]]

def patch_error: (untyped integration) -> String
end

class AppClientConfigurationChange < Base
@changes: Enumerable[[String, Numeric | bool | String | int]]
@origin: String

def initialize: (Enumerable[[String, Numeric | bool | String]] changes, String origin) -> void

def configuration: (int seq_id) -> Array[Hash[Symbol, untyped]]
end

class AppHeartbeat < Base
end

class AppClosing < Base
end
end
end
Expand Down
11 changes: 6 additions & 5 deletions sig/datadog/core/telemetry/heartbeat.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ module Datadog
module Telemetry
class Heartbeat < Core::Worker
include Core::Workers::Polling
include Core::Workers::Async::Thread
include Core::Workers::Async::Thread::PrependedMethods
include Core::Workers::IntervalLoop

DEFAULT_INTERVAL_SECONDS: 60
def initialize: (?enabled: bool, heartbeat_interval_seconds: Numeric) ?{ () -> void } -> void

def initialize: (?enabled: bool, ?interval: untyped) ?{ () -> untyped } -> void

def loop_wait_before_first_iteration?: () -> true
def loop_wait_before_first_iteration?: () -> bool?

private

def start: () -> untyped
def start: () -> void
end
end
end
Expand Down
17 changes: 10 additions & 7 deletions sig/datadog/core/telemetry/http/adapters/net.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ module Datadog
module Http
module Adapters
class Net
attr_reader hostname: untyped
type response = Datadog::Core::Telemetry::Http::Adapters::Net::Response | ::Datadog::Core::Telemetry::Http::InternalErrorResponse

attr_reader port: untyped
attr_reader hostname: String

attr_reader timeout: untyped
attr_reader port: Integer?

attr_reader ssl: untyped
attr_reader timeout: Float | Integer

attr_reader ssl: bool

DEFAULT_TIMEOUT: 30

def initialize: (hostname: untyped, ?port: untyped?, ?timeout: untyped, ?ssl: bool) -> void
def initialize: (hostname: String, ?port: Integer?, ?timeout: Float | Integer, ?ssl: bool?) -> void

def open: () { (::Net::HTTP http) -> ::Net::HTTPResponse } -> untyped

def open: () ?{ () -> untyped } -> untyped
def post: (untyped env) -> response

def post: (untyped env) -> Datadog::Core::Telemetry::Http::Adapters::Net::Response
class Response
include Datadog::Core::Telemetry::Http::Response

Expand Down
6 changes: 6 additions & 0 deletions sig/datadog/core/telemetry/http/ext.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ module Datadog

HEADER_DD_TELEMETRY_REQUEST_TYPE: "DD-Telemetry-Request-Type"

HEADER_CLIENT_LIBRARY_LANGUAGE: "DD-Client-Library-Language"

HEADER_CLIENT_LIBRARY_VERSION: "DD-Client-Library-Version"

HEADER_TELEMETRY_DEBUG_ENABLED: "DD-Telemetry-Debug-Enabled"

CONTENT_TYPE_APPLICATION_JSON: "application/json"

API_VERSION: "v1"
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/core/telemetry/http/response.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module Datadog

def unsupported?: () -> nil

def code: () -> nil

def not_found?: () -> nil

def client_error?: () -> nil
Expand Down
14 changes: 8 additions & 6 deletions sig/datadog/core/telemetry/http/transport.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ module Datadog
module Telemetry
module Http
class Transport
attr_reader host: untyped
@adapter: Http::Adapters::Net

attr_reader port: untyped
attr_reader host: String

attr_reader ssl: untyped
attr_reader port: Integer

attr_reader path: untyped
attr_reader ssl: bool

attr_reader path: String

def initialize: () -> void

def request: (request_type: String, payload: String) -> Datadog::Core::Telemetry::Http::Adapters::Net::Response
def request: (request_type: String, payload: String) -> Datadog::Core::Telemetry::Http::Adapters::Net::response

private

def headers: (request_type: untyped, ?api_version: untyped) -> ::Hash[untyped, untyped]

def adapter: () -> untyped
def adapter: () -> Http::Adapters::Net
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/core/transport/ext.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ module Datadog
HEADER_META_LANG_INTERPRETER: ::String

HEADER_META_TRACER_VERSION: ::String

HEADER_DD_INTERNAL_UNTRACED_REQUEST: ::String
end

module Test
Expand Down
1 change: 1 addition & 0 deletions sig/datadog/core/worker.rbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Datadog
module Core
class Worker
def initialize: () ?{ () -> void } -> void
end
end
end

0 comments on commit 66a74aa

Please sign in to comment.