rails_loki_exporter 1.0.4 → 1.1.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: bce248aa49394ba911efadd30695bc1d71a19ea2e8cd9909099339a4cb2bc5eb
4
- data.tar.gz: c744a44f2bd0ee8f01391d0a2b8da796bc84ff71fad4ac8d1cbf7b5d95c12fc3
3
+ metadata.gz: 93cc7ab2fe4c6fadb43616ca5f9416b0f82bc1f8434bfa8c389329c016d4528a
4
+ data.tar.gz: b70e7a5189a35825e996c582658d5b062f2849891dd2262181eacc025e5e52dc
5
5
  SHA512:
6
- metadata.gz: 40491ac4ac77da177c05f445ad2e31332535f4784654aaeebf78d81eb1ec15e45f5ad8db6306a955b47e67d887574f22cefcd7efac8759bcd4b050f05ecb3c90
7
- data.tar.gz: 5a5d1ec7f81b184cee101091a3330c6f7c6d31d300681f6028d28e113bb732aa8cf2690aaf99dae689218f9c473bea2c5585299a11f48fe12fa42541bddf7bd6
6
+ metadata.gz: 06fbb48beee20de45796edfbd1c58299649b919d9ec5551d4701c7dbae04a4033e07c5dfed3f83719f388d7e2b54285cd6eccd8e0afc5396ab79c2110b0f0b78
7
+ data.tar.gz: 425291ee06d0bff6430703a46894d2436f3116edb7b6d0def9e121b8685d7834e0e344f319c846833fdc7aa7645e4349d6351656b4df601bf967a78492fc531e
data/README.md CHANGED
@@ -32,6 +32,8 @@ user_name: 'Your User number'
32
32
  password: 'Your Grafana.com API Token'
33
33
  log_file_path: 'log/#{Rails.env}.log'
34
34
  logs_type: '%w(ERROR WARN FATAL INFO DEBUG)'
35
+ interaction_interval: 5
36
+ max_buffer_size: 100
35
37
  intercept_logs: true
36
38
  ```
37
39
  - Add block for **Rails Loki Exporter** in your `application.rb` file:
@@ -44,10 +44,10 @@ module RailsLokiExporter
44
44
  private
45
45
 
46
46
  def format_message(severity, datetime, progname, msg)
47
- puts "severity: #{severity}"
48
- puts "datetime: #{datetime}"
49
- puts "progname: #{progname}"
50
- puts "msg: #{msg}"
47
+ # puts "severity: #{severity}"
48
+ # puts "datetime: #{datetime}"
49
+ # puts "progname: #{progname}"
50
+ # puts "msg: #{msg}"
51
51
  "#{severity} #{progname}: #{msg}\n"
52
52
  end
53
53
 
@@ -21,8 +21,8 @@ module RailsLokiExporter
21
21
  @auth_enabled = config['auth_enabled']
22
22
  @log_buffer = []
23
23
  @last_interaction_time = nil
24
- @interaction_interval = 1 # in seconds, adjust as needed
25
- @max_buffer_size = 10 # set the maximum number of logs to buffer
24
+ @interaction_interval = (config['interaction_interval'] || '5').to_i # in seconds, adjust as needed
25
+ @max_buffer_size = (config['max_buffer_size'] || '100').to_i # set the maximum number of logs to buffer
26
26
 
27
27
  http = Net::HTTP.new(@base_url.to_s, @base_url.port)
28
28
  http.use_ssl = @base_url.scheme == 'https'
@@ -32,27 +32,30 @@ module RailsLokiExporter
32
32
  end
33
33
 
34
34
  def send_log(log_message)
35
- @log_buffer << log_message
36
- if @log_buffer.size >= @max_buffer_size || can_send_log?
37
- send_buffered_logs
38
- @last_interaction_time = Time.now
39
- else
40
- # @logger.info('Log buffered. Waiting for more logs or interaction interval.')
41
- end
35
+ current_timestamp = Time.now.to_f * 1_000_000_000
36
+ @log_buffer << [current_timestamp.to_i.to_s, log_message.chomp]
37
+ if @log_buffer.size >= @max_buffer_size || can_send_log?
38
+ send_buffered_logs
39
+ @last_interaction_time = Time.now
40
+ else
41
+ # @logger.info('Log buffered. Waiting for more logs or interaction interval.')
42
+ end
42
43
  end
43
44
 
44
45
  private
45
46
  def send_buffered_logs
46
47
  return if @log_buffer.empty?
47
48
 
48
- curr_datetime = Time.now.to_i * 1_000_000_000
49
49
  msg = "On server #{@host_name} detected error"
50
50
  payload = {
51
51
  'streams' => [
52
- { 'stream' => {
53
- 'job' => @job_name,
54
- 'host' => @host_name },
55
- 'values' => @log_buffer.map { |log| [curr_datetime.to_s, log] }}
52
+ {
53
+ 'stream' => {
54
+ 'job' => @job_name,
55
+ 'host' => @host_name,
56
+ },
57
+ 'values' => @log_buffer,
58
+ }
56
59
  ]
57
60
  }
58
61
 
@@ -1,3 +1,3 @@
1
1
  module RailsLokiExporter
2
- VERSION = '1.0.4'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -17,5 +17,6 @@ Gem::Specification.new do |spec|
17
17
  spec.extra_rdoc_files = ['README.md']
18
18
  spec.require_paths = ['lib']
19
19
  spec.add_dependency 'zeitwerk', '~> 2.4'
20
- spec.add_dependency 'rspec'
20
+ spec.add_development_dependency 'rspec'
21
+ spec.add_development_dependency 'rake'
21
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_loki_exporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - planning.how
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-03-04 00:00:00.000000000 Z
13
+ date: 2024-10-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: zeitwerk
@@ -33,7 +33,21 @@ dependencies:
33
33
  - - ">="
34
34
  - !ruby/object:Gem::Version
35
35
  version: '0'
36
- type: :runtime
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rake
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
37
51
  prerelease: false
38
52
  version_requirements: !ruby/object:Gem::Requirement
39
53
  requirements: