Skip to content

Commit

Permalink
Merge branch 'master' into 85-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
igor.tsupko committed Apr 3, 2018
2 parents 6992707 + 13d427d commit af18c82
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ gem 'chronic'
gem 'kubeclient'

gem 'pry', group: :development
gem 'dotenv', require: 'dotenv/load', group: :development
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ GEM
concurrent-ruby (1.0.5)
domain_name (0.5.20161021)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.2.1)
erubis (2.7.0)
faraday (0.14.0)
multipart-post (>= 1.2, < 3)
Expand Down Expand Up @@ -103,6 +104,7 @@ DEPENDENCIES
activesupport
chronic
clickhouse!
dotenv
json
kubeclient
parslet
Expand Down
10 changes: 8 additions & 2 deletions lib/loghouse_query/clickhouse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class LoghouseQuery
module Clickhouse
extend ActiveSupport::Concern
MAX_GREEDY_SEARCH_PERIODS = 2

def result
@result ||= begin
Expand Down Expand Up @@ -37,7 +38,9 @@ def to_clickhouse(table, from, to, lim = nil)
def result_older(start_time, lim, stop_at = nil)
result = []
time = start_time
while lim.positive? && (stop_at.blank? || time >= stop_at)
stop_at ||= start_time - LogsTables::PARTITION_PERIOD.hours * MAX_GREEDY_SEARCH_PERIODS

while lim.positive? && (time >= stop_at)
table = LogsTables.partition_table_name(time)
break unless ::Clickhouse.connection.exists_table(table)

Expand All @@ -55,7 +58,10 @@ def result_older(start_time, lim, stop_at = nil)
def result_newer(start_time, lim, stop_at = nil)
result = []
time = start_time
while lim.positive? && (stop_at.blank? || time <= stop_at)
stop_at ||= start_time + LogsTables::PARTITION_PERIOD.hours * MAX_GREEDY_SEARCH_PERIODS
stop_at = Time.zone.now if stop_at > Time.zone.now

while lim.positive? && (time <= stop_at)
table = LogsTables.partition_table_name(time)
break unless ::Clickhouse.connection.exists_table(table)

Expand Down

0 comments on commit af18c82

Please sign in to comment.