Module: ThreeScale::Backend::Stats::Keys
- Extended by:
- ThreeScale::Backend::StorageKeyHelpers
- Included in:
- Aggregator, Aggregators::ResponseCode, Aggregators::Usage
- Defined in:
- lib/3scale/backend/stats/keys.rb
Class Method Summary collapse
-
.application_key_prefix(prefix, application_id) ⇒ Object
It will be eventually renamed to application.
- .application_response_code_value_key(service_id, app_id, response_code, period) ⇒ Object
- .application_usage_value_key(service_id, app_id, metric_id, period) ⇒ Object
- .applications_key_prefix(prefix) ⇒ Object
-
.changed_keys_bucket_key(bucket) ⇒ Object
We want all the buckets to go to the same Redis shard.
- .changed_keys_key ⇒ Object
- .counter_key(prefix, period) ⇒ Object
- .metric_key_prefix(prefix, metric_id) ⇒ Object
- .response_code_key_prefix(prefix, response_code) ⇒ Object
-
.service_key_prefix(service_id) ⇒ Object
about key tags.
- .service_response_code_value_key(service_id, response_code, period) ⇒ Object
- .service_usage_value_key(service_id, metric_id, period) ⇒ Object
- .set_of_apps_with_traffic(service_id) ⇒ Object
- .transaction_keys(transaction, item, value) ⇒ Object
Methods included from ThreeScale::Backend::StorageKeyHelpers
Class Method Details
.application_key_prefix(prefix, application_id) ⇒ Object
Note:
For backwards compatibility, the key is called cinstance.
It will be eventually renamed to application.
17 18 19 |
# File 'lib/3scale/backend/stats/keys.rb', line 17 def application_key_prefix(prefix, application_id) "#{prefix}/cinstance:#{application_id}" end |
.application_response_code_value_key(service_id, app_id, response_code, period) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/3scale/backend/stats/keys.rb', line 55 def application_response_code_value_key(service_id, app_id, response_code, period) service_key = service_key_prefix(service_id) app_key = application_key_prefix(service_key, app_id) response_code_key = response_code_key_prefix(app_key, response_code) encode_key(counter_key(response_code_key, period)) end |
.application_usage_value_key(service_id, app_id, metric_id, period) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/3scale/backend/stats/keys.rb', line 40 def application_usage_value_key(service_id, app_id, metric_id, period) service_key = service_key_prefix(service_id) app_key = application_key_prefix(service_key, app_id) metric_key = metric_key_prefix(app_key, metric_id) encode_key(counter_key(metric_key, period)) end |
.applications_key_prefix(prefix) ⇒ Object
21 22 23 |
# File 'lib/3scale/backend/stats/keys.rb', line 21 def applications_key_prefix(prefix) "#{prefix}/cinstances" end |
.changed_keys_bucket_key(bucket) ⇒ Object
We want all the buckets to go to the same Redis shard. The reason is that SUNION support in Twemproxy requires that the supplied keys hash to the same server. We are already using a hash tag in the Twemproxy config file: “{}”. For that reason, if we specify a key that contains something like “stats_bucket”, we can be sure that all of them will be in the same shard.
86 87 88 |
# File 'lib/3scale/backend/stats/keys.rb', line 86 def changed_keys_bucket_key(bucket) "{stats_bucket}:#{bucket}" end |
.changed_keys_key ⇒ Object
90 91 92 |
# File 'lib/3scale/backend/stats/keys.rb', line 90 def changed_keys_key "keys_changed_set" end |
.counter_key(prefix, period) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/3scale/backend/stats/keys.rb', line 63 def counter_key(prefix, period) granularity = period.granularity key = "#{prefix}/#{granularity}" if granularity.to_sym != :eternity key += ":#{period.start.to_compact_s}" end key end |
.metric_key_prefix(prefix, metric_id) ⇒ Object
25 26 27 |
# File 'lib/3scale/backend/stats/keys.rb', line 25 def metric_key_prefix(prefix, metric_id) "#{prefix}/metric:#{metric_id}" end |
.response_code_key_prefix(prefix, response_code) ⇒ Object
29 30 31 |
# File 'lib/3scale/backend/stats/keys.rb', line 29 def response_code_key_prefix(prefix, response_code) "#{prefix}/response_code:#{response_code}" end |
.service_key_prefix(service_id) ⇒ Object
Note:
The { … } is the key tag. See redis docs for more info
about key tags.
11 12 13 |
# File 'lib/3scale/backend/stats/keys.rb', line 11 def service_key_prefix(service_id) "stats/{service:#{service_id}}" end |
.service_response_code_value_key(service_id, response_code, period) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/3scale/backend/stats/keys.rb', line 48 def service_response_code_value_key(service_id, response_code, period) service_key = service_key_prefix(service_id) response_code_key = response_code_key_prefix(service_key, response_code) encode_key(counter_key(response_code_key, period)) end |
.service_usage_value_key(service_id, metric_id, period) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/3scale/backend/stats/keys.rb', line 33 def service_usage_value_key(service_id, metric_id, period) service_key = service_key_prefix(service_id) metric_key = metric_key_prefix(service_key, metric_id) encode_key(counter_key(metric_key, period)) end |
.set_of_apps_with_traffic(service_id) ⇒ Object
73 74 75 76 77 |
# File 'lib/3scale/backend/stats/keys.rb', line 73 def set_of_apps_with_traffic(service_id) Stats::Keys.applications_key_prefix( Stats::Keys.service_key_prefix(service_id) ) end |
.transaction_keys(transaction, item, value) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/3scale/backend/stats/keys.rb', line 94 def transaction_keys(transaction, item, value) service_key = service_key_prefix(transaction.service_id) application_key = application_key_prefix(service_key, transaction.application_id) method = "#{item}_key_prefix".to_sym { service: public_send(method, service_key, value), application: public_send(method, application_key, value), } end |