Skip to content

Commit

Permalink
Fix rubocop violation for fluentd/fluent-plugin-loki (#1646)
Browse files Browse the repository at this point in the history
* Don't use sudo to install bundler

Follow [the official installation docs](https://github.com/rubygems/bundler#installation-and-usage).

* Fix rubocop viloation: kind_of? -> is_a?

```
lib/fluent/plugin/out_loki.rb:76:21: C: Style/ClassCheck: Prefer
Object#is_a? over Object#kind_of?.
        unless @uri.kind_of?(URI::HTTP) or @uri.kind_of?(URI::HTTPS)
                    ^^^^^^^^
```

* Fix rubocop violation

```
lib/fluent/plugin/out_loki.rb:78:9: C: Layout/EmptyLineAfterGuardClause:
Add empty line after guard clause.
        end
```

* Fix rubocup violation: or -> ||

```
lib/fluent/plugin/out_loki.rb:76:38: C: Style/AndOr: Use || instead of
or.
        unless @uri.is_a?(URI::HTTP) or @uri.is_a?(URI::HTTPS)
                                     ^^
```

* Fix rubocop violation: use single quoate

```
lib/fluent/plugin/out_loki.rb:77:38: C: Style/StringLiterals: Prefer
single-quoted strings when you don't need string interpolation or
special symbols.
          raise Fluent::ConfigError, "url parameter must be valid HTTP"
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

* Ignore rubocop violation: configure method is still not complex

Both rubocop and rspec fail with the current codes. Except for this
rubocop violation, they were fixed. this cyclomatic complexity violation
occurrs in configure method. However, it's still simple and the
implementation could be changed during spec fixation. So, this violation
should be ignored at this moment.

```
lib/fluent/plugin/out_loki.rb:72:7: C: Metrics/CyclomaticComplexity:
Cyclomatic complexity for configure is too high. [7/6]
      def configure(conf) ...
      ^^^^^^^^^^^^^^^^^^^
```
  • Loading branch information
takanabe authored Feb 6, 2020
1 parent cb79863 commit 8f8cb80
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fluentd/fluent-plugin-grafana-loki/bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ set -euo pipefail
IFS=$'\n\t'
set -vx

sudo gem install bundle
gem install bundler
bundle install
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ class LokiOutput < Fluent::Plugin::Output # rubocop:disable Metrics/ClassLength
config_set_default :chunk_keys, []
end

def configure(conf)
def configure(conf) # rubocop:disable Metrics/CyclomaticComplexity
compat_parameters_convert(conf, :buffer)
super
@uri = URI.parse(@url + '/loki/api/v1/push')
unless @uri.kind_of?(URI::HTTP) or @uri.kind_of?(URI::HTTPS)
raise Fluent::ConfigError, "url parameter must be valid HTTP"
unless @uri.is_a?(URI::HTTP) || @uri.is_a?(URI::HTTPS)
raise Fluent::ConfigError, 'url parameter must be valid HTTP'
end

@record_accessors = {}
conf.elements.select { |element| element.name == 'label' }.each do |element|
element.each_pair do |k, v|
Expand Down

0 comments on commit 8f8cb80

Please sign in to comment.