fluent-plugin-bunyan 0.0.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9f1d27ed2bb3fd6efe6d8a60caacf5e53a3da13c08e72ad217514f93d20b2b4d
4
+ data.tar.gz: 83fac6065435fb21ec697cea73673830f97387155bdae69859ce53596769014b
5
+ SHA512:
6
+ metadata.gz: a09cbfb473f5cf39bdba75fb25d83e7962d2348d4b76bc2f8026ff0bbbb208b585f47ea70c87610ae0297c4aae6bb827d75b04eb554ac7e828a1c9e19a4ec13e
7
+ data.tar.gz: c1b768920ca490d12ecc6d6dc40a16915d4c1d1c5f9080954eb9cdbdffebad70a239b51bc3d297643607f74085727b191bf7ed7b577956ff0d2bff14eb30a60e
@@ -0,0 +1,56 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ ## Documentation cache and generated files:
36
+ /.yardoc/
37
+ /_yardoc/
38
+ /doc/
39
+ /rdoc/
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ # Gemfile.lock
49
+ # .ruby-version
50
+ # .ruby-gemset
51
+
52
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
+ .rvmrc
54
+
55
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
+ # .rubocop-https?--*
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+
3
+ This file contains changes throughout the life of this project.
4
+
5
+ ### Development
6
+ [Full Changelog](https://github.com/gildas/fluent-plugin-bunyan/compare/v0.0.2...dev)
7
+
8
+ New Features:
9
+ * None Yet
10
+
11
+ Bug Fixes:
12
+ * None Yet
13
+
14
+ ### [0.0.2] / 2020-03-10
15
+
16
+ Bug Fixes:
17
+ * The GEM spec requires rake version 12.3.3 at least.
18
+ There is a vulnerability before rake 12.3.3: [CVE-2020-8130](https://github.com/advisories/GHSA-jppv-gw3r-w3q8).
19
+ We just should be on the safe side...
20
+
21
+ ### [0.0.1] / 2020-03-10
22
+
23
+ Initial Release
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,48 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fluent-plugin-bunyan (0.1.0)
5
+ fluentd (>= 0.14.10, < 2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ concurrent-ruby (1.1.6)
11
+ cool.io (1.6.0)
12
+ fluentd (1.9.3)
13
+ cool.io (>= 1.4.5, < 2.0.0)
14
+ http_parser.rb (>= 0.5.1, < 0.7.0)
15
+ msgpack (>= 1.3.1, < 2.0.0)
16
+ serverengine (>= 2.0.4, < 3.0.0)
17
+ sigdump (~> 0.2.2)
18
+ strptime (>= 0.2.2, < 1.0.0)
19
+ tzinfo (>= 1.0, < 3.0)
20
+ tzinfo-data (~> 1.0)
21
+ yajl-ruby (~> 1.0)
22
+ http_parser.rb (0.6.0)
23
+ msgpack (1.3.3)
24
+ power_assert (0.2.7)
25
+ rake (13.0.1)
26
+ serverengine (2.2.1)
27
+ sigdump (~> 0.2.2)
28
+ sigdump (0.2.4)
29
+ strptime (0.2.3)
30
+ test-unit (3.2.5)
31
+ power_assert
32
+ tzinfo (2.0.1)
33
+ concurrent-ruby (~> 1.0)
34
+ tzinfo-data (1.2019.3)
35
+ tzinfo (>= 1.0.0)
36
+ yajl-ruby (1.4.1)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ bundler (~> 1.14)
43
+ fluent-plugin-bunyan!
44
+ rake (>= 12.3.3)
45
+ test-unit (~> 3.0)
46
+
47
+ BUNDLED WITH
48
+ 1.16.1
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Gildas Cherruel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,44 @@
1
+ # fluent-plugin-bunyan
2
+
3
+ [Fluentd](https://fluentd.org/) parser plugin to process logs from applications that write [bunyan](https://github.com/gildas/go-logger/blob/master/trentm/node-bunyan) logs.
4
+
5
+ The plugin requires [Fluentd](https://fluentd.org/) 1.0 at least.
6
+
7
+ | | |
8
+ ---|---|
9
+ master | [![Build Status](https://dev.azure.com/keltiek/gildas/_apis/build/status/gildas.fluent-plugin-bunyan?branchName=master)](https://dev.azure.com/keltiek/gildas/_build/latest?definitionId=4&branchName=master)
10
+ dev | [![Build Status](https://dev.azure.com/keltiek/gildas/_apis/build/status/gildas.fluent-plugin-bunyan?branchName=dev)](https://dev.azure.com/keltiek/gildas/_build/latest?definitionId=4&branchName=dev)
11
+
12
+ ## Installation
13
+
14
+ Pretty straight forward:
15
+ ```console
16
+ $ gem install fluent-plugin-bunyan
17
+ ```
18
+
19
+ ## Configuration
20
+
21
+ Simply add the parser to the [Fluentd](https://fluentd.org/) configuration file, for example:
22
+
23
+ ```xml
24
+ <source>
25
+ @type tail # say the logs come from stdout
26
+ <parse>
27
+ @type bunyan
28
+ </parse>
29
+ </source>
30
+ ```
31
+
32
+ ## Testing
33
+
34
+ To run the unit tests, make sure you have the [Fluentd](https://fluentd.org/) gem installed and run:
35
+
36
+ ```console
37
+ bundle exec rake test
38
+ ```
39
+
40
+ ## Copyright
41
+
42
+ * Copyright(c) 2020- Gildas Cherruel
43
+ * License
44
+ * Apache License, Version 2.0
@@ -0,0 +1,13 @@
1
+ require "bundler"
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs.push("lib", "test")
8
+ t.test_files = FileList["test/**/test_*.rb"]
9
+ t.verbose = true
10
+ t.warning = true
11
+ end
12
+
13
+ task default: [:test]
@@ -0,0 +1,24 @@
1
+ # Ruby
2
+ # Package your Ruby project.
3
+ # Add steps that install rails, analyze code, save build artifacts, deploy, and more:
4
+ # https://docs.microsoft.com/azure/devops/pipelines/languages/ruby
5
+
6
+ trigger:
7
+ - master
8
+ - dev
9
+
10
+ pool:
11
+ vmImage: 'ubuntu-latest'
12
+
13
+ steps:
14
+ - task: UseRubyVersion@0
15
+ inputs:
16
+ versionSpec: '>= 2.5'
17
+
18
+ - script: |
19
+ gem install bundler -v 1.16.1
20
+ bundle install --retry=3 --jobs=4
21
+ displayName: 'bundle install'
22
+
23
+ - script: bundle exec rake
24
+ displayName: 'bundle exec rake'
@@ -0,0 +1,31 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "fluent-plugin-bunyan"
6
+ spec.version = "0.0.2"
7
+ spec.authors = ["Gildas Cherruel"]
8
+ spec.email = ["gildas@breizh.org"]
9
+
10
+ spec.summary = %q{Fluentd Parser for applications that produce [Bunyan](https://github.com/trentm/node-bunyan) logs.}
11
+ spec.description = spec.summary
12
+ spec.homepage = "https://github.com/gildas/fluent-plugin-bunyan"
13
+ spec.license = "MIT"
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = spec.homepage
17
+ spec.metadata["changelog_uri"] = "https://github.com/gildas/fluent-plugin-bunyan/blob/master/CHANGELOG.md"
18
+
19
+ test_files, files = `git ls-files -z`.split("\x0").partition do |f|
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
22
+ spec.files = files
23
+ spec.executables = files.grep(%r{^bin/}) { |f| File.basename(f) }
24
+ spec.test_files = test_files
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.14"
28
+ spec.add_development_dependency "rake", ">= 12.3.3"
29
+ spec.add_development_dependency "test-unit", "~> 3.0"
30
+ spec.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"]
31
+ end
@@ -0,0 +1,54 @@
1
+ #
2
+ # Copyright 2020- Gildas Cherruel
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require "fluent/plugin/parser"
17
+ #require "fluent/parser"
18
+
19
+ module Fluent
20
+ module Plugin
21
+ class BunyanParser < JSONParser
22
+ Fluent::Plugin.register_parser("bunyan", self)
23
+
24
+ def configure(conf)
25
+ conf["time_format"] = "%iso8601"
26
+ super(conf)
27
+ end
28
+
29
+ def parse(text)
30
+ super(text) do |time, record|
31
+ record["severity"] = severity(record["level"] || 0)
32
+ record["host"] = record.delete("hostname")
33
+ record["message"] = record.delete("msg")
34
+
35
+ record.delete("v")
36
+ yield time, record
37
+ end
38
+ end
39
+
40
+ def severity(level)
41
+ return "fatal" if level >= 60
42
+ return "error" if level >= 50
43
+ return "warn" if level >= 40
44
+ return "info" if level >= 30
45
+ return "debug" if level >= 20
46
+ return "trace"
47
+ end
48
+
49
+ def version
50
+ return "0.0.2"
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.expand_path("../../", __FILE__))
2
+ require "test-unit"
3
+ require "fluent/test"
4
+ require "fluent/test/driver/parser"
5
+ require "fluent/test/helpers"
6
+
7
+ Test::Unit::TestCase.include(Fluent::Test::Helpers)
8
+ Test::Unit::TestCase.extend(Fluent::Test::Helpers)
@@ -0,0 +1,89 @@
1
+ require "helper"
2
+ require "fluent/plugin/parser_bunyan.rb"
3
+
4
+ class BunyanParserTest < Test::Unit::TestCase
5
+ setup do
6
+ Fluent::Test.setup
7
+ end
8
+
9
+ CONFIG = %[
10
+ pattern apache
11
+ ]
12
+
13
+ sub_test_case "parse" do
14
+ test "can parse simple entry" do
15
+ driver = create_driver(CONFIG)
16
+ text = '{"hostname":"helloworld-go-helloworld-5649dfd7bd-k8954","level":30,"msg":"The message","name":"helloworld","pid":1,"scope":"main","tid":1,"time":"2020-03-10T07:08:41Z","topic":"main","v":0}'
17
+ expected_time = Time.utc(2020, 3, 10, 7, 8, 41).to_i
18
+ expected_record = {
19
+ "host" => "helloworld-go-helloworld-5649dfd7bd-k8954",
20
+ "name" => "helloworld",
21
+ "severity" => "info",
22
+ "level" => 30,
23
+ "message" => "The message",
24
+ "topic" => "main",
25
+ "scope" => "main",
26
+ "pid" => 1,
27
+ "tid" => 1,
28
+ }
29
+ driver.instance.parse(text) do |time, record|
30
+ assert_equal(expected_record, record)
31
+ assert_equal(expected_time, time)
32
+ end
33
+ end
34
+
35
+ test "can parse entry with custom properties" do
36
+ driver = create_driver(CONFIG)
37
+ text = '{"hostname":"helloworld-go-helloworld-5649dfd7bd-k8954","level":50,"msg":"Failed to be happy","name":"helloworld","pid":1,"reqid":"0ba850ff-1e1f-4bcf-8288-135927bb850f","scope":"start","tid":21,"time":"2020-03-10T15:04:19Z","topic":"server","v":0}'
38
+ expected_time = Time.utc(2020, 3, 10, 15, 4, 19).to_i
39
+ expected_record = {
40
+ "host" => "helloworld-go-helloworld-5649dfd7bd-k8954",
41
+ "name" => "helloworld",
42
+ "severity" => "error",
43
+ "level" => 50,
44
+ "message" => "Failed to be happy",
45
+ "topic" => "server",
46
+ "scope" => "start",
47
+ "pid" => 1,
48
+ "tid" => 21,
49
+ "reqid" => "0ba850ff-1e1f-4bcf-8288-135927bb850f",
50
+ }
51
+ driver.instance.parse(text) do |time, record|
52
+ assert_equal(expected_record, record)
53
+ assert_equal(expected_time, time)
54
+ end
55
+ end
56
+
57
+ test "can parse entry with complex custom properties" do
58
+ driver = create_driver(CONFIG)
59
+ text = '{"hostname":"helloworld-go-helloworld-5649dfd7bd-k8954","level":50,"msg":"Failed to be happy","name":"helloworld","pid":1,"err":{"text": "aouch", "code": 404},"reqid":"0ba850ff-1e1f-4bcf-8288-135927bb850f","scope":"start","tid":21,"time":"2020-03-10T15:04:19Z","topic":"server","v":0}'
60
+ expected_time = Time.utc(2020, 3, 10, 15, 4, 19).to_i
61
+ expected_record = {
62
+ "host" => "helloworld-go-helloworld-5649dfd7bd-k8954",
63
+ "name" => "helloworld",
64
+ "severity" => "error",
65
+ "level" => 50,
66
+ "message" => "Failed to be happy",
67
+ "topic" => "server",
68
+ "scope" => "start",
69
+ "pid" => 1,
70
+ "tid" => 21,
71
+ "reqid" => "0ba850ff-1e1f-4bcf-8288-135927bb850f",
72
+ "err" => {
73
+ "code" => 404,
74
+ "text" => "aouch",
75
+ },
76
+ }
77
+ driver.instance.parse(text) do |time, record|
78
+ assert_equal(expected_record, record)
79
+ assert_equal(expected_time, time)
80
+ end
81
+ end
82
+ end
83
+
84
+ private
85
+
86
+ def create_driver(conf = CONFIG)
87
+ Fluent::Test::Driver::Parser.new(Fluent::Plugin::BunyanParser).configure(conf)
88
+ end
89
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-bunyan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Gildas Cherruel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-03-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 12.3.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 12.3.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fluentd
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.14.10
62
+ - - "<"
63
+ - !ruby/object:Gem::Version
64
+ version: '2'
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 0.14.10
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: '2'
75
+ description: Fluentd Parser for applications that produce [Bunyan](https://github.com/trentm/node-bunyan)
76
+ logs.
77
+ email:
78
+ - gildas@breizh.org
79
+ executables: []
80
+ extensions: []
81
+ extra_rdoc_files: []
82
+ files:
83
+ - ".gitignore"
84
+ - CHANGELOG.md
85
+ - Gemfile
86
+ - Gemfile.lock
87
+ - LICENSE
88
+ - README.md
89
+ - Rakefile
90
+ - azure-pipelines.yml
91
+ - fluent-plugin-bunyan.gemspec
92
+ - lib/fluent/plugin/parser_bunyan.rb
93
+ - test/helper.rb
94
+ - test/plugin/test_parser_bunyan.rb
95
+ homepage: https://github.com/gildas/fluent-plugin-bunyan
96
+ licenses:
97
+ - MIT
98
+ metadata:
99
+ homepage_uri: https://github.com/gildas/fluent-plugin-bunyan
100
+ source_code_uri: https://github.com/gildas/fluent-plugin-bunyan
101
+ changelog_uri: https://github.com/gildas/fluent-plugin-bunyan/blob/master/CHANGELOG.md
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.7.6
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Fluentd Parser for applications that produce [Bunyan](https://github.com/trentm/node-bunyan)
122
+ logs.
123
+ test_files:
124
+ - test/helper.rb
125
+ - test/plugin/test_parser_bunyan.rb