kinesis-tools 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 72f013adab5a99e32e235b0aaef93c5ca50c824f
4
+ data.tar.gz: 055384b28ded2e8a4095e9fc7059c79aa94d6932
5
+ SHA512:
6
+ metadata.gz: 89dd41eb9d524253c6e53f4a1ec243b531bf67c6f43cb8523cf245da2ea7189ee61663e55e2de442434f49d1f4d4f8a50fed22cf92f6540d75081a487e3eb3df
7
+ data.tar.gz: 962c232482bd398c16bd6d4606dd709e09266a656737e99f41666e6c022943d8ff666b92630620e6907036a6ab6a348c93c61f73d4e72f7f128bec5ed24f4aaf
@@ -0,0 +1,3 @@
1
+ vendor/bundle/**
2
+ .bundle/**
3
+ pkg/**
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
@@ -0,0 +1,25 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kinesis-tools (0.1.0)
5
+ aws-sdk
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ aws-sdk (2.2.8)
11
+ aws-sdk-resources (= 2.2.8)
12
+ aws-sdk-core (2.2.8)
13
+ jmespath (~> 1.0)
14
+ aws-sdk-resources (2.2.8)
15
+ aws-sdk-core (= 2.2.8)
16
+ jmespath (1.1.3)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ kinesis-tools!
23
+
24
+ BUNDLED WITH
25
+ 1.11.2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Johannes Müller, AutoScout24 GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,19 @@
1
+ # kinesis-tools
2
+ Tools for working with AWS Kinesis streams
3
+
4
+ ## kinesis-tail
5
+ "tail -f" for AWS Kinesis streams
6
+
7
+ ### Usage
8
+ ```
9
+ ./kinesis-tail.rb streamName
10
+ ```
11
+
12
+ ## kinesis-resharding
13
+ - Easy upscaling of AWS Kinesis streams
14
+ - Doubles the amount of shards
15
+
16
+ ### Usage
17
+ ```
18
+ ./kinesis-resharding.rb streamName up
19
+ ```
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'aws-sdk'
4
+
5
+ Aws.use_bundled_cert!
6
+ kinesis = Aws::Kinesis::Client.new
7
+
8
+ stream_name = ARGV.shift
9
+
10
+ shards = kinesis.describe_stream(:stream_name => stream_name)[:stream_description][:shards]
11
+
12
+ iterators = {}
13
+
14
+ shards.each do |shard|
15
+ response = kinesis.get_shard_iterator(:stream_name => stream_name, :shard_id => shard[:shard_id], :shard_iterator_type => 'LATEST')
16
+ iterators[shard[:shard_id]] = response[:shard_iterator]
17
+ end
18
+
19
+ while true
20
+ shards.each do |shard|
21
+ response = kinesis.get_records(:shard_iterator => iterators[shard[:shard_id]], :limit => 100)
22
+
23
+ iterators[shard[:shard_id]] = response[:next_shard_iterator]
24
+ response[:records].each do |record|
25
+ puts record[:data]
26
+ end
27
+ end
28
+ sleep 10
29
+ end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'aws-sdk'
4
+
5
+ Aws.use_bundled_cert!
6
+ def has_child_shard(shards,shard_id)
7
+ shards.select{ |s| s[:parent_shard_id] == shard_id}.length > 0
8
+ end
9
+
10
+ kinesis = Aws::Kinesis::Client.new
11
+
12
+ stream_name = ARGV.shift
13
+ updown = ARGV.shift
14
+
15
+ stream = kinesis.describe_stream(:stream_name => stream_name)[:stream_description]
16
+ cur_shards = stream[:shards]
17
+
18
+ if updown == 'up'
19
+ puts "Scaling up, double shards"
20
+ cur_shards.select{ |s| !has_child_shard(cur_shards, s[:shard_id]) }.each do |shard|
21
+ puts "splitting shard #{shard[:shard_id]}"
22
+ new_starting_hash_key = ((shard[:hash_key_range][:starting_hash_key].to_i + shard[:hash_key_range][:ending_hash_key].to_i) / 2).to_s
23
+ response = kinesis.split_shard(:stream_name => stream_name, :shard_to_split => shard[:shard_id], :new_starting_hash_key => new_starting_hash_key)
24
+ while true
25
+ sleep 10
26
+ break if kinesis.describe_stream(:stream_name => stream_name)[:stream_description][:stream_status] == 'ACTIVE'
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "kinesis-tools"
5
+ s.version = "0.1.0"
6
+ s.authors = ["Marten Veldthuis"]
7
+ s.email = "marten@veldthuis.com"
8
+
9
+ s.summary = "Small CLI tool to tail an AWS Kinesis stream"
10
+ s.homepage = 'https://github.com/marten/kinesis-tools'
11
+ s.license = 'MIT'
12
+
13
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
14
+ s.bindir = "bin"
15
+ s.executables = ["kinesis-tail"]
16
+ s.require_paths = ["lib"]
17
+
18
+ s.add_dependency "aws-sdk"
19
+ end
20
+
@@ -0,0 +1,3 @@
1
+ module KinesisTools
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kinesis-tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marten Veldthuis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email: marten@veldthuis.com
29
+ executables:
30
+ - kinesis-tail
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - LICENSE
38
+ - README.md
39
+ - Rakefile
40
+ - bin/kinesis-tail
41
+ - kinesis-resharding.rb
42
+ - kinesis-tools.gemspec
43
+ - lib/kinesis-tools.rb
44
+ homepage: https://github.com/marten/kinesis-tools
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.5.1
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Small CLI tool to tail an AWS Kinesis stream
68
+ test_files: []
69
+ has_rdoc: