fluent-plugin-logdna 0.3.1 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7dc5c3a579927d59c9a9705bd5ceec17d5a6dc3d8964d1639dd51afb23eaca80
4
- data.tar.gz: 2519afb42481d5840bd11b5d579637e4ea55008dc89996421013185d76439374
3
+ metadata.gz: f3c61cb20aee4655e2214d113b957d810e9347f48faed5c0e25d11b17756f619
4
+ data.tar.gz: 0ee054acb8ecffe663aee5e30ad56602d79b2020d9e7fd6762b084bb05cad303
5
5
  SHA512:
6
- metadata.gz: 511d77f656a7584723954052a7f4c0e70b39f8115f88cbfff2369b1d9e7388fac35242ff9b52a5e0b6b2292e73c757a3efb1025833bfd6b9a96dd9ef1437fad5
7
- data.tar.gz: c1058ffb07ab69ad383c3b1d8015aaf912ebe3d0632c612c6e63d2ba41b75c6b930fa03f8f4a415c066501bbf4ab38f900f8728b9d630cf41bee002f5b8f6b2c
6
+ metadata.gz: 8b78ca28b43d342694fa585c7fe3dbafdb993bacc8db24701c5ae955adb3291c0d12a8e83a84e082a74d2d2c2e2cf77df951975a80c912ce5f429cec7126a26a
7
+ data.tar.gz: 75898267356efe81538acfb82abeacefc566e7bd667c1bb263b84b113d4838e0d9f828a8105d183a1c655171638d74cc2ecebd913f2b2a59a3060ff5403f8441
@@ -0,0 +1,126 @@
1
+ version: 2.1
2
+ tagged_build_filters: &tagged_build_filters
3
+ branches:
4
+ ignore: /.*/
5
+ tags:
6
+ only: /v[0-9]+\.[0-9]+\.[0-9]+/
7
+ test_build_filters: &test_build_filters
8
+ branches:
9
+ only: /.*/
10
+ tags:
11
+ ignore: /v[0-9]+\.[0-9]+\.[0-9]+/
12
+ executors:
13
+ releaser:
14
+ docker:
15
+ - image: circleci/golang:1.12
16
+ ruby265:
17
+ docker:
18
+ - image: circleci/ruby:2.6.5
19
+ ruby23:
20
+ docker:
21
+ - image: circleci/ruby:2.3
22
+ jobs:
23
+ test:
24
+ parameters:
25
+ ruby:
26
+ type: executor
27
+ executor: << parameters.ruby >>
28
+ steps:
29
+ - checkout
30
+ - run: bundle install
31
+ - run: rubocop -c .rubocop.yml
32
+ - run: rake test
33
+ build:
34
+ executor: ruby265
35
+ steps:
36
+ - checkout
37
+ - run:
38
+ name: Check Tagged Push
39
+ command: |
40
+ PKG_VERSION=$(cat fluent-plugin-logdna.gemspec | grep "\.version" | cut -d'"' -f2)
41
+ if [[ "${CIRCLE_TAG}" != "v${PKG_VERSION}" ]]; then
42
+ echo "There is mismatch:"
43
+ echo " TAG_VERSION: ${CIRCLE_TAG}"
44
+ echo " PKG_VERSION: v${PKG_VERSION}"
45
+ exit 1
46
+ fi
47
+ - run: gem build fluent-plugin-logdna.gemspec
48
+ - persist_to_workspace:
49
+ root: .
50
+ paths:
51
+ - ./fluent-plugin-logdna-*.gem
52
+ release:
53
+ executor: releaser
54
+ steps:
55
+ - attach_workspace:
56
+ at: .
57
+ - run: go get -u github.com/tcnksm/ghr
58
+ - run:
59
+ name: Create a Release
60
+ command: |
61
+ ghr \
62
+ -n "LogDNA Ruby Logger ${CIRCLE_TAG}" \
63
+ -t ${GITHUB_TOKEN} \
64
+ -u ${CIRCLE_PROJECT_USERNAME} \
65
+ -r ${CIRCLE_PROJECT_REPONAME} \
66
+ -draft ${CIRCLE_TAG} ./
67
+ - persist_to_workspace:
68
+ root: .
69
+ paths:
70
+ - ./fluent-plugin-logdna-*.gem
71
+ approve:
72
+ machine: true
73
+ steps:
74
+ - attach_workspace:
75
+ at: .
76
+ - persist_to_workspace:
77
+ root: .
78
+ paths:
79
+ - ./fluent-plugin-logdna-*.gem
80
+ publish:
81
+ executor: ruby265
82
+ steps:
83
+ - attach_workspace:
84
+ at: .
85
+ - run:
86
+ name: Setup gem credentials
87
+ command: |
88
+ mkdir -p ~/.gem
89
+ cat \<<EOF > ~/.gem/credentials
90
+ ---
91
+ :rubygems_api_key: ${RUBYGEMS_API_KEY}
92
+ EOF
93
+ chmod 0600 ~/.gem/credentials
94
+ - run: gem push *.gem
95
+ workflows:
96
+ update:
97
+ jobs:
98
+ - test:
99
+ matrix:
100
+ parameters:
101
+ ruby: [ruby23, ruby265]
102
+ filters: *tagged_build_filters
103
+ - build:
104
+ requires:
105
+ - test
106
+ filters: *tagged_build_filters
107
+ - release:
108
+ requires:
109
+ - build
110
+ filters: *tagged_build_filters
111
+ - approve:
112
+ type: approval
113
+ requires:
114
+ - release
115
+ filters: *tagged_build_filters
116
+ - publish:
117
+ requires:
118
+ - approve
119
+ filters: *tagged_build_filters
120
+ test:
121
+ jobs:
122
+ - test:
123
+ matrix:
124
+ parameters:
125
+ ruby: [ruby23, ruby265]
126
+ filters: *test_build_filters
data/.gitignore CHANGED
@@ -42,11 +42,12 @@ build-iPhoneSimulator/
42
42
 
43
43
  # for a library or gem, you might want to ignore these files since the code is
44
44
  # intended to run in multiple environments; otherwise, check them in:
45
- # Gemfile.lock
46
- # .ruby-version
47
- # .ruby-gemset
45
+ Gemfile.lock
46
+ .ruby-version
47
+ .ruby-gemset
48
48
 
49
49
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
50
  .rvmrc
51
51
 
52
- .DS_Store
52
+ .DS_Store
53
+ Makefile
@@ -0,0 +1,136 @@
1
+ # Too short methods lead to extraction of single-use methods, which can make
2
+ # the code easier to read (by naming things), but can also clutter the class
3
+ Metrics/MethodLength:
4
+ Max: 100
5
+
6
+ # The guiding principle of classes is SRP, SRP can't be accurately measured by LoC
7
+ Metrics/ClassLength:
8
+ Max: 1500
9
+
10
+ Metrics/AbcSize:
11
+ Max: 40
12
+
13
+ Metrics/CyclomaticComplexity:
14
+ Max: 40
15
+
16
+ Metrics/PerceivedComplexity:
17
+ Max: 40
18
+
19
+ # Commonly used screens these days easily fit more than 80 characters.
20
+ Layout/LineLength:
21
+ Max: 120
22
+
23
+ # Single quotes being faster is hardly measurable and only affects parse time.
24
+ # Enforcing double quotes reduces the times where you need to change them
25
+ # when introducing an interpolation. Use single quotes only if their semantics
26
+ # are needed.
27
+ Style/StringLiterals:
28
+ EnforcedStyle: double_quotes
29
+
30
+ # We do not need to support Ruby 1.9, so this is good to use.
31
+ Style/SymbolArray:
32
+ Enabled: true
33
+
34
+ # Mixing the styles looks just silly.
35
+ Style/HashSyntax:
36
+ EnforcedStyle: ruby19_no_mixed_keys
37
+
38
+ # has_key? and has_value? are far more readable than key? and value?
39
+ Style/PreferredHashMethods:
40
+ Enabled: false
41
+
42
+ # String#% is by far the least verbose and only object oriented variant.
43
+ Style/FormatString:
44
+ EnforcedStyle: percent
45
+
46
+ Style/CollectionMethods:
47
+ Enabled: true
48
+ PreferredMethods:
49
+ # inject seems more common in the community.
50
+ reduce: "inject"
51
+
52
+ Style/RescueStandardError:
53
+ Enabled: false
54
+
55
+ # Either allow this style or don't. Marking it as safe with parenthesis
56
+ # is silly. Let's try to live without them for now.
57
+ Style/ParenthesesAroundCondition:
58
+ AllowSafeAssignment: false
59
+
60
+ # A specialized exception class will take one or more arguments and construct the message from it.
61
+ # So both variants make sense.
62
+ Style/RaiseArgs:
63
+ Enabled: false
64
+
65
+ # Fail is an alias of raise. Avoid aliases, it's more cognitive load for no gain.
66
+ # The argument that fail should be used to abort the program is wrong too,
67
+ # there's Kernel#abort for that.
68
+ Style/SignalException:
69
+ EnforcedStyle: only_raise
70
+
71
+ Style/GuardClause:
72
+ Enabled: false
73
+
74
+ # { ... } for multi-line blocks is okay, follow Weirichs rule instead:
75
+ # https://web.archive.org/web/20140221124509/http://onestepback.org/index.cgi/Tech/Ruby/BraceVsDoEnd.rdoc
76
+ Style/BlockDelimiters:
77
+ Enabled: false
78
+
79
+ # do / end blocks should be used for side effects,
80
+ # methods that run a block for side effects and have
81
+ # a useful return value are rare, assign the return
82
+ # value to a local variable for those cases.
83
+ Style/MethodCalledOnDoEndBlock:
84
+ Enabled: true
85
+
86
+ # Enforcing the names of variables? To single letter ones? Just no.
87
+ Style/SingleLineBlockParams:
88
+ Enabled: false
89
+
90
+ # Shadowing outer local variables with block parameters is often useful
91
+ # to not reinvent a new name for the same thing, it highlights the relation
92
+ # between the outer variable and the parameter. The cases where it's actually
93
+ # confusing are rare, and usually bad for other reasons already, for example
94
+ # because the method is too long.
95
+ Lint/ShadowingOuterLocalVariable:
96
+ Enabled: false
97
+
98
+ Lint/AssignmentInCondition:
99
+ Enabled: false
100
+
101
+ # Check with yard instead.
102
+ Style/Documentation:
103
+ Enabled: false
104
+
105
+ # This is just silly. Calling the argument `other` in all cases makes no sense.
106
+ Naming/BinaryOperatorParameterName:
107
+ Enabled: false
108
+
109
+ # There are valid cases, for example debugging Cucumber steps,
110
+ # also they'll fail CI anyway
111
+ Lint/Debugger:
112
+ Enabled: false
113
+
114
+ Security/Eval:
115
+ Enabled: false
116
+ # Style preference
117
+ Style/MethodDefParentheses:
118
+ Enabled: false
119
+
120
+ Style/TrailingCommaInHashLiteral:
121
+ Enabled: false
122
+
123
+ Style/IfUnlessModifier:
124
+ Enabled: false
125
+
126
+ Lint/DuplicateMethods:
127
+ Enabled: true
128
+
129
+ Style/RedundantSelf:
130
+ Enabled: false
131
+
132
+ Style/NegatedIf:
133
+ Enabled: false
134
+
135
+ Style/SafeNavigation:
136
+ Enabled: false
@@ -0,0 +1,15 @@
1
+ # Contributing
2
+
3
+ ## Github Workflow
4
+
5
+ Contributions are always welcome! Be sure to follow the [github workflow](https://guides.github.com/introduction/flow/) when contributing to this project:
6
+
7
+ * Create an issue, or comment on an issue to indicate what you are working on. This avoids work duplication.
8
+ * Fork the repository and clone to your local machine
9
+ * You should already be on the default branch `master` - if not, check it out (`git checkout master`)
10
+ * Create a new branch for your feature/fix `git checkout -b my-new-feature`)
11
+ * Write your feature/fix
12
+ * Stage the changed files for a commit (`git add .`)
13
+ * Commit your files with a *useful* commit message ([example](https://github.com/Azure/azure-quickstart-templates/commit/53699fed9983d4adead63d9182566dec4b8430d4)) (`git commit`)
14
+ * Push your new branch to your GitHub Fork (`git push origin my-new-feature`)
15
+ * Visit this repository in GitHub and create a Pull Request.
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
2
4
 
3
5
  gemspec
4
6
 
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
- MIT License
1
+ The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 Answerbook, Inc.
3
+ Copyright (c) 2020 LogDNA
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -6,75 +6,84 @@ Using fluent-plugin-logdna, you can send the logs you collect with Fluentd to Lo
6
6
 
7
7
  ## Instructions
8
8
 
9
- * Install [Fluentd](http://www.fluentd.org/download)
10
- * Alternative install if using fluentd package manager (td-agent): `td-agent-gem install fluent-plugin-logdna`
11
- * Add the contents below to `/etc/fluent/fluent.conf`. For td-agent, use `/etc/td-agent/td-agent.conf`:
12
- * Alternative install without td-agent is: `gem install fluent-plugin-logdna`
9
+ * Requirements:
10
+ * `ruby >= 2.3`
11
+ * `fluentd < 2.0`
12
+ * Install Fluentd
13
+ * [Download here](http://www.fluentd.org/download)
14
+ * If using fluentd package manager (td-agent): `td-agent-gem install fluent-plugin-logdna`
15
+ * To install without td-agent: `gem install fluent-plugin-logdna`
16
+ * Add the config below to `/etc/fluent/fluent.conf`. For `td-agent`, `/etc/td-agent/td-agent.conf`:
17
+
18
+ ## Configuration
19
+
20
+ ### Configuration Parameters
21
+ - `api_key`: [Ingestion Key](https://docs.logdna.com/docs/ingestion-key), *Required*
22
+ - `hostname`: Hostname, *Required*
23
+ - `app`: App Name, *Optional*
24
+ - `mac`: MAC Address, *Optional*
25
+ - `ip`: IP Address, *Optional*
26
+ - `tags`: Comma-Separated List of Tags, *Optional*
27
+ - `request_timeout`: HTTPS POST Request Timeout, *Optional*
28
+ - **Note**: Supports `s` and `ms` Suffices
29
+ - **Default**: `30 s`
30
+ - `ingester_domain`: Custom Ingester URL, *Optional*
31
+ - **Default**: `htttps://logs.logdna.com`
32
+ - `ingester_endpoint`: Custom Ingester Endpoint, *Optional*
33
+ - **Default**: `/logs/ingest`
34
+
35
+ ### Sample Configuration
13
36
 
14
37
  ~~~~~configuration
15
38
  <match **>
16
39
  @type logdna
17
- api_key xxxxxxxxxxxxxxxxxxxxxxxxxxx # paste your api key here (required)
18
- hostname "#{Socket.gethostname}" # your hostname (required)
19
- app my_app # replace with your app name
20
- #mac C0:FF:EE:C0:FF:EE # optional mac address
21
- #ip 127.0.0.1 # optional ip address
22
- #tags web,dev # optional tags
23
- request_timeout 30000 ms # optional timeout for upload request, supports seconds (s, default) and milliseconds (ms) suffixes, default 30 seconds
24
- buffer_chunk_limit 1m # do not increase past 8m (8MB) or your logs will be rejected by our server.
25
- flush_at_shutdown true # only needed with file buffer
40
+ api_key xxxxxxxxxxxxxxxxxxxxxxxxxxx
41
+ hostname "#{Socket.gethostname}"
42
+ app my_app
43
+ mac C0:FF:EE:C0:FF:EE
44
+ ip 127.0.0.1
45
+ tags web,dev
46
+ request_timeout 30000 ms
47
+ ingester_domain https://logs.logdna.com
26
48
  </match>
27
49
  ~~~~~
28
50
 
29
- * Restart fluentd to pick up the configuration changes.
30
- * `sudo /etc/init.d/td-agent stop`
31
- * `sudo /etc/init.d/td-agent start`
51
+ ## Line Parameters
32
52
 
33
- ### Recommended Configuration Parameters
34
-
35
- * buffer_type
36
- * We recommend setting this to memory for development and file for production (file setting requires a buffer_path).
37
- * buffer_queue_limit, buffer_chunk_limit
38
- * We do not recommend increasing buffer_chunk_limit past 8MB.
39
- * flush_interval
40
- * Default is 60s. We recommend keeping this well above 5s.
41
- * retry_wait, max_retry_wait, retry_limit, disable_retry_limit
42
- * We recommend increasing these values if you are encountering problems.
43
-
44
- ### Options
45
-
46
- * App name and log level can also be provided on a line-by-line basis over JSON:
47
- * `_app` and `level` will override the config
48
-
49
- If you don't have a LogDNA account, you can create one on [https://logdna.com](https://logdna.com) or if you're on macOS w/[Homebrew](https://brew.sh) installed:
50
-
51
- ~~~~~bash
52
- brew cask install logdna-cli
53
- logdna register <email>
54
- # now paste the api key above
55
- ~~~~~
53
+ The following line parameters can be set to the information coming from each `record` object:
54
+ - `level`: [Level](https://github.com/logdna/logger-node#supported-log-levels): `record['level']` or `record['severity']` or the last `tag` given in each `record`
55
+ - `file`: File Name: set to `file` given in each `record`
56
+ - `app`: App Name: set to either `_app` or `app` given in each `record`
57
+ - **Default**: `app` given in the configuration
58
+ - `env`: Environment Name: set to `env` given in each `record`
59
+ - `meta`: Meta Object: set to `meta` given in each `record`
56
60
 
57
61
  ### LogDNA Pay-per-gig Pricing
58
62
 
59
- Our [paid plans](https://logdna.com/#pricing) start at $1.25/GB per month, pay for what you use / no fixed data buckets / all paid plans include all features.
63
+ Our [paid plans](https://logdna.com/pricing/) start at $1.25/GB per month, and it's based only on usage. There are no fixed data buckets and all paid plans include all features.
60
64
 
61
65
  ## Building a debian package for td-agent
62
66
 
63
- If you use td-agent you can build a debian package instead of installing via
64
- td-agent-gem. This requires that td-agent is already installed and that you've
65
- installed [fpm](http://fpm.readthedocs.io/en/latest/index.html). Then just run
66
- `make` in your git directory.
67
+ If you use td-agent you can build a debian package instead of installing via `td-agent-gem`. This requires that td-agent is already installed and that you've installed [fpm](http://fpm.readthedocs.io/en/latest/index.html). Then run `make` in your git directory.
67
68
 
68
69
  ~~~~~bash
69
- gem install --no-ri --no-rdoc fpm
70
+ gem install --no-document fpm
70
71
  git clone https://github.com/logdna/fluent-plugin-logdna
71
72
  cd fluent-plugin-logdna
72
- make
73
+ gem build fluent-plugin-logdna.gemspec
74
+ fpm --input-type gem --output-type deb \
75
+ --no-auto-depends \
76
+ --no-gem-fix-name \
77
+ --depends 'td-agent > 2' \
78
+ --deb-build-depends 'td-agent > 2' \
79
+ fluent-plugin-logdna-*.gem
73
80
  sudo dpkg -i fluent-plugin-logdna*.deb
74
81
  ~~~~~
75
82
 
76
83
  ## Additional Options
77
84
 
78
- For advanced configuration options, please refer to the [buffered output parameters documentation.](http://docs.fluentd.org/articles/output-plugin-overview#buffered-output-parameters)
85
+ For advanced configuration options, please refer to the [buffered output parameters documentation.](https://docs.fluentd.org/v/0.12/output#buffered-output-parameters)
79
86
 
80
87
  Questions or concerns? Contact [support@logdna.com](mailto:support@logdna.com).
88
+
89
+ Contributions are always welcome. See the [contributing guide](/CONTRIBUTING.md) to learn how you can help.
data/Rakefile CHANGED
@@ -1,8 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "set"
4
+ require "rake/clean"
5
+ require "rake/testtask"
2
6
 
3
7
  # Directory to place gems to bundle with our main gem
4
8
  PACKAGE_DIR = "pkg"
5
- require "rake/clean"
6
9
  CLOBBER.include PACKAGE_DIR
7
10
 
8
11
  desc "Copies gem dependencies to the #{PACKAGE_DIR} folder"
@@ -12,14 +15,14 @@ end
12
15
 
13
16
  desc "Copies gem dependencies which don't overlap with td-agent to the #{PACKAGE_DIR} folder"
14
17
  task "gemdep:minimal" do
15
- MINIMAL_GEMS = %W[
18
+ MINIMAL_GEMS = %w[
16
19
  unf_ext
17
20
  unf
18
21
  domain_name
19
22
  http-cookie
20
23
  http-form_data
21
24
  http
22
- ]
25
+ ].freeze
23
26
  gem_copy gen_gem_list MINIMAL_GEMS
24
27
  end
25
28
 
@@ -28,12 +31,11 @@ def gen_gem_list(subset = [])
28
31
  to_pull = Set[]
29
32
  Bundler.locked_gems.specs.each do |spec|
30
33
  next if spec.name == myself.name
34
+
31
35
  if subset.empty?
32
36
  to_pull.add(spec)
33
- else
34
- if subset.include? spec.name
35
- to_pull.add(spec)
36
- end
37
+ elsif subset.include? spec.name
38
+ to_pull.add(spec)
37
39
  end
38
40
  end
39
41
  to_pull
@@ -43,6 +45,10 @@ end
43
45
  # Bundler.app_cache with the gems of dependencies).
44
46
  def gem_copy(specs)
45
47
  Bundler.mkdir_p PACKAGE_DIR
46
- sources = specs.collect { |s| Bundler.app_cache.join "#{s.full_name}.gem" }
47
- FileUtils.cp sources, PACKAGE_DIR, :verbose => true
48
+ sources = specs.map { |s| Bundler.app_cache.join "#{s.full_name}.gem" }
49
+ FileUtils.cp sources, PACKAGE_DIR, verbose: true
50
+ end
51
+
52
+ Rake::TestTask.new do |task|
53
+ task.pattern = "test/**/*.rb"
48
54
  end
@@ -1,23 +1,24 @@
1
- # -*- encoding: utf-8 -*-
2
- require 'date'
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
3
4
 
4
5
  Gem::Specification.new do |s|
5
- s.name = 'fluent-plugin-logdna'
6
- s.version = '0.3.1'
6
+ s.name = "fluent-plugin-logdna"
7
+ s.version = "0.4.0"
7
8
  s.date = Date.today.to_s
8
- s.summary = 'LogDNA plugin for Fluentd'
9
- s.description = 'Fluentd plugin for supplying output to LogDNA.'
10
- s.authors = ['Edwin Lai']
11
- s.email = 'edwin@logdna.com'
12
- s.files = ['lib/fluent/plugin/out_logdna.rb']
13
- s.homepage = 'https://github.com/logdna/fluent-plugin-logdna'
14
- s.license = 'MIT'
9
+ s.summary = "LogDNA Plugin for Fluentd"
10
+ s.description = "Fluentd Plugin for Supplying Output to LogDNA."
11
+ s.authors = ["LogDNA, Inc."]
12
+ s.email = "help@logdna.com"
13
+ s.homepage = "https://github.com/logdna/fluent-plugin-logdna"
14
+ s.license = "MIT"
15
15
 
16
- s.require_paths = ['lib']
16
+ s.require_paths = ["lib"]
17
17
  s.files = `git ls-files -z`.split("\x0")
18
18
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- s.required_ruby_version = Gem::Requirement.new('>= 2.0.0')
19
+ s.required_ruby_version = Gem::Requirement.new(">= 2.3")
20
+ s.add_runtime_dependency "fluentd", ">= 0.12.0", "< 2"
21
+ s.add_runtime_dependency "http", "~> 2.0", ">= 2.0.3"
20
22
  s.add_development_dependency "bundler", "~> 1.16"
21
- s.add_runtime_dependency 'fluentd', '>= 0.12.0', '< 2'
22
- s.add_runtime_dependency 'http', '~> 2.0', '>= 2.0.3'
23
+ s.add_development_dependency "rubocop", "~> 0.78"
23
24
  end
@@ -1,8 +1,10 @@
1
- require 'fluent/output'
1
+ # frozen_string_literal: true
2
+
3
+ require "fluent/output"
2
4
 
3
5
  module Fluent
4
6
  class LogDNAOutput < Fluent::BufferedOutput
5
- Fluent::Plugin.register_output('logdna', self)
7
+ Fluent::Plugin.register_output("logdna", self)
6
8
 
7
9
  MAX_RETRIES = 5
8
10
 
@@ -13,20 +15,21 @@ module Fluent
13
15
  config_param :ip, :string, default: nil
14
16
  config_param :app, :string, default: nil
15
17
  config_param :file, :string, default: nil
16
- config_param :ingester_domain, :string, default: 'https://logs.logdna.com'
17
- config_param :request_timeout, :string, default: '30'
18
+ config_param :ingester_domain, :string, default: "https://logs.logdna.com"
19
+ config_param :ingester_endpoint, :string, default: "/logs/ingest"
20
+ config_param :request_timeout, :string, default: "30"
18
21
 
19
22
  def configure(conf)
20
23
  super
21
- @host = conf['hostname']
24
+ @host = conf["hostname"]
22
25
 
23
26
  # make these two variables globals
24
- timeout_unit_map = { s: 1.0, ms: 0.001 }
25
- timeout_regex = Regexp.new("^([0-9]+)\s*(#{timeout_unit_map.keys.join("|")})$")
27
+ timeout_unit_map = { s: 1.0, ms: 0.001 }
28
+ timeout_regex = Regexp.new("^([0-9]+)\s*(#{timeout_unit_map.keys.join('|')})$")
26
29
 
27
30
  # this section goes into this part of the code
28
31
  num_component = 30.0
29
- unit_component = 's'
32
+ unit_component = "s"
30
33
 
31
34
  timeout_regex.match(@request_timeout) do |match|
32
35
  num_component = match[1].to_f
@@ -38,10 +41,10 @@ module Fluent
38
41
 
39
42
  def start
40
43
  super
41
- require 'json'
42
- require 'base64'
43
- require 'http'
44
- HTTP.default_options = { :keep_alive_timeout => 60 }
44
+ require "json"
45
+ require "base64"
46
+ require "http"
47
+ HTTP.default_options = { keep_alive_timeout: 60 }
45
48
  @ingester = HTTP.persistent @ingester_domain
46
49
  @requests = Queue.new
47
50
  end
@@ -58,7 +61,8 @@ module Fluent
58
61
  def write(chunk)
59
62
  body = chunk_to_body(chunk)
60
63
  response = send_request(body)
61
- raise 'Encountered server error' if response.code >= 400
64
+ raise "Encountered server error" if response.code >= 400
65
+
62
66
  response.flush
63
67
  end
64
68
 
@@ -77,31 +81,31 @@ module Fluent
77
81
 
78
82
  def gather_line_data(tag, time, record)
79
83
  line = {
80
- level: record['level'] || record['severity'] || tag.split('.').last,
84
+ level: record["level"] || record["severity"] || tag.split(".").last,
81
85
  timestamp: time,
82
86
  line: record.to_json
83
87
  }
84
88
  # At least one of "file" or "app" is required.
85
- line[:file] = record['file']
89
+ line[:file] = record["file"]
86
90
  line[:file] ||= @file if @file
87
91
  line.delete(:file) if line[:file].nil?
88
- line[:app] = record['_app'] || record['app']
92
+ line[:app] = record["_app"] || record["app"]
89
93
  line[:app] ||= @app if @app
90
94
  line.delete(:app) if line[:app].nil?
91
- line[:env] = record['env']
95
+ line[:env] = record["env"]
92
96
  line.delete(:env) if line[:env].nil?
93
- line[:meta] = record['meta']
97
+ line[:meta] = record["meta"]
94
98
  line.delete(:meta) if line[:meta].nil?
95
99
  line
96
100
  end
97
101
 
98
102
  def send_request(body)
99
103
  now = Time.now.to_i
100
- url = "/logs/ingest?hostname=#{@host}&mac=#{@mac}&ip=#{@ip}&now=#{now}&tags=#{@tags}"
101
- @ingester.headers('apikey' => @api_key,
102
- 'content-type' => 'application/json')
103
- .timeout(connect: @request_timeout, write: @request_timeout, read: @request_timeout)
104
- .post(url, json: body)
104
+ url = "#{@ingester_endpoint}?hostname=#{@host}&mac=#{@mac}&ip=#{@ip}&now=#{now}&tags=#{@tags}"
105
+ @ingester.headers("apikey" => @api_key,
106
+ "content-type" => "application/json")
107
+ .timeout(connect: @request_timeout, write: @request_timeout, read: @request_timeout)
108
+ .post(url, json: body)
105
109
  end
106
110
  end
107
111
  end
@@ -1,4 +1,6 @@
1
- $LOAD_PATH.unshift(File.expand_path("../../", __FILE__))
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(File.expand_path("..", __dir__))
2
4
  require "test-unit"
3
5
  require "fluent/test"
4
6
  require "fluent/test/driver/output"
@@ -1,110 +1,109 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # https://docs.fluentd.org/plugin-development/api-plugin-output#how-to-write-tests
2
4
 
3
- require_relative '../helper'
4
- require 'fluent/test/driver/output'
5
- require 'fluent/plugin/out_stdout'
6
- require 'fluent/plugin/input'
7
- require 'webmock/test_unit'
8
- include WebMock::API
5
+ require_relative "../helper"
6
+ require "fluent/test/driver/output"
7
+ require "fluent/plugin/out_stdout"
8
+ require "fluent/plugin/input"
9
+ require "webmock/test_unit"
9
10
 
10
- require 'lib/fluent/plugin/out_logdna.rb'
11
+ require "lib/fluent/plugin/out_logdna.rb"
11
12
 
12
13
  class LogdnaOutputTest < Test::Unit::TestCase
14
+ include WebMock::API
15
+
13
16
  def setup
14
17
  Fluent::Test.setup
15
18
 
16
- stub_request(:post, /logs.logdna.com\/logs\/ingest/)
19
+ stub_request(:post, %r{logs.logdna.com/logs/ingest})
17
20
  end
18
21
 
19
22
  # default configuration for tests
20
- CONFIG = %[
23
+ CONFIG = %(
21
24
  api_key this-is-my-key
22
25
  hostname "localhost"
23
26
  app my_app
24
27
  mac C0:FF:EE:C0:FF:EE
25
28
  ip 127.0.0.1
26
29
  tags "my-tag"
27
- ]
30
+ )
28
31
 
29
32
  def create_driver(conf = CONFIG)
30
33
  Fluent::Test::Driver::Output.new(Fluent::LogDNAOutput).configure(conf)
31
34
  end
32
35
 
33
- sub_test_case 'configuration' do
34
- test 'instantiate the plugin and check default config values' do
35
- d = create_driver
36
- time = event_time
37
-
38
- # check defaults
39
- assert_equal 'https://logs.logdna.com', d.instance.ingester_domain
40
- assert_equal 30, d.instance.request_timeout
41
- end
42
-
43
- test 'instantiate the plugin and check setting config values' do
44
- conf = %[
45
- api_key this-is-my-key
46
- hostname "localhost"
47
- app my_app
48
- mac C0:FF:EE:C0:FF:EE
49
- ip 127.0.0.1
50
- tags "my-tag"
51
- request_timeout 17s
52
- ]
53
-
54
- d = create_driver(conf)
55
-
56
- # check set config values
57
- assert_equal 'my-tag', d.instance.tags
58
- assert_equal 17, d.instance.request_timeout
59
- end
60
-
61
- test 'instantiate the plugin with ms request_timeout value' do
62
-
63
- conf = %[
64
- api_key this-is-my-key
65
- hostname "localhost"
66
- app my_app
67
- mac C0:FF:EE:C0:FF:EE
68
- ip 127.0.0.1
69
- tags "my-tag"
70
- request_timeout 17000 ms
71
- ]
72
-
73
- d = create_driver(conf)
74
-
75
- # check set config values
76
- assert_equal 17, d.instance.request_timeout
77
- end
36
+ test "instantiate the plugin and check default config values" do
37
+ d = create_driver
78
38
 
79
- test 'instantiate the plugin with nonesense request_timeout value' do
39
+ # check defaults
40
+ assert_equal "https://logs.logdna.com", d.instance.ingester_domain
41
+ assert_equal 30, d.instance.request_timeout
42
+ end
80
43
 
81
- conf = %[
82
- api_key this-is-my-key
83
- hostname "localhost"
84
- app my_app
85
- mac C0:FF:EE:C0:FF:EE
86
- ip 127.0.0.1
87
- tags "my-tag"
88
- request_timeout "asdf ms"
89
- ]
44
+ test "instantiate the plugin and check setting config values" do
45
+ conf = %(
46
+ api_key this-is-my-key
47
+ hostname "localhost"
48
+ app my_app
49
+ mac C0:FF:EE:C0:FF:EE
50
+ ip 127.0.0.1
51
+ tags "my-tag"
52
+ request_timeout 17s
53
+ ingester_endpoint this/is/my/alternate/endpoint
54
+ )
55
+
56
+ d = create_driver(conf)
57
+
58
+ # check set config values
59
+ assert_equal "my-tag", d.instance.tags
60
+ assert_equal 17, d.instance.request_timeout
61
+ assert_equal "this/is/my/alternate/endpoint", d.instance.ingester_endpoint
62
+ end
90
63
 
91
- d = create_driver(conf)
64
+ test "instantiate the plugin with ms request_timeout value" do
65
+ conf = %(
66
+ api_key this-is-my-key
67
+ hostname "localhost"
68
+ app my_app
69
+ mac C0:FF:EE:C0:FF:EE
70
+ ip 127.0.0.1
71
+ tags "my-tag"
72
+ request_timeout 17000 ms
73
+ )
74
+
75
+ d = create_driver(conf)
76
+
77
+ # check set config values
78
+ assert_equal 17, d.instance.request_timeout
79
+ end
92
80
 
93
- # check set config values
94
- assert_equal 30, d.instance.request_timeout
95
- end
81
+ test "instantiate the plugin with nonesense request_timeout value" do
82
+ conf = %(
83
+ api_key this-is-my-key
84
+ hostname "localhost"
85
+ app my_app
86
+ mac C0:FF:EE:C0:FF:EE
87
+ ip 127.0.0.1
88
+ tags "my-tag"
89
+ request_timeout "asdf ms"
90
+ )
91
+
92
+ d = create_driver(conf)
93
+
94
+ # check set config values
95
+ assert_equal 30, d.instance.request_timeout
96
96
  end
97
97
 
98
- test 'simple #write' do
98
+ test "simple #write" do
99
99
  d = create_driver
100
100
  time = event_time
101
101
 
102
102
  d.run do
103
- d.feed("output.test", time, {'foo' => 'bar', 'message' => 'myLine'})
104
- d.feed("output.test", time, {'foo' => 'bar', 'message' => 'myLine'})
103
+ d.feed("output.test", time, { "foo" => "bar", "message" => "myLine" })
104
+ d.feed("output.test", time, { "foo" => "bar", "message" => "myLine" })
105
105
  end
106
106
 
107
107
  assert_equal(2, d.formatted.size)
108
108
  end
109
-
110
109
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-logdna
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
- - Edwin Lai
7
+ - LogDNA, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-21 00:00:00.000000000 Z
11
+ date: 2020-09-17 00:00:00.000000000 Z
12
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
13
  - !ruby/object:Gem::Dependency
28
14
  name: fluentd
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -64,18 +50,46 @@ dependencies:
64
50
  - - ">="
65
51
  - !ruby/object:Gem::Version
66
52
  version: 2.0.3
67
- description: Fluentd plugin for supplying output to LogDNA.
68
- email: edwin@logdna.com
53
+ - !ruby/object:Gem::Dependency
54
+ name: bundler
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.16'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '1.16'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rubocop
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '0.78'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '0.78'
81
+ description: Fluentd Plugin for Supplying Output to LogDNA.
82
+ email: help@logdna.com
69
83
  executables: []
70
84
  extensions: []
71
85
  extra_rdoc_files: []
72
86
  files:
87
+ - ".circleci/config.yml"
73
88
  - ".gitignore"
74
- - ".ruby-version"
89
+ - ".rubocop.yml"
90
+ - CONTRIBUTING.md
75
91
  - Gemfile
76
- - Gemfile.lock
77
92
  - LICENSE
78
- - Makefile
79
93
  - README.md
80
94
  - Rakefile
81
95
  - fluent-plugin-logdna.gemspec
@@ -94,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
108
  requirements:
95
109
  - - ">="
96
110
  - !ruby/object:Gem::Version
97
- version: 2.0.0
111
+ version: '2.3'
98
112
  required_rubygems_version: !ruby/object:Gem::Requirement
99
113
  requirements:
100
114
  - - ">="
@@ -104,5 +118,5 @@ requirements: []
104
118
  rubygems_version: 3.0.3
105
119
  signing_key:
106
120
  specification_version: 4
107
- summary: LogDNA plugin for Fluentd
121
+ summary: LogDNA Plugin for Fluentd
108
122
  test_files: []
@@ -1 +0,0 @@
1
- 2.3.1
@@ -1,70 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- fluent-plugin-logdna (0.3.1)
5
- fluentd (>= 0.12.0, < 2)
6
- http (~> 2.0, >= 2.0.3)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- addressable (2.7.0)
12
- public_suffix (>= 2.0.2, < 5.0)
13
- concurrent-ruby (1.1.6)
14
- cool.io (1.6.0)
15
- crack (0.4.3)
16
- safe_yaml (~> 1.0.0)
17
- domain_name (0.5.20190701)
18
- unf (>= 0.0.5, < 1.0.0)
19
- fluentd (1.11.1)
20
- cool.io (>= 1.4.5, < 2.0.0)
21
- http_parser.rb (>= 0.5.1, < 0.7.0)
22
- msgpack (>= 1.3.1, < 2.0.0)
23
- serverengine (>= 2.0.4, < 3.0.0)
24
- sigdump (~> 0.2.2)
25
- strptime (>= 0.2.2, < 1.0.0)
26
- tzinfo (>= 1.0, < 3.0)
27
- tzinfo-data (~> 1.0)
28
- yajl-ruby (~> 1.0)
29
- hashdiff (1.0.1)
30
- http (2.2.2)
31
- addressable (~> 2.3)
32
- http-cookie (~> 1.0)
33
- http-form_data (~> 1.0.1)
34
- http_parser.rb (~> 0.6.0)
35
- http-cookie (1.0.3)
36
- domain_name (~> 0.5)
37
- http-form_data (1.0.3)
38
- http_parser.rb (0.6.0)
39
- msgpack (1.3.3)
40
- public_suffix (4.0.3)
41
- rake (12.3.3)
42
- safe_yaml (1.0.5)
43
- serverengine (2.2.1)
44
- sigdump (~> 0.2.2)
45
- sigdump (0.2.4)
46
- strptime (0.2.4)
47
- tzinfo (2.0.2)
48
- concurrent-ruby (~> 1.0)
49
- tzinfo-data (1.2020.1)
50
- tzinfo (>= 1.0.0)
51
- unf (0.1.4)
52
- unf_ext
53
- unf_ext (0.0.7.7)
54
- webmock (3.8.3)
55
- addressable (>= 2.3.6)
56
- crack (>= 0.3.2)
57
- hashdiff (>= 0.4.0, < 2.0.0)
58
- yajl-ruby (1.4.1)
59
-
60
- PLATFORMS
61
- ruby
62
-
63
- DEPENDENCIES
64
- bundler (~> 1.16)
65
- fluent-plugin-logdna!
66
- rake (~> 12.3)
67
- webmock
68
-
69
- BUNDLED WITH
70
- 1.17.2
data/Makefile DELETED
@@ -1,62 +0,0 @@
1
- # Generate a debian package for fluent-plugin-logdna
2
- #
3
- # This assumes that you have the td-agent package already installed
4
- # https://docs.fluentd.org/v1.0/articles/install-by-deb
5
- #
6
- # The package is created with fpm (it does not necessarily need to be
7
- # installed into the td-agent embedded ruby). To install fpm run:
8
- # $ sudo gem install --no-ri --no-rdoc fpm
9
- #
10
- # The td-agent package installs an embedded ruby distribution in
11
- # /opt/td-agent/embedded which has its own list of gems. Our built package
12
- # cannot conflict with those gems so we will elect to bundle a subset of gems
13
- # with our package. This may conflict with other packages and this package is
14
- # not intended to be a general purpose package.
15
-
16
- # Paths to td-agent specific versions of bundle and gem
17
- BUNDLE=/opt/td-agent/embedded/bin/bundle
18
- GEM=/opt/td-agent/embedded/bin/gem
19
- RUBY=/opt/td-agent/embedded/bin/ruby
20
- RAKE=/opt/td-agent/embedded/bin/rake
21
- FPM=fpm
22
-
23
- # Bundle will unpack gems into the bundle directory
24
- BUNDLE_DIR=./vendor/bundle
25
- # Bundle will save gems in the cache directory
26
- CACHE_DIR=./vendor/cache
27
- PKG_DIR=pkg
28
- # Bundle will store settings and locks in the dot_bundle directory
29
- DOT_BUNDLE=./.bundle
30
-
31
- GEMSPEC := ${wildcard *.gemspec}
32
- NAME := ${shell $(RUBY) -e 'puts Gem::Specification::load("$(GEMSPEC)").name'}
33
- VERSION := ${shell $(RUBY) -e 'puts Gem::Specification::load("$(GEMSPEC)").version.to_s'}
34
- GEMFILE := ${shell $(RUBY) -e 'puts Gem::Specification::load("$(GEMSPEC)").file_name'}
35
- DEBFILE := $(NAME)_$(VERSION)_all.deb
36
-
37
- all: $(DEBFILE)
38
-
39
- $(BUNDLE_DIR): Gemfile.lock
40
- $(BUNDLE) install --frozen --path $(BUNDLE_DIR)
41
-
42
- $(CACHE_DIR): $(BUNDLE_DIR) Gemfile.lock
43
- $(BUNDLE) package --no-install
44
-
45
- $(GEMFILE): $(BUNDLE_DIR)
46
- $(BUNDLE) exec $(GEM) build -V $(GEMSPEC)
47
-
48
- $(DEBFILE): $(GEMFILE) $(CACHE_DIR)
49
- $(BUNDLE) exec $(RAKE) gemdep:minimal
50
- $(FPM) --input-type gem --output-type deb \
51
- --no-auto-depends \
52
- --no-gem-fix-name \
53
- --gem-gem $(GEM) \
54
- --depends 'td-agent > 2' \
55
- --deb-build-depends 'td-agent > 2' \
56
- pkg/*.gem $(GEMFILE)
57
-
58
- clean:
59
- -$(BUNDLE) exec $(RAKE) clobber
60
- rm -rf $(BUNDLE_DIR) $(CACHE_DIR) $(DOT_BUNDLE) $(GEMFILE) $(DEBFILE)
61
-
62
- .PHONY: all clean