fluent-plugin-record-sort 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a597fc13e52932c701e620431cafd05bdc5b78b9f89d7b78dbd35adbb4427c00
4
+ data.tar.gz: f27104cea5600636f4fcb70fe52a5a8776aa1469481ed059759abb68a43adbd7
5
+ SHA512:
6
+ metadata.gz: 15d3b4b87ceba36c922c8861adcc6e3faa42f534b9978bced01bb7c6aecc345041b2f7cdfbe4349420259486a02357a7002f31c85733657d125c575332283b0e
7
+ data.tar.gz: 7aaa2eba49f30fcdbe8a38910ebe6d4668b89b989a0cedbd5ab3c0a324a19cfca55c2e4c2565df818e351e8c78f6e9c3408000a9c7c2ab13373629621f2a77e7
@@ -0,0 +1,70 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.3
11
+
12
+ # Specify service dependencies here if necessary
13
+ # CircleCI maintains a library of pre-built images
14
+ # documented at https://circleci.com/docs/2.0/circleci-images/
15
+ # - image: circleci/postgres:9.4
16
+
17
+ working_directory: ~/repo
18
+
19
+ steps:
20
+ - checkout
21
+
22
+ # Download and cache dependencies
23
+ - restore_cache:
24
+ keys:
25
+ - v1-dependencies-{{ checksum "Gemfile" }}
26
+ # fallback to using the latest cache if no exact match is found
27
+ - v1-dependencies-
28
+
29
+ - run:
30
+ name: install dependencies
31
+ command: |
32
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
33
+
34
+ - save_cache:
35
+ paths:
36
+ - ./vendor/bundle
37
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
38
+
39
+ - run:
40
+ name: run default rake target
41
+ command: |
42
+ bundle exec rake
43
+
44
+ - run:
45
+ name: publish to rubygems.org
46
+ command: |
47
+ bin/deploy
48
+
49
+ - run:
50
+ name: list filesystem
51
+ command: find .
52
+
53
+ # run tests!
54
+ # - run:
55
+ # name: run tests
56
+ # command: |
57
+ # mkdir /tmp/test-results
58
+ # TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
59
+ #
60
+ # bundle exec rspec --format progress \
61
+ # --format RspecJunitFormatter \
62
+ # --out /tmp/test-results/rspec.xml \
63
+ # --format progress \
64
+ # $TEST_FILES
65
+ #
66
+ # collect reports
67
+ - store_test_results:
68
+ path: /tmp/test-results
69
+ - store_artifacts:
70
+ path: pkg
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # We're a library
14
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,4 @@
1
+ AllCops:
2
+ Exclude:
3
+ - fluent-plugin-record-sort.gemspec
4
+ - vendor/**/*
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.3
7
+ before_install: gem install bundler -v 1.16.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in fluent-plugin-record-sort.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Sam Pointer
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ # Fluentd Sort Plugin [![CircleCI](https://circleci.com/gh/sampointer/fluent-plugin-record-sort.svg?style=shield)](https://circleci.com/gh/sampointer/fluent-plugin-record-sort)
2
+
3
+ ## Introduction
4
+ This plugin does two things:
5
+
6
+ * Sorts the field in each record according to the default ruby `#Array.sort`
7
+ * Removes fields who's values it considers to either be `nil?` or `empty?`
8
+
9
+ ## Configuration
10
+ ```xml
11
+ <filter **>
12
+ @type record_sort
13
+ </filter>
14
+ ```
15
+
16
+ ## Rationale
17
+ AWS Athena and Glue prefer sorted JSON in S3 that has truthy values for all keys.
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: %i[rubocop spec build]
@@ -0,0 +1,2 @@
1
+ ---
2
+ :rubygems_api_key: REPLACEME
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'fluent/plugin/record/sort'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
@@ -0,0 +1,16 @@
1
+ #!/bin/bash
2
+ #
3
+ # deploy to rubygems.
4
+
5
+ if [[ -z ${CI} ]]; then
6
+ echo "not running inside a CI system, exiting"
7
+ exit 1
8
+ fi
9
+
10
+ gem=$(ls pkg/*.gem | tail -1)
11
+ mkdir -p ~/.gem/
12
+ cp assets/credentials ~/.gem/credentials
13
+ sed -i "s/REPLACEME/${rubygems_api_key}/g" ~/.gem/credentials
14
+ chmod 0600 ~/.gem/credentials
15
+ echo "Pushing ${gem}"
16
+ gem push ${gem}
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,41 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'fluent/plugin/record/sort/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'fluent-plugin-record-sort'
7
+ spec.version = Fluent::Plugin::Record::Sort::VERSION
8
+ spec.authors = ['Sam Pointer']
9
+ spec.email = ['sam@outsidethe.net']
10
+ spec.summary = 'Fluentd plugin for sorting record fields.'
11
+ spec.description = 'Fluentd plugin for sorting record fields.'
12
+ spec.homepage = 'https://github.com/sampointer/fluent-plugin-record-sort'
13
+ spec.license = 'MIT'
14
+
15
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the
16
+ # 'allowed_push_host' # to allow pushing to a single host or delete this
17
+ # section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
22
+ 'public gem pushes.'
23
+ end
24
+
25
+ # Specify which files should be added to the gem when it is released.
26
+ # The `git ls-files -z` loads the files in the RubyGem that have been added
27
+ # into git.
28
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
29
+ `git ls-files -z`.split("\x0").reject do |f|
30
+ f.match(%r{^(test|spec|features)/})
31
+ end
32
+ end
33
+ spec.bindir = 'exe'
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ['lib']
36
+
37
+ spec.add_development_dependency 'bundler', '~> 1.16'
38
+ spec.add_development_dependency 'rake', '~> 10.0'
39
+ spec.add_development_dependency 'rspec', '~> 3.0'
40
+ spec.add_development_dependency 'rubocop', '0.58.2'
41
+ end
@@ -0,0 +1,30 @@
1
+ require 'fluent/plugin/filter'
2
+ require 'fluent/config/error'
3
+
4
+ module Fluent
5
+ module Plugin
6
+ #
7
+ # Filter to sort records and remove fields with no value
8
+ #
9
+ class RecordSortFilter < Fluent::Plugin::Filter
10
+ Fluent::Plugin.register_filter('record_sort', self)
11
+ def configure(conf)
12
+ super
13
+ end
14
+
15
+ def filter(_tag, _time, record)
16
+ # Remove empty fields
17
+ begin
18
+ record.reject! do |_k, v|
19
+ v.nil? || (v.respond_to?(:empty?) && v.empty?)
20
+ end
21
+ rescue NoMethodError
22
+ log.warn('record_sort plugin has rescued NoMethodError, meaning it'\
23
+ ' let an object pass through without empty field filtering')
24
+ end
25
+
26
+ record.sort.to_h
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,12 @@
1
+ require 'fluent/plugin/record/sort/version'
2
+
3
+ module Fluent
4
+ module Plugin
5
+ module Record
6
+ # Container
7
+ module Sort
8
+ # Your code goes here...
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ module Fluent
2
+ module Plugin
3
+ module Record
4
+ module Sort
5
+ VERSION = '0.1.0'.freeze
6
+ end
7
+ end
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-record-sort
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sam Pointer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-06 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.58.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.58.2
69
+ description: Fluentd plugin for sorting record fields.
70
+ email:
71
+ - sam@outsidethe.net
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".circleci/config.yml"
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".rubocop.yml"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - assets/credentials
86
+ - bin/console
87
+ - bin/deploy
88
+ - bin/setup
89
+ - fluent-plugin-record-sort.gemspec
90
+ - lib/fluent/plugin/filter_record_sort.rb
91
+ - lib/fluent/plugin/record/sort.rb
92
+ - lib/fluent/plugin/record/sort/version.rb
93
+ homepage: https://github.com/sampointer/fluent-plugin-record-sort
94
+ licenses:
95
+ - MIT
96
+ metadata:
97
+ allowed_push_host: https://rubygems.org
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.7.7
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Fluentd plugin for sorting record fields.
118
+ test_files: []