zuora_connect 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/MIT-LICENSE +20 -0
- data/Rakefile +38 -0
- data/app/assets/javascripts/hallway_wrapper/after.js +15 -0
- data/app/assets/javascripts/hallway_wrapper/before.js +2 -0
- data/app/assets/javascripts/zuora_connect/api/v1/app_instance.js +2 -0
- data/app/assets/javascripts/zuora_connect/application.js +13 -0
- data/app/assets/stylesheets/zuora_connect/api/v1/app_instance.css +4 -0
- data/app/assets/stylesheets/zuora_connect/application.css +15 -0
- data/app/controllers/zuora_connect/admin/tenant_controller.rb +11 -0
- data/app/controllers/zuora_connect/api/v1/app_instance_controller.rb +58 -0
- data/app/controllers/zuora_connect/application_controller.rb +8 -0
- data/app/controllers/zuora_connect/static_controller.rb +58 -0
- data/app/helpers/zuora_connect/api/v1/app_instance_helper.rb +4 -0
- data/app/helpers/zuora_connect/application_helper.rb +5 -0
- data/app/models/zuora_connect/app_instance.rb +5 -0
- data/app/models/zuora_connect/app_instance_base.rb +952 -0
- data/app/models/zuora_connect/login.rb +36 -0
- data/app/models/zuora_connect/telegraf.rb +93 -0
- data/app/views/layouts/zuora_connect/application.html.erb +14 -0
- data/app/views/sql/refresh_aggregate_table.txt +85 -0
- data/app/views/zuora_connect/static/invalid_app_instance_error.html.erb +65 -0
- data/app/views/zuora_connect/static/invalid_launch_request.html +65 -0
- data/app/views/zuora_connect/static/launch.html.erb +80 -0
- data/app/views/zuora_connect/static/session_error.html.erb +63 -0
- data/config/initializers/apartment.rb +95 -0
- data/config/initializers/aws.rb +2 -0
- data/config/initializers/elastic_apm.rb +25 -0
- data/config/initializers/object_method_hooks.rb +27 -0
- data/config/initializers/postgresql_adapter.rb +32 -0
- data/config/initializers/prometheus.rb +40 -0
- data/config/initializers/redis.rb +13 -0
- data/config/initializers/resque.rb +22 -0
- data/config/initializers/to_bool.rb +24 -0
- data/config/initializers/unicorn.rb +9 -0
- data/config/routes.rb +16 -0
- data/db/migrate/20100718151733_create_connect_app_instances.rb +9 -0
- data/db/migrate/20101024162319_add_tokens_to_app_instance.rb +6 -0
- data/db/migrate/20101024220705_add_token_to_app_instance.rb +5 -0
- data/db/migrate/20110131211919_add_sessions_table.rb +13 -0
- data/db/migrate/20110411200303_add_expiration_to_app_instance.rb +5 -0
- data/db/migrate/20110413191512_add_new_api_token.rb +5 -0
- data/db/migrate/20110503003602_add_catalog_data_to_app_instance.rb +6 -0
- data/db/migrate/20110503003603_add_catalog_mappings_to_app_instance.rb +5 -0
- data/db/migrate/20110503003604_catalog_default.rb +5 -0
- data/db/migrate/20180301052853_add_catalog_attempted_at.rb +5 -0
- data/db/migrate/20181206162339_add_fields_to_instance.rb +5 -0
- data/lib/metrics/influx/point_value.rb +79 -0
- data/lib/metrics/net.rb +218 -0
- data/lib/middleware/metrics_middleware.rb +134 -0
- data/lib/resque/additions.rb +53 -0
- data/lib/resque/dynamic_queues.rb +222 -0
- data/lib/resque/plugins/custom_logger.rb +46 -0
- data/lib/resque/self_lookup.rb +19 -0
- data/lib/resque/silence_done.rb +71 -0
- data/lib/tasks/zuora_connect_tasks.rake +24 -0
- data/lib/zuora_connect.rb +42 -0
- data/lib/zuora_connect/configuration.rb +53 -0
- data/lib/zuora_connect/controllers/helpers.rb +261 -0
- data/lib/zuora_connect/engine.rb +34 -0
- data/lib/zuora_connect/exceptions.rb +67 -0
- data/lib/zuora_connect/railtie.rb +63 -0
- data/lib/zuora_connect/version.rb +3 -0
- data/lib/zuora_connect/views/helpers.rb +9 -0
- data/test/controllers/zuora_connect/api/v1/app_instance_controller_test.rb +13 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/fixtures/zuora_connect/app_instances.yml +11 -0
- data/test/integration/navigation_test.rb +8 -0
- data/test/lib/generators/zuora_connect/datatable_generator_test.rb +16 -0
- data/test/models/zuora_connect/app_instance_test.rb +9 -0
- data/test/test_helper.rb +21 -0
- data/test/zuora_connect_test.rb +7 -0
- metadata +443 -0
@@ -0,0 +1,95 @@
|
|
1
|
+
# You can have Apartment route to the appropriate Tenant by adding some Rack middleware.
|
2
|
+
# Apartment can support many different "Elevators" that can take care of this routing to your data.
|
3
|
+
# Require whichever Elevator you're using below or none if you have a custom one.
|
4
|
+
#
|
5
|
+
# require 'apartment/elevators/generic'
|
6
|
+
# require 'apartment/elevators/domain'
|
7
|
+
#require 'apartment/elevators/subdomain'
|
8
|
+
# require 'apartment/elevators/first_subdomain'
|
9
|
+
#
|
10
|
+
# Apartment Configuration
|
11
|
+
#
|
12
|
+
Apartment.configure do |config|
|
13
|
+
|
14
|
+
# Add any models that you do not want to be multi-tenanted, but remain in the global (public) namespace.
|
15
|
+
# A typical example would be a Customer or Tenant model that stores each Tenant's information.
|
16
|
+
#
|
17
|
+
# config.excluded_models = %w{ Tenant }
|
18
|
+
|
19
|
+
# In order to migrate all of your Tenants you need to provide a list of Tenant names to Apartment.
|
20
|
+
# You can make this dynamic by providing a Proc object to be called on migrations.
|
21
|
+
# This object should yield either:
|
22
|
+
# - an array of strings representing each Tenant name.
|
23
|
+
# - a hash which keys are tenant names, and values custom db config (must contain all key/values required in database.yml)
|
24
|
+
#
|
25
|
+
# config.tenant_names = lambda{ Customer.pluck(:tenant_name) }
|
26
|
+
# config.tenant_names = ['tenant1', 'tenant2']
|
27
|
+
# config.tenant_names = {
|
28
|
+
# 'tenant1' => {
|
29
|
+
# adapter: 'postgresql',
|
30
|
+
# host: 'some_server',
|
31
|
+
# port: 5555,
|
32
|
+
# database: 'postgres' # this is not the name of the tenant's db
|
33
|
+
# # but the name of the database to connect to before creating the tenant's db
|
34
|
+
# # mandatory in postgresql
|
35
|
+
# },
|
36
|
+
# 'tenant2' => {
|
37
|
+
# adapter: 'postgresql',
|
38
|
+
# database: 'postgres' # this is not the name of the tenant's db
|
39
|
+
# # but the name of the database to connect to before creating the tenant's db
|
40
|
+
# # mandatory in postgresql
|
41
|
+
# }
|
42
|
+
# }
|
43
|
+
# config.tenant_names = lambda do
|
44
|
+
# Tenant.all.each_with_object({}) do |tenant, hash|
|
45
|
+
# hash[tenant.name] = tenant.db_configuration
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
config.tenant_names = lambda { ZuoraConnect::AppInstance.pluck :id }
|
50
|
+
if defined?(ActiveRecord::SessionStore::Session)
|
51
|
+
config.excluded_models = ["ZuoraConnect::AppInstance","ZuoraConnect::AppInstanceBase", "ActiveRecord::SessionStore::Session"]
|
52
|
+
else
|
53
|
+
config.excluded_models = ["ZuoraConnect::AppInstance","ZuoraConnect::AppInstanceBase"]
|
54
|
+
end
|
55
|
+
#
|
56
|
+
# ==> PostgreSQL only options
|
57
|
+
|
58
|
+
# Specifies whether to use PostgreSQL schemas or create a new database per Tenant.
|
59
|
+
# The default behaviour is true.
|
60
|
+
#
|
61
|
+
config.use_schemas = true
|
62
|
+
|
63
|
+
# Apartment can be forced to use raw SQL dumps instead of schema.rb for creating new schemas.
|
64
|
+
# Use this when you are using some extra features in PostgreSQL that can't be respresented in
|
65
|
+
# schema.rb, like materialized views etc. (only applies with use_schemas set to true).
|
66
|
+
# (Note: this option doesn't use db/structure.sql, it creates SQL dump by executing pg_dump)
|
67
|
+
#
|
68
|
+
# config.use_sql = false
|
69
|
+
|
70
|
+
# There are cases where you might want some schemas to always be in your search_path
|
71
|
+
# e.g when using a PostgreSQL extension like hstore.
|
72
|
+
# Any schemas added here will be available along with your selected Tenant.
|
73
|
+
#
|
74
|
+
config.persistent_schemas = %w{ shared_extensions }
|
75
|
+
|
76
|
+
# <== PostgreSQL only options
|
77
|
+
#
|
78
|
+
|
79
|
+
# By default, and only when not using PostgreSQL schemas, Apartment will prepend the environment
|
80
|
+
# to the tenant name to ensure there is no conflict between your environments.
|
81
|
+
# This is mainly for the benefit of your development and test environments.
|
82
|
+
# Uncomment the line below if you want to disable this behaviour in production.
|
83
|
+
#
|
84
|
+
# config.prepend_environment = !Rails.env.production?
|
85
|
+
end
|
86
|
+
|
87
|
+
# Setup a custom Tenant switching middleware. The Proc should return the name of the Tenant that
|
88
|
+
# you want to switch to.
|
89
|
+
# Rails.application.config.middleware.use 'Apartment::Elevators::Generic', lambda { |request|
|
90
|
+
# request.host.split('.').first
|
91
|
+
# }
|
92
|
+
|
93
|
+
# Rails.application.config.middleware.use 'Apartment::Elevators::Domain'
|
94
|
+
#Rails.application.config.middleware.use 'Apartment::Elevators::Subdomain'
|
95
|
+
# Rails.application.config.middleware.use 'Apartment::Elevators::FirstSubdomain'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
if defined?(ElasticAPM)
|
2
|
+
if ZuoraConnect.configuration.enable_apm && !defined?(Rails::Console)
|
3
|
+
ElasticAPM.agent.config.disable_send = false
|
4
|
+
else
|
5
|
+
ElasticAPM.agent.config.disable_send = true
|
6
|
+
end
|
7
|
+
case Rails.env.to_s
|
8
|
+
when 'production'
|
9
|
+
ElasticAPM.agent.config.server_url = "http://apm-server.logging:8200"
|
10
|
+
ElasticAPM.agent.config.transaction_sample_rate = 0.20
|
11
|
+
ElasticAPM.agent.config.capture_body = false
|
12
|
+
when 'staging'
|
13
|
+
ElasticAPM.agent.config.server_url = "http://apm-server.logging:8200"
|
14
|
+
ElasticAPM.agent.config.transaction_sample_rate = 1.0
|
15
|
+
when 'development'
|
16
|
+
ElasticAPM.agent.config.server_url = "http://logging.0.ecc.auw2.zuora:8200"
|
17
|
+
ElasticAPM.agent.config.transaction_sample_rate = 1.0
|
18
|
+
end
|
19
|
+
ElasticAPM.agent.config.pool_size = 1
|
20
|
+
ElasticAPM.agent.config.transaction_max_spans = 500
|
21
|
+
ElasticAPM.agent.config.ignore_url_patterns = ['^\/admin\/resque.*', '^\/admin\/redis.*', '^\/admin\/peek.*', '^\/peek.*']
|
22
|
+
ElasticAPM.agent.config.verify_server_cert = false
|
23
|
+
ElasticAPM.agent.config.log_level = Logger::INFO
|
24
|
+
ElasticAPM.agent.config.service_name = ::ZuoraConnect::Telegraf.app_name
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Object
|
2
|
+
def self.method_hook(*args)
|
3
|
+
options = args.extract_options!
|
4
|
+
return unless (options[:before].present? or options[:after].present?)
|
5
|
+
args.each do |method_name|
|
6
|
+
old_method = instance_method(method_name) rescue next
|
7
|
+
|
8
|
+
define_method(method_name) do |*args|
|
9
|
+
# invoke before callback
|
10
|
+
if options[:before].present?
|
11
|
+
options[:before].is_a?(Proc) ? options[:before].call(method_name, self):
|
12
|
+
send(options[:before], method_name)
|
13
|
+
end
|
14
|
+
|
15
|
+
# you can modify the code to call after callback
|
16
|
+
# only when the old method returns true etc..
|
17
|
+
old_method.bind(self).call(*args)
|
18
|
+
|
19
|
+
# invoke after callback
|
20
|
+
if options[:after].present?
|
21
|
+
options[:after].is_a?(Proc) ? options[:after].call(method_name, self):
|
22
|
+
send(options[:after], method_name)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
class PostgreSQLAdapter < AbstractAdapter
|
4
|
+
private
|
5
|
+
def load_additional_types(type_map, oids = nil)
|
6
|
+
initializer = OID::TypeMapInitializer.new(type_map)
|
7
|
+
if supports_ranges?
|
8
|
+
query = <<-SQL
|
9
|
+
SELECT DISTINCT on (t.typname) t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
|
10
|
+
FROM pg_type as t
|
11
|
+
LEFT JOIN pg_range as r ON oid = rngtypid
|
12
|
+
SQL
|
13
|
+
else
|
14
|
+
query = <<-SQL
|
15
|
+
SELECT DISTINCT on (t.typname) t.oid, t.typname, t.typelem, t.typdelim, t.typinput, t.typtype, t.typbasetype
|
16
|
+
FROM pg_type as t
|
17
|
+
SQL
|
18
|
+
end
|
19
|
+
|
20
|
+
if oids
|
21
|
+
query += "WHERE t.oid::integer IN (%s)" % oids.join(", ")
|
22
|
+
else
|
23
|
+
query += initializer.query_conditions_for_initial_load(type_map)
|
24
|
+
end
|
25
|
+
|
26
|
+
execute_and_clear(query, "SCHEMA", []) do |records|
|
27
|
+
initializer.run(records)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
if defined? Prometheus
|
2
|
+
module Prometheus
|
3
|
+
require "zuora_connect/version"
|
4
|
+
require "zuora_api/version"
|
5
|
+
|
6
|
+
# Create a default Prometheus registry for our metrics.
|
7
|
+
prometheus = Prometheus::Client.registry
|
8
|
+
|
9
|
+
# Create your metrics.
|
10
|
+
ZUORA_VERSION = Prometheus::Client::Gauge.new(:zuora_version, 'The current Zuora Gem version.')
|
11
|
+
CONNECT_VERSION = Prometheus::Client::Gauge.new(:gem_version, 'The current Connect Gem version.')
|
12
|
+
RAILS_VERSION = Prometheus::Client::Gauge.new(:rails_version, 'The current Rails version.')
|
13
|
+
RUBY_V = Prometheus::Client::Gauge.new(:ruby_version, 'The current Ruby version.')
|
14
|
+
|
15
|
+
# Register your metrics with the registry we previously created.
|
16
|
+
prometheus.register(ZUORA_VERSION);ZUORA_VERSION.set({version: ZuoraAPI::VERSION, name: ZuoraConnect::Telegraf.app_name},0)
|
17
|
+
prometheus.register(CONNECT_VERSION);CONNECT_VERSION.set({version: ZuoraConnect::VERSION, name: ZuoraConnect::Telegraf.app_name},0)
|
18
|
+
prometheus.register(RAILS_VERSION);RAILS_VERSION.set({version: Rails.version, name: ZuoraConnect::Telegraf.app_name},0)
|
19
|
+
prometheus.register(RUBY_V);RUBY_V.set({version: RUBY_VERSION, name: ZuoraConnect::Telegraf.app_name},0)
|
20
|
+
|
21
|
+
# Do they have resque jobs?
|
22
|
+
if defined? Resque.redis
|
23
|
+
REDIS_CONNECTION = Prometheus::Client::Gauge.new(:redis_connection, 'The status of the redis connection, 0 or 1')
|
24
|
+
FINISHED_JOBS = Prometheus::Client::Gauge.new(:finished_jobs, 'Done resque jobs')
|
25
|
+
WORKERS = Prometheus::Client::Gauge.new(:workers, 'Total resque workers')
|
26
|
+
ACTIVE_WORKERS = Prometheus::Client::Gauge.new(:active_workers, 'Active resque workers')
|
27
|
+
FAILED_JOBS = Prometheus::Client::Gauge.new(:failed_jobs, 'Failed resque jobs')
|
28
|
+
PENDING_JOBS = Prometheus::Client::Gauge.new(:pending_jobs, 'Pending resque jobs')
|
29
|
+
|
30
|
+
prometheus.register(REDIS_CONNECTION)
|
31
|
+
prometheus.register(FINISHED_JOBS)
|
32
|
+
prometheus.register(ACTIVE_WORKERS)
|
33
|
+
prometheus.register(WORKERS)
|
34
|
+
prometheus.register(FAILED_JOBS)
|
35
|
+
prometheus.register(PENDING_JOBS)
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
redis_url = ENV["REDIS_URL"].present? ? ENV["REDIS_URL"] : defined?(Rails.application.secrets.redis) ? Rails.application.secrets.redis : 'redis://localhost:6379/1'
|
2
|
+
resque_url = ENV["RESQUE_URL"].present? ? ENV["RESQUE_URL"] : defined?(Rails.application.secrets.resque) ? Rails.application.secrets.resque : 'redis://localhost:6379/1'
|
3
|
+
if defined?(Redis.current)
|
4
|
+
Redis.current = Redis.new(:id => "#{ZuoraConnect::Telegraf.full_process_name(process_name: 'Redis')}", :url => redis_url, :timeout => 6, :reconnect_attempts => 2)
|
5
|
+
if defined?(Resque.redis)
|
6
|
+
Resque.redis = resque_url != redis_url ? Redis.new(:id => "#{ZuoraConnect::Telegraf.full_process_name(process_name: 'Resque')}", :url => resque_url, :timeout => 6, :reconnect_attempts => 2) : Redis.current
|
7
|
+
end
|
8
|
+
end
|
9
|
+
if defined?(RedisBrowser)
|
10
|
+
RedisBrowser.configure("connections" => {
|
11
|
+
"Redis" => { "url" => redis_url },
|
12
|
+
"Resque" => { "url" => resque_url }})
|
13
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
if defined?(Resque::Worker)
|
2
|
+
Resque.send(:extend, Resque::Additions)
|
3
|
+
Resque::Worker.send(:include, Resque::DynamicQueues)
|
4
|
+
Resque::Worker.send(:include, Resque::SilenceDone) if ZuoraConnect.configuration.silencer_resque_finish == true
|
5
|
+
Resque::Job.send(:include, Resque::SelfLookup)
|
6
|
+
end
|
7
|
+
|
8
|
+
Resque.module_eval do
|
9
|
+
# Returns a hash, mapping queue names to queue sizes
|
10
|
+
def queue_sizes
|
11
|
+
paused_queues = Resque.redis.zrange("PauseQueue", 0, -1).map! {|key| key.split("__")[0]}
|
12
|
+
queue_names = queues.delete_if{|name| paused_queues.include?(name.split("_")[0])}
|
13
|
+
|
14
|
+
sizes = redis.pipelined do
|
15
|
+
queue_names.each do |name|
|
16
|
+
redis.llen("queue:#{name}")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Hash[queue_names.zip(sizes)]
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class String
|
2
|
+
def to_bool
|
3
|
+
return self if (self.class == TrueClass || self.class == FalseClass)
|
4
|
+
return true if self == true || self =~ (/(true|t|yes|y|1)$/i)
|
5
|
+
return false if self == false || self.blank? || self =~ (/(false|f|no|n|0)$/i)
|
6
|
+
return false
|
7
|
+
raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
class TrueClass
|
11
|
+
def to_bool
|
12
|
+
return self
|
13
|
+
end
|
14
|
+
end
|
15
|
+
class FalseClass
|
16
|
+
def to_bool
|
17
|
+
return self
|
18
|
+
end
|
19
|
+
end
|
20
|
+
class NilClass
|
21
|
+
def to_bool
|
22
|
+
return false
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
if defined?(Unicorn::WorkerKiller)
|
2
|
+
Unicorn::WorkerKiller.module_eval do
|
3
|
+
self.singleton_class.send(:alias_method, :kill_self_old, :kill_self)
|
4
|
+
def self.kill_self(logger, start_time)
|
5
|
+
self.kill_self_old(logger, start_time)
|
6
|
+
ZuoraConnect::AppInstance.write_to_telegraf(direction: 'Unicorn-Killer', tags: {app_instance: 0}, values: {kill: 1})
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
ZuoraConnect::Engine.routes.draw do
|
2
|
+
get '/health' => 'static#health'
|
3
|
+
get '/internal/data' => 'static#metrics'
|
4
|
+
get '/invalid_session' => 'static#session_error', :as => :invalid_session
|
5
|
+
get '/invalid_instance' => "static#invalid_app_instance_error", :as => :invalid_instance
|
6
|
+
post '/initialize_app' => 'static#initialize_app'
|
7
|
+
|
8
|
+
namespace :api do
|
9
|
+
namespace :v1 do
|
10
|
+
resources :app_instance, :only => [:index], defaults: {format: :json} do
|
11
|
+
match "drop", via: [:get, :post], on: :collection
|
12
|
+
match "cache_bust", via: [:get, :post], on: :collection
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
class AddTokensToAppInstance < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
add_column :zuora_connect_app_instances, :access_token, :string unless column_exists? :zuora_connect_app_instances, :access_token
|
4
|
+
add_column :zuora_connect_app_instances, :refresh_token, :string unless column_exists? :zuora_connect_app_instances, :refresh_token
|
5
|
+
end
|
6
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class AddSessionsTable < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
if !ActiveRecord::Base.connection.table_exists?('sessions')
|
4
|
+
create_table :sessions do |t|
|
5
|
+
t.string :session_id, :null => false
|
6
|
+
t.text :data
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
add_index :sessions, :session_id, :unique => true
|
10
|
+
add_index :sessions, :updated_at
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
class AddCatalogDataToAppInstance < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
add_column :zuora_connect_app_instances, :catalog_updated_at, :datetime unless column_exists? :zuora_connect_app_instances, :catalog_updated_at
|
4
|
+
add_column :zuora_connect_app_instances, :catalog, :jsonb, default: {} unless column_exists? :zuora_connect_app_instances, :catalog
|
5
|
+
end
|
6
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module InfluxDB
|
2
|
+
# Convert data point to string using Line protocol
|
3
|
+
class PointValue
|
4
|
+
attr_reader :series, :values, :tags, :timestamp
|
5
|
+
|
6
|
+
def initialize(data)
|
7
|
+
@series = escape data[:series], :measurement
|
8
|
+
@values = escape_values data[:values]
|
9
|
+
@tags = escape_tags data[:tags]
|
10
|
+
@timestamp = data[:timestamp]
|
11
|
+
end
|
12
|
+
|
13
|
+
def dump
|
14
|
+
dump = @series.dup
|
15
|
+
dump << ",#{@tags}" if @tags
|
16
|
+
dump << " #{@values}"
|
17
|
+
dump << " #{@timestamp}" if @timestamp
|
18
|
+
dump
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
ESCAPES = {
|
24
|
+
measurement: [' '.freeze, ','.freeze],
|
25
|
+
tag_key: ['='.freeze, ' '.freeze, ','.freeze],
|
26
|
+
tag_value: ['='.freeze, ' '.freeze, ','.freeze],
|
27
|
+
field_key: ['='.freeze, ' '.freeze, ','.freeze, '"'.freeze],
|
28
|
+
field_value: ["\\".freeze, '"'.freeze],
|
29
|
+
}.freeze
|
30
|
+
|
31
|
+
private_constant :ESCAPES
|
32
|
+
|
33
|
+
def escape(str, type)
|
34
|
+
# rubocop:disable Layout/AlignParameters
|
35
|
+
str = str.encode "UTF-8".freeze, "UTF-8".freeze,
|
36
|
+
invalid: :replace,
|
37
|
+
undef: :replace,
|
38
|
+
replace: "".freeze
|
39
|
+
# rubocop:enable Layout/AlignParameters
|
40
|
+
|
41
|
+
ESCAPES[type].each do |ch|
|
42
|
+
str = str.gsub(ch) { "\\#{ch}" }
|
43
|
+
end
|
44
|
+
str
|
45
|
+
end
|
46
|
+
|
47
|
+
def escape_values(values)
|
48
|
+
return if values.nil?
|
49
|
+
values.map do |k, v|
|
50
|
+
key = escape(k.to_s, :field_key)
|
51
|
+
val = escape_value(v)
|
52
|
+
"#{key}=#{val}"
|
53
|
+
end.join(",".freeze)
|
54
|
+
end
|
55
|
+
|
56
|
+
def escape_value(value)
|
57
|
+
if value.is_a?(String)
|
58
|
+
'"'.freeze + escape(value, :field_value) + '"'.freeze
|
59
|
+
elsif value.is_a?(Integer)
|
60
|
+
"#{value}i"
|
61
|
+
else
|
62
|
+
value.to_s
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def escape_tags(tags)
|
67
|
+
return if tags.nil?
|
68
|
+
|
69
|
+
tags = tags.map do |k, v|
|
70
|
+
key = escape(k.to_s, :tag_key)
|
71
|
+
val = escape(v.to_s, :tag_value)
|
72
|
+
|
73
|
+
"#{key}=#{val}" unless key == "".freeze || val == "".freeze
|
74
|
+
end.compact
|
75
|
+
|
76
|
+
tags.join(",") unless tags.empty?
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|