activeinsights 0.1.3 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 224f2e05720b4f7ed167aef5cb469c741f38092d6151b6654087ad8b2f9d1c97
4
- data.tar.gz: 4c78b34bfd30da47e0583752f814211a6bc0d26aa6715312a726a9b9b36b1e58
3
+ metadata.gz: dadcb3ff31dcb9021bea6a79dbbe8c2e9de03a268a0c82f6a36158bd513c9f2a
4
+ data.tar.gz: 6c99fafe1e426fbd8de6fbe53c889e5bd780a4d5b37fdc110665e0eddff0ae0a
5
5
  SHA512:
6
- metadata.gz: c6718d87d6db17476c8ecc4c9738bc3069064a0a842afbc01d6279993515607a67cf6d41535b32a93bebd7097869871fd19f28662093df3851aae2b11e88ef51
7
- data.tar.gz: fdf1d55c14ed9d7ec9c98e7f98c71aa9e9e5bcf6520ff4c728412ea3199cb9f9e95c06f5733c7fb3c84b8e554f1d2576895fc63ebad8387dfb624a902d972091
6
+ metadata.gz: 732e3356cdcb0d23798fc0a5c3f6414b3f1f7e1fa5226b1d27b100f58a7081190fdb5dec27ae71b836beee660cd0dfe3e26ed9c1d9d2cb8d089e22787a4ef649
7
+ data.tar.gz: 03a8cd017f4fa4b5da97825a2ad2414a4e18b4ec771f14ff38e9bf90d9afa6f40e50f9ea262c90e354fea3baf0d4184bde4aeea15eae77ab7e93dd98666c1a1a
data/README.md CHANGED
@@ -48,6 +48,12 @@ options for the `Request` model.
48
48
  ActiveInsights.connects_to = { database: { writing: :requests, reading: :requests } }
49
49
  ```
50
50
 
51
+ You can supply an array of ignored endpoints
52
+
53
+ ```ruby
54
+ ActiveInsights.ignored_endpoints = ["Rails::HealthController#show"]
55
+ ```
56
+
51
57
  ## Development
52
58
 
53
59
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
@@ -24,5 +24,14 @@ module ActiveInsights
24
24
  Date.current
25
25
  end.beginning_of_day
26
26
  end
27
+
28
+ def base_scope
29
+ scope = ActiveInsights::Request.where(started_at: @date)
30
+ if ActiveInsights.ignored_endpoints.present?
31
+ scope = scope.where.
32
+ not(formatted_controller: ActiveInsights.ignored_endpoints)
33
+ end
34
+ scope
35
+ end
27
36
  end
28
37
  end
@@ -17,8 +17,7 @@ module ActiveInsights
17
17
 
18
18
  def minutes
19
19
  @minutes ||=
20
- ActiveInsights::Request.where(started_at: @date).
21
- where(formatted_controller: params[:formatted_controller]).
20
+ base_scope.where(formatted_controller: params[:formatted_controller]).
22
21
  minute_by_minute.with_durations.select_started_at
23
22
  end
24
23
  end
@@ -15,9 +15,7 @@ module ActiveInsights
15
15
  private
16
16
 
17
17
  def minutes
18
- @minutes ||=
19
- ActiveInsights::Request.where(started_at: @date).
20
- minute_by_minute.with_durations.select_started_at
18
+ @minutes ||= base_scope.minute_by_minute.with_durations.select_started_at
21
19
  end
22
20
  end
23
21
  end
@@ -4,10 +4,8 @@ module ActiveInsights
4
4
  class RequestsController < ApplicationController
5
5
  def index
6
6
  @requests =
7
- ActiveInsights::Request.where(started_at: @date).
8
- with_durations.select(:formatted_controller).
9
- group(:formatted_controller).
10
- sort_by { |model| model.durations.count(",") + 1 }.reverse
7
+ base_scope.with_durations.select(:formatted_controller).
8
+ group(:formatted_controller).sort_by(&:agony).reverse
11
9
  end
12
10
  end
13
11
  end
@@ -4,9 +4,10 @@ module ActiveInsights
4
4
  class RpmController < ApplicationController
5
5
  def index
6
6
  @minutes =
7
- ActiveInsights::Request.where(started_at: @date).
8
- minute_by_minute.select("COUNT(id) AS rpm").select_started_at.
9
- map { |minute| [minute.started_at.strftime("%-l:%M%P"), minute.rpm] }
7
+ base_scope.minute_by_minute.select("COUNT(id) AS rpm").
8
+ select_started_at.map do |minute|
9
+ [minute.started_at.strftime("%-l:%M%P"), minute.rpm]
10
+ end
10
11
  end
11
12
 
12
13
  def redirection
@@ -39,7 +39,7 @@ module ActiveInsights
39
39
  private
40
40
 
41
41
  def percentile_value(data, percentile)
42
- value = data[(percentile * data.size).ceil - 1]
42
+ value = data.sort[(percentile * data.size).ceil - 1]
43
43
 
44
44
  value&.round(1) || "N/A"
45
45
  end
@@ -4,10 +4,12 @@ module ActiveInsights
4
4
  class Request < ::ActiveInsights::Record
5
5
  scope :with_durations, lambda {
6
6
  case connection.adapter_name
7
- when "SQLite", "Mysql2", "Mysql2Spatial", "Mysql2Rgeo", "Trilogy"
8
- select("GROUP_CONCAT(duration) AS durations")
7
+ when "SQLite"
8
+ select("JSON_GROUP_ARRAY(duration) AS durations")
9
+ when "Mysql2", "Mysql2Spatial", "Mysql2Rgeo", "Trilogy"
10
+ select("JSON_ARRAYAGG(duration) AS durations")
9
11
  when "PostgreSQL"
10
- select("STRING_AGG(CAST(duration AS varchar), ',') AS durations")
12
+ select("JSON_AGG(duration) AS durations")
11
13
  end
12
14
  }
13
15
  scope :minute_by_minute, lambda {
@@ -42,7 +44,11 @@ module ActiveInsights
42
44
  def parsed_durations
43
45
  return unless respond_to?(:durations)
44
46
 
45
- @parsed_durations ||= durations.split(",").map(&:to_f).sort
47
+ @parsed_durations ||=
48
+ if durations.is_a?(Array) then durations
49
+ else
50
+ JSON.parse(durations)
51
+ end.sort
46
52
  end
47
53
 
48
54
  def pretty_started_at
@@ -41,7 +41,7 @@
41
41
  </tr>
42
42
  </thead>
43
43
  <tbody>
44
- <% @requests.sort_by(&:agony).reverse.each do |model| %>
44
+ <% @requests.each do |model| %>
45
45
  <tr>
46
46
  <td><%= link_to model.formatted_controller, controller_p_values_path(@date.first.to_date, model.formatted_controller) %></td>
47
47
  <td><%= per_minute(model.parsed_durations.size, (@date.last - @date.first).seconds) %></td>
@@ -20,7 +20,8 @@ module ActiveInsights
20
20
  ActiveSupport::Notifications.
21
21
  subscribe("process_action.action_controller") do |_name,
22
22
  started, finished, unique_id, payload|
23
- next if Rails.env.development?
23
+ next if Rails.env.development? ||
24
+ ActiveInsights.ignored_endpoint?(payload)
24
25
 
25
26
  Thread.new do
26
27
  ActiveRecord::Base.connection_pool.with_connection do
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveInsights
4
- VERSION = "0.1.3"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -7,5 +7,11 @@ require "active_insights/version"
7
7
  require "active_insights/engine"
8
8
 
9
9
  module ActiveInsights
10
- mattr_accessor :connects_to
10
+ mattr_accessor :connects_to, :ignored_endpoints
11
+
12
+ def self.ignored_endpoint?(payload)
13
+ ignored_endpoints.to_a.include?(
14
+ "#{payload[:controller]}##{payload[:action]}"
15
+ )
16
+ end
11
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeinsights
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Pezza