Coder Social home page Coder Social logo

fluent-plugin-sql's Introduction

SQL input plugin for Fluentd event collector

Overview

This SQL plugin has two parts:

  1. SQL input plugin reads records from RDBMSes periodically. An example use case would be getting "diffs" of a table (based on the "updated_at" field).
  2. SQL output plugin that writes records into RDBMSes. An example use case would be aggregating server/app/sensor logs into RDBMS systems.

Requirements

fluent-plugin-sql fluentd ruby
>= 1.0.0 >= v0.14.4 >= 2.1
< 1.0.0 < v0.14.0 >= 1.9

NOTE: fluent-plugin-sql v2's buffer format is different from v1. If you update the plugin to v2, don't reuse v1's buffer.

Installation

$ fluent-gem install fluent-plugin-sql --no-document
$ fluent-gem install pg --no-document # for postgresql

You should install actual RDBMS driver gem together. pg gem for postgresql adapter or mysql2 gem for mysql2 adapter. Other adapters supported by ActiveRecord should work.

We recommend that mysql2 gem is higher than 0.3.12 and pg gem is higher than 0.16.0.

If you use ruby 2.1, use pg gem 0.21.0 (< 1.0.0) because ActiveRecord 5.1.4 or earlier doesn't support Ruby 2.1.

Input: How It Works

This plugin runs following SQL periodically:

SELECT * FROM table WHERE update_column > last_update_column_value ORDER BY update_column ASC LIMIT 500

What you need to configure is update_column. The column should be an incremental column (such as AUTO_ INCREMENT primary key) so that this plugin reads newly INSERTed rows. Alternatively, you can use a column incremented every time when you update the row (such as last_updated_at column) so that this plugin reads the UPDATEd rows as well. If you omit to set update_column parameter, it uses primary key.

It stores last selected rows to a file (named state_file) to not forget the last row when Fluentd restarts.

Input: Configuration

<source>
  @type sql

  host rdb_host
  port rdb_port
  database rdb_database
  adapter mysql2_or_postgresql_or_etc
  username myusername
  password mypassword

  tag_prefix my.rdb  # optional, but recommended

  select_interval 60s  # optional
  select_limit 500     # optional

  state_file /var/run/fluentd/sql_state

  <table>
    table table1
    tag table1  # optional
    update_column update_col1
    time_column time_col2  # optional
  </table>

  <table>
    table table2
    tag table2  # optional
    update_column updated_at
    time_column updated_at  # optional
    time_format %Y-%m-%d %H:%M:%S.%6N # optional
  </table>

  # detects all tables instead of <table> sections
  #all_tables
</source>
  • host RDBMS host
  • port RDBMS port
  • database RDBMS database name
  • adapter RDBMS driver name. You should install corresponding gem before start (mysql2 gem for mysql2 adapter, pg gem for postgresql adapter, etc.)
  • username RDBMS login user name
  • password RDBMS login password
  • tag_prefix prefix of tags of events. actual tag will be this_tag_prefix.tables_tag (optional)
  • select_interval interval to run SQLs (optional)
  • select_limit LIMIT of number of rows for each SQL (optional)
  • state_file path to a file to store last rows
  • all_tables reads all tables instead of configuring each tables in <table> sections

<table> sections:

  • tag tag name of events (optional; default value is table name)
  • table RDBM table name
  • update_column: see above description
  • time_column (optional): if this option is set, this plugin uses this column's value as the the event's time. Otherwise it uses current time.
  • primary_key (optional): if you want to get data from the table which doesn't have primary key like PostgreSQL's View, set this parameter.
  • time_format (optional): if you want to specify the format of the date used in the query, useful when using alternative adapters which have restrictions on format

Input: Limitation

You should make sure target tables have index (and/or partitions) on the update_column. Otherwise SELECT causes full table scan and serious performance problem.

You can't replicate DELETEd rows.

Output: How It Works

This plugin takes advantage of ActiveRecord underneath. For host, port, database, adapter, username, password, socket parameters, you can think of ActiveRecord's equivalent parameters.

Output: Configuration

<match my.rdb.*>
  @type sql
  host rdb_host
  port 3306
  database rdb_database
  adapter mysql2_or_postgresql_or_etc
  username myusername
  password mypassword
  socket path_to_socket
  remove_tag_prefix my.rdb # optional, dual of tag_prefix in in_sql

  <table>
    table table1
    column_mapping 'timestamp:created_at,fluentdata1:dbcol1,fluentdata2:dbcol2,fluentdata3:dbcol3'
    # This is the default table because it has no "pattern" argument in <table>
    # The logic is such that if all non-default <table> blocks
    # do not match, the default one is chosen.
    # The default table is required.
  </table>

  <table hello.*> # You can pass the same pattern you use in match statements.
    table table2
    # This is the non-default table. It is chosen if the tag matches the pattern
    # AFTER remove_tag_prefix is applied to the incoming event. For example, if
    # the message comes in with the tag my.rdb.hello.world, "remove_tag_prefix my.rdb"
    # makes it "hello.world", which gets matched here because of "pattern hello.*".
  </table>
  
  <table hello.world>
    table table3
    # This is the second non-default table. You can have as many non-default tables
    # as you wish. One caveat: non-default tables are matched top-to-bottom and
    # the events go into the first table it matches to. Hence, this particular table
    # never gets any data, since the above "hello.*" subsumes "hello.world".
  </table>
</match>
  • host RDBMS host
  • port RDBMS port
  • database RDBMS database name
  • adapter RDBMS driver name. You should install corresponding gem before start (mysql2 gem for mysql2 adapter, pg gem for postgresql adapter, etc.)
  • username RDBMS login user name
  • password RDBMS login password
  • socket RDBMS socket path
  • pool A connection pool synchronizes thread access to a limited number of database connections
  • timeout RDBMS connection timeout
  • remove_tag_prefix remove the given prefix from the events. See "tag_prefix" in "Input: Configuration". (optional)

<table> sections:

  • table RDBM table name
  • column_mapping: [Required] Record to table schema mapping. The format is consists of from:to or key values are separated by ,. For example, if set 'item_id:id,item_text:data,updated_at' to column_mapping, item_id field of record is stored into id column and updated_at field of record is stored into updated_at column.
  • <table pattern>: the pattern to which the incoming event's tag (after it goes through remove_tag_prefix, if given). The patterns should follow the same syntax as that of <match>. Exactly one <table> element must NOT have this parameter so that it becomes the default table to store data.

fluent-plugin-sql's People

Contributors

ashie avatar cosmo0920 avatar dependabot[bot] avatar eherot avatar frsyuki avatar ganmacs avatar gmile avatar jaegeunbang avatar kakoni avatar kamipo avatar kenhys avatar kiyoto avatar ljou avatar mishina2228 avatar okkez avatar patrixr avatar phongtattuan avatar pocke avatar repeatedly avatar rophy avatar static-max avatar toru-takahashi avatar yui-knk avatar zamanimehdi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fluent-plugin-sql's Issues

(output plugin) Store fluent tag into db table column.

Is there a way to store the fluent tag into a table column?
In the examples different tags are directed to different tables, but in my case I have many subsystems (hence different tags), all logging to the same table, so it is necessary to be able to know the tag of each logged entry.
If it is not already implemented, I'd also appreciate any pointer on how to add this myself.

Thanks in advance.

event time is not passed to record

@format_proc is never invoked with time it receives from fluent and the data dict also does not contain the time field. If use name the field time in source, there is no way to capture that field using this plugin

Unable to write timestamp to postgres

Hi,

I'm trying to send my record to postgres with a field containing the timestamp.

Here is my schema:

CREATE TABLE simple_table (
    id SERIAL PRIMARY KEY,
    timestamp timestamptz,
);

Here is a config sample

    <filter record.**>
      @type record_transformer
      enable_ruby  true
      <record>
        timestamp ${time}
      </record>
    </filter>

    <filter record.**>
      @type stdout
    </filter>

    <match record.**> 
        
        @type sql
        host myhost
        username myuser
        password mypassword
        port 5432
        database mydb
        adapter postgresql

        <table>
          table simple_table
          column_mapping 'timestamp:timestamp'
        </table>
        
        flush_interval 1s
        # disable_retry_limit
        # num_threads 8
        # slow_flush_log_threshold 40.0
    </match>

No record is sent to SQL with such configuration. This stacktrace can be found in the log:

2019-05-13 13:55:55 +0000 [warn]: #0 emit transaction failed: error_class=NoMethodError error="undefined method `to_msgpack' for 2019-05-13 13:55:55 +0000:Time" location="/var/lib/gems/2.3.0/gems/msgpack-1.2.10/lib/msgpack.rb:44:in `write'" tag="argos.var.log.containers.log-app_argos_log-app-f99e0f0225be7f253b11d6744f1b6f5ced604b679701571dc4319138e56b587f.log"
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/msgpack-1.2.10/lib/msgpack.rb:44:in `write'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/msgpack-1.2.10/lib/msgpack.rb:44:in `pack'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/msgpack-1.2.10/lib/msgpack/core_ext.rb:11:in `to_msgpack'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/fluent-plugin-sql-1.1.1/lib/fluent/plugin/out_sql.rb:223:in `format'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/fluentd-1.4.1/lib/fluent/plugin/output.rb:985:in `block in handle_stream_simple'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/fluentd-1.4.1/lib/fluent/event.rb:193:in `block in each'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/activesupport-5.2.3/lib/active_support/core_ext/range/each.rb:9:in `each'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/activesupport-5.2.3/lib/active_support/core_ext/range/each.rb:9:in `each'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/fluentd-1.4.1/lib/fluent/event.rb:192:in `each'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/fluentd-1.4.1/lib/fluent/plugin/output.rb:984:in `handle_stream_simple'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/fluentd-1.4.1/lib/fluent/plugin/output.rb:870:in `execute_chunking'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/fluentd-1.4.1/lib/fluent/plugin/output.rb:793:in `emit_buffered'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/fluentd-1.4.1/lib/fluent/event_router.rb:159:in `emit_events'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/fluentd-1.4.1/lib/fluent/event_router.rb:96:in `emit_stream'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/fluentd-1.4.1/lib/fluent/plugin/in_tail.rb:402:in `receive_lines'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/fluentd-1.4.1/lib/fluent/plugin/in_tail.rb:520:in `wrap_receive_lines'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/fluentd-1.4.1/lib/fluent/plugin/in_tail.rb:747:in `block in handle_notify'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/fluentd-1.4.1/lib/fluent/plugin/in_tail.rb:791:in `with_io'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/fluentd-1.4.1/lib/fluent/plugin/in_tail.rb:725:in `handle_notify'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/fluentd-1.4.1/lib/fluent/plugin/in_tail.rb:721:in `block in on_notify'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/fluentd-1.4.1/lib/fluent/plugin/in_tail.rb:721:in `synchronize'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/fluentd-1.4.1/lib/fluent/plugin/in_tail.rb:721:in `on_notify'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/fluentd-1.4.1/lib/fluent/plugin/in_tail.rb:550:in `on_notify'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/fluentd-1.4.1/lib/fluent/plugin/in_tail.rb:636:in `on_timer'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/cool.io-1.5.4/lib/cool.io/loop.rb:88:in `run_once'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/cool.io-1.5.4/lib/cool.io/loop.rb:88:in `run'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/fluentd-1.4.1/lib/fluent/plugin_helper/event_loop.rb:93:in `block in start'
  2019-05-13 13:55:55 +0000 [warn]: #0 /var/lib/gems/2.3.0/gems/fluentd-1.4.1/lib/fluent/plugin_helper/thread.rb:78:in `block in thread_create'
2019-05-13 13:56:05.878816961 +0000 argos.var.log.containers.log-app_argos_log-app-f99e0f0225be7f253b11d6744f1b6f5ced604b679701571dc4319138e56b587f.log: {"data":"data","timestamp":"2019-05-13T13:56:05.878+00:00"}

I'm customising the fluentd image available in the kubernetes repo. Gemfile:

gem 'activesupport', '~>5.2.2'
gem 'fluentd', '<=1.4.1'
gem 'fluent-plugin-concat', '~>2.3.0'
gem 'fluent-plugin-detect-exceptions', '~>0.0.12'
gem 'fluent-plugin-elasticsearch', '~>3.3.3'
gem 'fluent-plugin-kubernetes_metadata_filter', '~>2.1.6'
gem 'fluent-plugin-multi-format-parser', '~>1.0.0'
gem 'fluent-plugin-prometheus', '~>1.3.0'
gem 'fluent-plugin-systemd', '~>1.0.2'
gem 'oj', '~>3.7.9'
gem 'fluent-plugin-sql', '~>1.1.1'
gem 'pg', '0.21.0'
# I have tried to install msgpack and mspack-rails separately but it did not solve the error
gem 'msgpack'
gem 'msgpack-rails', :git => 'git://github.com/nzifnab/msgpack-rails.git'

When writing a text or varchar it's working fine, only when the destination type is a timestamp I can't write it and this error shows up.

I can probably write the timestamp as a 'text' but it's not the same. Is there a dependency I'm missing ?

Thank you for your help

error Failed to build gem native extension when trying to install mysql2

on fresh ubuntu 16

just running this commands:

curl -L https://toolbelt.treasuredata.com/sh/install-ubuntu-xenial-td-agent2.sh | sh
/etc/init.d/td-agent restart
/etc/init.d/td-agent status
 /usr/sbin/td-agent-gem install fluent-plugin-sql --no-document
 /usr/sbin/td-agent-gem install mysql2 --no-document

getting this error:

Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.

/opt/td-agent/embedded/bin/ruby -r ./siteconf20170720-26354-32lupl.rb extconf.rb

checking for rb_absint_size()... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.

Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/opt/td-agent/embedded/bin/ruby
/opt/td-agent/embedded/lib/ruby/2.1.0/mkmf.rb:467:in try_do': The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first. from /opt/td-agent/embedded/lib/ruby/2.1.0/mkmf.rb:552:in try_link0'
from /opt/td-agent/embedded/lib/ruby/2.1.0/mkmf.rb:567:in try_link' from /opt/td-agent/embedded/lib/ruby/2.1.0/mkmf.rb:747:in try_func'
from /opt/td-agent/embedded/lib/ruby/2.1.0/mkmf.rb:1032:in block in have_func' from /opt/td-agent/embedded/lib/ruby/2.1.0/mkmf.rb:923:in block in checking_for'
from /opt/td-agent/embedded/lib/ruby/2.1.0/mkmf.rb:351:in block (2 levels) in postpone' from /opt/td-agent/embedded/lib/ruby/2.1.0/mkmf.rb:321:in open'
from /opt/td-agent/embedded/lib/ruby/2.1.0/mkmf.rb:351:in block in postpone' from /opt/td-agent/embedded/lib/ruby/2.1.0/mkmf.rb:321:in open'
from /opt/td-agent/embedded/lib/ruby/2.1.0/mkmf.rb:347:in postpone' from /opt/td-agent/embedded/lib/ruby/2.1.0/mkmf.rb:922:in checking_for'
from /opt/td-agent/embedded/lib/ruby/2.1.0/mkmf.rb:1031:in have_func' from extconf.rb:26:in

'

extconf failed, exit code 1

Gem files will remain installed in /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/mysql2-0.4.8 for inspection.
Results logged to /opt/td-agent/embedded/lib/ruby/gems/2.1.0/extensions/x86_64-linux/2.1.0/mysql2-0.4.8/gem_make.out

I tried running sudo apt-get install libmysqlclient-dev and then tried again to install mysql2 but no luck same error

tzinfo-2.0.2 conflicts with tzinfo (~> 1.1)

I'm having conflict issues with adding fluent-plugin-sql & pg to my project so that FluentD can start outputting to my PSQL Docker container. Prior to adding these I've had no issues, but now after getting pg to work (which was a riot of its own) the cointainer after building and starting immediately stops with a conflict error from something called activesupport-5.2.4.2 due to something called tzinfo-2.0.2 conflicting with another tzinfo of 1.1. I'll explain what I've found and tried further down in this issue.

I'm running FluentD, PostgreSQL and my applications all as Docker containers, using their respective official images (fluent/fluentd:v1.10-1 and postgres:9.6), started through a docker-compose.yml file.

fleuntd.docker:

FROM fluent/fluentd:v1.10-1

ENV PSQL_HOST "psql-server"
ENV PSQL_PORT "5432"
ENV PSQL_DB "fluentd-logs-db"
ENV PSQL_USERNAME "dadmin1"
ENV PSQL_PASSWORD "letmeinplease"

USER root

VOLUME /fluentd/log

# libpq-dev

RUN apk add --no-cache --update --virtual .build-deps postgresql-dev \
        sudo build-base ruby-dev \
 && sudo gem install fluent-plugin-route fluent-plugin-record-modifier fluent-plugin-rewrite-tag-filter \
                     fluent-plugin-sql pg \
 && sudo gem sources --clear-all \
 && apk del .build-deps postgresql-dev \
 && rm -rf /tmp/* /var/tmp/* /usr/lib/ruby/gems/*/cache/*.gem
# && rm -rf /var/cache/apk/* /home/fluent/.gem/ruby/2.5.0/cache/*.gem

COPY docker/fluentd-conf/fluent.conf /fluentd/etc/fluent.conf
COPY docker/fluentd-conf/fluentd.sh /bin/entrypoint.sh

RUN chmod +x /bin/entrypoint.sh
CMD ["/bin/entrypoint.sh"]

Side note: These ENV credentials are not real, this personal project is used locally only and is not openly hosted anywhere.

I have already resolved issues of not being able to find the pg gem, by adding the postgresql-dev instead of libpq-dev (which doesn't seem to work wherever I place it in the RUN...). I found that idea here, #65-454016821
The image finally builds now, but I get a new error within FluentD itself:

...
Creating fluentd-host   ... done
Attaching to fluentd-host
fluentd-host   | 2020-04-15 11:22:46 +0000 [info]: parsing config file is succeeded path="/fluentd/etc/fluent.conf"
fluentd-host   | 2020-04-15 11:22:46 +0000 [info]: gem 'fluent-plugin-record-modifier' version '2.1.0'
fluentd-host   | 2020-04-15 11:22:46 +0000 [info]: gem 'fluent-plugin-rewrite-tag-filter' version '2.3.0'
fluentd-host   | 2020-04-15 11:22:46 +0000 [info]: gem 'fluent-plugin-route' version '1.0.0'
fluentd-host   | 2020-04-15 11:22:46 +0000 [info]: gem 'fluent-plugin-sql' version '1.1.1'
fluentd-host   | 2020-04-15 11:22:46 +0000 [info]: gem 'fluentd' version '1.10.1'
fluentd-host   | /usr/lib/ruby/2.5.0/rubygems/specification.rb:2325:in `raise_if_conflicts': Unable to activate activesupport-5.2.4.2, because tzinfo-2.0.2 conflicts with tzinfo (~> 1.1) (Gem::ConflictError)
fluentd-host   |        from /usr/lib/ruby/2.5.0/rubygems/specification.rb:1438:in `activate'
fluentd-host   |        from /usr/lib/ruby/2.5.0/rubygems/specification.rb:1472:in `block in activate_dependencies'
fluentd-host   |        from /usr/lib/ruby/2.5.0/rubygems/specification.rb:1458:in `each'
fluentd-host   |        from /usr/lib/ruby/2.5.0/rubygems/specification.rb:1458:in `activate_dependencies'
fluentd-host   |        from /usr/lib/ruby/2.5.0/rubygems/specification.rb:1440:in `activate'
fluentd-host   |        from /usr/lib/ruby/2.5.0/rubygems.rb:224:in `rescue in try_activate'
fluentd-host   |        from /usr/lib/ruby/2.5.0/rubygems.rb:217:in `try_activate'
fluentd-host   |        from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
fluentd-host   |        from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:39:in `require'
fluentd-host   |        from /usr/lib/ruby/gems/2.5.0/gems/fluent-plugin-sql-1.1.1/lib/fluent/plugin/out_sql.rb:147:in `initialize'
fluentd-host   |        from /usr/lib/ruby/gems/2.5.0/gems/fluentd-1.10.1/lib/fluent/plugin.rb:158:in `new'
fluentd-host   |        from /usr/lib/ruby/gems/2.5.0/gems/fluentd-1.10.1/lib/fluent/plugin.rb:158:in `new_impl'
fluentd-host   |        from /usr/lib/ruby/gems/2.5.0/gems/fluentd-1.10.1/lib/fluent/plugin.rb:109:in `new_output'
fluentd-host   |        from /usr/lib/ruby/gems/2.5.0/gems/fluentd-1.10.1/lib/fluent/agent.rb:130:in `add_match'
fluentd-host   |        from /usr/lib/ruby/gems/2.5.0/gems/fluentd-1.10.1/lib/fluent/agent.rb:74:in `block in configure'
fluentd-host   |        from /usr/lib/ruby/gems/2.5.0/gems/fluentd-1.10.1/lib/fluent/agent.rb:64:in `each'
fluentd-host   |        from /usr/lib/ruby/gems/2.5.0/gems/fluentd-1.10.1/lib/fluent/agent.rb:64:in `configure'
fluentd-host   |        from /usr/lib/ruby/gems/2.5.0/gems/fluentd-1.10.1/lib/fluent/label.rb:31:in `configure'
fluentd-host   |        from /usr/lib/ruby/gems/2.5.0/gems/fluentd-1.10.1/lib/fluent/root_agent.rb:143:in `block in configure'
fluentd-host   |        from /usr/lib/ruby/gems/2.5.0/gems/fluentd-1.10.1/lib/fluent/root_agent.rb:143:in `each'
fluentd-host   |        from /usr/lib/ruby/gems/2.5.0/gems/fluentd-1.10.1/lib/fluent/root_agent.rb:143:in `configure'
fluentd-host   |        from /usr/lib/ruby/gems/2.5.0/gems/fluentd-1.10.1/lib/fluent/engine.rb:105:in `configure'
fluentd-host   |        from /usr/lib/ruby/gems/2.5.0/gems/fluentd-1.10.1/lib/fluent/engine.rb:80:in `run_configure'
fluentd-host   |        from /usr/lib/ruby/gems/2.5.0/gems/fluentd-1.10.1/lib/fluent/supervisor.rb:547:in `run_supervisor'
fluentd-host   |        from /usr/lib/ruby/gems/2.5.0/gems/fluentd-1.10.1/lib/fluent/command/fluentd.rb:330:in `<top (required)>'
fluentd-host   |        from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
fluentd-host   |        from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
fluentd-host   |        from /usr/lib/ruby/gems/2.5.0/gems/fluentd-1.10.1/bin/fluentd:8:in `<top (required)>'
fluentd-host   |        from /usr/bin/fluentd:23:in `load'
fluentd-host   |        from /usr/bin/fluentd:23:in `<main>'
fluentd-host exited with code 1

Additionally (before the error above, but who knows it might be related in some way), I also get an error from i-18-n during the gem install procedure:

...
Successfully installed fluent-plugin-route-1.0.0
Successfully installed fluent-plugin-record-modifier-2.1.0
Successfully installed fluent-config-regexp-type-1.0.0
Successfully installed fluent-plugin-rewrite-tag-filter-2.3.0
Successfully installed thread_safe-0.3.6
Successfully installed tzinfo-1.2.7

HEADS UP! i18n 1.1 changed fallbacks to exclude default locale.
But that may break your application.

If you are upgrading your Rails application from an older version of Rails:

Please check your Rails app for 'config.i18n.fallbacks = true'.
If you're using I18n (>= 1.1.0) and Rails (< 5.2.2), this should be
'config.i18n.fallbacks = [I18n.default_locale]'.
If not, fallbacks will be broken in your app by I18n 1.1.x.

If you are starting a NEW Rails application, you can ignore this notice.

For more info see:
https://github.com/svenfuchs/i18n/releases/tag/v1.1.0

Successfully installed i18n-1.8.2
Successfully installed minitest-5.14.0
Successfully installed activesupport-5.2.4.2
Successfully installed activemodel-5.2.4.2
Successfully installed arel-9.0.0
Successfully installed activerecord-5.2.4.2
Successfully installed activerecord-import-0.28.2
Successfully installed fluent-plugin-sql-1.1.1
Building native extensions. This could take a while...
Successfully installed pg-0.21.0
15 gems installed
...

I have seen mentions of this issue in places like fluent/fluentd#2726 but the fix they seem to have implemented there seems to not have it fixed for my case.

Like I mentioned, I have tried using libpq-dev (alone or in addition to postgresql-dev) and setting pg:0.21.0 but these would get issues earlier on about not being able to find config files.

I have put the full output log in a file attached to this issue for review.

output.txt

If state_file is empty, then @data becomes boolean false and the code breaks.

Perhaps we should check if the YAML is valid here? -> https://github.com/frsyuki/fluent-plugin-sql/blob/master/lib/fluent/plugin/in_sql.rb#L219

UPDATE:

Sorry, I forgot to paste the error log:

2013-12-03 19:07:25 -0800 [error]: unexpected error error="undefined method `[]' for false:FalseClass"
  2013-12-03 19:07:25 -0800 [error]: /Users/owenestea/.rvm/gems/ruby-2.0.0-p0/gems/fluent-plugin-sql-0.2.1/lib/fluent/plugin/in_sql.rb:207:in `last_records'
  2013-12-03 19:07:25 -0800 [error]: /Users/owenestea/.rvm/gems/ruby-2.0.0-p0/gems/fluent-plugin-sql-0.2.1/lib/fluent/plugin/in_sql.rb:185:in `block in thread_main'
  2013-12-03 19:07:25 -0800 [error]: /Users/owenestea/.rvm/gems/ruby-2.0.0-p0/gems/fluent-plugin-sql-0.2.1/lib/fluent/plugin/in_sql.rb:183:in `each'
  2013-12-03 19:07:25 -0800 [error]: /Users/owenestea/.rvm/gems/ruby-2.0.0-p0/gems/fluent-plugin-sql-0.2.1/lib/fluent/plugin/in_sql.rb:183:in `thread_main'
2013-12-03 19:07:25 -0800 fluent.error: {"error":"undefined method `[]' for false:FalseClass","message":"unexpected error"}
2013-12-03 19:07:35 -0800 [error]: unexpected error error="undefined method `[]' for false:FalseClass"
  2013-12-03 19:07:35 -0800 [error]: /Users/owenestea/.rvm/gems/ruby-2.0.0-p0/gems/fluent-plugin-sql-0.2.1/lib/fluent/plugin/in_sql.rb:207:in `last_records'
  2013-12-03 19:07:35 -0800 [error]: /Users/owenestea/.rvm/gems/ruby-2.0.0-p0/gems/fluent-plugin-sql-0.2.1/lib/fluent/plugin/in_sql.rb:185:in `block in thread_main'
  2013-12-03 19:07:35 -0800 [error]: /Users/owenestea/.rvm/gems/ruby-2.0.0-p0/gems/fluent-plugin-sql-0.2.1/lib/fluent/plugin/in_sql.rb:183:in `each'
  2013-12-03 19:07:35 -0800 [error]: /Users/owenestea/.rvm/gems/ruby-2.0.0-p0/gems/fluent-plugin-sql-0.2.1/lib/fluent/plugin/in_sql.rb:183:in `thread_main'
2013-12-03 19:07:35 -0800 fluent.error: {"error":"undefined method `[]' for false:FalseClass","message":"unexpected error"}

Could not load 'active_record/connection_adapters/postgresql_adapter when using docker image fluent/fluentd:v1.3-debian-onbuild

Dockerfile:
`FROM fluent/fluentd:v1.3-debian-onbuild

RUN buildDeps="sudo make gcc g++ libc-dev ruby-dev libpq-dev"
&& apt-get update
&& apt-get install -y --no-install-recommends $buildDeps
&& sudo gem install
fluent-plugin-sql --no-document
&& sudo gem install
pg -v 0.21.0 --no-document
&& sudo gem install
fluent-plugin-remote_syslog --no-document \
&& sudo gem sources --clear-all
&& SUDO_FORCE_REMOVE=yes
apt-get purge -y --auto-remove
-o APT::AutoRemove::RecommendsImportant=false
$buildDeps
&& rm -rf /var/lib/apt/lists/*
/home/fluent/.gem/ruby/2.3.0/cache/*.gem`

Error:

2018-12-05 09:20:11 +0000 [error]: #0 Could not load 'active_record/connection_adapters/postgresql_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile. path=nil error_class=LoadError error="Could not load 'active_record/connection_adapters/postgresql_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile."

cannot load such file -- fluent/plugin/output

Hello,

I have an ubuntu 18.04 machine and installed td-agent with
http://toolbelt.treasuredata.com/sh/install-ubuntu-precise-td-agent2.sh
and installed the plugin and database gem with
td-agent-gem install fluent-plugin-sql --no-document
td-agent-gem install pg -v 0.21.0 --no-document

First tested with output to file which works. Then added config for output to postgresql

<match web01.php-fpm.access>
  @type sql
  database fluent
  username td-agent
  adapter postgresql
  
  <table>
  table phpfpm_access
  column_mapping 'timestamp:ts,req,status,script,dur,mem,cpu'
  </table>
</match>

When i did td-agent --dry-run I get error:

2018-12-19 14:51:28 +0100 [info]: reading config file path="/etc/td-agent/td-agent.conf"
2018-12-19 14:51:28 +0100 [info]: starting fluentd-0.12.40 as dry run mode
2018-12-19 14:51:28 +0100 [info]: gem 'fluent-mixin-plaintextformatter' version '0.2.6'
2018-12-19 14:51:28 +0100 [info]: gem 'fluent-plugin-kafka' version '0.6.1'
2018-12-19 14:51:28 +0100 [info]: gem 'fluent-plugin-mongo' version '0.8.1'
2018-12-19 14:51:28 +0100 [info]: gem 'fluent-plugin-rewrite-tag-filter' version '1.5.6'
2018-12-19 14:51:28 +0100 [info]: gem 'fluent-plugin-s3' version '0.8.5'
2018-12-19 14:51:28 +0100 [info]: gem 'fluent-plugin-scribe' version '0.10.14'
2018-12-19 14:51:28 +0100 [info]: gem 'fluent-plugin-sql' version '1.0.0'
2018-12-19 14:51:28 +0100 [info]: gem 'fluent-plugin-td' version '0.10.29'
2018-12-19 14:51:28 +0100 [info]: gem 'fluent-plugin-td-monitoring' version '0.2.3'
2018-12-19 14:51:28 +0100 [info]: gem 'fluent-plugin-webhdfs' version '0.7.1'
2018-12-19 14:51:28 +0100 [info]: gem 'fluentd' version '0.12.40'
2018-12-19 14:51:28 +0100 [info]: adding match pattern="td.*.*" type="tdlog"
2018-12-19 14:51:28 +0100 [info]: adding match pattern="debug.**" type="stdout"
2018-12-19 14:51:28 +0100 [info]: adding match pattern="web01.php-fpm.access" type="sql"
/opt/td-agent/embedded/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- fluent/plugin/output (LoadError)
        from /opt/td-agent/embedded/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluent-plugin-sql-1.0.0/lib/fluent/plugin/out_sql.rb:1:in `<top (required)>'
        from /opt/td-agent/embedded/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /opt/td-agent/embedded/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.40/lib/fluent/plugin.rb:173:in `block in try_load_plugin'
        from /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.40/lib/fluent/plugin.rb:170:in `each'
        from /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.40/lib/fluent/plugin.rb:170:in `try_load_plugin'
        from /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.40/lib/fluent/plugin.rb:130:in `new_impl'
        from /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.40/lib/fluent/plugin.rb:59:in `new_output'
        from /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.40/lib/fluent/agent.rb:131:in `add_match'
        from /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.40/lib/fluent/agent.rb:64:in `block in configure'
        from /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.40/lib/fluent/agent.rb:57:in `each'
        from /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.40/lib/fluent/agent.rb:57:in `configure'
        from /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.40/lib/fluent/root_agent.rb:86:in `configure'
        from /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.40/lib/fluent/engine.rb:129:in `configure'
        from /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.40/lib/fluent/engine.rb:103:in `run_configure'
        from /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.40/lib/fluent/supervisor.rb:489:in `run_configure'
        from /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.40/lib/fluent/supervisor.rb:200:in `dry_run'
        from /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.40/lib/fluent/supervisor.rb:147:in `start'
        from /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.40/lib/fluent/command/fluentd.rb:173:in `<top (required)>'
        from /opt/td-agent/embedded/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /opt/td-agent/embedded/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.40/bin/fluentd:5:in `<top (required)>'
        from /opt/td-agent/embedded/bin/fluentd:23:in `load'
        from /opt/td-agent/embedded/bin/fluentd:23:in `<top (required)>'
        from /usr/sbin/td-agent:7:in `load'
        from /usr/sbin/td-agent:7:in `<main>'

Oracle

Hi,

I just started using Fluentd and am looking for a way of saving events to an Oracle database. At the moment I'm trying to use the enhanced_oracle adapter but it just doesn't seem to work. Fluentd starts and exists without error.
Could you point me in the right direction on how to set this up? Do I also need to install an Oracle client?

Best regards,

Peter

Tables and views in schemas are not supported (PostgreSQL)

If I want to use a view thats inside a schema, I get the following error:

2015-12-11 14:49:10 +0100 [warn]: Can't handle 'data.my-view' table. Ignoring. error="wrong constant name Data.my_view" error_class=NameError
  2015-12-11 14:49:10 +0100 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluent-plugin-sql-0.4.3/lib/fluent/plugin/in_sql.rb:81:in `const_set'
  2015-12-11 14:49:10 +0100 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluent-plugin-sql-0.4.3/lib/fluent/plugin/in_sql.rb:81:in `init'
  2015-12-11 14:49:10 +0100 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluent-plugin-sql-0.4.3/lib/fluent/plugin/in_sql.rb:207:in `block in start'
  2015-12-11 14:49:10 +0100 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluent-plugin-sql-0.4.3/lib/fluent/plugin/in_sql.rb:205:in `reject!'
  2015-12-11 14:49:10 +0100 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluent-plugin-sql-0.4.3/lib/fluent/plugin/in_sql.rb:205:in `start'
  2015-12-11 14:49:10 +0100 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.12/lib/fluent/root_agent.rb:111:in `block in start'
  2015-12-11 14:49:10 +0100 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.12/lib/fluent/root_agent.rb:110:in `each'
  2015-12-11 14:49:10 +0100 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.12/lib/fluent/root_agent.rb:110:in `start'

Creating the view in the "public" schema is currently the only workaround I see.

out-sql performance

Trying to push data into psql database using out-sql plugin.
I'm using in_tail plugin as a source (files with few million rows).

I've seen various error messages like
failed to write data into buffer by buffer overflow
and
`buffer space has too many data``

Any ideas where I should start with optimization?
I tried with buffer_queue_full_action blockbut didnt help

How to debug?

There are precious few debug points in the plugin - if there is a process using fluent-debug let me know and I'm happy to contribute to readme.

Can't output data from PostgreSQL to Elasticsearch

Hi all ,

I've been install fluent-plugin-sql and pg by td-agent-gem
and run systemctl start td-agent correctly
(@tail is working correctly, and no error in journalctl)

But data is not output to Elasticsearch when I inserted into PostgreSQL
and /var/run/fluentd/sql_state is not established

Here is my setting of td-agent about postgreSQL to elasticsearch and enviriment

CentOS 7
Elasticsearch 6.5.4
PostgreSQL 9.2.23 on x86_64-redhat-linux-gnu

id and ctime are columns in td_agent_raw_log_test

<source>
  @type sql

  host psql_host
  port 7432
  database my_db
  adapter postgresql
  username username
  password password

  tag_prefix tmp.my_db.rdb

  select_interval 60s
  select_limit 500

  state_file /var/run/fluentd/sql_state

  <table>
    table td_agent_raw_log_test
    tag td_agent_raw_log_test
    update_column id
    time_column ctime
  </table>

</source>

<match tmp.etugoal.rdb.*>
  @type elasticsearch
  host es_host
  port 9200
  index_name fluentd
  flush_interval 10s
  logstash_prefix psql-tmp-agent-raw-log-test
  logstash_format true
</match>

Any help would be greatly appreciated.

/etc/init.d/td-agent start

Starting td-agent: 2016-04-28 15:01:00 +0800 [error]: fluent/supervisor.rb:359:rescue in main_process: config error file="/etc/td-agent/td-agent.conf" error="Unknown output plugin 'sql'. Run 'gem search -rd fluent-plugin' to find plugins"

Successfully installed fluent-plugin-sql-0.5.1
Parsing documentation for fluent-plugin-sql-0.5.1
Done installing documentation for fluent-plugin-sql after 0 seconds
1 gem installed

fluent-gem install pg error

root@e99fcc218a15:/# fluent-gem install pg -v 0.21.0 --no-document
Fetching: pg-0.21.0.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
	ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.3.0/gems/pg-0.21.0/ext
/usr/bin/ruby2.3 -r ./siteconf20180711-9-zt3vi6.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.3.0/gems/pg-0.21.0 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/pg-0.21.0/gem_make.out
root@e99fcc218a15:/# 

Credentials from env

We are planning on dockerizing our SQL agent and would like to pass the database config credentials via env so that it can be reproducable/re-usable without having to hard-code the credentials into a flat file somewhere.
For example, the record_transformer filter plugin allows for Ruby expressions. Perhaps something similar could be implemented for this plugin, such as:

host ${ENV["DBHOST"]}
database ${ENV["DBNAME"]}
...

error="undefined method `key' for #<Fluent::Plugin::Buffer::MemoryChunk:0x00007fa50795d6d0>"

I want to insert some logs in postgres but I get an error.
Here are the logs:

fluentd-g     | 2019-11-15 15:18:47 +0000 [info]: starting fluentd-1.6.3 pid=6 ruby="2.6.3"
fluentd-g     | 2019-11-15 15:18:47 +0000 [info]: spawn command to main:  cmdline=["/usr/local/bin/ruby", "-Eascii-8bit:ascii-8bit", "/usr/local/bundle/bin/fluentd", "-c", "/fluentd/etc/fluent.conf", "-p", "/flue
ntd/plugins", "--under-supervisor"]
fluentd-g     | 2019-11-15 15:18:49 +0000 [info]: gem 'fluent-plugin-rewrite-tag-filter' version '2.2.0'
fluentd-g     | 2019-11-15 15:18:49 +0000 [info]: gem 'fluent-plugin-sql' version '1.1.1'
fluentd-g     | 2019-11-15 15:18:49 +0000 [info]: gem 'fluentd' version '1.6.3'
fluentd-g     | 2019-11-15 15:18:49 +0000 [info]: gem 'fluentd' version '1.6.2'
fluentd-g     | 2019-11-15 15:18:49 +0000 [info]: adding match pattern="guacamole" type="rewrite_tag_filter"
fluentd-g     | 2019-11-15 15:18:49 +0000 [info]: #0 adding rewrite_tag_filter rule: tracker_type [#<Fluent::PluginHelper::RecordAccessor::Accessor:0x00007fa50ae34368 @keys="tracker_type">, /.*/, "", "${tag}.$1"]
fluentd-g     | 2019-11-15 15:18:49 +0000 [info]: adding match pattern="guacamole.*" type="sql"
fluentd-g     | 2019-11-15 15:18:49 +0000 [warn]: #0 secondary type should be same with primary one primary="Fluent::Plugin::SQLOutput" secondary="Fluent::Plugin::StdoutOutput"
fluentd-g     | 2019-11-15 15:18:49 +0000 [info]: adding source type="forward"
fluentd-g     | 2019-11-15 15:18:49 +0000 [info]: #0 starting fluentd worker pid=14 ppid=6 worker=0
fluentd-g     | 2019-11-15 15:18:53 +0000 [info]: #0 Selecting 'utr_guacamole_connections' table
fluentd-g     | 2019-11-15 15:18:53 +0000 [info]: #0 Selecting 'usr_guacamole_connections' table
fluentd-g     | 2019-11-15 15:18:53 +0000 [info]: #0 listening port port=24224 bind="0.0.0.0"
fluentd-g     | 2019-11-15 15:18:53 +0000 [info]: #0 fluentd worker is now running worker=0
fluentd-g     | 2019-11-15 15:20:32 +0000 [warn]: #0 got unrecoverable error in primary. Skip retry and flush chunk to secondary error_class=NoMethodError error="undefined method `key' for #<Fluent::Plugin::Buffe
r::MemoryChunk:0x00007fa50795d6d0>"
fluentd-g     |   2019-11-15 15:20:32 +0000 [warn]: #0 /usr/local/lib/ruby/gems/2.6.0/gems/fluent-plugin-sql-1.1.1/lib/fluent/plugin/out_sql.rb:234:in `block (2 levels) in write'
fluentd-g     |   2019-11-15 15:20:32 +0000 [warn]: #0 /usr/local/lib/ruby/gems/2.6.0/gems/fluent-plugin-sql-1.1.1/lib/fluent/plugin/out_sql.rb:233:in `each'
fluentd-g     |   2019-11-15 15:20:32 +0000 [warn]: #0 /usr/local/lib/ruby/gems/2.6.0/gems/fluent-plugin-sql-1.1.1/lib/fluent/plugin/out_sql.rb:233:in `block in write'
fluentd-g     |   2019-11-15 15:20:32 +0000 [warn]: #0 /usr/local/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `with_connection'
fluentd-g     |   2019-11-15 15:20:32 +0000 [warn]: #0 /usr/local/lib/ruby/gems/2.6.0/gems/fluent-plugin-sql-1.1.1/lib/fluent/plugin/out_sql.rb:231:in `write'
fluentd-g     |   2019-11-15 15:20:32 +0000 [warn]: #0 /usr/local/lib/ruby/gems/2.6.0/gems/fluentd-1.6.3/lib/fluent/plugin/output.rb:1128:in `try_flush'
fluentd-g     |   2019-11-15 15:20:32 +0000 [warn]: #0 /usr/local/lib/ruby/gems/2.6.0/gems/fluentd-1.6.3/lib/fluent/plugin/output.rb:1434:in `flush_thread_run'
fluentd-g     |   2019-11-15 15:20:32 +0000 [warn]: #0 /usr/local/lib/ruby/gems/2.6.0/gems/fluentd-1.6.3/lib/fluent/plugin/output.rb:457:in `block (2 levels) in start'
fluentd-g     |   2019-11-15 15:20:32 +0000 [warn]: #0 /usr/local/lib/ruby/gems/2.6.0/gems/fluentd-1.6.3/lib/fluent/plugin_helper/thread.rb:78:in `block in thread_create'

It seems from the documentation that chunk.key doesn't exists and extract_placeholders should be used to extract tag.

So I tried to clone this repository and to install the plugin from sources with this dockerfile:

FROM fluent/fluentd:v1.6.2-debian-1.0
USER root

COPY fluent-plugin-sql/fluent-plugin-sql-1.1.1.gem .

RUN BUILD_DEPS="sudo make gcc g++ libc-dev ruby-dev" \
  && apt-get update \
  && apt-get install -y --no-install-recommends $BUILD_DEPS \
  && apt-get install -y libpq-dev \
  && fluent-gem install fluent-plugin-rewrite-tag-filter \
  && sudo gem install pg \
  && fluent-gem install -g fluent-plugin-sql-1.1.1.gem --no-document \
  && fluent-gem install pg -v 0.21.0 --no-document \
  && sudo gem sources --clear-all \
  && SUDO_FORCE_REMOVE=yes \
    apt-get purge -y --auto-remove \
                  -o APT::AutoRemove::RecommendsImportant=false \
                  $BUILD_DEPS \
  && rm -rf /var/lib/apt/lists/* \
           /home/fluent/.gem/ruby/2.3.0/cache/*.gem

COPY fluent.conf /fluentd/etc/

USER fluent

but I get the following error:

ERROR:  While executing gem ... (NameError)
    undefined local variable or method `metadata' for #<Gem::RequestSet::GemDependencyAPI:0x00007fa5aa439020>

Even if I didn't modified the source code!

Unable to fetch data from postgresql view: NilClass

Hi, I'm trying to fetch data from a view (not table) on postgresql and seeing the error as followed:

  2015-01-22 14:11:23 +0900 [error]: unexpected error error="can't dup NilClass" error_class=TypeError
  2015-01-22 14:11:23 +0900 [error]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluent-plugin-sql-0.3.0/lib/fluent/plugin/in_sql.rb:123:in `dup'
  2015-01-22 14:11:23 +0900 [error]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluent-plugin-sql-0.3.0/lib/fluent/plugin/in_sql.rb:123:in `emit_next_records'
  2015-01-22 14:11:23 +0900 [error]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluent-plugin-sql-0.3.0/lib/fluent/plugin/in_sql.rb:227:in `block in thread_main'
  2015-01-22 14:11:23 +0900 [error]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluent-plugin-sql-0.3.0/lib/fluent/plugin/in_sql.rb:224:in `each'
  2015-01-22 14:11:23 +0900 [error]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluent-plugin-sql-0.3.0/lib/fluent/plugin/in_sql.rb:224:in `thread_main'

Is it possible to fetch data from a view in first place?

Regards,

pg Gem Load Error

2018-02-05 10:44:33 +0000 [info]: starting fluentd-1.0.2 pid=11304 ruby="2.4.2" 2018-02-05 10:44:33 +0000 [info]: spawn command to main: cmdline=["/opt/td-agent/embedded/bin/ruby", "-Eascii-8bit:ascii-8bit", "/opt/td-agent/embedded/bin/fluentd", "--log", "/var/log/td-agent/td-agent.log", "--daemon", "/var/run/td-agent/td-agent.pid", "--under-supervisor"] 2018-02-05 10:44:33 +0000 [info]: gem 'fluent-plugin-elasticsearch' version '2.4.0' 2018-02-05 10:44:33 +0000 [info]: gem 'fluent-plugin-kafka' version '0.6.5' 2018-02-05 10:44:33 +0000 [info]: gem 'fluent-plugin-rewrite-tag-filter' version '2.0.1' 2018-02-05 10:44:33 +0000 [info]: gem 'fluent-plugin-s3' version '1.1.0' 2018-02-05 10:44:33 +0000 [info]: gem 'fluent-plugin-sql' version '0.6.1' 2018-02-05 10:44:33 +0000 [info]: gem 'fluent-plugin-td' version '1.0.0' 2018-02-05 10:44:33 +0000 [info]: gem 'fluent-plugin-td-monitoring' version '0.2.3' 2018-02-05 10:44:33 +0000 [info]: gem 'fluent-plugin-webhdfs' version '1.2.2' 2018-02-05 10:44:33 +0000 [info]: gem 'fluentd' version '1.0.2' 2018-02-05 10:44:33 +0000 [info]: adding match pattern="logfile" type="sql" 2018-02-05 10:44:33 +0000 [info]: adding match pattern="td.*.*" type="tdlog" 2018-02-05 10:44:33 +0000 [warn]: #0 secondary type should be same with primary one primary="Fluent::Plugin::TreasureDataLogOutput" secondary="Fluent::Plugin::FileOutput" 2018-02-05 10:44:33 +0000 [info]: adding match pattern="debug.**" type="stdout" 2018-02-05 10:44:33 +0000 [info]: adding source type="tail" 2018-02-05 10:44:33 +0000 [info]: adding source type="forward" 2018-02-05 10:44:33 +0000 [info]: adding source type="http" 2018-02-05 10:44:33 +0000 [info]: adding source type="debug_agent" 2018-02-05 10:44:33 +0000 [info]: #0 starting fluentd worker pid=11315 ppid=11310 worker=0 2018-02-05 10:44:33 +0000 [error]: #0 unexpected error error_class=Gem::LoadError error="Specified 'postgresql' for database adapter, but the gem is not loaded. Add gem 'pg'to your Gemfile (and ensure its version is at the minimum required by ActiveRecord)." 2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/activerecord-4.2.10/lib/active_record/connection_adapters/connection_specification.rb:177:inrescue in spec'
2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/activerecord-4.2.10/lib/active_record/connection_adapters/connection_specification.rb:174:in spec' 2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/activerecord-4.2.10/lib/active_record/connection_handling.rb:50:in establish_connection'
2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/activerecord-import-0.22.0/lib/activerecord-import/import.rb:205:in establish_connection_with_activerecord_import' 2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluent-plugin-sql-0.6.1/lib/fluent/plugin/out_sql.rb:202:in start'
2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.0.2/lib/fluent/compat/call_super_mixin.rb:42:in start' 2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.0.2/lib/fluent/root_agent.rb:165:in block in start'
2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.0.2/lib/fluent/root_agent.rb:154:in block (2 levels) in lifecycle' 2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.0.2/lib/fluent/root_agent.rb:153:in each'
2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.0.2/lib/fluent/root_agent.rb:153:in block in lifecycle' 2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.0.2/lib/fluent/root_agent.rb:140:in each'
2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.0.2/lib/fluent/root_agent.rb:140:in lifecycle' 2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.0.2/lib/fluent/root_agent.rb:164:in start'
2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.0.2/lib/fluent/engine.rb:274:in start' 2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.0.2/lib/fluent/engine.rb:219:in run'
2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.0.2/lib/fluent/supervisor.rb:774:in run_engine' 2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.0.2/lib/fluent/supervisor.rb:523:in block in run_worker'
2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.0.2/lib/fluent/supervisor.rb:699:in main_process' 2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.0.2/lib/fluent/supervisor.rb:518:in run_worker'
2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.0.2/lib/fluent/command/fluentd.rb:316:in <top (required)>' 2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in require'
2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in require' 2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.0.2/bin/fluentd:8:in <top (required)>'
2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/bin/fluentd:23:in load' 2018-02-05 10:44:33 +0000 [error]: #0 /opt/td-agent/embedded/bin/fluentd:23:in

'
2018-02-05 10:44:33 +0000 [error]: #0 Specified 'postgresql' for database adapter, but the gem is not loaded. Add gem 'pg' to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). path=nil error_class=Gem::LoadError error="Specified 'postgresql' for database adapter, but the gem is not loaded. Add gem 'pg' to your Gemfile (and ensure its version is at the minimum required by ActiveRecord)."
2018-02-05 10:44:33 +0000 [error]: #0 suppressed same stacktrace
2018-02-05 10:44:34 +0000 [info]: Worker 0 finished unexpectedly with status 2
2018-02-05 10:44:34 +0000 [info]: Received graceful stop`

Cannot Install on Ubuntu 14.04 with td-agent-gem

I'm trying to issue on my server:

sudo /usr/sbin/td-agent-gem install fluent-plugin-sql --no-ri --no-rdoc -v '0.3.0'

However, I'm experiencing issues similar to this stackoverflow:

http://stackoverflow.com/questions/15186924/installing-gem-pg-for-postgresql-openssl-libraries

Looks like their solution was to reinstall ruby to reference to proper ssl lib. Is there anything that you think can be done here (perhaps in the td-agent ubuntu package)? I imagine worst case I can use the fluentd gem and my own ruby instead.

Thanks,
Jesse

Cannot use postgresql adapter

Hi,

I've installed the pg gem and set adapter postgresql, but got the following errors:

fluentd_1  | 2017-04-24 13:15:42 +0000 [info]: reading config file path="/fluentd/etc/fluent.conf"
fluentd_1  | 2017-04-24 13:15:42 +0000 [info]: starting fluentd-0.12.35
fluentd_1  | 2017-04-24 13:15:42 +0000 [info]: gem 'fluent-plugin-sql' version '0.6.0'
fluentd_1  | 2017-04-24 13:15:42 +0000 [info]: gem 'fluentd' version '0.12.35'
fluentd_1  | 2017-04-24 13:15:42 +0000 [info]: adding match pattern="**" type="stdout"
fluentd_1  | 2017-04-24 13:15:43 +0000 [info]: adding source type="http"
fluentd_1  | 2017-04-24 13:15:43 +0000 [info]: adding source type="sql"
fluentd_1  | 2017-04-24 13:15:43 +0000 [info]: using configuration file: <ROOT>
fluentd_1  |   <source>
fluentd_1  |     @type sql
fluentd_1  |     host my-postgresql-server
fluentd_1  |     database mydb
fluentd_1  |     adapter postgresql
fluentd_1  |     username dbuser
fluentd_1  |     password xxxxxx
fluentd_1  |     tag_prefix mytag
fluentd_1  |     select_interval 2s
fluentd_1  |     select_limit 100
fluentd_1  |     state_file /tmp/fluentd_sql_state
fluentd_1  |     <table>
fluentd_1  |       table logs
fluentd_1  |       tag logs
fluentd_1  |       update_column log_id
fluentd_1  |       time_column created_time
fluentd_1  |     </table>
fluentd_1  |   </source>
fluentd_1  |   <match **>
fluentd_1  |     @type stdout
fluentd_1  |   </match>
fluentd_1  | </ROOT>
fluentd_1  | 2017-04-24 13:15:43 +0000 [info]: shutting down fluentd
fluentd_1  | 2017-04-24 13:15:43 +0000 [info]: shutting down input type="http" plugin_id="object:3fe85d8afacc"
fluentd_1  | 2017-04-24 13:15:43 +0000 [info]: shutting down output type="stdout" plugin_id="object:3fe85d729d74"
fluentd_1  | /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': Could not load 'active_record/connection_adapters/postgresql_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile. (LoadError)
fluentd_1  |    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
fluentd_1  |    from /home/fluent/.gem/ruby/2.3.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:293:in `block in require'
fluentd_1  |    from /home/fluent/.gem/ruby/2.3.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:259:in `load_dependency'
fluentd_1  |    from /home/fluent/.gem/ruby/2.3.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:293:in `require'
fluentd_1  |    from /home/fluent/.gem/ruby/2.3.0/gems/pg-0.20.0/lib/pg.rb:4:in `<top (required)>'
fluentd_1  |    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
fluentd_1  |    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
fluentd_1  |    from /home/fluent/.gem/ruby/2.3.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:293:in `block in require'
fluentd_1  |    from /home/fluent/.gem/ruby/2.3.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:259:in `load_dependency'
fluentd_1  |    from /home/fluent/.gem/ruby/2.3.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:293:in `require'
fluentd_1  |    from /home/fluent/.gem/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/postgresql_adapter.rb:3:in `<top (required)>'
fluentd_1  |    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
fluentd_1  |    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
fluentd_1  |    from /home/fluent/.gem/ruby/2.3.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:293:in `block in require'
fluentd_1  |    from /home/fluent/.gem/ruby/2.3.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:259:in `load_dependency'
fluentd_1  |    from /home/fluent/.gem/ruby/2.3.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:293:in `require'
fluentd_1  |    from /home/fluent/.gem/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'
fluentd_1  |    from /home/fluent/.gem/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_handling.rb:53:in `establish_connection'
fluentd_1  |    from /home/fluent/.gem/ruby/2.3.0/gems/fluent-plugin-sql-0.6.0/lib/fluent/plugin/in_sql.rb:206:in `start'
fluentd_1  |    from /var/lib/gems/2.3.0/gems/fluentd-0.12.35/lib/fluent/root_agent.rb:115:in `block in start'
fluentd_1  |    from /var/lib/gems/2.3.0/gems/fluentd-0.12.35/lib/fluent/root_agent.rb:114:in `each'
fluentd_1  |    from /var/lib/gems/2.3.0/gems/fluentd-0.12.35/lib/fluent/root_agent.rb:114:in `start'
fluentd_1  |    from /var/lib/gems/2.3.0/gems/fluentd-0.12.35/lib/fluent/engine.rb:237:in `start'
fluentd_1  |    from /var/lib/gems/2.3.0/gems/fluentd-0.12.35/lib/fluent/engine.rb:187:in `run'
fluentd_1  |    from /var/lib/gems/2.3.0/gems/fluentd-0.12.35/lib/fluent/supervisor.rb:570:in `run_engine'
fluentd_1  |    from /var/lib/gems/2.3.0/gems/fluentd-0.12.35/lib/fluent/supervisor.rb:162:in `block in start'
fluentd_1  |    from /var/lib/gems/2.3.0/gems/fluentd-0.12.35/lib/fluent/supervisor.rb:366:in `main_process'
fluentd_1  |    from /var/lib/gems/2.3.0/gems/fluentd-0.12.35/lib/fluent/supervisor.rb:339:in `block in supervise'
fluentd_1  |    from /var/lib/gems/2.3.0/gems/fluentd-0.12.35/lib/fluent/supervisor.rb:338:in `fork'
fluentd_1  |    from /var/lib/gems/2.3.0/gems/fluentd-0.12.35/lib/fluent/supervisor.rb:338:in `supervise'
fluentd_1  |    from /var/lib/gems/2.3.0/gems/fluentd-0.12.35/lib/fluent/supervisor.rb:156:in `start'
fluentd_1  |    from /var/lib/gems/2.3.0/gems/fluentd-0.12.35/lib/fluent/command/fluentd.rb:173:in `<top (required)>'
fluentd_1  |    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
fluentd_1  |    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
fluentd_1  |    from /var/lib/gems/2.3.0/gems/fluentd-0.12.35/bin/fluentd:5:in `<top (required)>'
fluentd_1  |    from /usr/local/bin/fluentd:22:in `load'
fluentd_1  |    from /usr/local/bin/fluentd:22:in `<main>'
fluentd_1  | 2017-04-24 13:15:43 +0000 [info]: process finished code=256
fluentd_1  | 2017-04-24 13:15:43 +0000 [warn]: process died within 1 second. exit.

And the fluent-gem list result is:

activemodel (5.0.2, 4.2.8)
activerecord (5.0.2, 4.2.8)
activerecord-import (0.18.1)
activerecord-postgresql-adapter (0.0.1)
activerecord-sqlserver-adapter (5.0.7)
activesupport (5.0.2, 4.2.8)
arel (7.1.4, 6.0.4)
bigdecimal (1.2.8)
builder (3.2.3)
concurrent-ruby (1.0.5)
cool.io (1.5.0)
did_you_mean (1.0.0)
fluent-plugin-sql (0.6.0)
fluentd (0.12.35)
http_parser.rb (0.6.0)
i18n (0.8.1)
io-console (0.4.5)
json (2.1.0, 1.8.3)
mini_portile2 (2.1.0)
minitest (5.9.0)
msgpack (1.1.0)
net-telnet (0.1.1)
oj (2.18.5)
pg (0.20.0)
power_assert (0.2.7)
psych (2.1.0)
rake (10.5.0)
rdoc (4.2.1)
sigdump (0.2.4)
string-scrub (0.0.5)
test-unit (3.1.7)
thread_safe (0.3.6)
tiny_tds (1.3.0)
tzinfo (1.2.3)
tzinfo-data (1.2017.2)
yajl-ruby (1.3.0)

Is there something I missed? Thanks.

warn parameter 'pattern' in <table>

Using table with pattern does not work. gives the following warnings:

2015-05-29 07:22:50 +0000 [warn]: Detect duplicate default table definition

2015-05-29 07:22:50 +0000 [warn]: parameter 'pattern' in


pattern my.tag
table Table1
column_mapping filed:field

is not used.

How to I get to use multiple tables with different patterns?

It always uses the last specified table. So all my data is written to the last table, and never to what it should match.

here is my match config:

<match sql.table.**>
    type sql
    host 127.0.0.1
    port 3306
    database database1
    adapter mysql2
    username root
    password root
    remove_tag_prefix sql.table

    <table>
        pattern tablename
        table tablename
        column_mapping 'id:id,field1:field1'
    </table>            

    <table>
        pattern tablename2
        table tablename2
        column_mapping 'id:id,field1:field1,field2:field2'
    </table>                

</match>

Cannot use with fluentd-1.7

fluent-plugin-sql cannot use with fluentd-1.7 due to conflicting tzinfo versions (as mentioned in fluent/fluentd#2634).

  • fluentd-1.7 requires tzinfo 2.0
  • fluent-plugin-sql requires tzinfo 1.1 via ActiveSupport
2019-10-15 14:22:24 +0900 [info]: parsing config file is succeeded path="conf/fluent.conf"
2019-10-15 14:22:24 +0900 [info]: adding forwarding server '192.168.0.12:24224' host="192.168.0.12" port=24224 weight=60 plugin_id="object:2ab07d33ebd8"
2019-10-15 14:22:24 +0900 [info]: [forward_output] adding forwarding server '192.168.0.11:24224' host="192.168.0.11" port=24224 weight=60 plugin_id="forward_output"
2019-10-15 14:22:24 +0900 [info]: [http_input] Oj is not installed, and failing back to Yajl for json parser
Traceback (most recent call last):
	35: from /usr/local/bin/fluentd:23:in `<main>'
	34: from /usr/local/bin/fluentd:23:in `load'
	33: from /var/lib/gems/2.5.0/gems/fluentd-1.7.3/bin/fluentd:8:in `<top (required)>'
	32: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
	31: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
	30: from /var/lib/gems/2.5.0/gems/fluentd-1.7.3/lib/fluent/command/fluentd.rb:314:in `<top (required)>'
	29: from /var/lib/gems/2.5.0/gems/fluentd-1.7.3/lib/fluent/supervisor.rb:504:in `run_supervisor'
	28: from /var/lib/gems/2.5.0/gems/fluentd-1.7.3/lib/fluent/supervisor.rb:599:in `supervise'
	27: from /var/lib/gems/2.5.0/gems/fluentd-1.7.3/lib/fluent/supervisor.rb:581:in `dry_run'
	26: from /var/lib/gems/2.5.0/gems/fluentd-1.7.3/lib/fluent/supervisor.rb:804:in `run_configure'
	25: from /var/lib/gems/2.5.0/gems/fluentd-1.7.3/lib/fluent/engine.rb:96:in `run_configure'
	24: from /var/lib/gems/2.5.0/gems/fluentd-1.7.3/lib/fluent/engine.rb:131:in `configure'
	23: from /var/lib/gems/2.5.0/gems/fluentd-1.7.3/lib/fluent/root_agent.rb:156:in `configure'
	22: from /var/lib/gems/2.5.0/gems/fluentd-1.7.3/lib/fluent/root_agent.rb:156:in `each'
	21: from /var/lib/gems/2.5.0/gems/fluentd-1.7.3/lib/fluent/root_agent.rb:160:in `block in configure'
	20: from /var/lib/gems/2.5.0/gems/fluentd-1.7.3/lib/fluent/root_agent.rb:315:in `add_source'
	19: from /var/lib/gems/2.5.0/gems/fluentd-1.7.3/lib/fluent/plugin.rb:100:in `new_input'
	18: from /var/lib/gems/2.5.0/gems/fluentd-1.7.3/lib/fluent/plugin.rb:146:in `new_impl'
	17: from /var/lib/gems/2.5.0/gems/fluentd-1.7.3/lib/fluent/registry.rb:44:in `lookup'
	16: from /var/lib/gems/2.5.0/gems/fluentd-1.7.3/lib/fluent/registry.rb:99:in `search'
	15: from /var/lib/gems/2.5.0/gems/fluentd-1.7.3/lib/fluent/registry.rb:99:in `each'
	14: from /var/lib/gems/2.5.0/gems/fluentd-1.7.3/lib/fluent/registry.rb:102:in `block in search'
	13: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
	12: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
	11: from /var/lib/gems/2.5.0/gems/fluent-plugin-sql-1.1.1/lib/fluent/plugin/in_sql.rb:21:in `<top (required)>'
	10: from /var/lib/gems/2.5.0/gems/fluent-plugin-sql-1.1.1/lib/fluent/plugin/in_sql.rb:23:in `<module:Plugin>'
	 9: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:39:in `require'
	 8: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
	 7: from /usr/lib/ruby/2.5.0/rubygems.rb:217:in `try_activate'
	 6: from /usr/lib/ruby/2.5.0/rubygems.rb:224:in `rescue in try_activate'
	 5: from /usr/lib/ruby/2.5.0/rubygems/specification.rb:1440:in `activate'
	 4: from /usr/lib/ruby/2.5.0/rubygems/specification.rb:1458:in `activate_dependencies'
	 3: from /usr/lib/ruby/2.5.0/rubygems/specification.rb:1458:in `each'
	 2: from /usr/lib/ruby/2.5.0/rubygems/specification.rb:1472:in `block in activate_dependencies'
	 1: from /usr/lib/ruby/2.5.0/rubygems/specification.rb:1438:in `activate'
/usr/lib/ruby/2.5.0/rubygems/specification.rb:2327:in `raise_if_conflicts': Unable to activate activesupport-5.2.3, because tzinfo-2.0.0 conflicts with tzinfo (~> 1.1) (Gem::ConflictError)

No reconnect after error

Hello Folks,

i have got a problem that a have i huge logging file of 250Mb (please do not ask) that i want to import to a mysql database. The entries itself are small enought to get inserted one by one into the database. But if i want to import the whole file i first got the error "Mysql Server has gone away". It seems to me that there was a 250Mb insert statement generated that sure enought failed cause of the size. Fluentd logging says "Got deterministic error. Fallback to one-by-one import". So this is catched and the plugin tries to do it one by one. But there seems no reconnect is going on for the database. So inserts are tried on a connection that is not alive anymore. You might see this at the following logging.

fluentd    | 2020-01-14 08:40:56 +0100 [warn]: #0 Failed to import a record: retry number = 1 error_class=Mysql2::Error error="MySQL client is not connected"
fluentd    | 2020-01-14 08:40:57 +0100 [warn]: #0 Failed to import a record: retry number = 2 error_class=Mysql2::Error error="MySQL client is not connected"
fluentd    | 2020-01-14 08:40:57 +0100 [warn]: #0 Failed to import a record: retry number = 3 error_class=Mysql2::Error error="MySQL client is not connected"
fluentd    | 2020-01-14 08:40:58 +0100 [warn]: #0 Failed to import a record: retry number = 4 error_class=Mysql2::Error error="MySQL client is not connected"
fluentd    | 2020-01-14 08:40:58 +0100 [warn]: #0 Failed to import a record: retry number = 5 error_class=Mysql2::Error error="MySQL client is not connected"
fluentd    | 2020-01-14 08:40:59 +0100 [error]: #0 Can't recover undeterministic error. Dump a record error_class=Mysql2::Error error="MySQL client is not connected" record=#<Fluent::Plugin::SQLOutput::BaseModel_1539762876::Log id: nil, time: "2020-01-07 00:00:00", source: "Igetnow.Api.Logic.PusherManager", level: "Error", message: "Pusher error while checking online status of chann...", exception_name: "System.Net.Http.HttpRequestException", exception_message: "Cannot assign requested address ---> System.Net.So...", exception_stacktrace: "System.Net.Http.HttpRequestException: Cannot assig...">

That might be an issue to look into, For us there were a lot of errors gone witch we needed to prevent bigger damage.

And in addition to that. Is it possible to split the bucket size? So that there is not 250Mb Statement generated?

td-agent not start after added database adaptor

  1. installed td-agent-3.5.1
  2. installed sql input plugin by follow this link: https://github.com/fluent/fluent-plugin-sql
  3. installed postgres adaptor by follow this link: https://github.com/fluent/fluent-plugin-sql
  4. installed oracle adaptor by follow this link: https://github.com/rsim/oracle-enhanced
  5. both cases, cannot start td-agent after added postgres/oracle db info in td-agent config.
    no error message, just cannot start td-agent. no errror in td-agent logs, but seems not able to read in the db info.

below is my oracle db info in the td-agent config:

<source>
  @type sql
  adapter oracle_enhanced
  host idb00295.ute.fedex.com
  port 1526
  database GTM_TEST3_SVC1_L2    // or GTM_TEST3_SVC1.ute.fedex.com ??
  username pex
  password K6WDQWjHXQhXxWbxu9zgcdYug
  tag_prefix mydb  # optional, but recommended
  select_interval 60s  # optional
  select_limit 500     # optional
  state_file /var/run/fluentd/sql_state
  <table>
    table MESSAGE_TABLE
    update_column id
  </table>
</source>

high availability

I'm trying to add secondary config but seems not working.

Do you have any recommendation to apply high availability?

Support nested fields

We have some nested fields that we want to use within column_mapping, such as column_mapping 'user.id:user_id,user.name:name', but this code is preventing it from working:

def configure(conf)
super
@mapping = parse_column_mapping(@column_mapping)
@format_proc = Proc.new { |record|
new_record = {}
@mapping.each { |k, c|
new_record[c] = record[k]
}
new_record
}
end

Specifically record[k]. We patched this with record.dig(*k.split('.')) to support these nested fields, however this relies on Ruby >=2.3. Would you consider supporting our use case? If so, I'd be glad to help.

Error running tests

I'm not familiar with ruby, so I apologize in advance if I am doing something terribly stupid.

I'm trying to run the tests, but it always give me the same error:

$ gem install bundler
$ bundle install --with=development
$ bundle exec rake test
/usr/local/bin/ruby -w -I"lib:lib:test" -I"/gems/gems/rake-12.3.0/lib" "/gems/gems/rake-12.3.0/lib/rake/rake_test_loader.rb" "test/fixtures/schema.rb" "test/plugin/test_in_sql.rb" "test/plugin/test_out_sql.rb"
/gems/gems/activesupport-4.2.10/lib/active_support/core_ext/enumerable.rb:20: warning: method redefined; discarding old sum

File does not exist:

rake aborted!
Command failed with status (1): [ruby -w -I"lib:lib:test" -I"/gems/gems/rake-12.3.0/lib" "/gems/gems/rake-12.3.0/lib/rake/rake_test_loader.rb" "test/fixtures/schema.rb" "test/plugin/test_in_sql.rb" "test/plugin/test_out_sql.rb" ]
/gems/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
Tasks: TOP => test
(See full trace by running task with --trace)

This happens both on my machine (OSX) and in a debian Docker container I've put together to exclude local problems (in the docker container I've installed libpq-dev and postgres, and created the database user and db).

Table name rotation

I have several questions as blow. please check it out.

Q1. can I rotate table name by each day?
I'd like to use the variables which was dedicated table name by each day.
i.e.) table logtable => table logtable_{yyyyMMdd}, logtable_20160220, logtable_20160221 ...
If not, would you suggest better ideas?

Q2. can I create DB table when necessary or check to exist the table?
i.e) create table when is not existed the table.

Thank you.

"Out" plugin includes all columns in destination table, even if not configured

I'm writing records to MS SQL Server.

All of the columns in the destination table are included in the insert statements, even if they aren't in the column_mapping configuration (it just explicitly passes a NULL for the column).

For example, if the table is

CREATE TABLE [dbo].[Test](
	[RowIndex] [int] IDENTITY(1,1) NOT NULL,
	[message] [nvarchar](500) NULL
)

and the column_mapping is

<table>
   table Test
   column_mapping 'message:message'
</table>

The insert statement that is generated is

INSERT INTO [Test] ([RowIndex], [message] OUTPUT INSERTED.[Row] VALUES (NULL, N'message text')

This causes a problem when the destination column is an identity column or is not nullable (but has a default value), since neither of those will allow insert of a null.

I need either an identity column or a column with the insert timestamp for later processing.

Any way to explicitly exclude destination columns? Or any easy work-around?

Could not load 'active_record/connection_adapters/mysql2_adapter'.

Dockerfile:

FROM fluent/fluentd:v1.4-1

# Use root account to use apk
USER root

# below RUN includes plugin as examples elasticsearch is not required
# you may customize including plugins as you wish
RUN apk add --no-cache --update --virtual .build-deps sudo build-base ruby-dev mysql-dev \
    && sudo gem install fluent-plugin-elasticsearch fluent-plugin-sql \
    && fluent-gem install mysql2 --no-document \
    && sudo gem sources --clear-all \
    && apk del .build-deps \
    && rm -rf /home/fluent/.gem/ruby/2.5.0/cache/*.gem

USER fluent

error:

Could not load 'active_record/connection_adapters/mysql2_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile.

mysql2 version is mysql2-0.5.2

All rows are read into memory prior flushing

When I select a large table with no row limit, all rows a read into memory and the process never finishes.
It would be nice if there was some kind of batch/cursor read method, which flushes the rows before reading all of them.

How to add sqlserver 'table_name_prefix' support?

Hi,

I read this from activerecord-sqlserver-adapter's README:

Schemas & Users

Depending on your user and schema setup, it may be needed to use a table name prefix of dbo.. So something like this in your initializer file for ActiveRecord or the adapter.

ActiveRecord::Base.table_name_prefix = 'dbo.'

And want to add this feature for my own use but no luck:

 lib/fluent/plugin/in_sql.rb | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/fluent/plugin/in_sql.rb b/lib/fluent/plugin/in_sql.rb
index 1373c97..cd282dc 100644
--- a/lib/fluent/plugin/in_sql.rb
+++ b/lib/fluent/plugin/in_sql.rb
@@ -23,7 +23,7 @@ module Fluent
   require 'active_record'
 
   class SQLInput < Input
-    Plugin.register_input('sql', self)
+    Plugin.register_input('sql2', self)
 
     # For fluentd v0.12.16 or earlier
     class << self
@@ -65,6 +65,7 @@ module Fluent
       include Configurable
 
       config_param :table, :string
+      config_param :table_prefix, :string, :default => nil
       config_param :tag, :string, :default => nil
       config_param :update_column, :string, :default => nil
       config_param :time_column, :string, :default => nil
@@ -80,9 +81,11 @@ module Fluent
 
         # creates a model for this table
         table_name = @table
+        table_name_prefix = @table_prefix
         primary_key = @primary_key
         @model = Class.new(base_model) do
           self.table_name = table_name
+          self.table_name_prefix = table_name_prefix if table_name_prefix
           self.inheritance_column = '_never_use_'
           self.primary_key = primary_key if primary_key

The config:

<table>
  table "mylog"
  table_prefix "abc."
  update_column "log_id"
</table>

The errors:

[error]: unexpected error error="TinyTds::Error: Invalid object name 'mylog'.: EXEC sp_executesql N'SELECT  [mylog].* FROM [mylog]  ORDER BY log_id ASC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY', N'@0 int', @0 = 100" error_class=ActiveRecord::StatementInvalid

The correct sql query should be like this:

SELECT [abc].[mylog].* FROM [abc].[mylog] ORDER BY log_id ASC

Sorry I'm not familiar with Ruby and fluentd plugin development, maybe I made some mistakes?

Thank you.

send log to clickhouse db

hello,
I want to send event to clickhouse, That's why I install fluentd and fluent-plugin-sql.
then i create table in clickhouse :

CREATE TABLE zamanitable1
(
    dt DateTime,
    ComputerName String, 
    RecordNumber Int32,
    EventType Int32
)
ENGINE = MergeTree
PARTITION BY toYYYYMM(dt)
ORDER BY dt

and install this gem:

gem install clickhouse-activerecord

my fluentd config :

<match **>
  @type sql
  host *.*.*.*
  port 1317
  database system
  adapter clickhouse
  username default
  password ******
  socket 1317
  <table>
    table zamanitable1
    column_mapping 'TimeGenerated:dt,ComputerName:ComputerName,RecordNumber:RecordNumber,EventType:EventType'
  </table>
</match>

i get this error on fluentd cli:

2020-03-27 07:51:16 +0000 [warn]: #0 fluent/log.rb:342:warn: got unrecoverable error in primary and no secondary error_class=NoMethodError error="undefined method `to_sym' for false:FalseClass"
  2020-03-27 07:51:16 +0000 [warn]: #0 plugin/output.rb:452:block (2 levels) in start: /usr/lib/ruby/gems/2.5.0/gems/activerecord-import-0.28.2/lib/activerecord-import/import.rb:664:in `map'
  2020-03-27 07:51:16 +0000 [warn]: #0 plugin/output.rb:452:block (2 levels) in start: /usr/lib/ruby/gems/2.5.0/gems/activerecord-import-0.28.2/lib/activerecord-import/import.rb:664:in `import_helper'
  2020-03-27 07:51:16 +0000 [warn]: #0 plugin/output.rb:452:block (2 levels) in start: /usr/lib/ruby/gems/2.5.0/gems/activerecord-import-0.28.2/lib/activerecord-import/import.rb:526:in `bulk_import'
  2020-03-27 07:51:16 +0000 [warn]: #0 plugin/output.rb:452:block (2 levels) in start: /usr/lib/ruby/gems/2.5.0/gems/fluent-plugin-sql-1.1.1/lib/fluent/plugin/out_sql.rb:98:in `import'
  2020-03-27 07:51:16 +0000 [warn]: #0 plugin/output.rb:452:block (2 levels) in start: /usr/lib/ruby/gems/2.5.0/gems/fluent-plugin-sql-1.1.1/lib/fluent/plugin/out_sql.rb:238:in `block in write'
  2020-03-27 07:51:16 +0000 [warn]: #0 plugin/output.rb:452:block (2 levels) in start: /usr/lib/ruby/gems/2.5.0/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `with_connection'
  2020-03-27 07:51:16 +0000 [warn]: #0 plugin/output.rb:452:block (2 levels) in start: /usr/lib/ruby/gems/2.5.0/gems/fluent-plugin-sql-1.1.1/lib/fluent/plugin/out_sql.rb:231:in `write'
  2020-03-27 07:51:16 +0000 [warn]: #0 plugin/output.rb:452:block (2 levels) in start: /usr/lib/ruby/gems/2.5.0/gems/fluentd-1.3.2/lib/fluent/plugin/output.rb:1123:in `try_flush'
  2020-03-27 07:51:16 +0000 [warn]: #0 plugin/output.rb:452:block (2 levels) in start: /usr/lib/ruby/gems/2.5.0/gems/fluentd-1.3.2/lib/fluent/plugin/output.rb:1423:in `flush_thread_run'
  2020-03-27 07:51:16 +0000 [warn]: #0 plugin/output.rb:452:block (2 levels) in start: /usr/lib/ruby/gems/2.5.0/gems/fluentd-1.3.2/lib/fluent/plugin/output.rb:452:in `block (2 levels) in start'
  2020-03-27 07:51:16 +0000 [warn]: #0 plugin/output.rb:452:block (2 levels) in start: /usr/lib/ruby/gems/2.5.0/gems/fluentd-1.3.2/lib/fluent/plugin_helper/thread.rb:78:in `block in thread_create'
2020-03-27 07:51:16 +0000 [warn]: #0 fluent/log.rb:342:warn: bad chunk is moved to /tmp/fluent/backup/worker0/object_2ae0428ba298/5a1d15a2bc09ab3dcc3ca663644cb763.log

fluentd has successfully connected to clickhouse (Error message when table not exists) but cannot write to db, where is the problem from?

multi-column primary key

We've begun using this plugin to pull data out of sql tables, but we've run into an issue effectively tailing sql tables where there's not a single primary key, but instead a multi-column primary key. To solve this, we've begun creating views with inefficiently concatenated fields containing the multi-column primary keys, but this is not a particularly strong solution for large tables of data. Is there a recommended strategy for handling this kind of case?

How to config increase pool size of active connection for database?

It seems that the default connection settings are not for the operating environment. The following error will occur when below configuration set to large number.
flush_thread_count = 100

Error:

2020-03-31 12:31:05 +0000 [warn]: #0 fluent/log.rb:342:warn: failed to flush the buffer. retry_time=2 next_retry_seconds=2020-03-31 12:31:08 +0000 chunk="5a225bcd579342d569b144a242212e7b" error_class=ActiveRecord::ConnectionTimeoutError error="could not obtain a connection from the pool within 5.000 seconds (waited 5.000 seconds); all pooled connections were in use"

How to config increase pool size of active connection for database?

Flush failure

Using master fluentd/this plugin/pg. Database insert isnt working properly, seeing;

2016-04-25 23:45:51 +0300 [warn]: fluent/output.rb:331:rescue in try_flush: temporarily failed to flush the buffer. next_retry=2016-04-25 23:45:51 +0300 error_class=Ac
tiveRecord::ConnectionNotEstablished error="No connection pool for ActiveRecord::Base" plugin_id="object:3fc5d5c391ac"
  2016-04-25 23:45:51 +0300 [warn]: /Users/kakoni/.gem/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:570:in `ret
rieve_connection'
  2016-04-25 23:45:51 +0300 [warn]: /Users/kakoni/.gem/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
  2016-04-25 23:45:51 +0300 [warn]: /Users/kakoni/.gem/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_handling.rb:87:in `connection'
  2016-04-25 23:45:51 +0300 [warn]: /Users/kakoni/.gem/ruby/2.3.0/gems/activerecord-import-0.13.0/lib/activerecord-import/adapters/postgresql_adapter.rb:19:in `insert_
many'
  2016-04-25 23:45:51 +0300 [warn]: /Users/kakoni/.gem/ruby/2.3.0/gems/activerecord-import-0.13.0/lib/activerecord-import/import.rb:496:in `block in import_without_validations_or_callbacks'
  2016-04-25 23:45:51 +0300 [warn]: /Users/kakoni/.gem/ruby/2.3.0/gems/activerecord-import-0.13.0/lib/activerecord-import/import.rb:494:in `each'
  2016-04-25 23:45:51 +0300 [warn]: /Users/kakoni/.gem/ruby/2.3.0/gems/activerecord-import-0.13.0/lib/activerecord-import/import.rb:494:in `each_slice'
  2016-04-25 23:45:51 +0300 [warn]: /Users/kakoni/.gem/ruby/2.3.0/gems/activerecord-import-0.13.0/lib/activerecord-import/import.rb:494:in `import_without_validations_
or_callbacks'
  2016-04-25 23:45:51 +0300 [warn]: /Users/kakoni/.gem/ruby/2.3.0/gems/activerecord-import-0.13.0/lib/activerecord-import/import.rb:447:in `import_with_validations'
  2016-04-25 23:45:51 +0300 [warn]: /Users/kakoni/.gem/ruby/2.3.0/gems/activerecord-import-0.13.0/lib/activerecord-import/import.rb:390:in `import_helper'
  2016-04-25 23:45:51 +0300 [warn]: /Users/kakoni/.gem/ruby/2.3.0/gems/activerecord-import-0.13.0/lib/activerecord-import/import.rb:310:in `import'
  2016-04-25 23:45:51 +0300 [warn]: /Users/kakoni/.gem/ruby/2.3.0/bundler/gems/fluent-plugin-sql-c4056247bafc/lib/fluent/plugin/out_sql.rb:98:in `import'

Pluggable mechanizm for database adapters

Now, fluent-plugin-sql requires libmysqlclient-dev for mysql2 and libpq-dev for pg gems on Ubuntu.
It's a pain because users want to use one database, but need more packages to install fluent-plugin-sql.
We should extract adapters from fluent-plugin-sql core and provide pluggable mechanizm like fluent-plugin-sql-adapter-mysql or similar.

Null value is inserted in mysql tables.

Hi,

I am using "fluent-plugin-sql" for streaming nginx logs to Mysql database. "NULL" value are getting inserted in table column.Need help on this.

Any suggestion here would be very helpful. I am happy to provide td-agent.conf file if needed.

Thanks,
Reena

How to connect to sql server

I have tried installing tiny_tds, also tried activerecord-sqlserver-adapter but both give me the following error:

2019-10-14 07:21:34 +0000 [error]: #0 fluent/log.rb:362:error: Could not load the 'tiny_tds' Active Record adapter. Ensure that the adapter is spelled correctly in config/database.yml and that you've added the necessary adapter gem to your Gemfile. path=nil error_class=LoadError error="Could not load the 'tiny_tds' Active Record adapter. Ensure that the adapter is spelled correctly in config/database.yml and that you've added the necessary adapter gem to your Gemfile."
2019-10-14 07:21:34 +0000 [error]: #0 fluent/log.rb:362:error: Could not load the 'activerecord-sqlserver-adapter' Active Record adapter. Ensure that the adapter is spelled correctly in config/database.yml and that you've added the necessary adapter gem to your Gemfile. path=nil error_class=LoadError error="Could not load the 'activerecord-sqlserver-adapter' Active Record adapter. Ensure that the adapter is spelled correctly in config/database.yml and that you've added the necessary adapter gem to your Gemfile."

Dockerfile:

# AUTOMATICALLY GENERATED
# DO NOT EDIT THIS FILE DIRECTLY, USE /Dockerfile.template.erb

FROM alpine:3.9
LABEL maintainer "Fluentd developers <[email protected]>"
LABEL Description="Fluentd docker image" Vendor="Fluent Organization" Version="1.7.3"

# Do not split this into multiple RUN!
# Docker creates a layer for every RUN-Statement
# therefore an 'apk delete' has no effect
RUN apk update \
 && apk add --no-cache \
        ca-certificates linux-headers \
        ruby ruby-irb ruby-etc ruby-webrick \
        tini \
 && apk add --no-cache --virtual .build-deps \
        build-base \
        ruby-dev gnupg \
 && apk add freetds freetds-dev \
 && echo 'gem: --no-document' >> /etc/gemrc \
 && gem install tiny_tds -v 2.1.0 \
 && gem install fluent-plugin-sql -v 1.1.1 \
 && gem install activerecord-sqlserver-adapter -v 5.2.0 \
 && gem install oj -v 3.3.10 \
 && gem install json -v 2.2.0 \
 && gem install async-http -v 0.46.3 \
 && gem install fluentd -v 1.6.3 \
 && gem install bigdecimal -v 1.3.5 \
 && apk del .build-deps \
 && rm -rf /tmp/* /var/tmp/* /usr/lib/ruby/gems/*/cache/*.gem

RUN addgroup -S fluent && adduser -S -g fluent fluent \
    # for log storage (maybe shared with host)
    && mkdir -p /fluentd/log \
    # configuration/plugins path (default: copied from .)
    && mkdir -p /fluentd/etc /fluentd/plugins \
    && chown -R fluent /fluentd && chgrp -R fluent /fluentd


COPY fluent.conf /fluentd/etc/
COPY entrypoint.sh /bin/


ENV FLUENTD_CONF="fluent.conf"

ENV LD_PRELOAD=""
EXPOSE 24224 5140

USER fluent
ENTRYPOINT ["tini",  "--", "/bin/entrypoint.sh"]
CMD ["fluentd"]

conf

<source>
  @type forward
  port 24224
  bind 0.0.0.0
</source>

<match **>
  @type stdout
</match>
<match *>
  @type sql
  host ...
  port 1433
  database fluentd
  adapter tiny_tds / activerecord-sqlserver-adapter
  username ...
  password ...
  
  <table>
    table dbo.logs
    column_mapping 'timestamp:created_at,fluentdata1:dbcol1,fluentdata2:dbcol2,fluentdata3:dbcol3'
    # This is the default table because it has no "pattern" argument in <table>
    # The logic is such that if all non-default <table> blocks
    # do not match, the default one is chosen.
    # The default table is required.
  </table>

</match>

Oracle record update feature not available

I am using this plugin, Oracle instant client, ruby-oci8 and activerecord-oracle_enhanced-adapter.
Below is the configuration used:

<match oracle.input>
@type sql
host xxx.xxxxxx.xxxxx.xxxx.net
port 1555
database test
adapter oracle_enhanced
username xxxxxxxxxx
password xxxxxxxxxx
<table>
table reg_as_data
column_mapping 'tn:tn,regtime:regtime,domain:domain,scscf:scscf,pcscf:pcscf,deviceip:deviceip,devicename:devicename,subscribertype:subscribertype,hss:hss,expires:expires,devicemac:devicemac,provgroup:provgroup,cmts:cmts,account_no,account_no,sub_id:sub_id,zipcode:zipcode,icmp_ping:icmp_ping,sip_ping:sip_ping'
</table>
 </match>

In 'reg_as_data' table, 'tn' is the primary key.
With this setup, records are inserted into the table. However, when the same 'tn' sends updated data, the record is not getting updated. Error details given below for reference.

2019-06-07 11:05:03 +0000 [error]: #0 Got deterministic error again. Dump a record error_class=ActiveRecord::RecordNotUnique error="OCIError: ORA-00001: unique constraint (PDBADMIN.SYS_C0012535) violated: INSERT INTO \"REG_AS_DATA\" (\"TN\",\"REGTIME\",\"DOMAIN\",\"SCSCF\",\"PCSCF\",\"DEVICEIP\",\"DEVICENAME\",\"SUBSCRIBERTYPE\",\"HSS\",\"EXPIRES\",\"DEVICEMAC\",\"PROVGROUP\",\"CMTS\",\"ACCOUNT_NO\",\"SUB_ID\",\"ZIPCODE\",\"ICMP_PING\",\"SIP_PING\") VALUES ('2011010086',' 1559905418','xxxxxxx','scscfman2','pcscfman2','21.168.211.17','Load-Test1','BCV','hssman1','3600','mACB313E2ECCA','phil1',NULL,NULL,NULL,NULL,NULL,NULL)" record=#<Fluent::Plugin::SQLOutput::BaseModel_897089696::RegAsDatum tn: 0.2011010086e10, regtime: 0.1559905418e10, domain: "xxxxxxx", scscf: "scscfman2", pcscf: "pcscfman2", deviceip: "21.168.211.17", devicename: "Load-Test1", subscribertype: "BCV", hss: "hssman1", expires: 0.36e4, devicemac: "mACB313E2ECCA", provgroup: "phil1", cmts: nil, account_no: nil, sub_id: nil, zipcode: nil, icmp_ping: nil, sip_ping: nil>

Are there any configurations available to update records in ORACLE DB?
Thank you.

Encoding errors when processing some log messages

The plugin shows errors that it can not import records that use non ASCII-8BIT characters.

plugin/out_sql.rb:99:rescue in block in import: Failed to create the model. Ignore a record: error=""\xC3" from ASCII-8BIT to UTF-8"

Failed to flush the buffer

My fluentd is 1.4.2,pg is 0.21.0. And my td-agent.conf about input/output is as follows:

<source>
  @type sql

  tag_prefix my.rdb  # optional, but recommended

  select_interval 60s  # optional
  select_limit 500     # optional

  <table>
    table issues
    tag issues  # optional
    update_column id,title,author_id,project_id,created_at,updated_at,description,milestone_id,state,iid,updated_by_id,weight,confidential,due_date,moved_to_id,lock_version,title_html,description_html,time_estimate,relative_position,service_desk_reply_to,cached_markdown_version,last_edited_at,last_edited_by_id,discussion_locked,closed_at,closed_by_id,state_id
  </table>
</source>

<match my.rdb.*>
  @type sql
  remove_tag_prefix my.rdb # optional, dual of tag_prefix in in_sql

  <table>
    table issues
    column_mapping 'id:id,title:title,author_id:author_id,project_id:project_id,created_at:created_at,updated_at:updated_at,description:description,milestone_id:milestone_id,state:state,iid:iid,updated_by_id:updated_by_id:updated_by_id,weight:weight,confidential:confidential,due_date:due_date,moved_to_id:moved_to_id,lock_version:lock_version,title_html:title_html,description_html:description_html,time_estimate:time_estimate,relative_position:relative_position,service_desk_reply_to:service_desk_reply_to,cached_markdown_version:cached_markdown_version,last_edited_at:last_edited_at,last_edited_by_id:last_edited_by_id,discussion_locked:discussion_locked,closed_at:closed_at,closed_by_id:closed_by_id,state_id:state_id'
  </table>

</match>

When I start fluentd,it is failed. Error logs are as follows:

  2019-06-19 09:10:32 +0800 [warn]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/pg-0.21.0/lib/pg.rb:56:in `initialize'
  2019-06-19 09:10:32 +0800 [warn]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/pg-0.21.0/lib/pg.rb:56:in `new'
  2019-06-19 09:10:32 +0800 [warn]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/pg-0.21.0/lib/pg.rb:56:in `connect'
  2019-06-19 09:10:32 +0800 [warn]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:692:in `connect'
  2019-06-19 09:10:32 +0800 [warn]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:223:in `initialize'
  2019-06-19 09:10:32 +0800 [warn]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `new'
  2019-06-19 09:10:32 +0800 [warn]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `postgresql_connection'
  2019-06-19 09:10:32 +0800 [warn]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:811:in `new_connection'
  2019-06-19 09:10:32 +0800 [warn]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:855:in `checkout_new_connection'
  2019-06-19 09:10:32 +0800 [warn]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:834:in `try_to_checkout_new_connection'
  2019-06-19 09:10:32 +0800 [warn]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:795:in `acquire_connection'
  2019-06-19 09:10:32 +0800 [warn]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:523:in `checkout'
  2019-06-19 09:10:32 +0800 [warn]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection'
  2019-06-19 09:10:32 +0800 [warn]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:413:in `with_connection'
  2019-06-19 09:10:32 +0800 [warn]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluent-plugin-sql-1.1.1/lib/fluent/plugin/out_sql.rb:231:in `write'
  2019-06-19 09:10:32 +0800 [warn]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.4.2/lib/fluent/plugin/output.rb:1125:in `try_flush'
  2019-06-19 09:10:32 +0800 [warn]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.4.2/lib/fluent/plugin/output.rb:1425:in `flush_thread_run'
  2019-06-19 09:10:32 +0800 [warn]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.4.2/lib/fluent/plugin/output.rb:454:in `block (2 levels) in start'
  2019-06-19 09:10:32 +0800 [warn]: #0 /opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.4.2/lib/fluent/plugin_helper/thread.rb:78:in `block in thread_create'
2019-06-19 09:10:33 +0800 [warn]: #0 failed to flush the buffer. retry_time=1 next_retry_seconds=2019-06-19 09:10:34 +0800 chunk="58ba2e1a420609cf4aa6ef44dd53ad50" error_class=PG::ConnectionBad error="\xE8\x87\xB4\xE5\x91\xBD\xE9\x94\x99\xE8\xAF\xAF:  \xE6\xB2\xA1\xE6\x9C\x89\xE7\x94\xA8\xE4\xBA\x8E\xE4\xB8\xBB\xE6\x9C\xBA \"10.10.5.230\", \xE7\x94\xA8\xE6\x88\xB7 \"postgres\", \xE6\x95\xB0\xE6\x8D\xAE\xE5\xBA\x93 \"gitlabhq_production\", SSL \xE5\x85\xB3\xE9\x97\xAD \xE7\x9A\x84 pg_hba.conf \xE8\xAE\xB0\xE5\xBD\x95\n"
  2019-06-19 09:10:33 +0800 [warn]: #0 suppressed same stacktrace
2019-06-19 09:10:34 +0800 [warn]: #0 failed to flush the buffer. retry_time=2 next_retry_seconds=2019-06-19 09:10:36 +0800 chunk="58ba2e1a420609cf4aa6ef44dd53ad50" error_class=PG::ConnectionBad error="\xE8\x87\xB4\xE5\x91\xBD\xE9\x94\x99\xE8\xAF\xAF:  \xE6\xB2\xA1\xE6\x9C\x89\xE7\x94\xA8\xE4\xBA\x8E\xE4\xB8\xBB\xE6\x9C\xBA \"10.10.5.230\", \xE7\x94\xA8\xE6\x88\xB7 \"postgres\", \xE6\x95\xB0\xE6\x8D\xAE\xE5\xBA\x93 \"gitlabhq_production\", SSL \xE5\x85\xB3\xE9\x97\xAD \xE7\x9A\x84 pg_hba.conf \xE8\xAE\xB0\xE5\xBD\x95\n"
  2019-06-19 09:10:34 +0800 [warn]: #0 suppressed same stacktrace

I can't understand the error :

 failed to flush the buffer. retry_time=2 next_retry_seconds=2019-06-19 09:10:36 +0800 chunk="58ba2e1a420609cf4aa6ef44dd53ad50" error_class=PG::ConnectionBad error="\xE8\x87\xB4\xE5\x91\xBD\xE9\x94\x99\xE8\xAF\xAF:  \xE6\xB2\xA1\xE6\x9C\x89\xE7\x94\xA8\xE4\xBA\x8E\xE4\xB8\xBB\xE6\x9C\xBA \"10.10.5.230\", \xE7\x94\xA8\xE6\x88\xB7 \"postgres\", \xE6\x95\xB0\xE6\x8D\xAE\xE5\xBA\x93 \"gitlabhq_production\", SSL \xE5\x85\xB3\xE9\x97\xAD \xE7\x9A\x84 pg_hba.conf \xE8\xAE\xB0\xE5\xBD\x95\n

What should I solve it ?

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

ActiveRecord default timezone

Hi,

In reading from DB the time is always set to UTC, disregarding the DB setting.

To solve the issue, I tried to this line in the plugin:
ActiveRecord::Base.default_timezone = :local

It worked.

Regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.