Skip to content

Commit 49ddbee

Browse files
Tatarinhomatrixik
authored andcommitted
Monasca-log-agent fails to start if there is not connection to keystone (#14)
The purpose of this commit is to provide mechanism for monasca-log-agent to wait for keystone service for determined amount of times instead of failing at first try.
1 parent 4a10ec8 commit 49ddbee

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

lib/logstash/outputs/keystone/token.rb

+21-3
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,31 @@ class Token
2525
attr_accessor :id, :expires_at, :keystone_client
2626

2727
def request_new_token(username, user_domain_name, password, project_name, project_domain_name)
28-
token = @keystone_client
29-
.authenticate(username, user_domain_name, password, project_name, project_domain_name)
30-
set_token(token[:token], token[:expires_at])
28+
attempt = 0
29+
begin
30+
@logger.info("Connecting to keystone, attempt no. #{attempt}")
31+
token = @keystone_client
32+
.authenticate(username, user_domain_name, password, project_name, project_domain_name)
33+
set_token(token[:token], token[:expires_at])
34+
rescue => e
35+
attempt += 1
36+
sleep_for = get_sleep_time(attempt)
37+
@logger.error("Sending event to keystone threw exception, "\
38+
"will sleep for #{sleep_for} seconds.",
39+
:exceptionew => e)
40+
41+
Stud.stoppable_sleep(sleep_for)
42+
retry
43+
end
3144
@logger.info('New token requested')
3245
@logger.debug("token=#{@id}, expire_at=#{@expires_at}")
3346
end
3447

48+
def get_sleep_time(attempt)
49+
sleep_for = attempt**2
50+
sleep_for <= 60 ? sleep_for : 60
51+
end
52+
3553
def set_token(id, expires_at)
3654
@id = id
3755
@expires_at = expires_at

logstash-output-monasca_log_api.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = 'logstash-output-monasca_log_api'
3-
s.version = '2.0.0'
3+
s.version = '2.0.1'
44
s.licenses = ['Apache-2.0']
55
s.summary = 'This gem is a logstash output plugin to connect via http to monasca-log-api.'
66
s.description = 'This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program'

0 commit comments

Comments
 (0)