solid_apm 0.4.3 → 0.5.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: efcb9cac89d539656968bd244d4aa9b369c5bac01241bc4b87f4a4d3d374e231
4
- data.tar.gz: 322c070fe1eeafa50f4628fa54a59a26361b779427adbdf2aa861305891d27d9
3
+ metadata.gz: 8c079a73239f6410c8fba60e90a060136ea999c6887ff594104efd27ff90cb6e
4
+ data.tar.gz: c7125efd2a3ba768d5b0b2187d193195b5f8b33ae60aca5b2d84c25299cb68a5
5
5
  SHA512:
6
- metadata.gz: 4be9f2e4f94ddd42dac90ce6345a0601cd13060154a98f2a915152fafc09df8886281efa7cd5b024769331762c7ec2b1cb0f3d64f3ccb0d700206fc85a1ef787
7
- data.tar.gz: 79bcd0928c31b6199fab8ef1d455bcd635aa7ee6aec5465138a841876d268e943b32e077ff5958cd395591fa3e87586343671163fd8602904ed4a0c029686a15
6
+ metadata.gz: 82077863bb4ca5ed2b8d1fa9be8bb211b9849dba0fde4dbee648415d136aba80aa86c8873cb7128accbf0fa86c8f54fd60137aea993ff15f08ecb6fed35faeb8
7
+ data.tar.gz: 4e912fa0297c355534a4ab4904c863f25612191ed8d3f18d8ba64b9f2f25413ea33d146942ffab0c949ec7bee6fe2d05f83686e1a5b9b397c2f41b831cef3fcc
@@ -16,7 +16,6 @@ window.Stimulus.register('transaction-chart',
16
16
  static values = { name: String }
17
17
 
18
18
  connect() {
19
- console.log('Connected')
20
19
  var options = {
21
20
  chart: {
22
21
  type: 'bar',
@@ -40,18 +39,20 @@ window.Stimulus.register('transaction-chart',
40
39
  }
41
40
  }
42
41
 
43
- let path = window.location.pathname.includes('transactions') ? 'count_by_minutes' : 'transactions/count_by_minutes';
44
- path = path + "?";
42
+ let path = "count_time_aggregations?";
45
43
  if (this.nameValue) {
46
44
  path = path + "name=" + encodeURIComponent(this.nameValue);
47
45
  }
48
46
 
49
- const fromValue = document.querySelector('input[name="from_value"]').value
50
- const fromUnit = document.querySelector('select[name="from_unit"]').value;
47
+ const fromValue = document.querySelector('input[name="from_value"]')
48
+ const fromUnit = document.querySelector('select[name="from_unit"]');
51
49
  if (fromValue && fromUnit) {
52
- path = path + "&from_value=" + fromValue + "&from_unit=" + fromUnit;
50
+ path = path + "&from_value=" + fromValue.value + "&from_unit=" + fromUnit.value;
53
51
  }
54
52
 
53
+ const base = window.location.pathname.split('/transactions')[0];
54
+ path = base + "/transactions/" + path;
55
+ path = path.replace("//", "/");
55
56
  fetch(path)
56
57
  .then(response => response.json())
57
58
  .then(data => {
@@ -46,16 +46,16 @@ module SolidApm
46
46
  render json: @spans
47
47
  end
48
48
 
49
- def count_by_minutes
49
+ def count_time_aggregations
50
50
  scope = Transaction.all.order(timestamp: :desc)
51
51
  .where(created_at: from_to_range)
52
52
 
53
+
53
54
  if params[:name].present?
54
55
  scope = scope.where(name: params[:name])
55
56
  end
56
57
 
57
- render json: scope.group_by { |t| t.created_at.beginning_of_minute }
58
- .transform_values!(&:count)
58
+ render json: aggregate(scope.select(:id, :created_at).find_each, from_to_range, intervals_count: 20).transform_values!(&:count)
59
59
  end
60
60
 
61
61
  private
@@ -67,5 +67,14 @@ module SolidApm
67
67
  to = Time.current
68
68
  (from..to)
69
69
  end
70
+
71
+ def aggregate(items, range, intervals_count: 20)
72
+ start_time = range.begin
73
+ end_time = range.end
74
+ time_range_in_seconds = (end_time - start_time).to_i
75
+ time_interval_duration_in_seconds = (time_range_in_seconds / intervals_count.to_f).round
76
+
77
+ items.chunk { |item| Time.zone.at((item.created_at.to_i) / time_interval_duration_in_seconds * time_interval_duration_in_seconds, 0) }.to_h
78
+ end
70
79
  end
71
80
  end
data/config/routes.rb CHANGED
@@ -2,9 +2,7 @@ SolidApm::Engine.routes.draw do
2
2
  root 'transactions#index'
3
3
 
4
4
  get 'transactions', to: 'transactions#index'
5
- get 'transactions/count_by_minutes',
6
- to: 'transactions#count_by_minutes',
7
- as: 'transactions_count_by_minutes',
5
+ get 'transactions/count_time_aggregations',
8
6
  default: { format: 'json' }
9
7
 
10
8
  get 'transactions/:id', to: 'transactions#show', as: 'transaction', constraints: { id: /\d+/ }
@@ -1,3 +1,3 @@
1
1
  module SolidApm
2
- VERSION = "0.4.3"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solid_apm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Francis Bastien
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-15 00:00:00.000000000 Z
11
+ date: 2024-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
131
  requirements: []
132
- rubygems_version: 3.5.11
132
+ rubygems_version: 3.5.16
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: SolidApm is a DB base engine for Application Performance Monitoring.