oneapm_rpm 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +30 -0
- data/.rubocop.yml +725 -0
- data/Gemfile +3 -0
- data/Guardfile +7 -0
- data/LICENSE +1 -0
- data/README.md +3 -0
- data/config/cert/cacert.pem +1177 -0
- data/config/database.yml +5 -0
- data/lib/initializers/goliath.rb +11 -0
- data/lib/initializers/other.rb +1 -0
- data/lib/initializers/rails.rb +15 -0
- data/lib/one_apm/agent.rb +253 -0
- data/lib/one_apm/agent/agent.rb +283 -0
- data/lib/one_apm/agent/agent/connect.rb +175 -0
- data/lib/one_apm/agent/agent/container_data_manager.rb +218 -0
- data/lib/one_apm/agent/agent/forkable_dispatcher_functions.rb +96 -0
- data/lib/one_apm/agent/agent/helpers.rb +45 -0
- data/lib/one_apm/agent/agent/start.rb +226 -0
- data/lib/one_apm/agent/agent/start_worker_thread.rb +148 -0
- data/lib/one_apm/agent/busy_calculator.rb +115 -0
- data/lib/one_apm/agent/cross_app/cross_app_monitor.rb +181 -0
- data/lib/one_apm/agent/cross_app/cross_app_tracing.rb +336 -0
- data/lib/one_apm/agent/database.rb +308 -0
- data/lib/one_apm/agent/database/active_record_helper.rb +80 -0
- data/lib/one_apm/agent/database/obfuscation_helpers.rb +76 -0
- data/lib/one_apm/agent/database/obfuscator.rb +78 -0
- data/lib/one_apm/agent/database/postgres_explain_obfuscator.rb +45 -0
- data/lib/one_apm/agent/datastores.rb +175 -0
- data/lib/one_apm/agent/datastores/metric_helper.rb +83 -0
- data/lib/one_apm/agent/datastores/mongo.rb +27 -0
- data/lib/one_apm/agent/datastores/mongo/metric_translator.rb +189 -0
- data/lib/one_apm/agent/datastores/mongo/obfuscator.rb +37 -0
- data/lib/one_apm/agent/datastores/mongo/statement_formatter.rb +51 -0
- data/lib/one_apm/agent/event/event_listener.rb +40 -0
- data/lib/one_apm/agent/event/event_loop.rb +191 -0
- data/lib/one_apm/agent/event/worker_loop.rb +97 -0
- data/lib/one_apm/agent/harvester.rb +48 -0
- data/lib/one_apm/agent/inbound_request_monitor.rb +30 -0
- data/lib/one_apm/agent/javascript_instrumentor.rb +186 -0
- data/lib/one_apm/agent/pipe/pipe_channel_manager.rb +275 -0
- data/lib/one_apm/agent/pipe/pipe_service.rb +81 -0
- data/lib/one_apm/agent/sampler.rb +55 -0
- data/lib/one_apm/agent/sampler_collection.rb +65 -0
- data/lib/one_apm/agent/samplers/cpu_sampler.rb +49 -0
- data/lib/one_apm/agent/samplers/delayed_job_sampler.rb +109 -0
- data/lib/one_apm/agent/samplers/memory_sampler.rb +144 -0
- data/lib/one_apm/agent/samplers/object_sampler.rb +22 -0
- data/lib/one_apm/agent/samplers/vm_sampler.rb +124 -0
- data/lib/one_apm/agent/synthetics_monitor.rb +48 -0
- data/lib/one_apm/agent/threading/agent_thread.rb +74 -0
- data/lib/one_apm/agent/threading/backtrace_node.rb +133 -0
- data/lib/one_apm/agent/threading/backtrace_service.rb +259 -0
- data/lib/one_apm/agent/threading/thread_profile.rb +155 -0
- data/lib/one_apm/collector/collector/helper.rb +139 -0
- data/lib/one_apm/collector/collector/http_connection.rb +254 -0
- data/lib/one_apm/collector/collector/server_methods.rb +71 -0
- data/lib/one_apm/collector/collector_service.rb +123 -0
- data/lib/one_apm/collector/commands/agent_command.rb +17 -0
- data/lib/one_apm/collector/commands/thread_profiler_session.rb +108 -0
- data/lib/one_apm/collector/commands/xray_session.rb +53 -0
- data/lib/one_apm/collector/commands/xray_session_collection.rb +156 -0
- data/lib/one_apm/collector/containers/agent_command_router.rb +153 -0
- data/lib/one_apm/collector/containers/custom_event_aggregator.rb +94 -0
- data/lib/one_apm/collector/containers/error_collector.rb +349 -0
- data/lib/one_apm/collector/containers/sql_sampler.rb +331 -0
- data/lib/one_apm/collector/containers/stats_engine.rb +34 -0
- data/lib/one_apm/collector/containers/transaction_event_aggregator.rb +249 -0
- data/lib/one_apm/collector/containers/transaction_sampler.rb +352 -0
- data/lib/one_apm/collector/containers/utilization_data.rb +36 -0
- data/lib/one_apm/collector/stats_engine/gc_profiler.rb +106 -0
- data/lib/one_apm/collector/stats_engine/metric_stats.rb +243 -0
- data/lib/one_apm/collector/stats_engine/stats_hash.rb +105 -0
- data/lib/one_apm/configuration.rb +429 -0
- data/lib/one_apm/configuration/autostart.rb +41 -0
- data/lib/one_apm/configuration/default_source.rb +1026 -0
- data/lib/one_apm/configuration/environment_source.rb +113 -0
- data/lib/one_apm/configuration/high_security_source.rb +56 -0
- data/lib/one_apm/configuration/manual_source.rb +13 -0
- data/lib/one_apm/configuration/server_source.rb +60 -0
- data/lib/one_apm/configuration/yaml_source.rb +134 -0
- data/lib/one_apm/errors/agent_errors.rb +26 -0
- data/lib/one_apm/errors/internal_agent_error.rb +16 -0
- data/lib/one_apm/errors/noticed_error.rb +79 -0
- data/lib/one_apm/frameworks/external.rb +15 -0
- data/lib/one_apm/frameworks/rails.rb +103 -0
- data/lib/one_apm/frameworks/rails3.rb +37 -0
- data/lib/one_apm/frameworks/rails4.rb +21 -0
- data/lib/one_apm/frameworks/ruby.rb +21 -0
- data/lib/one_apm/frameworks/sinatra.rb +12 -0
- data/lib/one_apm/inst/3rd/active_merchant.rb +35 -0
- data/lib/one_apm/inst/3rd/acts_as_solr.rb +70 -0
- data/lib/one_apm/inst/3rd/authlogic.rb +23 -0
- data/lib/one_apm/inst/3rd/sunspot.rb +31 -0
- data/lib/one_apm/inst/background_job/active_job.rb +88 -0
- data/lib/one_apm/inst/background_job/delayed_job.rb +52 -0
- data/lib/one_apm/inst/background_job/delayed_job_injection.rb +8 -0
- data/lib/one_apm/inst/background_job/resque.rb +107 -0
- data/lib/one_apm/inst/background_job/sidekiq.rb +64 -0
- data/lib/one_apm/inst/dispatcher/passenger.rb +25 -0
- data/lib/one_apm/inst/dispatcher/rainbows.rb +23 -0
- data/lib/one_apm/inst/framework/grape.rb +94 -0
- data/lib/one_apm/inst/framework/padrino.rb +30 -0
- data/lib/one_apm/inst/framework/sinatra.rb +185 -0
- data/lib/one_apm/inst/framework/sinatra/ignorer.rb +50 -0
- data/lib/one_apm/inst/framework/sinatra/transaction_namer.rb +54 -0
- data/lib/one_apm/inst/http_clients/curb.rb +189 -0
- data/lib/one_apm/inst/http_clients/excon.rb +70 -0
- data/lib/one_apm/inst/http_clients/excon/connection.rb +31 -0
- data/lib/one_apm/inst/http_clients/excon/middleware.rb +55 -0
- data/lib/one_apm/inst/http_clients/httpclient.rb +44 -0
- data/lib/one_apm/inst/http_clients/net.rb +34 -0
- data/lib/one_apm/inst/http_clients/typhoeus.rb +76 -0
- data/lib/one_apm/inst/nosql/memcache.rb +134 -0
- data/lib/one_apm/inst/nosql/mongo.rb +126 -0
- data/lib/one_apm/inst/nosql/mongo_moped.rb +85 -0
- data/lib/one_apm/inst/nosql/redis.rb +83 -0
- data/lib/one_apm/inst/orm/active_record.rb +99 -0
- data/lib/one_apm/inst/orm/active_record_4.rb +28 -0
- data/lib/one_apm/inst/orm/data_mapper.rb +180 -0
- data/lib/one_apm/inst/orm/sequel.rb +47 -0
- data/lib/one_apm/inst/rack.rb +38 -0
- data/lib/one_apm/inst/rack/rack.rb +44 -0
- data/lib/one_apm/inst/rack/rack_builder.rb +51 -0
- data/lib/one_apm/inst/rails/action_controller.rb +118 -0
- data/lib/one_apm/inst/rails/action_web_service.rb +44 -0
- data/lib/one_apm/inst/rails/errors.rb +43 -0
- data/lib/one_apm/inst/rails3/action_controller.rb +172 -0
- data/lib/one_apm/inst/rails3/errors.rb +43 -0
- data/lib/one_apm/inst/rails4/action_controller.rb +27 -0
- data/lib/one_apm/inst/rails4/action_controller_subscriber.rb +121 -0
- data/lib/one_apm/inst/rails4/action_view.rb +23 -0
- data/lib/one_apm/inst/rails4/action_view_subscriber.rb +93 -0
- data/lib/one_apm/inst/rails4/active_record_subscriber.rb +96 -0
- data/lib/one_apm/inst/rails4/errors.rb +42 -0
- data/lib/one_apm/inst/rails_middleware.rb +40 -0
- data/lib/one_apm/inst/support/evented_subscriber.rb +98 -0
- data/lib/one_apm/inst/support/ignore_actions.rb +39 -0
- data/lib/one_apm/inst/support/queue_time.rb +76 -0
- data/lib/one_apm/inst/transaction_base.rb +405 -0
- data/lib/one_apm/logger/agent_logger.rb +206 -0
- data/lib/one_apm/logger/audit_logger.rb +78 -0
- data/lib/one_apm/logger/memory_logger.rb +50 -0
- data/lib/one_apm/logger/null_logger.rb +19 -0
- data/lib/one_apm/metrics/metric_data.rb +72 -0
- data/lib/one_apm/metrics/metric_spec.rb +82 -0
- data/lib/one_apm/metrics/stats.rb +173 -0
- data/lib/one_apm/probe.rb +16 -0
- data/lib/one_apm/probe/framework_loader.rb +53 -0
- data/lib/one_apm/probe/instance_methods.rb +105 -0
- data/lib/one_apm/probe/instrumentation.rb +60 -0
- data/lib/one_apm/rack/browser_monitoring.rb +144 -0
- data/lib/one_apm/rack/middleware_base.rb +27 -0
- data/lib/one_apm/rack/middleware_hooks.rb +17 -0
- data/lib/one_apm/rack/middleware_tracing.rb +81 -0
- data/lib/one_apm/rack/middleware_wrapper.rb +86 -0
- data/lib/one_apm/support/chained_call.rb +15 -0
- data/lib/one_apm/support/coerce.rb +81 -0
- data/lib/one_apm/support/collection_helper.rb +79 -0
- data/lib/one_apm/support/dotted_hash.rb +45 -0
- data/lib/one_apm/support/encoders.rb +34 -0
- data/lib/one_apm/support/environment_report.rb +127 -0
- data/lib/one_apm/support/event_buffer.rb +82 -0
- data/lib/one_apm/support/event_buffer/sampled_buffer.rb +45 -0
- data/lib/one_apm/support/event_buffer/sized_buffer.rb +21 -0
- data/lib/one_apm/support/event_buffer/synthetics_event_buffer.rb +40 -0
- data/lib/one_apm/support/helper.rb +49 -0
- data/lib/one_apm/support/hostname.rb +13 -0
- data/lib/one_apm/support/http_clients/curb_wrappers.rb +65 -0
- data/lib/one_apm/support/http_clients/excon_wrappers.rb +63 -0
- data/lib/one_apm/support/http_clients/httpclient_wrappers.rb +61 -0
- data/lib/one_apm/support/http_clients/net_http_wrappers.rb +48 -0
- data/lib/one_apm/support/http_clients/typhoeus_wrappers.rb +73 -0
- data/lib/one_apm/support/http_clients/uri_util.rb +39 -0
- data/lib/one_apm/support/json_marshaller.rb +68 -0
- data/lib/one_apm/support/json_wrapper.rb +130 -0
- data/lib/one_apm/support/language_support.rb +142 -0
- data/lib/one_apm/support/library_detection.rb +119 -0
- data/lib/one_apm/support/local_environment.rb +196 -0
- data/lib/one_apm/support/marshaller.rb +62 -0
- data/lib/one_apm/support/method_tracer.rb +334 -0
- data/lib/one_apm/support/method_tracer/helpers.rb +92 -0
- data/lib/one_apm/support/method_tracer/traced_method_stack.rb +103 -0
- data/lib/one_apm/support/obfuscator.rb +47 -0
- data/lib/one_apm/support/okjson.rb +601 -0
- data/lib/one_apm/support/parameter_filtering.rb +35 -0
- data/lib/one_apm/support/rules_engine.rb +56 -0
- data/lib/one_apm/support/rules_engine/replacement_rule.rb +80 -0
- data/lib/one_apm/support/rules_engine/segment_terms_rule.rb +46 -0
- data/lib/one_apm/support/server.rb +11 -0
- data/lib/one_apm/support/supported_versions.rb +257 -0
- data/lib/one_apm/support/system_info.rb +211 -0
- data/lib/one_apm/support/timer_lib.rb +29 -0
- data/lib/one_apm/support/version_number.rb +51 -0
- data/lib/one_apm/support/vm.rb +30 -0
- data/lib/one_apm/support/vm/jruby_vm.rb +38 -0
- data/lib/one_apm/support/vm/monotonic_gc_profiler.rb +43 -0
- data/lib/one_apm/support/vm/mri_vm.rb +85 -0
- data/lib/one_apm/support/vm/rubinius_vm.rb +129 -0
- data/lib/one_apm/support/vm/snapshot.rb +18 -0
- data/lib/one_apm/transaction.rb +336 -0
- data/lib/one_apm/transaction/class_methods.rb +132 -0
- data/lib/one_apm/transaction/instance_helpers.rb +82 -0
- data/lib/one_apm/transaction/metric_constants.rb +42 -0
- data/lib/one_apm/transaction/sample_buffer/force_persist_sample_buffer.rb +21 -0
- data/lib/one_apm/transaction/sample_buffer/slowest_sample_buffer.rb +21 -0
- data/lib/one_apm/transaction/sample_buffer/synthetics_sample_buffer.rb +21 -0
- data/lib/one_apm/transaction/sample_buffer/transaction_sample_buffer.rb +101 -0
- data/lib/one_apm/transaction/sample_buffer/xray_sample_buffer.rb +60 -0
- data/lib/one_apm/transaction/segment.rb +193 -0
- data/lib/one_apm/transaction/segment_summary.rb +51 -0
- data/lib/one_apm/transaction/thread_local_access.rb +73 -0
- data/lib/one_apm/transaction/transaction_analysis.rb +78 -0
- data/lib/one_apm/transaction/transaction_apdex.rb +20 -0
- data/lib/one_apm/transaction/transaction_cpu.rb +22 -0
- data/lib/one_apm/transaction/transaction_finish_append.rb +67 -0
- data/lib/one_apm/transaction/transaction_ignore.rb +33 -0
- data/lib/one_apm/transaction/transaction_jruby_functions.rb +40 -0
- data/lib/one_apm/transaction/transaction_metrics.rb +53 -0
- data/lib/one_apm/transaction/transaction_name.rb +90 -0
- data/lib/one_apm/transaction/transaction_namer.rb +49 -0
- data/lib/one_apm/transaction/transaction_sample.rb +204 -0
- data/lib/one_apm/transaction/transaction_sample_builder.rb +168 -0
- data/lib/one_apm/transaction/transaction_state.rb +149 -0
- data/lib/one_apm/transaction/transaction_summary.rb +28 -0
- data/lib/one_apm/transaction/transaction_synthetics.rb +40 -0
- data/lib/one_apm/transaction/transaction_timings.rb +54 -0
- data/lib/one_apm/version.rb +13 -0
- data/lib/oneapm_rpm.rb +16 -0
- data/lib/sequel/extensions/oneapm_instrumentation.rb +84 -0
- data/lib/sequel/plugins/oneapm_instrumentation.rb +66 -0
- data/oneapm.yml +135 -0
- data/oneapm_rpm.gemspec +58 -0
- metadata +474 -0
@@ -0,0 +1,127 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module OneApm
|
4
|
+
# The EnvironmentReport is responsible for analyzing the application's
|
5
|
+
# environment and generating the data for the Environment Report in OneApm's interface.
|
6
|
+
#
|
7
|
+
# It contains useful system information like Ruby version, OS, loaded gems,
|
8
|
+
# etc.
|
9
|
+
#
|
10
|
+
# Additional logic can be registered by using the EnvironmentReport.report_on
|
11
|
+
# hook.
|
12
|
+
class EnvironmentReport
|
13
|
+
|
14
|
+
# This is the main interface for registering logic that should be included
|
15
|
+
# in the Environment Report. For example:
|
16
|
+
#
|
17
|
+
# EnvironmentReport.report_on "Day of week" do
|
18
|
+
# Time.now.strftime("%A")
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# The passed blocks will be run in EnvironmentReport instances on #initialize.
|
22
|
+
#
|
23
|
+
# Errors raised in passed blocks will be handled and logged at debug, so it
|
24
|
+
# is safe to report on things that may not work in certain environments.
|
25
|
+
#
|
26
|
+
# The blocks should only return strings or arrays full of strings. Falsey
|
27
|
+
# values will be ignored.
|
28
|
+
def self.report_on(key, &block)
|
29
|
+
registered_reporters[key] = block
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.registered_reporters
|
33
|
+
@registered_reporters ||= Hash.new
|
34
|
+
end
|
35
|
+
|
36
|
+
# allow the logic to be swapped out in tests
|
37
|
+
def self.registered_reporters=(logic)
|
38
|
+
@registered_reporters = logic
|
39
|
+
end
|
40
|
+
|
41
|
+
# register reporting logic
|
42
|
+
####################################
|
43
|
+
report_on('Gems') do
|
44
|
+
begin
|
45
|
+
Bundler.rubygems.all_specs.map { |_gem| "#{_gem.name}(#{_gem.version})" }
|
46
|
+
rescue
|
47
|
+
# There are certain rubygem, bundler, rails combinations (e.g. gem
|
48
|
+
# 1.6.2, rails 2.3, bundler 1.2.3) where the code above throws an error
|
49
|
+
# in bundler because of rails monkey patching gem. The below does work
|
50
|
+
# though so try it if the above fails.
|
51
|
+
Bundler.load.specs.map do |spec|
|
52
|
+
version = (spec.respond_to?(:version) && spec.version)
|
53
|
+
spec.name + (version ? "(#{version})" : "")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
report_on('Plugin List' ) { ::Rails.configuration.plugins.to_a }
|
58
|
+
report_on('Ruby version' ) { RUBY_VERSION }
|
59
|
+
report_on('Ruby description' ) { RUBY_DESCRIPTION }
|
60
|
+
report_on('Ruby platform' ) { RUBY_PLATFORM }
|
61
|
+
report_on('Ruby patchlevel' ) { RUBY_PATCHLEVEL.to_s }
|
62
|
+
report_on('JRuby version' ) { JRUBY_VERSION }
|
63
|
+
report_on('Java VM version' ) { ENV_JAVA['java.vm.version'] }
|
64
|
+
report_on('Logical Processors') { ::OneApm::Agent::SystemInfo.num_logical_processors }
|
65
|
+
report_on('Physical Cores' ) { ::OneApm::Agent::SystemInfo.num_physical_cores }
|
66
|
+
report_on('Arch' ) { ::OneApm::Agent::SystemInfo.processor_arch }
|
67
|
+
report_on('OS version' ) { ::OneApm::Agent::SystemInfo.os_version }
|
68
|
+
report_on('OS' ) { ::OneApm::Agent::SystemInfo.ruby_os_identifier }
|
69
|
+
report_on('Database adapter' ) do
|
70
|
+
ActiveRecord::Base.configurations[OneApm::Probe.instance.env]['adapter']
|
71
|
+
end
|
72
|
+
report_on('Framework' ) { Agent.config[:framework].to_s }
|
73
|
+
report_on('Dispatcher' ) { Agent.config[:dispatcher].to_s }
|
74
|
+
report_on('Environment' ) { OneApm::Probe.instance.env }
|
75
|
+
report_on('Rails version' ) { ::Rails::VERSION::STRING }
|
76
|
+
report_on('Rails threadsafe') do
|
77
|
+
::Rails.configuration.action_controller.allow_concurrency
|
78
|
+
end
|
79
|
+
report_on('Rails Env') do
|
80
|
+
if defined? ::Rails and ::Rails.respond_to?(:env)
|
81
|
+
::Rails.env.to_s
|
82
|
+
else
|
83
|
+
ENV['RAILS_ENV']
|
84
|
+
end
|
85
|
+
end
|
86
|
+
# end reporting logic
|
87
|
+
####################################
|
88
|
+
|
89
|
+
|
90
|
+
attr_reader :data
|
91
|
+
# Generate the report based on the class level logic.
|
92
|
+
def initialize
|
93
|
+
@data = self.class.registered_reporters.inject(Hash.new) do |data, (key, logic)|
|
94
|
+
begin
|
95
|
+
value = logic.call
|
96
|
+
if value
|
97
|
+
data[key] = value
|
98
|
+
|
99
|
+
Agent.record_metric("Supportability/EnvironmentReport/success", 0.0)
|
100
|
+
Agent.record_metric("Supportability/EnvironmentReport/success/#{key}", 0.0)
|
101
|
+
else
|
102
|
+
Agent.logger.debug("EnvironmentReport ignoring value for #{key.inspect} which came back falsey: #{value.inspect}")
|
103
|
+
Agent.record_metric("Supportability/EnvironmentReport/empty", 0.0)
|
104
|
+
Agent.record_metric("Supportability/EnvironmentReport/empty/#{key}", 0.0)
|
105
|
+
end
|
106
|
+
rescue => e
|
107
|
+
Agent.logger.debug("EnvironmentReport failed to retrieve value for #{key.inspect}: #{e}")
|
108
|
+
Agent.record_metric("Supportability/EnvironmentReport/error", 0.0)
|
109
|
+
Agent.record_metric("Supportability/EnvironmentReport/error/#{key}", 0.0)
|
110
|
+
end
|
111
|
+
data
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def [](key)
|
116
|
+
@data[key]
|
117
|
+
end
|
118
|
+
|
119
|
+
def []=(key, value)
|
120
|
+
@data[key] = value
|
121
|
+
end
|
122
|
+
|
123
|
+
def to_a
|
124
|
+
@data.to_a
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# EventBuffer is intended to be an abstract base class. It should not be
|
4
|
+
# instantiated directly. Subclasses should define an `append_event` method
|
5
|
+
# looking something like this:
|
6
|
+
#
|
7
|
+
# def append_event(x)
|
8
|
+
# <attempt to append>
|
9
|
+
# if append_success?
|
10
|
+
# return x
|
11
|
+
# else
|
12
|
+
# return nil
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
|
16
|
+
module OneApm
|
17
|
+
module Agent
|
18
|
+
class EventBuffer
|
19
|
+
attr_reader :capacity
|
20
|
+
|
21
|
+
def initialize(capacity)
|
22
|
+
@capacity = capacity
|
23
|
+
@items = []
|
24
|
+
@seen = 0
|
25
|
+
end
|
26
|
+
|
27
|
+
def reset!
|
28
|
+
@items = []
|
29
|
+
@seen = 0
|
30
|
+
end
|
31
|
+
|
32
|
+
def capacity=(new_capacity)
|
33
|
+
@capacity = new_capacity
|
34
|
+
old_items = @items
|
35
|
+
@items = []
|
36
|
+
old_seen = @seen
|
37
|
+
old_items.each { |i| append(i) }
|
38
|
+
@seen = old_seen
|
39
|
+
end
|
40
|
+
|
41
|
+
def append(x)
|
42
|
+
@seen += 1
|
43
|
+
append_event(x)
|
44
|
+
end
|
45
|
+
|
46
|
+
def <<(x)
|
47
|
+
append(x)
|
48
|
+
self # return self for method chaining
|
49
|
+
end
|
50
|
+
|
51
|
+
def full?
|
52
|
+
@items.size >= @capacity
|
53
|
+
end
|
54
|
+
|
55
|
+
def size
|
56
|
+
@items.size
|
57
|
+
end
|
58
|
+
|
59
|
+
def note_dropped
|
60
|
+
@seen += 1
|
61
|
+
end
|
62
|
+
|
63
|
+
def num_seen
|
64
|
+
@seen
|
65
|
+
end
|
66
|
+
|
67
|
+
def num_dropped
|
68
|
+
@seen - @items.size
|
69
|
+
end
|
70
|
+
|
71
|
+
def sample_rate
|
72
|
+
@seen > 0 ? (size.to_f / @seen) : 0.0
|
73
|
+
end
|
74
|
+
|
75
|
+
def to_a
|
76
|
+
@items.dup
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# http://xlinux.nist.gov/dads/HTML/reservoirSampling.html
|
4
|
+
|
5
|
+
require 'one_apm/support/event_buffer'
|
6
|
+
|
7
|
+
module OneApm
|
8
|
+
module Agent
|
9
|
+
class SampledBuffer < EventBuffer
|
10
|
+
attr_reader :seen_lifetime, :captured_lifetime
|
11
|
+
|
12
|
+
def initialize(capacity)
|
13
|
+
super
|
14
|
+
@captured_lifetime = 0
|
15
|
+
@seen_lifetime = 0
|
16
|
+
end
|
17
|
+
|
18
|
+
def reset!
|
19
|
+
@captured_lifetime += @items.size
|
20
|
+
@seen_lifetime += @seen
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
def append_event(x)
|
25
|
+
if @items.size < @capacity
|
26
|
+
@items << x
|
27
|
+
return x
|
28
|
+
else
|
29
|
+
m = rand(@seen) # [0, @seen)
|
30
|
+
if m < @capacity
|
31
|
+
@items[m] = x
|
32
|
+
return x
|
33
|
+
else
|
34
|
+
# discard current sample
|
35
|
+
return nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def sample_rate_lifetime
|
41
|
+
@captured_lifetime > 0 ? (@captured_lifetime.to_f / @seen_lifetime) : 0.0
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'one_apm/support/event_buffer'
|
4
|
+
|
5
|
+
module OneApm
|
6
|
+
module Agent
|
7
|
+
class SizedBuffer < EventBuffer
|
8
|
+
|
9
|
+
def append_event(x)
|
10
|
+
if @items.size < @capacity
|
11
|
+
@items << x
|
12
|
+
return x
|
13
|
+
else
|
14
|
+
return nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'one_apm/support/event_buffer'
|
4
|
+
require 'one_apm/support/event_buffer/sized_buffer'
|
5
|
+
|
6
|
+
module OneApm
|
7
|
+
module Agent
|
8
|
+
class SyntheticsEventBuffer < SizedBuffer
|
9
|
+
|
10
|
+
def append_with_reject(x)
|
11
|
+
@seen += 1
|
12
|
+
if full?
|
13
|
+
timestamp = timestamp_for(x)
|
14
|
+
latest_event = @items.max_by do |item|
|
15
|
+
timestamp_for(item)
|
16
|
+
end
|
17
|
+
|
18
|
+
if timestamp < timestamp_for(latest_event)
|
19
|
+
# Make room!
|
20
|
+
@items.delete(latest_event)
|
21
|
+
return [append_event(x), latest_event]
|
22
|
+
else
|
23
|
+
return [nil, x]
|
24
|
+
end
|
25
|
+
else
|
26
|
+
return [append_event(x), nil]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
TIMESTAMP = "timestamp".freeze
|
31
|
+
|
32
|
+
def timestamp_for(event)
|
33
|
+
main_event, _ = event
|
34
|
+
main_event[TIMESTAMP]
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module OneApm
|
4
|
+
module Helper
|
5
|
+
extend self
|
6
|
+
|
7
|
+
# confirm a string is correctly encoded (in >= 1.9)
|
8
|
+
# If not force the encoding to ASCII-8BIT (binary)
|
9
|
+
if OneApm::LanguageSupport.supports_string_encodings?
|
10
|
+
def correctly_encoded(string)
|
11
|
+
return string unless string.is_a? String
|
12
|
+
# The .dup here is intentional, since force_encoding mutates the target,
|
13
|
+
# and we don't know who is going to use this string downstream of us.
|
14
|
+
string.valid_encoding? ? string : string.dup.force_encoding("ASCII-8BIT")
|
15
|
+
end
|
16
|
+
else
|
17
|
+
def correctly_encoded(string)
|
18
|
+
string
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def instance_method_visibility(klass, method_name)
|
23
|
+
if klass.private_instance_methods.map{|s|s.to_sym}.include? method_name.to_sym
|
24
|
+
:private
|
25
|
+
elsif klass.protected_instance_methods.map{|s|s.to_sym}.include? method_name.to_sym
|
26
|
+
:protected
|
27
|
+
else
|
28
|
+
:public
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def instance_methods_include?(klass, method_name)
|
33
|
+
method_name_sym = method_name.to_sym
|
34
|
+
(
|
35
|
+
klass.instance_methods.map{ |s| s.to_sym }.include?(method_name_sym) ||
|
36
|
+
klass.protected_instance_methods.map{ |s|s.to_sym }.include?(method_name_sym) ||
|
37
|
+
klass.private_instance_methods.map{ |s|s.to_sym }.include?(method_name_sym)
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def time_to_millis(time)
|
42
|
+
(time.to_f * 1000).round
|
43
|
+
end
|
44
|
+
|
45
|
+
def milliseconds_to_seconds(milliseconds)
|
46
|
+
milliseconds / 1000.0
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module OneApm
|
4
|
+
module Support
|
5
|
+
module HTTPClients
|
6
|
+
|
7
|
+
class CurbRequest
|
8
|
+
def initialize( curlobj )
|
9
|
+
@curlobj = curlobj
|
10
|
+
end
|
11
|
+
|
12
|
+
def type
|
13
|
+
'Curb'
|
14
|
+
end
|
15
|
+
|
16
|
+
def host
|
17
|
+
self["host"] || self["Host"] || self.uri.host
|
18
|
+
end
|
19
|
+
|
20
|
+
def method
|
21
|
+
@curlobj._oa_http_verb
|
22
|
+
end
|
23
|
+
|
24
|
+
def []( key )
|
25
|
+
@curlobj.headers[ key ]
|
26
|
+
end
|
27
|
+
|
28
|
+
def []=( key, value )
|
29
|
+
@curlobj.headers[ key ] = value
|
30
|
+
end
|
31
|
+
|
32
|
+
def uri
|
33
|
+
@uri ||= OneApm::Support::HTTPClients::URIUtil.parse_url(@curlobj.url)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
class CurbResponse
|
39
|
+
|
40
|
+
def initialize(curlobj)
|
41
|
+
@headers = {}
|
42
|
+
@curlobj = curlobj
|
43
|
+
end
|
44
|
+
|
45
|
+
def [](key)
|
46
|
+
@headers[ key.downcase ]
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_hash
|
50
|
+
@headers.dup
|
51
|
+
end
|
52
|
+
|
53
|
+
def append_header_data( data )
|
54
|
+
key, value = data.split( /:\s*/, 2 )
|
55
|
+
@headers[ key.downcase ] = value
|
56
|
+
@curlobj._oa_header_str ||= ''
|
57
|
+
@curlobj._oa_header_str << data
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|