fluentd 1.12.2-x64-mingw32 → 1.13.2-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fluentd might be problematic. Click here for more details.

Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.yaml +69 -0
  3. data/.github/ISSUE_TEMPLATE/feature_request.yaml +38 -0
  4. data/.github/workflows/linux-test.yaml +1 -1
  5. data/.github/workflows/windows-test.yaml +19 -3
  6. data/.gitlab-ci.yml +19 -19
  7. data/CHANGELOG.md +153 -0
  8. data/CONTRIBUTING.md +2 -2
  9. data/MAINTAINERS.md +1 -1
  10. data/README.md +8 -5
  11. data/bin/fluentd +8 -1
  12. data/example/counter.conf +1 -1
  13. data/fluentd.gemspec +4 -3
  14. data/lib/fluent/command/cat.rb +19 -3
  15. data/lib/fluent/command/fluentd.rb +1 -2
  16. data/lib/fluent/command/plugin_generator.rb +42 -2
  17. data/lib/fluent/config.rb +1 -1
  18. data/lib/fluent/config/section.rb +5 -0
  19. data/lib/fluent/config/types.rb +15 -0
  20. data/lib/fluent/config/v1_parser.rb +3 -2
  21. data/lib/fluent/env.rb +2 -1
  22. data/lib/fluent/log.rb +1 -0
  23. data/lib/fluent/oj_options.rb +62 -0
  24. data/lib/fluent/plugin/file_wrapper.rb +49 -4
  25. data/lib/fluent/plugin/formatter.rb +1 -0
  26. data/lib/fluent/plugin/formatter_json.rb +9 -7
  27. data/lib/fluent/plugin/in_http.rb +10 -0
  28. data/lib/fluent/plugin/in_tail.rb +150 -39
  29. data/lib/fluent/plugin/in_tail/position_file.rb +15 -1
  30. data/lib/fluent/plugin/out_forward.rb +14 -33
  31. data/lib/fluent/plugin/output.rb +11 -9
  32. data/lib/fluent/plugin/parser_csv.rb +2 -2
  33. data/lib/fluent/plugin/parser_json.rb +2 -3
  34. data/lib/fluent/plugin/parser_syslog.rb +2 -2
  35. data/lib/fluent/plugin/service_discovery.rb +0 -15
  36. data/lib/fluent/plugin/storage_local.rb +1 -1
  37. data/lib/fluent/plugin_helper/http_server/router.rb +1 -1
  38. data/lib/fluent/plugin_helper/server.rb +4 -2
  39. data/lib/fluent/plugin_helper/service_discovery.rb +39 -1
  40. data/lib/fluent/plugin_helper/service_discovery/manager.rb +11 -5
  41. data/lib/fluent/plugin_helper/socket_option.rb +2 -2
  42. data/lib/fluent/supervisor.rb +15 -0
  43. data/lib/fluent/system_config.rb +14 -0
  44. data/lib/fluent/test/driver/storage.rb +30 -0
  45. data/lib/fluent/version.rb +1 -1
  46. data/templates/new_gem/fluent-plugin.gemspec.erb +3 -3
  47. data/templates/new_gem/lib/fluent/plugin/storage.rb.erb +40 -0
  48. data/templates/new_gem/test/plugin/test_storage.rb.erb +18 -0
  49. data/test/command/test_cat.rb +99 -0
  50. data/test/command/test_plugin_generator.rb +2 -1
  51. data/test/config/test_section.rb +9 -0
  52. data/test/config/test_system_config.rb +46 -0
  53. data/test/config/test_types.rb +7 -0
  54. data/test/plugin/in_tail/test_io_handler.rb +4 -4
  55. data/test/plugin/in_tail/test_position_file.rb +54 -0
  56. data/test/plugin/out_forward/test_connection_manager.rb +0 -6
  57. data/test/plugin/test_file_wrapper.rb +115 -0
  58. data/test/plugin/test_in_forward.rb +59 -83
  59. data/test/plugin/test_in_http.rb +58 -40
  60. data/test/plugin/test_in_syslog.rb +66 -56
  61. data/test/plugin/test_in_tail.rb +329 -10
  62. data/test/plugin/test_in_tcp.rb +45 -32
  63. data/test/plugin/test_in_udp.rb +47 -33
  64. data/test/plugin/test_out_forward.rb +138 -105
  65. data/test/plugin/test_out_stream.rb +18 -8
  66. data/test/plugin/test_output.rb +15 -3
  67. data/test/plugin/test_output_as_buffered_backup.rb +2 -0
  68. data/test/plugin/test_parser_csv.rb +14 -0
  69. data/test/plugin/test_parser_syslog.rb +14 -0
  70. data/test/plugin_helper/http_server/test_route.rb +1 -1
  71. data/test/plugin_helper/service_discovery/test_manager.rb +1 -1
  72. data/test/plugin_helper/test_child_process.rb +1 -1
  73. data/test/plugin_helper/test_http_server_helper.rb +34 -27
  74. data/test/plugin_helper/test_server.rb +144 -139
  75. data/test/plugin_helper/test_service_discovery.rb +74 -14
  76. data/test/plugin_helper/test_socket.rb +16 -9
  77. data/test/test_config.rb +2 -1
  78. data/test/test_event_time.rb +2 -2
  79. data/test/test_oj_options.rb +55 -0
  80. data/test/test_output.rb +2 -2
  81. data/test/test_supervisor.rb +35 -0
  82. metadata +41 -11
  83. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -40
  84. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -23
data/MAINTAINERS.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  - [Naotoshi Seo](https://github.com/sonots), [ZOZO Technologies](https://tech.zozo.com/en/)
4
4
  - [Okkez](https://github.com/okkez)
5
- - [Hiroshi Hatake](https://github.com/cosmo0920), [ClearCode](https://www.clear-code.com/)
5
+ - [Hiroshi Hatake](https://github.com/cosmo0920), [Calyptia](https://www.calyptia.com/)
6
6
  - [Masahiro Nakagawa](https://github.com/repeatedly), [Treasure Data](https://www.treasuredata.com/)
7
7
  - [Satoshi Tagomori](https://github.com/tagomoris), [Treasure Data](https://www.treasuredata.com/)
8
8
  - [Eduardo Silva](https://github.com/edsiper), [Arm Treasure Data](https://www.treasuredata.com/)
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  Fluentd: Open-Source Log Collector
2
2
  ===================================
3
- Travis CI:
3
+ GitHub Actions:
4
4
 
5
- [<img src="https://travis-ci.org/fluent/fluentd.svg" />](https://travis-ci.org/fluent/fluentd) [![Code Climate](https://codeclimate.com/github/fluent/fluentd/badges/gpa.svg)](https://codeclimate.com/github/fluent/fluentd)
5
+ [![Testing on Ubuntu](https://github.com/fluent/fluentd/actions/workflows/linux-test.yaml/badge.svg?branch=master)](https://github.com/fluent/fluentd/actions/workflows/linux-test.yaml)
6
+ [![Testing on Windows](https://github.com/fluent/fluentd/actions/workflows/windows-test.yaml/badge.svg?branch=master)](https://github.com/fluent/fluentd/actions/workflows/windows-test.yaml)
7
+ [![Testing on macOS](https://github.com/fluent/fluentd/actions/workflows/macos-test.yaml/badge.svg?branch=master)](https://github.com/fluent/fluentd/actions/workflows/macos-test.yaml)
8
+ [![Code Climate](https://codeclimate.com/github/fluent/fluentd/badges/gpa.svg)](https://codeclimate.com/github/fluent/fluentd)
6
9
  [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/1189/badge)](https://bestpractices.coreinfrastructure.org/projects/1189)
7
10
  [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Ffluent%2Ffluentd.svg?type=shield)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Ffluent%2Ffluentd?ref=badge_shield)
8
11
 
@@ -22,9 +25,9 @@ An event consists of *tag*, *time* and *record*. Tag is a string separated with
22
25
 
23
26
  Use Case | Description | Diagram
24
27
  -------- | ------------|:---------:
25
- Centralizing Apache/Nginx Server Logs | Fluentd can be used to tail access/error logs and transport them reliably to remote systems. | <img src="https://www.fluentd.org/assets/img/recipes/elasticsearch-s3-fluentd.png" height="150"/>
28
+ Centralizing Apache/Nginx Server Logs | Fluentd can be used to tail access/error logs and transport them reliably to remote systems. | <img src="https://www.fluentd.org/images/recipes/elasticsearch-s3-fluentd.png" height="150"/>
26
29
  Syslog Alerting | Fluentd can "grep" for events and send out alerts. | <img src="https://www.fluentd.org/images/syslog-fluentd-alert.png" height="100"/>
27
- Mobile/Web Application Logging | Fluentd can function as middleware to enable asynchronous, scalable logging for user action events. | <img src="https://www.fluentd.org/assets/img/datasources/asynchronous_logging.png" height="150"/>
30
+ Mobile/Web Application Logging | Fluentd can function as middleware to enable asynchronous, scalable logging for user action events. | <img src="https://www.fluentd.org/images/datasources/asynchronous_logging.png" height="150"/>
28
31
 
29
32
  ## Quick Start
30
33
 
@@ -74,7 +77,7 @@ You can run specified test via `TEST` environment variable:
74
77
  - Website: https://www.fluentd.org/
75
78
  - Documentation: https://docs.fluentd.org/
76
79
  - Project repository: https://github.com/fluent
77
- - Discussion: https://groups.google.com/group/fluentd
80
+ - Discussion: https://discuss.fluentd.org/
78
81
  - Slack / Community: https://slack.fluentd.org
79
82
  - Newsletters: https://www.fluentd.org/newsletter
80
83
  - Author: [Sadayuki Furuhashi](https://github.com/frsyuki)
data/bin/fluentd CHANGED
@@ -1,7 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
- RubyVM::InstructionSequence.compile_option = {trace_instruction: false} rescue nil
4
+ # In recent CRuby, RubyVM::InstructionSequence is always defined.
5
+ # This optimization aims to reduce memory (avg 0.5 megabytes) at startup.
6
+ # ref: http://atdot.net/~ko1/activities/2017_fukuoka_rubykaigi_02.pdf
7
+ # But other implementation such as truffleruby does not provide such
8
+ # class.
9
+ if defined?(RubyVM::InstructionSequence)
10
+ RubyVM::InstructionSequence.compile_option = {trace_instruction: false}
11
+ end
5
12
 
6
13
  here = File.dirname(__FILE__)
7
14
  $LOAD_PATH << File.expand_path(File.join(here, '..', 'lib'))
data/example/counter.conf CHANGED
@@ -3,7 +3,7 @@
3
3
  scope server1
4
4
  bind 127.0.0.1
5
5
  port 24321
6
- path tmp/back
6
+ backup_path tmp/back
7
7
  </counter_server>
8
8
  </system>
9
9
 
data/fluentd.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |gem|
23
23
  gem.add_runtime_dependency("yajl-ruby", ["~> 1.0"])
24
24
  gem.add_runtime_dependency("cool.io", [">= 1.4.5", "< 2.0.0"])
25
25
  gem.add_runtime_dependency("serverengine", [">= 2.2.2", "< 3.0.0"])
26
- gem.add_runtime_dependency("http_parser.rb", [">= 0.5.1", "< 0.7.0"])
26
+ gem.add_runtime_dependency("http_parser.rb", [">= 0.5.1", "< 0.8.0"])
27
27
  gem.add_runtime_dependency("sigdump", ["~> 0.2.2"])
28
28
  gem.add_runtime_dependency("tzinfo", [">= 1.0", "< 3.0"])
29
29
  gem.add_runtime_dependency("tzinfo-data", ["~> 1.0"])
@@ -34,7 +34,8 @@ Gem::Specification.new do |gem|
34
34
  fake_platform = ENV['GEM_BUILD_FAKE_PLATFORM'].to_s
35
35
  gem.platform = fake_platform unless fake_platform.empty?
36
36
  if /mswin|mingw/ =~ fake_platform || (/mswin|mingw/ =~ RUBY_PLATFORM && fake_platform.empty?)
37
- gem.add_runtime_dependency("win32-service", ["~> 2.1.5"])
37
+ gem.add_runtime_dependency("win32-api", [">= 1.10", "< 2.0.0"])
38
+ gem.add_runtime_dependency("win32-service", ["~> 2.2.0"])
38
39
  gem.add_runtime_dependency("win32-ipc", ["~> 0.7.0"])
39
40
  gem.add_runtime_dependency("win32-event", ["~> 0.6.3"])
40
41
  gem.add_runtime_dependency("windows-pr", ["~> 1.2.6"])
@@ -45,7 +46,7 @@ Gem::Specification.new do |gem|
45
46
  gem.add_development_dependency("flexmock", ["~> 2.0"])
46
47
  gem.add_development_dependency("parallel_tests", ["~> 0.15.3"])
47
48
  gem.add_development_dependency("simplecov", ["~> 0.7"])
48
- gem.add_development_dependency("rr", ["~> 1.0"])
49
+ gem.add_development_dependency("rr", ["~> 3.0"])
49
50
  gem.add_development_dependency("timecop", ["~> 0.9"])
50
51
  gem.add_development_dependency("test-unit", ["~> 3.3"])
51
52
  gem.add_development_dependency("test-unit-rr", ["~> 1.0"])
@@ -152,14 +152,30 @@ class Writer
152
152
  super()
153
153
  end
154
154
 
155
+ def secondary_record?(record)
156
+ record.class != Hash &&
157
+ record.size == 2 &&
158
+ record.first.class == Fluent::EventTime &&
159
+ record.last.class == Hash
160
+ end
161
+
155
162
  def write(record)
156
- if record.class != Hash
157
- raise ArgumentError, "Input must be a map (got #{record.class})"
163
+ unless secondary_record?(record)
164
+ if record.class != Hash
165
+ raise ArgumentError, "Input must be a map (got #{record.class})"
166
+ end
158
167
  end
159
168
 
160
169
  time = Fluent::EventTime.now
161
170
  time = time.to_i if @time_as_integer
162
- entry = [time, record]
171
+ entry = if secondary_record?(record)
172
+ # Even though secondary contains Fluent::EventTime in record,
173
+ # fluent-cat just ignore it and set Fluent::EventTime.now instead.
174
+ # This specification is adopted to keep consistency.
175
+ [time, record.last]
176
+ else
177
+ [time, record]
178
+ end
163
179
  synchronize {
164
180
  unless write_impl([entry])
165
181
  # write failed
@@ -85,9 +85,8 @@ op.on('-o', '--log PATH', "log file path") {|s|
85
85
  opts[:log_path] = s
86
86
  }
87
87
 
88
- ROTATE_AGE = %w(daily weekly monthly)
89
88
  op.on('--log-rotate-age AGE', 'generations to keep rotated log files') {|age|
90
- if ROTATE_AGE.include?(age)
89
+ if Fluent::Log::LOG_ROTATE_AGE.include?(age)
91
90
  opts[:log_rotate_age] = age
92
91
  else
93
92
  begin
@@ -27,7 +27,7 @@ class FluentPluginGenerator
27
27
  attr_reader :type, :name
28
28
  attr_reader :license_name
29
29
 
30
- SUPPORTED_TYPES = ["input", "output", "filter", "parser", "formatter"]
30
+ SUPPORTED_TYPES = ["input", "output", "filter", "parser", "formatter", "storage"]
31
31
 
32
32
  def initialize(argv = ARGV)
33
33
  @argv = argv
@@ -105,7 +105,7 @@ Generate a project skeleton for creating a Fluentd plugin
105
105
 
106
106
  Arguments:
107
107
  \ttype: #{SUPPORTED_TYPES.join(",")}
108
- \tname: Your plugin name
108
+ \tname: Your plugin name (fluent-plugin- prefix will be added to <name>)
109
109
 
110
110
  Options:
111
111
  BANNER
@@ -151,6 +151,46 @@ BANNER
151
151
  underscore_name
152
152
  end
153
153
 
154
+ def gem_file_path
155
+ File.expand_path(File.join(File.dirname(__FILE__),
156
+ "../../../",
157
+ "Gemfile"))
158
+ end
159
+
160
+ def lock_file_path
161
+ File.expand_path(File.join(File.dirname(__FILE__),
162
+ "../../../",
163
+ "Gemfile.lock"))
164
+ end
165
+
166
+ def locked_gem_version(gem_name)
167
+ if File.exist?(lock_file_path)
168
+ d = Bundler::Definition.build(gem_file_path, lock_file_path, false)
169
+ d.locked_gems.dependencies[gem_name].requirement.requirements.first.last.version
170
+ else
171
+ # fallback even though Fluentd is installed without bundler
172
+ Gem::Specification.find_by_name(gem_name).version.version
173
+ end
174
+ end
175
+
176
+ def rake_version
177
+ locked_gem_version("rake")
178
+ end
179
+
180
+ def test_unit_version
181
+ locked_gem_version("test-unit")
182
+ end
183
+
184
+ def bundler_version
185
+ if File.exist?(lock_file_path)
186
+ d = Bundler::Definition.build(gem_file_path, lock_file_path, false)
187
+ d.locked_gems.bundler_version.version
188
+ else
189
+ # fallback even though Fluentd is installed without bundler
190
+ Gem::Specification.find_by_name("bundler").version.version
191
+ end
192
+ end
193
+
154
194
  def class_name
155
195
  "#{capitalized_name}#{type.capitalize}"
156
196
  end
data/lib/fluent/config.rb CHANGED
@@ -62,7 +62,7 @@ module Fluent
62
62
  Parser.parse(str, fname, basepath)
63
63
  when :ruby
64
64
  require 'fluent/config/dsl'
65
- $log.warn("Ruby DSL configuration format is deprecated. Please use original configuration format. https://docs.fluentd.org/configuration/config-file")
65
+ $log.warn("Ruby DSL configuration format is deprecated. Please use original configuration format. https://docs.fluentd.org/configuration/config-file") if $log
66
66
  Config::DSL::Parser.parse(str, File.join(basepath, fname))
67
67
  else
68
68
  raise "[BUG] unknown configuration parser specification:'#{parser}'"
@@ -50,6 +50,11 @@ module Fluent
50
50
  "<Fluent::Config::Section #{@params.to_json}>"
51
51
  end
52
52
 
53
+ # Used by PP and Pry
54
+ def pretty_print(q)
55
+ q.text(inspect)
56
+ end
57
+
53
58
  def nil?
54
59
  false
55
60
  end
@@ -20,6 +20,10 @@ require 'fluent/config/error'
20
20
 
21
21
  module Fluent
22
22
  module Config
23
+ def self.reformatted_value(type, val, opts = {}, name = nil)
24
+ REFORMAT_VALUE.call(type, val, opts, name)
25
+ end
26
+
23
27
  def self.size_value(str, opts = {}, name = nil)
24
28
  return nil if str.nil?
25
29
 
@@ -104,6 +108,16 @@ module Fluent
104
108
  Config.string_value(val, opts, name)
105
109
  }
106
110
 
111
+ def self.symbol_value(val, opts = {}, name = nil)
112
+ return nil if val.nil? || val.empty?
113
+
114
+ val.delete_prefix(":").to_sym
115
+ end
116
+
117
+ SYMBOL_TYPE = Proc.new { |val, opts = {}, name = nil|
118
+ Config.symbol_value(val, opts, name)
119
+ }
120
+
107
121
  def self.enum_value(val, opts = {}, name = nil)
108
122
  return nil if val.nil?
109
123
 
@@ -176,6 +190,7 @@ module Fluent
176
190
  when :bool then Config.bool_value(value, opts, name)
177
191
  when :time then Config.time_value(value, opts, name)
178
192
  when :regexp then Config.regexp_value(value, opts, name)
193
+ when :symbol then Config.symbol_value(value, opts, name)
179
194
  else
180
195
  raise "unknown type in REFORMAT: #{type}"
181
196
  end
@@ -37,6 +37,7 @@ module Fluent
37
37
  super(strscan, eval_context)
38
38
  @include_basepath = include_basepath
39
39
  @fname = fname
40
+ @logger = defined?($log) ? $log : nil
40
41
  end
41
42
 
42
43
  def parse!
@@ -99,7 +100,7 @@ module Fluent
99
100
 
100
101
  elsif root_element && skip(/(\@include|include)#{SPACING}/)
101
102
  if !prev_match.start_with?('@')
102
- $log.warn "'include' is deprecated. Use '@include' instead"
103
+ @logger.warn "'include' is deprecated. Use '@include' instead" if @logger
103
104
  end
104
105
  parse_include(attrs, elems)
105
106
 
@@ -123,7 +124,7 @@ module Fluent
123
124
  parse_error! "'@' is the system reserved prefix. Don't use '@' prefix parameter in the configuration: #{k}"
124
125
  else
125
126
  # TODO: This is for backward compatibility. It will throw an error in the future.
126
- $log.warn "'@' is the system reserved prefix. It works in the nested configuration for now but it will be rejected: #{k}"
127
+ @logger.warn "'@' is the system reserved prefix. It works in the nested configuration for now but it will be rejected: #{k}" if @logger
127
128
  end
128
129
  end
129
130
 
data/lib/fluent/env.rb CHANGED
@@ -15,13 +15,14 @@
15
15
  #
16
16
 
17
17
  require 'serverengine/utils'
18
+ require 'fluent/oj_options'
18
19
 
19
20
  module Fluent
20
21
  DEFAULT_CONFIG_PATH = ENV['FLUENT_CONF'] || '/etc/fluent/fluent.conf'
21
22
  DEFAULT_PLUGIN_DIR = ENV['FLUENT_PLUGIN'] || '/etc/fluent/plugin'
22
23
  DEFAULT_SOCKET_PATH = ENV['FLUENT_SOCKET'] || '/var/run/fluent/fluent.sock'
23
24
  DEFAULT_BACKUP_DIR = ENV['FLUENT_BACKUP_DIR'] || '/tmp/fluent'
24
- DEFAULT_OJ_OPTIONS = {bigdecimal_load: :float, mode: :compat, use_to_json: true}
25
+ DEFAULT_OJ_OPTIONS = Fluent::OjOptions.load_env
25
26
  DEFAULT_DIR_PERMISSION = 0755
26
27
  DEFAULT_FILE_PERMISSION = 0644
27
28
 
data/lib/fluent/log.rb CHANGED
@@ -49,6 +49,7 @@ module Fluent
49
49
  LOG_TYPE_DEFAULT = :default # show logs in all supervisor/workers, with worker id in workers (default)
50
50
 
51
51
  LOG_TYPES = [LOG_TYPE_SUPERVISOR, LOG_TYPE_WORKER0, LOG_TYPE_DEFAULT].freeze
52
+ LOG_ROTATE_AGE = %w(daily weekly monthly)
52
53
 
53
54
  def self.str_to_level(log_level_str)
54
55
  case log_level_str.downcase
@@ -0,0 +1,62 @@
1
+ require 'fluent/config/types'
2
+
3
+ module Fluent
4
+ class OjOptions
5
+ OPTIONS = {
6
+ 'bigdecimal_load': :symbol,
7
+ 'max_nesting': :integer,
8
+ 'mode': :symbol,
9
+ 'use_to_json': :bool
10
+ }
11
+
12
+ ALLOWED_VALUES = {
13
+ 'bigdecimal_load': %i[bigdecimal float auto],
14
+ 'mode': %i[strict null compat json rails object custom]
15
+ }
16
+
17
+ DEFAULTS = {
18
+ 'bigdecimal_load': :float,
19
+ 'mode': :compat,
20
+ 'use_to_json': true
21
+ }
22
+
23
+ @@available = false
24
+
25
+ def self.available?
26
+ @@available
27
+ end
28
+
29
+ def self.load_env
30
+ options = self.get_options
31
+ begin
32
+ require 'oj'
33
+ Oj.default_options = options
34
+ @@available = true
35
+ rescue LoadError
36
+ @@available = false
37
+ end
38
+ options
39
+ end
40
+
41
+ private
42
+
43
+ def self.get_options
44
+ options = {}
45
+ DEFAULTS.each { |key, value| options[key] = value }
46
+
47
+ OPTIONS.each do |key, type|
48
+ env_value = ENV["FLUENT_OJ_OPTION_#{key.upcase}"]
49
+ next if env_value.nil?
50
+
51
+ cast_value = Fluent::Config.reformatted_value(OPTIONS[key], env_value, { strict: true })
52
+ next if cast_value.nil?
53
+
54
+ next if ALLOWED_VALUES[key] && !ALLOWED_VALUES[key].include?(cast_value)
55
+
56
+ options[key.to_sym] = cast_value
57
+ end
58
+
59
+ options
60
+ end
61
+ end
62
+ end
@@ -46,6 +46,48 @@ module Fluent
46
46
  end
47
47
  end
48
48
 
49
+ class Win32Error < StandardError
50
+ require 'windows/error'
51
+ include Windows::Error
52
+
53
+ attr_reader :errcode, :msg
54
+
55
+ WSABASEERR = 10000
56
+
57
+ def initialize(errcode, msg = nil)
58
+ @errcode = errcode
59
+ @msg = msg
60
+ end
61
+
62
+ def format_english_message(errcode)
63
+ buf = 0.chr * 260
64
+ flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY
65
+ english_lang_id = 1033 # The result of MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)
66
+ FormatMessageA.call(flags, 0, errcode, english_lang_id, buf, buf.size, 0)
67
+ buf.force_encoding(Encoding.default_external).strip
68
+ end
69
+
70
+ def to_s
71
+ msg = super
72
+ msg << ": code: #{@errcode}, #{format_english_message(@errcode)}"
73
+ msg << " - #{@msg}" if @msg
74
+ msg
75
+ end
76
+
77
+ def inspect
78
+ "#<#{to_s}>"
79
+ end
80
+
81
+ def ==(other)
82
+ return false if other.class != Win32Error
83
+ @errcode == other.errcode && @msg == other.msg
84
+ end
85
+
86
+ def wsaerr?
87
+ @errcode >= WSABASEERR
88
+ end
89
+ end
90
+
49
91
  # To open and get stat with setting FILE_SHARE_DELETE
50
92
  class WindowsFile
51
93
  require 'windows/file'
@@ -77,11 +119,14 @@ module Fluent
77
119
  @file_handle = CreateFile.call(@path, access, sharemode,
78
120
  0, creationdisposition, FILE_ATTRIBUTE_NORMAL, 0)
79
121
  if @file_handle == INVALID_HANDLE_VALUE
80
- err = GetLastError.call
81
- if err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND || err == ERROR_ACCESS_DENIED
82
- raise SystemCallError.new(2)
122
+ win32err = Win32Error.new(Win32::API.last_error, path)
123
+ errno = ServerEngine::RbWinSock.rb_w32_map_errno(win32err.errcode)
124
+ if errno == Errno::EINVAL::Errno || win32err.wsaerr?
125
+ # maybe failed to map
126
+ raise win32err
127
+ else
128
+ raise SystemCallError.new(win32err.message, errno)
83
129
  end
84
- raise SystemCallError.new(err)
85
130
  end
86
131
  end
87
132