skywalking 0.0.0.alpha

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.
Files changed (184) hide show
  1. checksums.yaml +7 -0
  2. data/.asf.yaml +40 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +236 -0
  5. data/CHANGELOG.md +15 -0
  6. data/CODE_OF_CONDUCT.md +132 -0
  7. data/LICENSE +201 -0
  8. data/NOTICE +5 -0
  9. data/README.md +18 -0
  10. data/Rakefile +23 -0
  11. data/docs/How-to-release.md +179 -0
  12. data/examples/rails-demo/.dockerignore +47 -0
  13. data/examples/rails-demo/.gitattributes +9 -0
  14. data/examples/rails-demo/.gitignore +34 -0
  15. data/examples/rails-demo/.kamal/hooks/docker-setup.sample +3 -0
  16. data/examples/rails-demo/.kamal/hooks/post-deploy.sample +14 -0
  17. data/examples/rails-demo/.kamal/hooks/post-proxy-reboot.sample +3 -0
  18. data/examples/rails-demo/.kamal/hooks/pre-build.sample +51 -0
  19. data/examples/rails-demo/.kamal/hooks/pre-connect.sample +47 -0
  20. data/examples/rails-demo/.kamal/hooks/pre-deploy.sample +109 -0
  21. data/examples/rails-demo/.kamal/hooks/pre-proxy-reboot.sample +3 -0
  22. data/examples/rails-demo/.kamal/secrets +17 -0
  23. data/examples/rails-demo/.rubocop.yml +8 -0
  24. data/examples/rails-demo/.ruby-version +1 -0
  25. data/examples/rails-demo/Dockerfile +72 -0
  26. data/examples/rails-demo/Gemfile +64 -0
  27. data/examples/rails-demo/README.md +24 -0
  28. data/examples/rails-demo/Rakefile +6 -0
  29. data/examples/rails-demo/app/assets/images/.keep +0 -0
  30. data/examples/rails-demo/app/assets/stylesheets/application.css +10 -0
  31. data/examples/rails-demo/app/controllers/application_controller.rb +4 -0
  32. data/examples/rails-demo/app/controllers/concerns/.keep +0 -0
  33. data/examples/rails-demo/app/helpers/application_helper.rb +2 -0
  34. data/examples/rails-demo/app/javascript/application.js +3 -0
  35. data/examples/rails-demo/app/javascript/controllers/application.js +9 -0
  36. data/examples/rails-demo/app/javascript/controllers/hello_controller.js +7 -0
  37. data/examples/rails-demo/app/javascript/controllers/index.js +4 -0
  38. data/examples/rails-demo/app/jobs/application_job.rb +7 -0
  39. data/examples/rails-demo/app/mailers/application_mailer.rb +4 -0
  40. data/examples/rails-demo/app/models/application_record.rb +3 -0
  41. data/examples/rails-demo/app/models/concerns/.keep +0 -0
  42. data/examples/rails-demo/app/views/layouts/application.html.erb +28 -0
  43. data/examples/rails-demo/app/views/layouts/mailer.html.erb +13 -0
  44. data/examples/rails-demo/app/views/layouts/mailer.text.erb +1 -0
  45. data/examples/rails-demo/app/views/pwa/manifest.json.erb +22 -0
  46. data/examples/rails-demo/app/views/pwa/service-worker.js +26 -0
  47. data/examples/rails-demo/bin/brakeman +7 -0
  48. data/examples/rails-demo/bin/bundle +109 -0
  49. data/examples/rails-demo/bin/dev +2 -0
  50. data/examples/rails-demo/bin/docker-entrypoint +14 -0
  51. data/examples/rails-demo/bin/importmap +4 -0
  52. data/examples/rails-demo/bin/jobs +6 -0
  53. data/examples/rails-demo/bin/kamal +27 -0
  54. data/examples/rails-demo/bin/rails +4 -0
  55. data/examples/rails-demo/bin/rake +4 -0
  56. data/examples/rails-demo/bin/rubocop +8 -0
  57. data/examples/rails-demo/bin/setup +34 -0
  58. data/examples/rails-demo/bin/thrust +5 -0
  59. data/examples/rails-demo/config/application.rb +27 -0
  60. data/examples/rails-demo/config/boot.rb +4 -0
  61. data/examples/rails-demo/config/cable.yml +17 -0
  62. data/examples/rails-demo/config/cache.yml +16 -0
  63. data/examples/rails-demo/config/credentials.yml.enc +1 -0
  64. data/examples/rails-demo/config/database.yml +41 -0
  65. data/examples/rails-demo/config/deploy.yml +116 -0
  66. data/examples/rails-demo/config/environment.rb +5 -0
  67. data/examples/rails-demo/config/environments/development.rb +72 -0
  68. data/examples/rails-demo/config/environments/production.rb +90 -0
  69. data/examples/rails-demo/config/environments/test.rb +53 -0
  70. data/examples/rails-demo/config/importmap.rb +7 -0
  71. data/examples/rails-demo/config/initializers/assets.rb +7 -0
  72. data/examples/rails-demo/config/initializers/content_security_policy.rb +25 -0
  73. data/examples/rails-demo/config/initializers/filter_parameter_logging.rb +8 -0
  74. data/examples/rails-demo/config/initializers/inflections.rb +16 -0
  75. data/examples/rails-demo/config/initializers/skywalking_ruby.rb +18 -0
  76. data/examples/rails-demo/config/locales/en.yml +31 -0
  77. data/examples/rails-demo/config/puma.rb +41 -0
  78. data/examples/rails-demo/config/queue.yml +18 -0
  79. data/examples/rails-demo/config/recurring.yml +10 -0
  80. data/examples/rails-demo/config/routes.rb +14 -0
  81. data/examples/rails-demo/config/storage.yml +34 -0
  82. data/examples/rails-demo/config.ru +6 -0
  83. data/examples/rails-demo/db/cable_schema.rb +11 -0
  84. data/examples/rails-demo/db/cache_schema.rb +14 -0
  85. data/examples/rails-demo/db/queue_schema.rb +129 -0
  86. data/examples/rails-demo/db/seeds.rb +9 -0
  87. data/examples/rails-demo/lib/tasks/.keep +0 -0
  88. data/examples/rails-demo/log/.keep +0 -0
  89. data/examples/rails-demo/public/400.html +114 -0
  90. data/examples/rails-demo/public/404.html +114 -0
  91. data/examples/rails-demo/public/406-unsupported-browser.html +114 -0
  92. data/examples/rails-demo/public/422.html +114 -0
  93. data/examples/rails-demo/public/500.html +114 -0
  94. data/examples/rails-demo/public/icon.png +0 -0
  95. data/examples/rails-demo/public/icon.svg +3 -0
  96. data/examples/rails-demo/public/robots.txt +1 -0
  97. data/examples/rails-demo/script/.keep +0 -0
  98. data/examples/rails-demo/storage/.keep +0 -0
  99. data/examples/rails-demo/test/application_system_test_case.rb +5 -0
  100. data/examples/rails-demo/test/controllers/.keep +0 -0
  101. data/examples/rails-demo/test/fixtures/files/.keep +0 -0
  102. data/examples/rails-demo/test/helpers/.keep +0 -0
  103. data/examples/rails-demo/test/integration/.keep +0 -0
  104. data/examples/rails-demo/test/mailers/.keep +0 -0
  105. data/examples/rails-demo/test/models/.keep +0 -0
  106. data/examples/rails-demo/test/system/.keep +0 -0
  107. data/examples/rails-demo/test/test_helper.rb +15 -0
  108. data/examples/rails-demo/tmp/.keep +0 -0
  109. data/examples/rails-demo/tmp/pids/.keep +0 -0
  110. data/examples/rails-demo/tmp/storage/.keep +0 -0
  111. data/examples/rails-demo/vendor/.keep +0 -0
  112. data/examples/rails-demo/vendor/javascript/.keep +0 -0
  113. data/examples/sinatra-demo/sinatra-demo.rb +32 -0
  114. data/lib/skywalking/agent.rb +98 -0
  115. data/lib/skywalking/configuration.rb +255 -0
  116. data/lib/skywalking/environment.rb +50 -0
  117. data/lib/skywalking/log/logger.rb +53 -0
  118. data/lib/skywalking/plugins/redis5.rb +70 -0
  119. data/lib/skywalking/plugins/sinatra.rb +55 -0
  120. data/lib/skywalking/plugins_manager.rb +84 -0
  121. data/lib/skywalking/proto/asyncprofiler/AsyncProfiler_pb.rb +23 -0
  122. data/lib/skywalking/proto/asyncprofiler/AsyncProfiler_services_pb.rb +45 -0
  123. data/lib/skywalking/proto/browser/BrowserPerfCompat_pb.rb +15 -0
  124. data/lib/skywalking/proto/browser/BrowserPerfCompat_services_pb.rb +42 -0
  125. data/lib/skywalking/proto/browser/BrowserPerf_pb.rb +21 -0
  126. data/lib/skywalking/proto/browser/BrowserPerf_services_pb.rb +46 -0
  127. data/lib/skywalking/proto/common/Command_pb.rb +20 -0
  128. data/lib/skywalking/proto/common/Common_pb.rb +21 -0
  129. data/lib/skywalking/proto/ebpf/accesslog_pb.rb +58 -0
  130. data/lib/skywalking/proto/ebpf/accesslog_services_pb.rb +42 -0
  131. data/lib/skywalking/proto/event/Event_pb.rb +21 -0
  132. data/lib/skywalking/proto/event/Event_services_pb.rb +45 -0
  133. data/lib/skywalking/proto/language-agent/CLRMetricCompat_pb.rb +15 -0
  134. data/lib/skywalking/proto/language-agent/CLRMetricCompat_services_pb.rb +38 -0
  135. data/lib/skywalking/proto/language-agent/CLRMetric_pb.rb +23 -0
  136. data/lib/skywalking/proto/language-agent/CLRMetric_services_pb.rb +42 -0
  137. data/lib/skywalking/proto/language-agent/ConfigurationDiscoveryService_pb.rb +19 -0
  138. data/lib/skywalking/proto/language-agent/ConfigurationDiscoveryService_services_pb.rb +51 -0
  139. data/lib/skywalking/proto/language-agent/JVMMetricCompat_pb.rb +15 -0
  140. data/lib/skywalking/proto/language-agent/JVMMetricCompat_services_pb.rb +39 -0
  141. data/lib/skywalking/proto/language-agent/JVMMetric_pb.rb +28 -0
  142. data/lib/skywalking/proto/language-agent/JVMMetric_services_pb.rb +43 -0
  143. data/lib/skywalking/proto/language-agent/MeterCompat_pb.rb +15 -0
  144. data/lib/skywalking/proto/language-agent/MeterCompat_services_pb.rb +39 -0
  145. data/lib/skywalking/proto/language-agent/Meter_pb.rb +24 -0
  146. data/lib/skywalking/proto/language-agent/Meter_services_pb.rb +48 -0
  147. data/lib/skywalking/proto/language-agent/TracingCompat_pb.rb +15 -0
  148. data/lib/skywalking/proto/language-agent/TracingCompat_services_pb.rb +48 -0
  149. data/lib/skywalking/proto/language-agent/Tracing_pb.rb +31 -0
  150. data/lib/skywalking/proto/language-agent/Tracing_services_pb.rb +71 -0
  151. data/lib/skywalking/proto/logging/Logging_pb.rb +26 -0
  152. data/lib/skywalking/proto/logging/Logging_services_pb.rb +46 -0
  153. data/lib/skywalking/proto/management/ManagementCompat_pb.rb +15 -0
  154. data/lib/skywalking/proto/management/ManagementCompat_services_pb.rb +44 -0
  155. data/lib/skywalking/proto/management/Management_pb.rb +21 -0
  156. data/lib/skywalking/proto/management/Management_services_pb.rb +48 -0
  157. data/lib/skywalking/proto/profile/ProfileCompat_pb.rb +15 -0
  158. data/lib/skywalking/proto/profile/ProfileCompat_services_pb.rb +43 -0
  159. data/lib/skywalking/proto/profile/Profile_pb.rb +22 -0
  160. data/lib/skywalking/proto/profile/Profile_services_pb.rb +47 -0
  161. data/lib/skywalking/proto/service-mesh-probe/service-mesh_pb.rb +25 -0
  162. data/lib/skywalking/proto/service-mesh-probe/service-mesh_services_pb.rb +43 -0
  163. data/lib/skywalking/reporter/buffer_trigger.rb +108 -0
  164. data/lib/skywalking/reporter/client/grpc_client.rb +114 -0
  165. data/lib/skywalking/reporter/client/proto.rb +29 -0
  166. data/lib/skywalking/reporter/grpc.rb +46 -0
  167. data/lib/skywalking/reporter/protocol.rb +28 -0
  168. data/lib/skywalking/reporter/report.rb +82 -0
  169. data/lib/skywalking/reporter/scheduler.rb +158 -0
  170. data/lib/skywalking/tracing/carrier.rb +121 -0
  171. data/lib/skywalking/tracing/carrier_item.rb +27 -0
  172. data/lib/skywalking/tracing/constants.rb +49 -0
  173. data/lib/skywalking/tracing/entry_span.rb +48 -0
  174. data/lib/skywalking/tracing/exit_span.rb +53 -0
  175. data/lib/skywalking/tracing/ignored_context.rb +34 -0
  176. data/lib/skywalking/tracing/noop_span.rb +32 -0
  177. data/lib/skywalking/tracing/segment.rb +57 -0
  178. data/lib/skywalking/tracing/span.rb +111 -0
  179. data/lib/skywalking/tracing/span_context.rb +242 -0
  180. data/lib/skywalking/tracing/tag.rb +49 -0
  181. data/lib/skywalking/utils/id_gen.rb +30 -0
  182. data/lib/skywalking/version.rb +18 -0
  183. data/lib/skywalking.rb +36 -0
  184. metadata +340 -0
@@ -0,0 +1,46 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership.
4
+ # The ASF licenses this file to You under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with
6
+ # the License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require_relative 'protocol'
17
+ require_relative 'client/grpc_client'
18
+
19
+ module Skywalking
20
+ module Reporter
21
+ class Grpc < Protocol
22
+ def initialize(config)
23
+ @cfg = config
24
+ @ms_client = Skywalking::Reporter::Client::GrpcClient::ManagementServiceGrpc.new(config)
25
+ @trace_client = Skywalking::Reporter::Client::GrpcClient::TraceSegmentReportServiceGrpc.new(config)
26
+ @send_properties_counter = 0
27
+ @counter_mutex = Mutex.new
28
+ end
29
+
30
+ def report_heartbeat
31
+ @counter_mutex.synchronize do
32
+ @send_properties_counter += 1
33
+ if (@send_properties_counter.abs % @cfg[:properties_report_period_factor]).zero?
34
+ @ms_client.report_instance_properties
35
+ else
36
+ @ms_client.report_heartbeat
37
+ end
38
+ end
39
+ end
40
+
41
+ def report_segment(enumerator)
42
+ @trace_client.report_segment(enumerator)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,28 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership.
4
+ # The ASF licenses this file to You under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with
6
+ # the License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ module Skywalking
17
+ module Reporter
18
+ class Protocol
19
+ def report_heartbeat
20
+ raise NotImplementedError 'The report_heartbeat method has not been implemented'
21
+ end
22
+
23
+ def report_segment
24
+ raise NotImplementedError 'The report_segment method has not been implemented'
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,82 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership.
4
+ # The ASF licenses this file to You under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with
6
+ # the License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require_relative 'grpc'
17
+ require_relative 'Scheduler'
18
+ require_relative 'buffer_trigger'
19
+
20
+ module Skywalking
21
+ module Reporter
22
+ class Report
23
+ def initialize(config)
24
+ @config = config
25
+ init_proto
26
+ end
27
+
28
+ def init_proto
29
+ return if @protocol
30
+
31
+ case @config[:report_protocol]
32
+ when 'grpc'
33
+ @protocol = Grpc.new(@config)
34
+ else
35
+ raise "Unsupported report protocol: #{@config[:report_protocol]}"
36
+ end
37
+ end
38
+
39
+ def init_reporter
40
+ @daemon_loop = []
41
+
42
+ @scheduler_loop = Scheduler.new
43
+ @daemon_loop << Thread.new do
44
+ init_worker_loop
45
+ @scheduler_loop.run
46
+ end
47
+
48
+ @@trigger = BufferTrigger.new(@config)
49
+ @daemon_loop << Thread.new do
50
+ report_segment
51
+ end
52
+ end
53
+
54
+ def self.trigger
55
+ @@trigger
56
+ end
57
+
58
+ def init_worker_loop
59
+ @scheduler_loop.subscribe(:report_heartbeat, @config[:collector_heartbeat_period]) { report_heartbeat }
60
+ end
61
+
62
+ def stop
63
+ @scheduler_loop.shutdown
64
+ @@trigger.close_queue
65
+ @daemon_loop.each do |daemon|
66
+ if daemon.alive?
67
+ daemon.wakeup
68
+ daemon.join
69
+ end
70
+ end
71
+ end
72
+
73
+ def report_heartbeat
74
+ @protocol.report_heartbeat
75
+ end
76
+
77
+ def report_segment
78
+ @protocol.report_segment(@@trigger.stream_data) until @@trigger.closed?
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,158 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership.
4
+ # The ASF licenses this file to You under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with
6
+ # the License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ module Skywalking
17
+ module Reporter
18
+ class Scheduler
19
+ include Log::Logging
20
+
21
+ def initialize
22
+ @read_side, @write_side = IO.pipe
23
+ @queue = Queue.new
24
+ @workers = {}
25
+ @jobs = Hash.new { |h, k| h[k] = [] }
26
+ @jobs[:timer_job] << proc { |worker| add_worker(worker) }
27
+ @jobs[:event_job] << proc { |event, blk| @jobs[event] << blk }
28
+ @running = true
29
+ end
30
+
31
+ def run
32
+ while running?
33
+ reads = IO.select([@read_side], nil, nil, find_next_trigger)
34
+ if reads&.dig(0, 0) == @read_side
35
+ @read_side.read(1)
36
+ end
37
+ @workers.each_value do |worker|
38
+ if worker.need_trigger?
39
+ @queue << [worker.job_name]
40
+ worker.set_latest_trigger_time
41
+ end
42
+ end
43
+
44
+ until @queue.empty?
45
+ job, args = @queue.pop
46
+ dispatch(job, args)
47
+ @workers[job]&.init_next_trigger_time
48
+ end
49
+ end
50
+ end
51
+
52
+ def dispatch(job, args)
53
+ @jobs[job].each do |orig_job|
54
+ begin
55
+ orig_job.call(*args)
56
+ rescue Exception => e
57
+ warn "Error in job #{job}: #{e.message}"
58
+ end
59
+ end
60
+ end
61
+
62
+ def subscribe(job_name, job_interval, &job_func)
63
+ trigger(:event_job, [job_name, job_func])
64
+ trigger(:timer_job, Timer.new(job_name, job_interval))
65
+ end
66
+
67
+ def trigger(job_type, *args)
68
+ @queue.push([job_type, *args])
69
+ notify
70
+ end
71
+
72
+ def find_next_trigger
73
+ return nil if @workers.empty?
74
+
75
+ timeout = @workers.values.map(&:next_trigger_time).min - Process.clock_gettime(Process::CLOCK_REALTIME)
76
+ timeout.positive? ? timeout : 0
77
+ end
78
+
79
+ def notify
80
+ @write_side.write_nonblock('n')
81
+ end
82
+
83
+ def add_worker(worker)
84
+ orig_job = @workers[worker.job_name]
85
+ orig_job.adjust_next_trigger_time(Process.clock_gettime(Process::CLOCK_REALTIME) - orig_job.latest_trigger) if orig_job
86
+
87
+ @workers[worker.job_name] = worker
88
+ trigger_worker(worker)
89
+ end
90
+
91
+ def trigger_worker(worker)
92
+ if worker.need_trigger?
93
+ @queue.push([worker.job_name])
94
+ worker.set_latest_trigger_time
95
+ end
96
+ end
97
+
98
+ def running?
99
+ @running
100
+ end
101
+
102
+ def shutdown
103
+ return unless running?
104
+
105
+ @running = false
106
+ @write_side.write_nonblock('s')
107
+ end
108
+
109
+ class Timer
110
+ attr_reader :job_name, :job_interval, :next_trigger_time, :latest_trigger_time
111
+
112
+ def initialize(job_name, job_interval)
113
+ @job_name = job_name
114
+ @job_interval = job_interval
115
+ @start_time = Process.clock_gettime(Process::CLOCK_REALTIME)
116
+ @latest_trigger_time = nil
117
+
118
+ init_next_trigger_time
119
+ end
120
+
121
+ def init_next_trigger_time
122
+ @next_trigger_time = gen_next_trigger_time
123
+ end
124
+
125
+ def set_latest_trigger_time
126
+ @latest_trigger_time = Process.clock_gettime(Process::CLOCK_REALTIME)
127
+ end
128
+
129
+ def to_s
130
+ "<Timer job_name: #{@job_name}, job_interval: #{@job_interval}, start_time: #{@start_time},
131
+ latest_trigger_time: #{@latest_trigger_time}>"
132
+ end
133
+
134
+ def latest_trigger
135
+ @start_time || @latest_trigger_time
136
+ end
137
+
138
+ def adjust_next_trigger_time(time)
139
+ @next_trigger_time -= time
140
+ end
141
+
142
+ def need_trigger?(now = Process.clock_gettime(Process::CLOCK_REALTIME))
143
+ now >= @next_trigger_time
144
+ end
145
+
146
+ def gen_next_trigger_time
147
+ now = Process.clock_gettime(Process::CLOCK_REALTIME)
148
+ return now if @job_interval == 0
149
+
150
+ ret = @latest_trigger_time || now
151
+ ret += @job_interval while ret <= now
152
+
153
+ ret
154
+ end
155
+ end
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,121 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership.
4
+ # The ASF licenses this file to You under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with
6
+ # the License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require 'base64'
17
+ require_relative 'carrier_item'
18
+
19
+ module Skywalking
20
+ module Tracing
21
+ class Carrier < CarrierItem
22
+ attr_reader :trace_id, :correlation_carrier, :service_instance,
23
+ :endpoint, :segment_id, :span_id, :peer
24
+
25
+ def initialize(
26
+ trace_id: '',
27
+ segment_id: '',
28
+ span_id: '',
29
+ service: '',
30
+ service_instance: '',
31
+ endpoint: '',
32
+ peer: '',
33
+ correlation: nil
34
+ )
35
+ super(key: 'sw8')
36
+
37
+ @trace_id = trace_id
38
+ @segment_id = segment_id
39
+ @span_id = span_id
40
+ @service = service
41
+ @service_instance = service_instance
42
+ @endpoint = endpoint
43
+ @peer = peer
44
+ @correlation_carrier = SW8CorrelationCarrier.new
45
+ @items = [@correlation_carrier, self]
46
+ @iter_index = 0
47
+ @correlation_carrier.correlation = correlation unless correlation.nil?
48
+ end
49
+
50
+ def val
51
+ [
52
+ '1',
53
+ Base64.strict_encode64(@trace_id),
54
+ Base64.strict_encode64(@segment_id),
55
+ @span_id,
56
+ Base64.strict_encode64(@service),
57
+ Base64.strict_encode64(@service_instance),
58
+ Base64.strict_encode64(@endpoint),
59
+ Base64.strict_encode64(@client_address)
60
+ ].join('-')
61
+ end
62
+
63
+ def val=(val)
64
+ @val = val
65
+ return if val.nil? || val.empty?
66
+
67
+ parts = val.split('-')
68
+ return if parts.size != 8
69
+
70
+ @trace_id = Base64.strict_decode64(parts[1])
71
+ @segment_id = Base64.strict_decode64(parts[2])
72
+ @span_id = parts[3]
73
+ @service = Base64.strict_decode64(parts[4])
74
+ @service_instance = Base64.strict_decode64(parts[5])
75
+ @endpoint = Base64.strict_decode64(parts[6])
76
+ @client_address = Base64.strict_decode64(parts[7])
77
+ end
78
+
79
+ def valid?
80
+ !@trace_id.empty? && !@segment_id.empty? && !@service.empty? &&
81
+ !@service_instance.empty? && !@endpoint.empty? &&
82
+ !@client_address.empty? && @span_id.match?(/^\d+$/)
83
+ end
84
+
85
+ def suppressed?
86
+ @val && !valid?
87
+ end
88
+
89
+ def each
90
+ @items.each { |item| yield item }
91
+ end
92
+ end
93
+
94
+ class SW8CorrelationCarrier < CarrierItem
95
+ attr_accessor :correlation
96
+
97
+ def initialize
98
+ super(key: 'sw8-correlation')
99
+ @correlation = {}
100
+ end
101
+
102
+ def val
103
+ return '' if @correlation.nil? || @correlation.empty?
104
+
105
+ @correlation.map { |k, v| "#{Base64.strict_encode64(k)}:#{Base64.strict_encode64(v)}" }.join(',')
106
+ end
107
+
108
+ def val=(val)
109
+ @val = val
110
+ return if val.nil? || val.empty?
111
+
112
+ val.split(',').each do |per|
113
+ parts = per.split(':')
114
+ next if parts.size != 2
115
+
116
+ @correlation[Base64.strict_decode64(parts[0])] = Base64.strict_decode64(parts[1])
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,27 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership.
4
+ # The ASF licenses this file to You under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with
6
+ # the License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ module Skywalking
17
+ module Tracing
18
+ class CarrierItem
19
+ attr_accessor :key, :value
20
+
21
+ def initialize(key: '', value: '')
22
+ @key = key
23
+ @value = value
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,49 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership.
4
+ # The ASF licenses this file to You under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with
6
+ # the License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ module Skywalking
17
+ module Tracing
18
+ module Component
19
+ Unknown = 0
20
+ Redis = 7
21
+ General = 12000
22
+ Sinatra = 12001
23
+ end
24
+
25
+ module Layer
26
+ Unknown = 0
27
+ Database = 1
28
+ RPCFramework = 2
29
+ Http = 3
30
+ MQ = 4
31
+ Cache = 5
32
+ FAAS = 6
33
+ end
34
+
35
+ module Kind
36
+ Local = 0
37
+ Entry = 1
38
+ Exit = 2
39
+ end
40
+
41
+ def self.find_mapping(category, value)
42
+ category.constants.each do |const_name|
43
+ return const_name if category.const_get(const_name) == value
44
+ end
45
+
46
+ 'Unknown'
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,48 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership.
4
+ # The ASF licenses this file to You under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with
6
+ # the License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require_relative 'span'
17
+
18
+ module Skywalking
19
+ module Tracing
20
+ class EntrySpan < Span
21
+ def initialize(
22
+ context:,
23
+ span_id: -1,
24
+ parent_id: -1,
25
+ operation: nil,
26
+ peer: nil,
27
+ component: nil,
28
+ layer: nil
29
+ )
30
+ super(context: context, span_id: span_id, parent_id: parent_id,
31
+ operation: operation, peer: peer, kind: Kind::Entry,
32
+ component: component, layer: layer)
33
+
34
+ @current_max_depth = 0
35
+ end
36
+
37
+ def start
38
+ super
39
+
40
+ @current_max_depth = @stack_depth
41
+ @component = Component::Unknown
42
+ @layer = Layer::Unknown
43
+ @lags = []
44
+ @tags = Hash.new { |hash, key| hash[key] = [] }
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,53 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership.
4
+ # The ASF licenses this file to You under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with
6
+ # the License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require_relative 'span'
17
+
18
+ module Skywalking
19
+ module Tracing
20
+ class ExitSpan < Span
21
+ def initialize(
22
+ context:,
23
+ span_id: -1,
24
+ parent_id: -1,
25
+ operation: nil,
26
+ peer: nil,
27
+ component: nil,
28
+ layer: nil
29
+ )
30
+ super(context: context, span_id: span_id, parent_id: parent_id,
31
+ operation: operation, peer: peer, kind: Kind::Exit,
32
+ component: component, layer: layer)
33
+ end
34
+
35
+ def cfg
36
+ @config ||= ::Skywalking::Agent.config
37
+ end
38
+
39
+ def inject
40
+ Carrier.new(
41
+ trace_id: @context.segment.related_traces[0].to_s,
42
+ segment_id: @context.segment.segment_id.to_s,
43
+ span_id: @span_id.to_s,
44
+ service: cfg[:service_name],
45
+ service_instance: cfg[:instance_name],
46
+ endpoint: @operation,
47
+ peer: @peer,
48
+ correlation: @context.correlation
49
+ )
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,34 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership.
4
+ # The ASF licenses this file to You under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with
6
+ # the License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require_relative 'span_context'
17
+
18
+ module Skywalking
19
+ module Tracing
20
+ class IgnoredContext < SpanContext
21
+ def initialize(context)
22
+ Span.new(context: context, operation: '', kind: Kind::Local)
23
+ end
24
+
25
+ def self.inject
26
+ Carrier.new
27
+ end
28
+
29
+ def self.extract(carrier)
30
+ nil
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,32 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership.
4
+ # The ASF licenses this file to You under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with
6
+ # the License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require_relative 'span'
17
+
18
+ module Skywalking
19
+ module Tracing
20
+ class NoopSpan < Span
21
+ def initialize(context: nil)
22
+ super(context: context, operation: '', kind: Tracing::Kind::EXIT)
23
+ end
24
+
25
+ def extract(carrier) end
26
+
27
+ def inject
28
+ Carrier.new
29
+ end
30
+ end
31
+ end
32
+ end