mina-infinum 2.2.0 → 2.3.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: b9e1081ff27138ce5b9264ec25ed270c8e394ffd35ee7272e9a60897a4e87a3b
4
- data.tar.gz: 81e98a8aaeceefbef746339be9ad07860a8ae11eff653131832b84444960312d
3
+ metadata.gz: d0ba2dc913ff35e4416588b4f58baab6070960c1d33dc619acbda331ed46da48
4
+ data.tar.gz: fc982c1d6374965b0c347fccd3f11983dcf8ccd5c94cdc48b65737fe57ce1437
5
5
  SHA512:
6
- metadata.gz: 6e4863e6edadd84172c87cc34d043b4db4445be056373d1b1ba8b6982e839a205e3c9390bc84050d0f9ded00911440e0ac541bedadeb396d26282369f84db0d8
7
- data.tar.gz: d02cb8f73830e4e4f5436d0e25a5eb5ae842543c8c55887e3ce739208780c3ba6309560abae8f04b14a26e0d28e762a290b467ae1a2f4326c93f50bb2a45aea0
6
+ metadata.gz: 83dc2eba39533955f29e8cec5ba626626b0b52d6c3f7cc1f6df2e77891217d615f304f989f46a58ff55532cb68bd41b8ef89fca08f2148a96cd17d755079e19e
7
+ data.tar.gz: a0d9cb6a87a5db0a41dbeb77fefcbbcf04d726807a986151e7eb931204fb4b55a4dc1d45a54e2a1ebd4154bbdb58c6e60b41945c72e332acc45d29c31e034b44
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [v2.3.0](https://github.com/infinum/mina-infinum/tree/v-2.3.0) (2025-10-02)
4
+ [Full Changelog](https://github.com/infinum/mina-infinum/compare/v2.2.0...v2.3.0)
5
+
6
+ ### Enhancements
7
+
8
+ - Add logs and logs:tail AWS tasks [\#8](https://github.com/infinum/mina-infinum/pull/8)
9
+
3
10
  ## [v2.2.0](https://github.com/infinum/mina-infinum/tree/v-2.2.0) (2025-07-25)
4
11
  [Full Changelog](https://github.com/infinum/mina-infinum/compare/v2.1.0...v2.2.0)
5
12
 
@@ -0,0 +1,112 @@
1
+ require 'time'
2
+ require 'mina/infinum/ecs/aws'
3
+
4
+ desc <<~TXT
5
+ Print logs from CloudWatch
6
+
7
+ Logs are printed from :log_group, which is a CloudWatch log group name.
8
+
9
+ Logs are fetched in range :since to :until (both inclusive). Both values must be
10
+ parseable by `Time.parse` (e.g. ISO8601 timestamps). :since is required,
11
+ :until is optional (if omitted, value will be current time).
12
+
13
+ If date is ommitted in either value, the current date is assumed.
14
+
15
+ Examples:
16
+ # logs since 26.9.2025. 14:00 in local time zone
17
+ $ mina logs since="2025-09-26 14:00"
18
+
19
+ # logs on 26.9.2025. between 14:00 and 15:00 in local time zone
20
+ $ mina logs since="2025-09-26 14:00" until="2025-09-26 15:00"
21
+
22
+ # logs between 14:00 and 15:00 today in local time zone
23
+ $ mina logs since="14:00" until="15:00"
24
+
25
+ # logs between 14:00 and 15:00 today in UTC
26
+ $ mina logs since="14:00Z" until="15:00Z"
27
+
28
+ # logs since 26.9.2025. 14:00 in UTC (ISO 8601 format)
29
+ $ mina logs since="2025-09-26T14:00Z"
30
+ TXT
31
+ task logs: ['aws:profile:check'] do
32
+ ensure!(:log_group)
33
+ ensure!(:since)
34
+
35
+ since_time = Time.parse(fetch(:since))
36
+ until_time = fetch(:until) ? Time.parse(fetch(:until)) : Time.now
37
+
38
+ puts "Printing logs from #{fetch(:log_group)} in range [#{since_time.iso8601},#{until_time.iso8601}]"
39
+ raw_logs = run_cmd squish(<<~CMD)
40
+ aws logs filter-log-events
41
+ --log-group-name #{fetch(:log_group)}
42
+ --profile #{fetch(:aws_profile)}
43
+ --start-time #{since_time.strftime('%s%L')}
44
+ --end-time #{until_time.strftime('%s%L')}
45
+ --output json
46
+ --query "events[].{timestamp: timestamp, message: message}"
47
+ CMD
48
+
49
+ next if raw_logs.empty? # response can be empty due to auth issues, user will see error in terminal
50
+
51
+ logs = JSON.parse(raw_logs)
52
+ if logs.any?
53
+ logs.each do |log|
54
+ time = Time.at(0, log.fetch('timestamp'), :millisecond)
55
+ puts "#{green_text(time.utc.iso8601)} #{log.fetch('message')}"
56
+ end
57
+ else
58
+ puts 'There are no logs'
59
+ end
60
+ end
61
+
62
+ namespace :logs do
63
+ desc <<~TXT
64
+ Tail logs from CloudWatch
65
+
66
+ Logs are tailed from :log_group, which is a CloudWatch log group name.
67
+
68
+ Before new logs are tailed, recent logs are first printed. You can control
69
+ from what time recent logs are printed with :since. The value can be absolute
70
+ time parseable by `Time.parse`, or relative time.
71
+
72
+ If date is ommitted in absolute time, the current date is assumed.
73
+
74
+ Examples:
75
+ # tail logs since 26.9.2025. 14:00 in local time zone
76
+ $ mina logs:tail since="2025-09-26 14:00"
77
+
78
+ # tail logs since 14:00 today in local time zone
79
+ $ mina logs:tail since="14:00"
80
+
81
+ # tail logs since 26.9.2025. 14:00 in UTC (ISO 8601 format)
82
+ $ mina logs:tail since="2025-09-26T14:00Z"
83
+
84
+ # tail logs since 5 minutes ago
85
+ $ mina logs:tail since="5m"
86
+
87
+ For more info on accepted :since values, see --since options
88
+ https://docs.aws.amazon.com/cli/latest/reference/logs/tail.html#options
89
+ TXT
90
+ task tail: ['aws:profile:check'] do
91
+ ensure!(:log_group)
92
+
93
+ since_time = fetch(:since)&.strip
94
+
95
+ if since_time && !since_time.empty? && !since_time.match?(/\A\d+\w\z/)
96
+ since_time = Time.parse(since_time).iso8601
97
+ end
98
+
99
+ puts "Tailing logs from #{fetch(:log_group)}"
100
+ run_cmd squish(<<~CMD), exec: true
101
+ aws logs tail #{fetch(:log_group)}
102
+ --profile #{fetch(:aws_profile)}
103
+ --follow
104
+ --format short
105
+ #{"--since #{since_time}" if since_time}
106
+ CMD
107
+ end
108
+ end
109
+
110
+ def green_text(text)
111
+ "\e[32m#{text}\e[0m"
112
+ end
@@ -1,5 +1,6 @@
1
1
  require 'mina/default'
2
2
  require 'mina/infinum/ecs/rails'
3
+ require 'mina/infinum/ecs/logs'
3
4
  require 'mina/infinum/ecs/db'
4
5
  require 'mina/infinum/ecs/params'
5
6
 
@@ -1,5 +1,5 @@
1
1
  module Mina
2
2
  module Infinum
3
- VERSION = '2.2.0'.freeze
3
+ VERSION = '2.3.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mina-infinum
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stjepan Hadjic
@@ -145,6 +145,7 @@ files:
145
145
  - lib/mina/infinum/ecs/aws.rb
146
146
  - lib/mina/infinum/ecs/db.rb
147
147
  - lib/mina/infinum/ecs/ecs.rb
148
+ - lib/mina/infinum/ecs/logs.rb
148
149
  - lib/mina/infinum/ecs/params.rb
149
150
  - lib/mina/infinum/ecs/rails.rb
150
151
  - lib/mina/infinum/helpers.rb