Skip to content

Instantly share code, notes, and snippets.

@jsvd
Last active April 20, 2021 15:14
Show Gist options
  • Save jsvd/5954e455bfc61bc94c128d94b2dde8dd to your computer and use it in GitHub Desktop.
Save jsvd/5954e455bfc61bc94c128d94b2dde8dd to your computer and use it in GitHub Desktop.
reproduce jdbc_static issues
1. start postgres instance using docker
2. generate csv and import it to a "data" table
3. download logstash and the postgres jdbc driver
4. use logstash configuration to stress the jdbc_static filter
docker run --name postgres-docker -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres
docker exec -it postgres-docker bash
# create csv with all combinations of 3 letters, and a second column with a random number
# e.g. "AAA,11414"
alphabet = 26.times.map {|i| (65+i).chr }
file = File.open("data.csv", "w")
alphabet.product(alphabet).map(&:join).product(alphabet).map(&:join).each {|el| file.write("#{el},#{rand(100000)}\n") };1
file.close
CREATE table data (name varchar(5), value int);
COPY data(name, value) FROM '/data' DELIMITER ',';
input {
generator { }
}
filter {
ruby {
code => 'key = 3.times.map { (rand(25)+65).chr }.join; event.set("name", key)'
}
jdbc_static {
loaders => [
{
id => "fetch data"
query => "select name, value from data order by name"
local_table => "data"
}
]
local_db_objects => [
{
name => "data"
index_columns => ["name"]
columns => [
["name", "varchar(5)"],
["value", "int"]
]
}
]
local_lookups => [
{
id => "local-servers"
query => "SELECT value FROM data WHERE name = :name"
parameters => {name => "[name]"}
target => "value"
}
]
staging_directory => "/tmp/import_data"
jdbc_user => "postgres"
jdbc_password => "postgres"
jdbc_driver_class => "org.postgresql.Driver"
jdbc_driver_library => "/Users/joaoduarte/cases/661/postgresql-42.2.12.jar"
jdbc_connection_string => "jdbc:postgresql://127.0.0.1:5432/postgres"
}
}
#output { stdout {codec => dots} }
output { stdout {} }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment