dripl 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 60717539687a586e7351695c5678d5b012b9dcdc
4
+ data.tar.gz: 26680e7b9d2267f9309ecf7037afb6615f2cf13c
5
+ SHA512:
6
+ metadata.gz: 42dec64bfeb390e6ac89776f4f5f0c7abd79ec3ecc6366621659d31b3867e9c7f3b0811dcc7185a35610a2a1747f94a6ed262f1763d2737c99e88d6ba06a75f3
7
+ data.tar.gz: ac15c933b30155ef710165c54165cefb87beae37e336eb9120d03146b1fe0ddc8b73e352211037995cd84857b0c225ebcc135d716cc530bd01efaf9ef04e9a11
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Ruby Druid Community
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # dripl
2
+
3
+ An interactive terminal for Druid. It allows fetching metadata and constructing and sending queries to a Druid cluster.
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ gem install dripl
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```
14
+ dripl --zookeeper localhost:2181
15
+ >> sources
16
+ [
17
+ [0] "events"
18
+ ]
19
+
20
+ >> use 0
21
+ Using events data source
22
+
23
+ >> metrics
24
+ [
25
+ [0] "actions"
26
+ [1] "words"
27
+ ]
28
+
29
+ >> dimensions
30
+ [
31
+ [0] "type"
32
+ ]
33
+
34
+ >> long_sum(:actions)
35
+ +---------+
36
+ | actions |
37
+ +---------+
38
+ | 98575 |
39
+ +---------+
40
+
41
+ >> long_sum(:actions, :words).last(3.days).granularity(:day)
42
+ +---------------+---------------+
43
+ | actions | words |
44
+ +---------------+---------------+
45
+ | 2013-12-11T00:00:00.000+01:00 |
46
+ +---------------+---------------+
47
+ | 537345 | 68974 |
48
+ +---------------+---------------+
49
+ | 2013-12-12T00:00:00.000+01:00 |
50
+ +---------------+---------------+
51
+ | 675431 | 49253 |
52
+ +---------------+---------------+
53
+ | 2013-12-13T00:00:00.000+01:00 |
54
+ +---------------+---------------+
55
+ | 749034 | 87542 |
56
+ +---------------+---------------+
57
+
58
+ >> long_sum(:actions, :words).last(3.days).granularity(:day).as_json
59
+ {
60
+ :dataSource => "events",
61
+ :granularity => {
62
+ :type => "period",
63
+ :period => "P1D",
64
+ :timeZone => "Europe/Berlin"
65
+ },
66
+ :intervals => [
67
+ [0] "2013-12-11T00:00:00+01:00/2013-12-13T09:41:10+01:00"
68
+ ],
69
+ :queryType => :groupBy,
70
+ :aggregations => [
71
+ [0] {
72
+ :type => "longSum",
73
+ :name => :actions,
74
+ :fieldName => :actions
75
+ },
76
+ [1] {
77
+ :type => "longSum",
78
+ :name => :words,
79
+ :fieldName => :words
80
+ }
81
+ ]
82
+ }
83
+ ```
data/bin/dripl ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ require "dripl"
3
+
4
+ # TODO: load .driplrc
5
+ cli = Dripl::CLI.new
6
+ cli.parse_options
7
+ cli.run
data/dripl.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $:.unshift(lib) unless $:.include?(lib)
3
+
4
+ require "dripl/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "dripl"
8
+ s.version = Dripl::VERSION
9
+ s.authors = ["Ruby Druid Community"]
10
+ s.summary = %q{An interactive terminal for Druid}
11
+ s.description = <<-EOF
12
+ dripl is an interactive terminal for Druid. It allows
13
+ fetching metadata and constructing and sending queries
14
+ to a Druid cluster.
15
+ EOF
16
+ s.homepage = "https://github.com/ruby-druid/dripl"
17
+ s.license = "MIT"
18
+
19
+ s.files = Dir["lib/**/*"] + %w{LICENSE README.md dripl.gemspec}
20
+ s.test_files = Dir["spec/**/*"]
21
+ s.require_paths = ["lib"]
22
+ s.executables = ["dripl"]
23
+
24
+ s.add_runtime_dependency "awesome_print", "~> 1.6"
25
+ s.add_runtime_dependency "mixlib-cli", "~> 1.6"
26
+ s.add_runtime_dependency "ruby-druid", "~> 0.9"
27
+ s.add_runtime_dependency "ripl", "~> 0.7"
28
+ s.add_runtime_dependency "terminal-table", "~> 1.5"
29
+ s.add_development_dependency "bundler", "~> 1.12"
30
+ s.add_development_dependency "rake", "~> 11.2"
31
+ s.add_development_dependency "rspec", "~> 3.4"
32
+ end
data/lib/dripl.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "dripl/cli"
2
+ require "dripl/formatter"
3
+ require "dripl/prompt"
4
+
5
+ module Dripl; end
data/lib/dripl/cli.rb ADDED
@@ -0,0 +1,40 @@
1
+ require "druid"
2
+ require "mixlib/cli"
3
+
4
+ module Dripl
5
+ class CLI
6
+ include Mixlib::CLI
7
+
8
+ option :zookeeper,
9
+ short: "-z URL",
10
+ long: "--zookeeper URL",
11
+ description: "Zookeeper URL"
12
+
13
+ option :source,
14
+ short: "-s NAME",
15
+ long: "--source NAME",
16
+ description: "default data source"
17
+
18
+ option :help,
19
+ short: "-h",
20
+ long: "--help",
21
+ description: "Show this message",
22
+ on: :tail,
23
+ boolean: true,
24
+ show_options: true,
25
+ exit: 0
26
+
27
+ def run
28
+ if zookeeper = config[:zookeeper]
29
+ client = Druid::Client.new(zookeeper)
30
+ end
31
+
32
+ unless client
33
+ puts "Couldn't create Druid client"
34
+ exit 1
35
+ end
36
+
37
+ Prompt.new(client, config[:source]).start
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,66 @@
1
+ require "awesome_print"
2
+ require "druid"
3
+ require "terminal-table"
4
+
5
+ module Dripl
6
+ module Formatter
7
+ def format_result(result)
8
+ return unless result
9
+
10
+ if result.is_a?(Druid::Query::Builder)
11
+ start_time = Time.now
12
+ response = eval("source", binding).post(result)
13
+ puts(format_query_response(result.query, response))
14
+ puts("Query took #{Time.now - start_time}s")
15
+ else
16
+ ap(result)
17
+ end
18
+
19
+ return # prevent default formatting
20
+ end
21
+
22
+ private
23
+
24
+ def format_query_response(query, response)
25
+ ap(query.as_json)
26
+ ap(response.as_json)
27
+ return if response.empty?
28
+ case query.queryType
29
+ when "timeseries", "groupBy"
30
+ format_timeseries_query_response(query, response)
31
+ when "segmentMetadata"
32
+ format_segment_metadata_response(query, response)
33
+ end
34
+ end
35
+
36
+ def response_key(type)
37
+ case type
38
+ when "timeseries"
39
+ "result"
40
+ when "groupBy"
41
+ "event"
42
+ end
43
+ end
44
+
45
+ def format_timeseries_query_response(query, response)
46
+ response_key = response_key(query.queryType)
47
+ keys = response.last[response_key].keys
48
+ grouped_response = response.group_by { |x| x["timestamp"] }
49
+
50
+ Terminal::Table.new(headings: keys) do
51
+ grouped_response.each do |timestamp, rows|
52
+ add_row(:separator) unless timestamp == response.first["timestamp"]
53
+ add_row([{ value: timestamp, colspan: keys.length }])
54
+ add_row(:separator)
55
+ rows.each { |row| add_row(keys.map { |key| row[response_key][key] }) }
56
+ end
57
+ end
58
+ end
59
+
60
+ def format_segment_metadata_response(query, response)
61
+ columns = response.map { |row| row["columns"].keys }
62
+ .to_a.flatten.uniq.sort
63
+ Terminal::Table.new(:headings => columns) {}
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,49 @@
1
+ require "druid"
2
+ require "ripl"
3
+
4
+ module Dripl
5
+ class Prompt
6
+ attr_accessor :client, :source
7
+
8
+ def initialize(client, source = nil)
9
+ @client = client
10
+ @source = nil
11
+ use(source) if source
12
+ end
13
+
14
+ def start
15
+ Ripl.start(argv: [], binding: binding)
16
+ end
17
+
18
+ def method_missing(*args)
19
+ query.public_send(*args)
20
+ end
21
+
22
+ def query
23
+ query = Druid::Query::Builder.new
24
+ query.data_source(@source.name)
25
+ query
26
+ end
27
+
28
+ def sources
29
+ @client.data_sources.keys
30
+ end
31
+
32
+ def dimensions
33
+ @source.dimensions.sort
34
+ end
35
+
36
+ def metrics
37
+ @source.metrics.sort
38
+ end
39
+
40
+ def use(source)
41
+ # TODO: source not found
42
+ source = @client.data_sources.keys[source] if source.is_a?(Numeric)
43
+ @source = @client.data_source(source)
44
+ puts("Using #{@source.name} data source")
45
+ end
46
+ end
47
+ end
48
+
49
+ Ripl::Shell.include(Dripl::Formatter)
@@ -0,0 +1,3 @@
1
+ module Dripl
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dripl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ruby Druid Community
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: awesome_print
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mixlib-cli
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ruby-druid
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.9'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ripl
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.7'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: terminal-table
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.5'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.12'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.12'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '11.2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '11.2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.4'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.4'
125
+ description: |2
126
+ dripl is an interactive terminal for Druid. It allows
127
+ fetching metadata and constructing and sending queries
128
+ to a Druid cluster.
129
+ email:
130
+ executables:
131
+ - dripl
132
+ extensions: []
133
+ extra_rdoc_files: []
134
+ files:
135
+ - LICENSE
136
+ - README.md
137
+ - bin/dripl
138
+ - dripl.gemspec
139
+ - lib/dripl.rb
140
+ - lib/dripl/cli.rb
141
+ - lib/dripl/formatter.rb
142
+ - lib/dripl/prompt.rb
143
+ - lib/dripl/version.rb
144
+ homepage: https://github.com/ruby-druid/dripl
145
+ licenses:
146
+ - MIT
147
+ metadata: {}
148
+ post_install_message:
149
+ rdoc_options: []
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ requirements: []
163
+ rubyforge_project:
164
+ rubygems_version: 2.5.1
165
+ signing_key:
166
+ specification_version: 4
167
+ summary: An interactive terminal for Druid
168
+ test_files: []