apisonator 3.3.2 → 3.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 881dcbb24dbe3757ed8d786f49cdf6aab9dce3bb060f26387f142b4e825e06a1
4
- data.tar.gz: e25f370546c286d5400fdbf19331ef554f34ce47c91df522007039c1fbf322e4
3
+ metadata.gz: 1a63aa45d4fa6c23fde95de0b422f771fc9fc104fa9dfebbcdc2c9c0d09219a1
4
+ data.tar.gz: 54809f95ad95b7cd4ab835a7ba3238fcd5d3bef1c9243bbabf1eb4fea95a7e97
5
5
  SHA512:
6
- metadata.gz: 618be1a317cee54f1892357f7a64739b79eb0e203e15ae03a367176642e4d526c72d283a59438640e1e6503fd5e72a85be230deab76e6ac13c2305e8080aacd5
7
- data.tar.gz: e7150ec528c2dc2b2b0f53a69fa50b2f5b7af52f736ca0a74196a38ae6be1b8a6913fd81fc609f00e18278c2fab571a7a926f647635b9b264b7abd7099673584
6
+ metadata.gz: c6810598c592d306959e53c89fa602f1f866613f6b6e9001126785f26d688ca71d909a97caafcff1f56ea368d375f146874ff6fd978260c9a8ecd364725afa95
7
+ data.tar.gz: 011c656c600e048725a869a949316171d583fd0cdac4f7bec84ea7231753571cb6d2b5409a9e41f8600d94c5fbb773a187ffe6a3aa5942e7c6a53c7e8b2e05b7
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  Notable changes to Apisonator will be tracked in this document.
4
4
 
5
+ ## 3.3.3 - 2021-03-09
6
+
7
+ ### Changed
8
+
9
+ - Check if alerts can be raised before calculating utilization (perf
10
+ optimization) ([#275](https://github.com/3scale/apisonator/pull/275)).
11
+
12
+ ### Removed
13
+
14
+ - Stop maintaining unused "current_max" key in Alerts
15
+ ([#272](https://github.com/3scale/apisonator/pull/272)).
16
+
5
17
  ## 3.3.2 - 2021-02-23
6
18
 
7
19
  ### Fixed
data/Gemfile.lock CHANGED
@@ -36,7 +36,7 @@ GIT
36
36
  PATH
37
37
  remote: .
38
38
  specs:
39
- apisonator (3.3.2)
39
+ apisonator (3.3.3)
40
40
 
41
41
  GEM
42
42
  remote: https://rubygems.org/
data/Gemfile.on_prem.lock CHANGED
@@ -36,7 +36,7 @@ GIT
36
36
  PATH
37
37
  remote: .
38
38
  specs:
39
- apisonator (3.3.2)
39
+ apisonator (3.3.3)
40
40
 
41
41
  GEM
42
42
  remote: https://rubygems.org/
@@ -6,11 +6,10 @@ module ThreeScale
6
6
 
7
7
  # The compacted hour in the params refers to the
8
8
  # TimeHacks.to_compact_s method.
9
- def alert_keys(service_id, app_id, discrete_utilization, compacted_hour_start)
9
+ def alert_keys(service_id, app_id, discrete_utilization)
10
10
  {
11
11
  already_notified: key_already_notified(service_id, app_id, discrete_utilization),
12
12
  allowed: key_allowed_set(service_id),
13
- current_max: key_current_max(service_id, app_id, compacted_hour_start),
14
13
  current_id: key_current_id
15
14
  }
16
15
  end
@@ -31,11 +30,6 @@ module ThreeScale
31
30
  "#{prefix}allowed_set"
32
31
  end
33
32
 
34
- def key_current_max(service_id, app_id, compacted_hour_start)
35
- prefix = key_prefix(service_id, app_id)
36
- "#{prefix}#{compacted_hour_start}/current_max"
37
- end
38
-
39
33
  def key_current_id
40
34
  'alerts/current_id'.freeze
41
35
  end
@@ -43,6 +37,7 @@ module ThreeScale
43
37
 
44
38
  extend self
45
39
  extend KeyHelpers
40
+ include Memoizer::Decorator
46
41
 
47
42
  ALERT_TTL = 24*3600 # 1 day (only one message per day)
48
43
  ## zero must be here and sorted, yes or yes
@@ -50,6 +45,16 @@ module ThreeScale
50
45
  FIRST_ALERT_BIN = ALERT_BINS.first
51
46
  RALERT_BINS = ALERT_BINS.reverse.freeze
52
47
 
48
+ def can_raise_more_alerts?(service_id, app_id)
49
+ allowed_bins = allowed_set_for_service(service_id).sort
50
+
51
+ return false if allowed_bins.empty?
52
+
53
+ # If the bin with the highest value has already been notified, there's
54
+ # no need to notify anything else.
55
+ not notified?(service_id, app_id, allowed_bins.last)
56
+ end
57
+
53
58
  def utilization(app_usage_reports)
54
59
  max_utilization = -1.0
55
60
  max_record = nil
@@ -77,25 +82,12 @@ module ThreeScale
77
82
 
78
83
  def update_utilization(service_id, app_id, max_utilization, max_record, timestamp)
79
84
  discrete = utilization_discrete(max_utilization)
80
- max_utilization_i = (max_utilization * 100.0).round
81
85
 
82
- beginning_of_day = Period::Boundary.day_start(timestamp)
83
- period_hour = Period::Boundary.hour_start(timestamp).to_compact_s
84
- # UNIX timestamp for key expiration - add 1 day + 5 mins
85
- expire_at = (beginning_of_day + 86700).to_i
86
+ keys = alert_keys(service_id, app_id, discrete)
86
87
 
87
- keys = alert_keys(service_id, app_id, discrete, period_hour)
88
-
89
- already_alerted, allowed, current_max, _ = storage.pipelined do
88
+ already_alerted, allowed = storage.pipelined do
90
89
  storage.get(keys[:already_notified])
91
90
  storage.sismember(keys[:allowed], discrete)
92
- storage.get(keys[:current_max])
93
- storage.expireat(keys[:current_max], expire_at)
94
- end
95
-
96
- ## update the status of utilization
97
- if max_utilization_i > current_max.to_i
98
- storage.set(keys[:current_max], max_utilization_i)
99
91
  end
100
92
 
101
93
  if already_alerted.nil? && allowed && discrete.to_i > 0
@@ -129,6 +121,16 @@ module ThreeScale
129
121
  "#{record.current_value}/#{record.max_value}"
130
122
  end
131
123
 
124
+ def allowed_set_for_service(service_id)
125
+ storage.smembers(key_allowed_set(service_id)).map(&:to_i) # Redis returns strings always
126
+ end
127
+ memoize :allowed_set_for_service
128
+
129
+ def notified?(service_id, app_id, bin)
130
+ storage.get(key_already_notified(service_id, app_id, bin))
131
+ end
132
+ memoize :notified?
133
+
132
134
  def storage
133
135
  Storage.instance
134
136
  end
@@ -149,6 +149,12 @@ module ThreeScale
149
149
  # enqueued. No need to update alerts in that case.
150
150
  next unless application
151
151
 
152
+ # The operations below are costly. They load all the usage limits
153
+ # and current usages to find the current utilization levels.
154
+ # That's why before that, we check if there are any alerts that
155
+ # can be raised.
156
+ next unless Alerts.can_raise_more_alerts?(service_id, values[:application_id])
157
+
152
158
  application.load_metric_names
153
159
  usage = Usage.application_usage(application, current_timestamp)
154
160
  status = Transactor::Status.new(service_id: service_id,
@@ -1,5 +1,5 @@
1
1
  module ThreeScale
2
2
  module Backend
3
- VERSION = '3.3.2'
3
+ VERSION = '3.3.3'
4
4
  end
5
5
  end
data/licenses.xml CHANGED
@@ -23,7 +23,7 @@
23
23
  </dependency>
24
24
  <dependency>
25
25
  <packageName>apisonator</packageName>
26
- <version>3.3.2</version>
26
+ <version>3.3.3</version>
27
27
  <licenses>
28
28
  <license>
29
29
  <name>Apache 2.0</name>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apisonator
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.2
4
+ version: 3.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Ciganek
@@ -16,7 +16,7 @@ authors:
16
16
  autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
- date: 2021-02-23 00:00:00.000000000 Z
19
+ date: 2021-03-09 00:00:00.000000000 Z
20
20
  dependencies: []
21
21
  description: This gem provides a daemon that handles authorization and reporting of
22
22
  web services managed by 3scale.