Everying where "ESQuery.new" is used needs to be adjusted
Signed-off-by: Wu Zhende wuzhende666@163.com --- container/assign-account/start | 4 ++++ container/assist-result/start | 6 ++++++ container/delimiter/start | 6 ++++++ container/mail-robot/start | 5 +++++ lib/commit_status.rb | 2 +- lib/compare.rb | 4 ++-- lib/es_jobs.rb | 2 +- lib/es_query.rb | 6 ++---- sbin/es-find | 2 +- src/lib/web_backend.rb | 2 +- 10 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/container/assign-account/start b/container/assign-account/start index b926853..c8c55da 100755 --- a/container/assign-account/start +++ b/container/assign-account/start @@ -4,6 +4,8 @@
. ../defconfig.sh
+load_service_authentication + docker_rm assign-account
cmd=( @@ -11,6 +13,8 @@ cmd=( --restart=always --name=assign-account -d + -e ES_USER=$ES_USER + -e ES_PASSWORD=$ES_PASSWORD -v /etc:/etc:rw -v /srv/account-info:/opt/account_data/:rw -v /home:/home:rw diff --git a/container/assist-result/start b/container/assist-result/start index af812aa..9998588 100755 --- a/container/assist-result/start +++ b/container/assist-result/start @@ -9,11 +9,17 @@ require_relative '../defconfig.rb' names = Set.new %w[ ES_HOST ES_PORT + ES_USER + ES_PASSWORD ASSIST_RESULT_HOST ASSIST_RESULT_PORT ]
defaults = relevant_defaults(names) + +service_authentication = relevant_service_authentication(names) +defaults.merge!(service_authentication) + env = docker_env(defaults)
DEFAULT_LKP = '/c/lkp-tests' diff --git a/container/delimiter/start b/container/delimiter/start index 9485750..53adc03 100755 --- a/container/delimiter/start +++ b/container/delimiter/start @@ -9,9 +9,15 @@ require_relative '../defconfig.rb' names = Set.new %w[ TASKQUEUE_HOST TASKQUEUE_PORT + ES_USER + ES_PASSWORD ]
defaults = relevant_defaults(names) + +service_authentication = relevant_service_authentication(names) +defaults.merge!(service_authentication) + env = docker_env(defaults)
DEFAULT_LKP = '/c/lkp-tests' diff --git a/container/mail-robot/start b/container/mail-robot/start index ce18498..07aea39 100755 --- a/container/mail-robot/start +++ b/container/mail-robot/start @@ -15,6 +15,8 @@ names = Set.new %w[ SCHED_HTTPS_HOST SCHED_HTTPS_PORT ES_PORT + ES_USER + ES_PASSWORD MAILDIR ACCOUNT_ISSUER lab @@ -22,6 +24,9 @@ names = Set.new %w[
defaults = relevant_defaults(names)
+service_authentication = relevant_service_authentication(names) +defaults.merge!(service_authentication) + env = docker_env(defaults)
cmd = %w[ diff --git a/lib/commit_status.rb b/lib/commit_status.rb index 81aeb29..baae530 100644 --- a/lib/commit_status.rb +++ b/lib/commit_status.rb @@ -26,7 +26,7 @@ def query_latest_good_commit(job, error_id) end
def query_jobs_from_es(items) - es = ESQuery.new(ES_HOST, ES_PORT) + es = ESQuery.new result = es.multi_field_query items jobs_list = result['hits']['hits'] jobs_list.map! { |job| job['_source'] } diff --git a/lib/compare.rb b/lib/compare.rb index 7c182c4..7386cae 100644 --- a/lib/compare.rb +++ b/lib/compare.rb @@ -38,7 +38,7 @@ end def create_matrices_list(conditions) matrices_list = [] suite_list = [] - es = ESQuery.new(ES_HOST, ES_PORT) + es = ESQuery.new conditions.each do |condition| query_results = es.multi_field_query(condition, desc_keyword: 'start_time') matrix, suites = combine_query_data(query_results) @@ -71,7 +71,7 @@ def compare_group(argv, dimensions, options) end
def create_groups_matrices_list(conditions, dims) - es = ESQuery.new(ES_HOST, ES_PORT) + es = ESQuery.new query_results = es.multi_field_query(conditions, desc_keyword: 'start_time') combine_group_query_data(query_results['hits']['hits'], dims) end diff --git a/lib/es_jobs.rb b/lib/es_jobs.rb index 25e54b4..3c29b66 100644 --- a/lib/es_jobs.rb +++ b/lib/es_jobs.rb @@ -23,7 +23,7 @@ class ESJobs end
def query_jobs_from_es - es = ESQuery.new(ES_HOST, ES_PORT) + es = ESQuery.new result = es.multi_field_query @es_query jobs = result['hits']['hits'] jobs.map! { |job| job['_source'] } diff --git a/lib/es_query.rb b/lib/es_query.rb index 22d68a9..dd6d97d 100644 --- a/lib/es_query.rb +++ b/lib/es_query.rb @@ -7,12 +7,10 @@ require_relative 'constants.rb'
# build multiple query request body class ESQuery - HOST = (ENV.key?('ES_HOST') ? ENV['ES_HOST'] : ES_HOST) - PORT = (ENV.key?('ES_PORT') ? ENV['ES_PORT'] : ES_PORT).to_i - def initialize(host = HOST, port = PORT, index: 'jobs') + def initialize(hosts = ES_HOSTS, index: 'jobs') @index = index @scroll_id = '' - @client = Elasticsearch::Client.new url: "http://#%7Bhost%7D:#%7Bport%7D" + @client = Elasticsearch::Client.new hosts: hosts raise 'Connect Elasticsearch error!' unless @client.ping end
diff --git a/sbin/es-find b/sbin/es-find index f548fc1..78e30a8 100755 --- a/sbin/es-find +++ b/sbin/es-find @@ -77,7 +77,7 @@ options = { nr_jobs: 10, desc_keyword: 'start_time' } range = nil count = nil
-es = ESQuery.new(ES_HOST, ES_PORT) +es = ESQuery.new(ES_HOSTS)
opt_parser = OptionParser.new do |opts| opts.banner = 'Usage: es-find [options] search_key1=val1[,val2..] ..' diff --git a/src/lib/web_backend.rb b/src/lib/web_backend.rb index c4d4edd..91287b4 100644 --- a/src/lib/web_backend.rb +++ b/src/lib/web_backend.rb @@ -657,7 +657,7 @@ def get_error_objects(filter_items) end
def get_job_list(items) - es = ESQuery.new(ES_HOST, ES_PORT) + es = ESQuery.new query_results = es.multi_field_query(items)
extract_jobs_list(query_results['hits']['hits'])