betterlog 0.9.0 → 0.10.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: 35b30ba42034bf3d4a09a4558f8a21b8e48b2a5145b2e56299b4f73f9e14ebd4
4
- data.tar.gz: 03df9bb690c3fedb95696fa1c0708a08da9ed5f41246233115fa6444b761a1f5
3
+ metadata.gz: dade612b41a387e538c98ef623a79fdb483d4e230daed8d154cad2fa64465235
4
+ data.tar.gz: ac0ada91ced10e9d1cf64f4dfaecef4a7e9c24b63715fe7e7ddca231044646ed
5
5
  SHA512:
6
- metadata.gz: 4982f6fb3cd975ef1069a8b36617e5494f346084069d3d6eed723152e854bde651d76859cb4e33681889c22821b8be19626dcc1fa396a4bdd166373e5def483e
7
- data.tar.gz: 109c8fd2ff8c4f9217188450793aeacf32a580f47c82eafec33e6abea77fa152028207f82a05fbab91142fd73eaf8a34a2493bd1d85e2e3e770434fce12acf27
6
+ metadata.gz: 1b896f2288f53dedad255dccc578c072052fa6db07f6dfb2093db32ca8b38cfc1464ce5f26b2d94b4e8cf40b25889f1759920974cc0be6890f9cba026e8b83f9
7
+ data.tar.gz: 8dd4191451947ed9c9be2ff04ad2877b5902685599c1db9e32a25797a7393b5c9a49141565afa1216e2348fa90addab371664151cf01a973f9c8dc7a80f8628d
@@ -1,5 +1,6 @@
1
1
  rvm:
2
2
  - 2.6
3
+ - 2.7
3
4
  sudo: false
4
5
  services:
5
6
  - redis-server
data/Makefile CHANGED
@@ -1,4 +1,4 @@
1
- # Pass BASE_IMAGE=alpine:3.10.0
1
+ # Pass BASE_IMAGE=alpine:3.13.3
2
2
  DOCKER_IMAGE_LATEST = betterlog
3
3
  DOCKER_IMAGE = $(DOCKER_IMAGE_LATEST):$(REVISION_SHORT)
4
4
  PROJECT_ID = betterplace-183212
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.0
1
+ 0.10.0
@@ -1,19 +1,19 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: betterlog 0.9.0 ruby lib
2
+ # stub: betterlog 0.10.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "betterlog".freeze
6
- s.version = "0.9.0"
6
+ s.version = "0.10.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["betterplace Developers".freeze]
11
- s.date = "2020-01-17"
11
+ s.date = "2020-01-22"
12
12
  s.description = "This library provides structure json logging for our rails projects".freeze
13
13
  s.email = "developers@betterplace.org".freeze
14
14
  s.executables = ["betterlog".freeze, "betterlog_pusher".freeze, "betterlog_sink".freeze]
15
15
  s.extra_rdoc_files = ["README.md".freeze, "lib/betterlog.rb".freeze, "lib/betterlog/global_metadata.rb".freeze, "lib/betterlog/log.rb".freeze, "lib/betterlog/log/event.rb".freeze, "lib/betterlog/log/event_formatter.rb".freeze, "lib/betterlog/log/severity.rb".freeze, "lib/betterlog/log_event_formatter.rb".freeze, "lib/betterlog/logger.rb".freeze, "lib/betterlog/notifiers.rb".freeze, "lib/betterlog/railtie.rb".freeze, "lib/betterlog/version.rb".freeze]
16
- s.files = [".gitignore".freeze, ".travis.yml".freeze, "Dockerfile".freeze, "Gemfile".freeze, "LICENSE".freeze, "Makefile".freeze, "README.md".freeze, "Rakefile".freeze, "TODO.md".freeze, "VERSION".freeze, "betterlog.gemspec".freeze, "betterlog/config.go".freeze, "betterlog/healthz.go".freeze, "betterlog/redis_cert_cache.go".freeze, "bin/betterlog".freeze, "bin/betterlog_pusher".freeze, "bin/betterlog_sink".freeze, "cmd/betterlog-server/LICENSE".freeze, "cmd/betterlog-server/main.go".freeze, "config/log.yml".freeze, "go.mod".freeze, "go.sum".freeze, "lib/betterlog.rb".freeze, "lib/betterlog/global_metadata.rb".freeze, "lib/betterlog/log.rb".freeze, "lib/betterlog/log/event.rb".freeze, "lib/betterlog/log/event_formatter.rb".freeze, "lib/betterlog/log/severity.rb".freeze, "lib/betterlog/log_event_formatter.rb".freeze, "lib/betterlog/logger.rb".freeze, "lib/betterlog/notifiers.rb".freeze, "lib/betterlog/railtie.rb".freeze, "lib/betterlog/version.rb".freeze, "spec/betterlog/global_metadata_spec.rb".freeze, "spec/betterlog/log/event_spec.rb".freeze, "spec/betterlog/log/severity_spec.rb".freeze, "spec/betterlog/log_spec.rb".freeze, "spec/betterlog/logger_spec.rb".freeze, "spec/spec_helper.rb".freeze]
16
+ s.files = [".gitignore".freeze, ".travis.yml".freeze, "Dockerfile".freeze, "Gemfile".freeze, "LICENSE".freeze, "Makefile".freeze, "README.md".freeze, "Rakefile".freeze, "TODO.md".freeze, "VERSION".freeze, "betterlog.gemspec".freeze, "betterlog/config.go".freeze, "betterlog/healthz.go".freeze, "betterlog/redis_cert_cache.go".freeze, "bin/betterlog".freeze, "bin/betterlog_pusher".freeze, "bin/betterlog_sink".freeze, "cloudbuild.yaml".freeze, "cmd/betterlog-server/LICENSE".freeze, "cmd/betterlog-server/main.go".freeze, "config/log.yml".freeze, "go.mod".freeze, "go.sum".freeze, "lib/betterlog.rb".freeze, "lib/betterlog/global_metadata.rb".freeze, "lib/betterlog/log.rb".freeze, "lib/betterlog/log/event.rb".freeze, "lib/betterlog/log/event_formatter.rb".freeze, "lib/betterlog/log/severity.rb".freeze, "lib/betterlog/log_event_formatter.rb".freeze, "lib/betterlog/logger.rb".freeze, "lib/betterlog/notifiers.rb".freeze, "lib/betterlog/railtie.rb".freeze, "lib/betterlog/version.rb".freeze, "spec/betterlog/global_metadata_spec.rb".freeze, "spec/betterlog/log/event_spec.rb".freeze, "spec/betterlog/log/severity_spec.rb".freeze, "spec/betterlog/log_spec.rb".freeze, "spec/betterlog/logger_spec.rb".freeze, "spec/spec_helper.rb".freeze]
17
17
  s.homepage = "http://github.com/betterplace/betterlog".freeze
18
18
  s.rdoc_options = ["--title".freeze, "Betterlog".freeze, "--main".freeze, "README.md".freeze]
19
19
  s.rubygems_version = "3.1.2".freeze
@@ -32,7 +32,7 @@ loop do
32
32
  lm.lock!(File.basename($0), lock_time) do
33
33
  print ?…
34
34
  logger.each_slice(lines).with_index do |batch, i|
35
- count.zero? and print ?(
35
+ count.zero? and print ?○
36
36
  count += batch.sum(&:size)
37
37
  attempt(attempts: 10, sleep: -60, reraise: true) do
38
38
  print ?┄
@@ -44,7 +44,7 @@ loop do
44
44
  if count.zero?
45
45
  sleep 1
46
46
  else
47
- print "→%s)" % Tins::Unit.format(count, format: '%.2f %U', prefix: 1024, unit: ?b)
47
+ print "→ %s sent.\n" % Tins::Unit.format(count, format: '%.2f %U', prefix: 1024, unit: ?b)
48
48
  end
49
49
  rescue Redlock::LockError => e
50
50
  STDERR.puts "Caught #{e.class}: #{e} => Retrying!"
@@ -0,0 +1,9 @@
1
+ steps:
2
+ - name: gcr.io/cloud-builders/docker
3
+ args: ['pull', '${_BASE_IMAGE}']
4
+ - name: gcr.io/cloud-builders/docker
5
+ args: ['build', '-t', 'eu.gcr.io/$PROJECT_ID/${_IMAGE_NAME}:$SHORT_SHA', '-t', 'eu.gcr.io/$PROJECT_ID/${_IMAGE_NAME}', '--build-arg=BASE_IMAGE=${_BASE_IMAGE}', '.']
6
+ images:
7
+ - 'eu.gcr.io/$PROJECT_ID/${_IMAGE_NAME}:$SHORT_SHA'
8
+ - 'eu.gcr.io/$PROJECT_ID/${_IMAGE_NAME}'
9
+ timeout: 600s
@@ -4,6 +4,7 @@ module Betterlog
4
4
  class Logger < ::Logger
5
5
  def initialize(redis, shift_age = 0, shift_size = 1048576, name: nil, buffer_size: nil, **opts)
6
6
  @redis = redis
7
+ @fallback = ::Logger.new(STDERR)
7
8
  @name = name || self.class.name
8
9
  @buffer_size = determine_buffer_size(buffer_size)
9
10
  super(nil, shift_age, shift_size, **opts)
@@ -29,11 +30,8 @@ module Betterlog
29
30
  private def redis_write(msg)
30
31
  # Stop before reaching configured buffer_size limit, after warning a lot.
31
32
  if @redis.strlen(@name) > (@buffer_size * 96) / 100
32
- return nil
33
- end
34
- if @redis.strlen(@name) > (@buffer_size * 95) / 100
35
- @redis.append @name, "\nRedis memory limit will soon be reached =>"\
36
- " Log output to redis stops now unless log data is pushed away!\n"
33
+ @fallback.error("Redis memory limit will soon be reached =>"\
34
+ " Log output to redis stops now unless log data is pushed away!")
37
35
  return nil
38
36
  end
39
37
  @redis.append @name, msg
@@ -60,10 +58,14 @@ module Betterlog
60
58
  redis_write(
61
59
  format_message(format_severity(severity), Time.now, progname, message))
62
60
  true
61
+ rescue Redis::BaseConnectionError
62
+ @fallback.add(severity, message, progname)
63
63
  end
64
64
 
65
65
  def <<(msg)
66
66
  redis_write(msg)
67
+ rescue Redis::BaseConnectionError
68
+ @fallback << msg
67
69
  end
68
70
 
69
71
  def clear
@@ -73,18 +75,40 @@ module Betterlog
73
75
 
74
76
  def each_chunk(chunk_size: 100 * 1024, &block)
75
77
  chunk_size > 0 or raise ArgumentError, 'chunk_size > 0 required'
78
+
79
+ # Delete any remaining temporary keys if we were interrtupted earlier
80
+ # (or in some other process.)
81
+ @redis.scan_each(match: "#{@name}_*") do |key|
82
+ @redis.del key
83
+ rescue Redis::BaseConnectionError
84
+ end
85
+
76
86
  @redis.exists(@name) or return Enumerator.new {}
87
+
77
88
  Enumerator.new do |y|
78
89
  name_tmp = "#{@name}_#{rand}"
79
90
  @redis.rename @name, name_tmp
91
+
80
92
  s = 0
81
93
  e = @redis.strlen(name_tmp) - 1
82
94
  until s > e
83
95
  y.yield @redis.getrange(name_tmp, s, s + chunk_size - 1)
84
96
  s += chunk_size
85
97
  end
86
- @redis.del name_tmp
98
+
99
+ ensure
100
+ begin
101
+ @redis.del name_tmp
102
+ rescue Redis::BaseConnectionError
103
+ # We have to delete this later if del command failed here,
104
+ # see the beginning of this method.
105
+ end
87
106
  end.each(&block)
107
+
108
+ rescue Redis::BaseConnectionError => e
109
+ # Maybe it works again later, just log the error…
110
+ @fallback.error(e)
111
+ Enumerator.new {}
88
112
  end
89
113
 
90
114
  def each(chunk_size: 100 * 1024, &block)
@@ -1,6 +1,6 @@
1
1
  module Betterlog
2
2
  # Betterlog version
3
- VERSION = '0.9.0'
3
+ VERSION = '0.10.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -58,7 +58,7 @@ describe Betterlog::Log do
58
58
 
59
59
  describe '#info with internal logging error' do
60
60
  it 'should not crash ever, just log the problem to Rails.logger' do
61
- expect_any_instance_of(instance.logger.class).to receive(:fatal).and_call_original
61
+ expect_any_instance_of(instance.logger.class).to receive(:fatal)
62
62
  expect(Log.info(BasicObject.new)).to eq Log.instance
63
63
  end
64
64
  end
@@ -77,6 +77,10 @@ describe Betterlog::Log do
77
77
  Betterlog::Notifiers.notifiers.clear
78
78
  end
79
79
 
80
+ before do
81
+ expect_any_instance_of(::Logger).to receive(:send).with(:info, any_args)
82
+ end
83
+
80
84
  it 'can send explicit notifications' do
81
85
  expect(notifier).to receive(:notify).with(
82
86
  'test',
@@ -26,6 +26,14 @@ describe Betterlog::Logger do
26
26
  with('Betterlog::Logger', 'foo')
27
27
  logger << 'foo'
28
28
  end
29
+
30
+ it 'falls back if redis errors' do
31
+ allow(logger.instance_variable_get(:@redis)).to receive(:append).
32
+ and_raise(Redis::BaseConnectionError)
33
+ expect(logger.instance_variable_get(:@fallback)).to\
34
+ receive(:<<).with('foo')
35
+ logger << 'foo'
36
+ end
29
37
  end
30
38
 
31
39
  describe '#add' do
@@ -34,6 +42,14 @@ describe Betterlog::Logger do
34
42
  with('Betterlog::Logger', /INFO -- : foo/)
35
43
  logger.info 'foo'
36
44
  end
45
+
46
+ it 'falls back if redis errors' do
47
+ allow(logger.instance_variable_get(:@redis)).to receive(:append).
48
+ and_raise(Redis::BaseConnectionError)
49
+ expect(logger.instance_variable_get(:@fallback)).to\
50
+ receive(:add).with(::Logger::INFO, 'foo', nil)
51
+ logger.info 'foo'
52
+ end
37
53
  end
38
54
 
39
55
  describe '#each_chunk' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: betterlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - betterplace Developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-17 00:00:00.000000000 Z
11
+ date: 2020-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -222,6 +222,7 @@ files:
222
222
  - bin/betterlog
223
223
  - bin/betterlog_pusher
224
224
  - bin/betterlog_sink
225
+ - cloudbuild.yaml
225
226
  - cmd/betterlog-server/LICENSE
226
227
  - cmd/betterlog-server/main.go
227
228
  - config/log.yml