solid_apm 0.4.4 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97cdcafb0a31dea64161262374dcfd274cf450836668be0df7f4f5b5d7e70f58
4
- data.tar.gz: bd0af22ac948642e3ecb63c9b4528011ddc7df7f9ea997caee806687eba7f25b
3
+ metadata.gz: 8c079a73239f6410c8fba60e90a060136ea999c6887ff594104efd27ff90cb6e
4
+ data.tar.gz: c7125efd2a3ba768d5b0b2187d193195b5f8b33ae60aca5b2d84c25299cb68a5
5
5
  SHA512:
6
- metadata.gz: 9c65419c5facee2826defd7428aff0c175e9a982879b4572867370e8b0e0acd265d33f3471c111dbcf64ec192ee9fbc34290f481ad2e79be7e10f2dfb71b9408
7
- data.tar.gz: 000e091daa7ef33222824974c216d9cc4544d6be37ba6640c3eee87d18c16ced922c7b946d6368a95976f010f0cf6871892afaa229b6153ad6ba32be59f7b84c
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,8 +39,7 @@ 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
  }
@@ -52,6 +50,9 @@ window.Stimulus.register('transaction-chart',
52
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.4"
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.4
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.