iron_trail 0.1.0 → 0.1.2

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: 3e922d927b8d15e66a500efdb61b10b6c46bdfef803a4c5b9073f6bd08514a93
4
- data.tar.gz: db70caa06c04c8ec6efaea449613419162a6a84d1a677d86a92e8fa7b8570c26
3
+ metadata.gz: f67019754098a19e12ca5bf753f081e219f6586e3624ef1baf6369e70a9e0d72
4
+ data.tar.gz: e8acc199e3135380e404662bf6a4e5622efe18a4c78fac2d9f70a24f02ee0e7a
5
5
  SHA512:
6
- metadata.gz: 8f8d1e73e606dabb8fca56e17ef4e5eaacbb935e28153ece111469b2c25b1bb193c94a2d5745eb0d27734ebe0a641e53df5c238d03a74526fa6df5ecc8dbafea
7
- data.tar.gz: 065f9432f14e29f63e6c26ae5fbbf2800ed285c5af9bca9376871acc5a65d14efdc4951bcfd2bcdfb83c8b5498b4adb47d810ac9eb83cbab1deb3328f61038ab
6
+ metadata.gz: 925b5f28134a23ab70b10880fbfb40a7b3f7d431d287f5f5b000cdf7c11f07ca743932a11320a59e6c3fd5f1dda874e305f1d6d2457a8b451f23605433bec7b1
7
+ data.tar.gz: 6c074aadae308632cabbd37edb01f6c77607c4dabcac80cfbcf505a4793aace2b4a96a2976cba9a03dc2de40023f5bba948e517694508411a8d4bb9fab5426d5
@@ -56,11 +56,32 @@ module IronTrail
56
56
  connection.execute(query)
57
57
  end
58
58
 
59
+ # Counting rows in Postgres is known to be a slow operation for large tables.
60
+ # Because of this, avoid using this for monitoring new errors. Instead,
61
+ # use the trigger_errors_metrics method.
59
62
  def trigger_errors_count
60
63
  stmt = 'SELECT COUNT(*) AS c FROM "irontrail_trigger_errors"'
61
64
  connection.execute(stmt).first['c']
62
65
  end
63
66
 
67
+ # This returns metrics intended to be used for monitoring. One can send
68
+ # these values to something like a Prometheus deployment and add monitoring
69
+ # on top of it.
70
+ # It should be much faster to run than trigger_errors_count.
71
+ #
72
+ # If the irontrail_trigger_errors table is empty, the resulting values
73
+ # will all be zero and never nil. This is so that data in a monitoring setup
74
+ # can tell apart a failure from a no-data scenario.
75
+ def trigger_errors_metrics
76
+ stmt = 'SELECT MAX(created_at) maxdate, MAX(id) AS maxid FROM "irontrail_trigger_errors"'
77
+ res = connection.execute(stmt).first
78
+
79
+ {
80
+ max_created_at: (res && res['maxdate'] && res['maxdate'].to_i) || 0,
81
+ max_id: (res && res['maxid']) || 0,
82
+ }
83
+ end
84
+
64
85
  def collect_all_tables(schema: 'public')
65
86
  # query pg_class rather than information schema because this way
66
87
  # we can get only regular tables and ignore partitions.
@@ -36,7 +36,9 @@ BEGIN
36
36
  IF (TG_OP = 'INSERT' AND new_obj ? 'created_at') THEN
37
37
  created_at = NEW.created_at;
38
38
  ELSIF (TG_OP = 'UPDATE' AND new_obj ? 'updated_at') THEN
39
- created_at = NEW.updated_at;
39
+ IF (NEW.updated_at <> OLD.updated_at) THEN
40
+ created_at = NEW.updated_at;
41
+ END IF;
40
42
  END IF;
41
43
 
42
44
  IF (created_at IS NULL) THEN
@@ -1,5 +1,5 @@
1
1
  # frozen_literal_string: true
2
2
 
3
3
  module IronTrail
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.2'
5
5
  end
data/lib/iron_trail.rb CHANGED
@@ -52,17 +52,6 @@ module IronTrail
52
52
  config.enable
53
53
  end
54
54
 
55
- # def test_mode!
56
- # if [ENV['RAILS_ENV'], ENV['RACK_ENV']].include?('production')
57
- # raise "IronTrail test mode cannot be enabled in production!"
58
- # end
59
- # @test_mode = true
60
- # end
61
- #
62
- # def test_mode?
63
- # @test_mode
64
- # end
65
-
66
55
  def ignore_table?(name)
67
56
  (OWN_TABLES + (config.ignored_tables || [])).include?(name)
68
57
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron_trail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - André Diego Piske
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-29 00:00:00.000000000 Z
10
+ date: 2025-02-11 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rails
@@ -153,7 +153,13 @@ files:
153
153
  homepage: https://github.com/trusted/iron_trail
154
154
  licenses:
155
155
  - MIT
156
- metadata: {}
156
+ metadata:
157
+ bug_tracker_uri: https://github.com/trusted/iron_trail/issues
158
+ changelog_uri: https://github.com/trusted/iron_trail/blob/main/CHANGELOG.md
159
+ documentation_uri: https://github.com/trusted/iron_trail/blob/main/README.md
160
+ homepage_uri: https://github.com/trusted/iron_trail
161
+ source_code_uri: https://github.com/trusted/iron_trail
162
+ wiki_uri: https://github.com/trusted/iron_trail/wiki
157
163
  rdoc_options: []
158
164
  require_paths:
159
165
  - lib