keen-cli 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -1
- data/lib/keen-cli/queries.rb +23 -5
- data/lib/keen-cli/version.rb +1 -1
- data/spec/keen-cli/queries_spec.rb +19 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -162,7 +162,7 @@ Parameters:
|
|
162
162
|
|
163
163
|
+ `--collection`, `-c`: – The collection to query against. Can also be set on the environment via `KEEN_COLLECTION_NAME`.
|
164
164
|
+ `--analysis-type`, `-a`: The analysis type for the query. Only needed when not using a query command alias.
|
165
|
-
+ `--group-by`, `-g`: A group by for the query.
|
165
|
+
+ `--group-by`, `-g`: A group by for the query. Multiple fields seperated by comma are supported.
|
166
166
|
+ `--target-property`, `-y`: A target property for the query.
|
167
167
|
+ `--timeframe`, `-t`: A relative timeframe, e.g. `last_60_minutes`.
|
168
168
|
+ `--start`, `-s`: The start time of an absolute timeframe.
|
@@ -173,6 +173,7 @@ Parameters:
|
|
173
173
|
+ `--property-names`: A comma-separated list of property names. Extractions only.
|
174
174
|
+ `--latest`: Number of latest events to retrieve. Extractions only.
|
175
175
|
+ `--email`: Send extraction results via email, asynchronously. Extractions only.
|
176
|
+
+ `--spark`: Format output for [spark](https://github.com/holman/spark) ▁▂▃▅▇ Interval and timeframe fields required.
|
176
177
|
|
177
178
|
Input source parameters:
|
178
179
|
+ `--data`, `-d`: Specify query parameters as JSON instead of query params.
|
@@ -266,6 +267,7 @@ Parameters that apply to most commands include:
|
|
266
267
|
|
267
268
|
### Changelog
|
268
269
|
|
270
|
+
+ 0.2.0 - Add support for [spark](https://github.com/holman/spark) ▁▂▃▅▇
|
269
271
|
+ 0.1.9 - Supports JSON-encoded filters and comma-seperated multiple group by
|
270
272
|
+ 0.1.8 - Inputted lines can also be arrays of JSON objects. `--batch-size` param is now properly recognized.
|
271
273
|
+ 0.1.7 - Add docs command
|
data/lib/keen-cli/queries.rb
CHANGED
@@ -18,11 +18,16 @@ module KeenCli
|
|
18
18
|
option :end, :aliases => ['e']
|
19
19
|
end
|
20
20
|
|
21
|
+
def self.viz_options
|
22
|
+
option :"spark", :type => :boolean
|
23
|
+
end
|
24
|
+
|
21
25
|
desc 'queries:run', 'Run a query and print the result'
|
22
26
|
map 'queries:run' => :queries_run
|
23
27
|
shared_options
|
24
28
|
query_options
|
25
29
|
data_options
|
30
|
+
viz_options
|
26
31
|
def queries_run(analysis_type=nil)
|
27
32
|
|
28
33
|
Utils.process_options!(options)
|
@@ -35,13 +40,25 @@ module KeenCli
|
|
35
40
|
|
36
41
|
query_options = to_query_options(options)
|
37
42
|
|
38
|
-
Keen.query(analysis_type, collection, query_options)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
+
result = Keen.query(analysis_type, collection, query_options)
|
44
|
+
|
45
|
+
if (options[:spark])
|
46
|
+
raise 'Spark only applies to series queries!' unless options[:interval]
|
47
|
+
numbers = result.map do |object|
|
48
|
+
object['value']
|
49
|
+
end
|
50
|
+
return numbers.join(' ').tap do |numbers_str|
|
51
|
+
Utils.out(numbers_str, options)
|
43
52
|
end
|
44
53
|
end
|
54
|
+
|
55
|
+
if result.is_a?(Hash) || result.is_a?(Array)
|
56
|
+
Utils.out_json(result, options)
|
57
|
+
else
|
58
|
+
Utils.out(result, options)
|
59
|
+
end
|
60
|
+
|
61
|
+
result
|
45
62
|
end
|
46
63
|
|
47
64
|
desc 'queries:url', 'Print the URL for a query'
|
@@ -78,6 +95,7 @@ module KeenCli
|
|
78
95
|
shared_options
|
79
96
|
query_options
|
80
97
|
data_options
|
98
|
+
viz_options
|
81
99
|
self.send(:define_method, method_name) { queries_run(underscored_analysis_type) }
|
82
100
|
end
|
83
101
|
|
data/lib/keen-cli/version.rb
CHANGED
@@ -36,6 +36,14 @@ describe KeenCli::CLI do
|
|
36
36
|
expect(_).to eq(10)
|
37
37
|
end
|
38
38
|
|
39
|
+
it 'parses filters as JSON' do
|
40
|
+
url = "https://api.keen.io/3.0/projects/#{project_id}/queries/count?event_collection=minecraft-deaths&filters=%5B%7B%22property_name%22%3A%22enemy%22%2C%22operator%22%3A%22eq%22%2C%22property_value%22%3A%22creeper%22%7D%5D"
|
41
|
+
stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
|
42
|
+
filters = '[{"property_name":"enemy","operator":"eq","property_value":"creeper"}]'
|
43
|
+
_, options = start "queries:run --analysis-type count --collection minecraft-deaths --filters #{filters}"
|
44
|
+
expect(_).to eq(10)
|
45
|
+
end
|
46
|
+
|
39
47
|
it 'accepts extraction-specific properties' do
|
40
48
|
url = "https://api.keen.io/3.0/projects/#{project_id}/queries/extraction?event_collection=minecraft-deaths&property_names=%5B%22foo%22,%22bar%22%5D&latest=1&email=bob@bob.io"
|
41
49
|
stub_request(:get, url).to_return(:body => { :result => 10 }.to_json)
|
@@ -96,6 +104,17 @@ describe KeenCli::CLI do
|
|
96
104
|
|
97
105
|
end
|
98
106
|
|
107
|
+
describe 'spark format' do
|
108
|
+
|
109
|
+
it 'should emit interval results as numbers' do
|
110
|
+
url = "https://api.keen.io/3.0/projects/#{project_id}/queries/count?event_collection=minecraft-deaths&timeframe=last_2_minutes&interval=minutely"
|
111
|
+
stub_request(:get, url).to_return(:body => { :result => [{ value: 10 }, { value: 20 }] }.to_json)
|
112
|
+
_ = start 'queries:run --collection minecraft-deaths --analysis-type count --timeframe last_2_minutes --interval minutely --spark'
|
113
|
+
expect(_).to eq("10 20")
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
99
118
|
describe "queries:run aliases" do
|
100
119
|
KeenCli::CLI::ANALYSIS_TYPES.each do |analysis_type|
|
101
120
|
describe analysis_type do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keen-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-08-
|
12
|
+
date: 2014-08-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: keen
|