d13n 0.5.2
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 +35 -0
- data/.rspec +6 -0
- data/.rubocop.yml +5 -0
- data/.ruby-version +1 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +151 -0
- data/Guardfile +63 -0
- data/README.md +200 -0
- data/bin/d13n +11 -0
- data/d13n.gemspec +34 -0
- data/lib/d13n/application/class_methods.rb +56 -0
- data/lib/d13n/application.rb +3 -0
- data/lib/d13n/cli/command.rb +76 -0
- data/lib/d13n/cli/commands/scaffold.rb +345 -0
- data/lib/d13n/configuration/default_source.rb +200 -0
- data/lib/d13n/configuration/dotted_hash.rb +39 -0
- data/lib/d13n/configuration/environment_source.rb +89 -0
- data/lib/d13n/configuration/manager.rb +239 -0
- data/lib/d13n/configuration/manual_source.rb +4 -0
- data/lib/d13n/configuration/mask_defaults.rb +6 -0
- data/lib/d13n/configuration/server_source.rb +83 -0
- data/lib/d13n/configuration/yaml_source.rb +66 -0
- data/lib/d13n/configuration.rb +6 -0
- data/lib/d13n/ext/string.rb +17 -0
- data/lib/d13n/logger/log_once.rb +24 -0
- data/lib/d13n/logger/memory_logger.rb +48 -0
- data/lib/d13n/logger/null_logger.rb +16 -0
- data/lib/d13n/logger.rb +213 -0
- data/lib/d13n/metric/conductor.rb +123 -0
- data/lib/d13n/metric/helper.rb +62 -0
- data/lib/d13n/metric/http_clients/http_helper.rb +15 -0
- data/lib/d13n/metric/http_clients/net_http_wrappers.rb +54 -0
- data/lib/d13n/metric/http_clients.rb +4 -0
- data/lib/d13n/metric/instrumentation/app_exception.rb +70 -0
- data/lib/d13n/metric/instrumentation/controller_instrumentation.rb +91 -0
- data/lib/d13n/metric/instrumentation/em-websocket.rb +71 -0
- data/lib/d13n/metric/instrumentation/exception.rb +65 -0
- data/lib/d13n/metric/instrumentation/middleware_tracing.rb +82 -0
- data/lib/d13n/metric/instrumentation/net.rb +36 -0
- data/lib/d13n/metric/instrumentation/sinatra/stream_namer.rb +35 -0
- data/lib/d13n/metric/instrumentation/sinatra.rb +165 -0
- data/lib/d13n/metric/instrumentation/websocket_instrumentation.rb +42 -0
- data/lib/d13n/metric/instrumentation.rb +41 -0
- data/lib/d13n/metric/manager.rb +106 -0
- data/lib/d13n/metric/metrics/app_database_metric.rb +4 -0
- data/lib/d13n/metric/metrics/app_http_metric.rb +229 -0
- data/lib/d13n/metric/metrics/app_state_metric.rb +103 -0
- data/lib/d13n/metric/metrics/base.rb +14 -0
- data/lib/d13n/metric/metrics/biz_state_metric.rb +4 -0
- data/lib/d13n/metric/metrics.rb +6 -0
- data/lib/d13n/metric/stream/span_tracer_helpers.rb +72 -0
- data/lib/d13n/metric/stream/stream_tracer_helpers.rb +141 -0
- data/lib/d13n/metric/stream/traced_span_stack.rb +73 -0
- data/lib/d13n/metric/stream.rb +322 -0
- data/lib/d13n/metric/stream_state.rb +68 -0
- data/lib/d13n/metric.rb +11 -0
- data/lib/d13n/rack/d13n_middleware.rb +21 -0
- data/lib/d13n/rack/metric_middleware.rb +18 -0
- data/lib/d13n/service/background_job/sinatra.rb +24 -0
- data/lib/d13n/service/background_job.rb +1 -0
- data/lib/d13n/service/start.rb +75 -0
- data/lib/d13n/service.rb +91 -0
- data/lib/d13n/support/request_id.rb +29 -0
- data/lib/d13n/version.rb +14 -0
- data/lib/d13n.rb +92 -0
- data/templates/.rspec.template +6 -0
- data/templates/.ruby-version.template +1 -0
- data/templates/Gemfile.template +16 -0
- data/templates/Guardfile.template +64 -0
- data/templates/Jenkinsfile.template +85 -0
- data/templates/Makefile.template +178 -0
- data/templates/README.md.template +1 -0
- data/templates/Rakefile.template +6 -0
- data/templates/application.yml.template +14 -0
- data/templates/config.ru.template +4 -0
- data/templates/docker/.dockerignore.template +5 -0
- data/templates/docker/Dockerfile.application.development +15 -0
- data/templates/docker/Dockerfile.cache.development +18 -0
- data/templates/docker/Dockerfile.development +27 -0
- data/templates/docker/Dockerfile.release +16 -0
- data/templates/docker/docker-compose.yml.development +53 -0
- data/templates/docker/docker-compose.yml.release +37 -0
- data/templates/lib/api/service.rb.template +10 -0
- data/templates/lib/api/support.rb.template +38 -0
- data/templates/lib/api/version.rb.template +3 -0
- data/templates/lib/api.rb.template +4 -0
- data/templates/lib/application.rb.template +49 -0
- data/templates/lib/service.rb.template +4 -0
- data/templates/lib/version.rb.template +3 -0
- data/templates/scripts/test.sh.template +7 -0
- data/templates/spec/spec_helper.rb.template +56 -0
- data/templates/tasks/migration.rake.template +11 -0
- data/templates/tasks/spec.rake.template +21 -0
- metadata +199 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'd13n/support/request_id'
|
2
|
+
|
3
|
+
module <%= application_base %>::Api
|
4
|
+
class Service < ::Sinatra::Base
|
5
|
+
use Rack::RequestId
|
6
|
+
set :public_folder, File.join(File.dirname(__FILE__), *%w[.. .. public])
|
7
|
+
set :views, File.join(File.dirname(__FILE__), *%w[.. .. views])
|
8
|
+
set :show_exceptions, false
|
9
|
+
set :logging, true
|
10
|
+
|
11
|
+
before do
|
12
|
+
headers 'X-Powered-By' => "<%= application_base %>#{<%= application_base %>::VERSION}"
|
13
|
+
headers 'X-Api-Version' => "#{<%= application_base %>::Api::VERSION}"
|
14
|
+
D13n::Metric::StreamState.st_get.request_info = request_info
|
15
|
+
end
|
16
|
+
|
17
|
+
get "/" do
|
18
|
+
"<%= application_base %>(#{<%= application_base %>::VERSION}:#{<%= application_base %>::Api::VERSION}) Say Hi"
|
19
|
+
end
|
20
|
+
|
21
|
+
#TODO refactor format handling
|
22
|
+
get "/check" do
|
23
|
+
{status: "OK"}.to_json
|
24
|
+
end
|
25
|
+
|
26
|
+
get "/config" do
|
27
|
+
<%= application_base %>.config.to_collector_hash.to_json
|
28
|
+
end
|
29
|
+
|
30
|
+
def request_info
|
31
|
+
{
|
32
|
+
"host" => request.host,
|
33
|
+
"ip" => request.ip,
|
34
|
+
"request_id" => env['HTTP_X_REQUEST_ID']
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'd13n'
|
2
|
+
require '<%= application %>/version'
|
3
|
+
module <%= application_base %>
|
4
|
+
extend D13n::Application::ClassMethods
|
5
|
+
# D13n defined logger, config and config's default configuration 'default_source' in <%= application_base %>, you can use
|
6
|
+
# <%= application_base %>.config=
|
7
|
+
# <%= application_base %>.logger=
|
8
|
+
# to assign another configurator or logger.
|
9
|
+
#
|
10
|
+
# To config default configuration, you can use
|
11
|
+
# <%= application_base %>.default_source=
|
12
|
+
# to assign some default configuration in application start. To define the default configuration,
|
13
|
+
# <%= application_base %>.default_source = {
|
14
|
+
# :'service.broker.host' => {
|
15
|
+
# :default => 'localhost',
|
16
|
+
# :public => true,
|
17
|
+
# :type => String,
|
18
|
+
# :allowed_from_server => true,
|
19
|
+
# :description => 'Broker Host Name.'
|
20
|
+
# },
|
21
|
+
# :'service.broker.port' => {
|
22
|
+
# :default => '61614',
|
23
|
+
# :public => true,
|
24
|
+
# :type => String,
|
25
|
+
# :allowed_from_server => true,
|
26
|
+
# :description => 'Broker Host Port.'
|
27
|
+
# },
|
28
|
+
# :'service.broker.username' => {
|
29
|
+
# :default => 'laxino_service',
|
30
|
+
# :public => true,
|
31
|
+
# :type => String,
|
32
|
+
# :allowed_from_server => true,
|
33
|
+
# :description => 'Broker Host Service Username.'
|
34
|
+
# },
|
35
|
+
# :'service.broker.password' => {
|
36
|
+
# :default => 'laxino_service',
|
37
|
+
# :public => true,
|
38
|
+
# :type => String,
|
39
|
+
# :allowed_from_server => true,
|
40
|
+
# :description => 'Broker Host Password.'
|
41
|
+
# }
|
42
|
+
# }
|
43
|
+
#
|
44
|
+
# More information about configuration pls refer config_kit repository: http://stash.mo.laxino.com/users/ben.wu/repos/config_kit/browse
|
45
|
+
# Or Axle Configuration documentation: http://stash.mo.laxino.com/projects/G2/repos/idc_config/browse
|
46
|
+
end
|
47
|
+
|
48
|
+
require '<%= application %>/service'
|
49
|
+
require '<%= application %>/api'
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
SimpleCov.start do
|
4
|
+
add_filter "/spec/"
|
5
|
+
add_filter "/vendor/"
|
6
|
+
coverage_dir "#{File.dirname(__FILE__)}/../reports/coverage/"
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'faker'
|
10
|
+
require 'factory_girl'
|
11
|
+
require 'as-duration'
|
12
|
+
require '<%= application %>'
|
13
|
+
|
14
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
15
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
16
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
17
|
+
# loaded once.
|
18
|
+
#
|
19
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
20
|
+
RSpec.configure do |config|
|
21
|
+
#config.treat_symbols_as_metadata_keys_with_true_values = true
|
22
|
+
# config.run_all_when_everything_filtered = true
|
23
|
+
# config.filter_run :focus
|
24
|
+
|
25
|
+
# Run specs in random order to surface order dependencies. If you find an
|
26
|
+
# order dependency and want to debug it, you can fix the order by providing
|
27
|
+
# the seed, which is printed after each run.
|
28
|
+
# --seed 1234
|
29
|
+
config.order = 'random'
|
30
|
+
|
31
|
+
# config.before(:suite) do
|
32
|
+
|
33
|
+
# end
|
34
|
+
|
35
|
+
# config.before(:each) do
|
36
|
+
# DatabaseCleaner.strategy = :transaction
|
37
|
+
# end
|
38
|
+
# config.before(:each) do
|
39
|
+
#{Application}.logger = {Application}::Logger::SilenceLogger.new
|
40
|
+
# end
|
41
|
+
|
42
|
+
# config.before(:each) do
|
43
|
+
# # open transaction
|
44
|
+
# DatabaseCleaner.clean_with :deletion
|
45
|
+
# DatabaseCleaner.start
|
46
|
+
# end
|
47
|
+
|
48
|
+
# config.after(:each) do
|
49
|
+
# DatabaseCleaner.clean
|
50
|
+
# end
|
51
|
+
|
52
|
+
FactoryGirl.find_definitions
|
53
|
+
config.profile_examples = 3
|
54
|
+
|
55
|
+
config.include FactoryGirl::Syntax::Methods
|
56
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
namespace :spec do
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
desc "Run all specs for CI"
|
4
|
+
RSpec::Core::RakeTask.new(:ci) do |spec|
|
5
|
+
Rake::Task['db:migrate:up'].invoke
|
6
|
+
spec.rspec_opts = '-c --format documentation --format html --out reports/spec.html'
|
7
|
+
end
|
8
|
+
|
9
|
+
desc "Run unit test specs"
|
10
|
+
RSpec::Core::RakeTask.new(:unit) do |t|
|
11
|
+
# ENV['DATABASE_URL'] ||= 'sqlite://migrations/test.db'
|
12
|
+
Rake::Task['db:migrate:up'].invoke
|
13
|
+
t.pattern = Dir['spec/unit/**/*_spec.rb'].reject{ |f| f['/functional'] }
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Run functional test specs"
|
17
|
+
RSpec::Core::RakeTask.new(:functional) do |t|
|
18
|
+
Rake::Task['db:migrate:up'].invoke
|
19
|
+
t.pattern = "spec/functional/**/*_spec.rb"
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: d13n
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Wu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-06-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.14'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: statsd-instrument
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.2'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 2.2.0
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '2.2'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 2.2.0
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: config_kit
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - '='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 0.0.16
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.0.16
|
75
|
+
description: Write a longer description or delete this line.
|
76
|
+
email:
|
77
|
+
- ben.wu@laxino.com
|
78
|
+
executables:
|
79
|
+
- d13n
|
80
|
+
extensions: []
|
81
|
+
extra_rdoc_files: []
|
82
|
+
files:
|
83
|
+
- ".gitignore"
|
84
|
+
- ".rspec"
|
85
|
+
- ".rubocop.yml"
|
86
|
+
- ".ruby-version"
|
87
|
+
- Gemfile
|
88
|
+
- Gemfile.lock
|
89
|
+
- Guardfile
|
90
|
+
- README.md
|
91
|
+
- bin/d13n
|
92
|
+
- d13n.gemspec
|
93
|
+
- lib/d13n.rb
|
94
|
+
- lib/d13n/application.rb
|
95
|
+
- lib/d13n/application/class_methods.rb
|
96
|
+
- lib/d13n/cli/command.rb
|
97
|
+
- lib/d13n/cli/commands/scaffold.rb
|
98
|
+
- lib/d13n/configuration.rb
|
99
|
+
- lib/d13n/configuration/default_source.rb
|
100
|
+
- lib/d13n/configuration/dotted_hash.rb
|
101
|
+
- lib/d13n/configuration/environment_source.rb
|
102
|
+
- lib/d13n/configuration/manager.rb
|
103
|
+
- lib/d13n/configuration/manual_source.rb
|
104
|
+
- lib/d13n/configuration/mask_defaults.rb
|
105
|
+
- lib/d13n/configuration/server_source.rb
|
106
|
+
- lib/d13n/configuration/yaml_source.rb
|
107
|
+
- lib/d13n/ext/string.rb
|
108
|
+
- lib/d13n/logger.rb
|
109
|
+
- lib/d13n/logger/log_once.rb
|
110
|
+
- lib/d13n/logger/memory_logger.rb
|
111
|
+
- lib/d13n/logger/null_logger.rb
|
112
|
+
- lib/d13n/metric.rb
|
113
|
+
- lib/d13n/metric/conductor.rb
|
114
|
+
- lib/d13n/metric/helper.rb
|
115
|
+
- lib/d13n/metric/http_clients.rb
|
116
|
+
- lib/d13n/metric/http_clients/http_helper.rb
|
117
|
+
- lib/d13n/metric/http_clients/net_http_wrappers.rb
|
118
|
+
- lib/d13n/metric/instrumentation.rb
|
119
|
+
- lib/d13n/metric/instrumentation/app_exception.rb
|
120
|
+
- lib/d13n/metric/instrumentation/controller_instrumentation.rb
|
121
|
+
- lib/d13n/metric/instrumentation/em-websocket.rb
|
122
|
+
- lib/d13n/metric/instrumentation/exception.rb
|
123
|
+
- lib/d13n/metric/instrumentation/middleware_tracing.rb
|
124
|
+
- lib/d13n/metric/instrumentation/net.rb
|
125
|
+
- lib/d13n/metric/instrumentation/sinatra.rb
|
126
|
+
- lib/d13n/metric/instrumentation/sinatra/stream_namer.rb
|
127
|
+
- lib/d13n/metric/instrumentation/websocket_instrumentation.rb
|
128
|
+
- lib/d13n/metric/manager.rb
|
129
|
+
- lib/d13n/metric/metrics.rb
|
130
|
+
- lib/d13n/metric/metrics/app_database_metric.rb
|
131
|
+
- lib/d13n/metric/metrics/app_http_metric.rb
|
132
|
+
- lib/d13n/metric/metrics/app_state_metric.rb
|
133
|
+
- lib/d13n/metric/metrics/base.rb
|
134
|
+
- lib/d13n/metric/metrics/biz_state_metric.rb
|
135
|
+
- lib/d13n/metric/stream.rb
|
136
|
+
- lib/d13n/metric/stream/span_tracer_helpers.rb
|
137
|
+
- lib/d13n/metric/stream/stream_tracer_helpers.rb
|
138
|
+
- lib/d13n/metric/stream/traced_span_stack.rb
|
139
|
+
- lib/d13n/metric/stream_state.rb
|
140
|
+
- lib/d13n/rack/d13n_middleware.rb
|
141
|
+
- lib/d13n/rack/metric_middleware.rb
|
142
|
+
- lib/d13n/service.rb
|
143
|
+
- lib/d13n/service/background_job.rb
|
144
|
+
- lib/d13n/service/background_job/sinatra.rb
|
145
|
+
- lib/d13n/service/start.rb
|
146
|
+
- lib/d13n/support/request_id.rb
|
147
|
+
- lib/d13n/version.rb
|
148
|
+
- templates/.rspec.template
|
149
|
+
- templates/.ruby-version.template
|
150
|
+
- templates/Gemfile.template
|
151
|
+
- templates/Guardfile.template
|
152
|
+
- templates/Jenkinsfile.template
|
153
|
+
- templates/Makefile.template
|
154
|
+
- templates/README.md.template
|
155
|
+
- templates/Rakefile.template
|
156
|
+
- templates/application.yml.template
|
157
|
+
- templates/config.ru.template
|
158
|
+
- templates/docker/.dockerignore.template
|
159
|
+
- templates/docker/Dockerfile.application.development
|
160
|
+
- templates/docker/Dockerfile.cache.development
|
161
|
+
- templates/docker/Dockerfile.development
|
162
|
+
- templates/docker/Dockerfile.release
|
163
|
+
- templates/docker/docker-compose.yml.development
|
164
|
+
- templates/docker/docker-compose.yml.release
|
165
|
+
- templates/lib/api.rb.template
|
166
|
+
- templates/lib/api/service.rb.template
|
167
|
+
- templates/lib/api/support.rb.template
|
168
|
+
- templates/lib/api/version.rb.template
|
169
|
+
- templates/lib/application.rb.template
|
170
|
+
- templates/lib/service.rb.template
|
171
|
+
- templates/lib/version.rb.template
|
172
|
+
- templates/scripts/test.sh.template
|
173
|
+
- templates/spec/spec_helper.rb.template
|
174
|
+
- templates/tasks/migration.rake.template
|
175
|
+
- templates/tasks/spec.rake.template
|
176
|
+
homepage: http://github.com/cheokman
|
177
|
+
licenses: []
|
178
|
+
metadata:
|
179
|
+
allowed_push_host: https://rubygems.org
|
180
|
+
post_install_message:
|
181
|
+
rdoc_options: []
|
182
|
+
require_paths:
|
183
|
+
- lib
|
184
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
194
|
+
requirements: []
|
195
|
+
rubygems_version: 3.1.6
|
196
|
+
signing_key:
|
197
|
+
specification_version: 4
|
198
|
+
summary: Write a short summary, because Rubygems requires one.
|
199
|
+
test_files: []
|