mirror of
https://github.com/cmur2/dyndnsd.git
synced 2025-07-01 22:30:19 +02:00
tracing: add opentracing for rack and dyndnsd with configurable jaeger-client support and spanmanager
This commit is contained in:
@ -21,8 +21,10 @@ module Dyndnsd
|
||||
end
|
||||
|
||||
def save
|
||||
File.open(@db_file, 'w') { |f| JSON.dump(@db, f) }
|
||||
@db_hash = @db.hash
|
||||
Helper.span('database_save') do |_span|
|
||||
File.open(@db_file, 'w') { |f| JSON.dump(@db, f) }
|
||||
@db_hash = @db.hash
|
||||
end
|
||||
end
|
||||
|
||||
def changed?
|
||||
|
@ -10,15 +10,15 @@ module Dyndnsd
|
||||
@additional_zone_content = config['additional_zone_content']
|
||||
end
|
||||
|
||||
def generate(zone)
|
||||
def generate(db)
|
||||
out = []
|
||||
out << "$TTL #{@ttl}"
|
||||
out << "$ORIGIN #{@domain}."
|
||||
out << ''
|
||||
out << "@ IN SOA #{@dns} #{@email_addr} ( #{zone['serial']} 3h 5m 1w 1h )"
|
||||
out << "@ IN SOA #{@dns} #{@email_addr} ( #{db['serial']} 3h 5m 1w 1h )"
|
||||
out << "@ IN NS #{@dns}"
|
||||
out << ''
|
||||
zone['hosts'].each do |hostname, ips|
|
||||
db['hosts'].each do |hostname, ips|
|
||||
ips.each do |ip|
|
||||
ip = IPAddr.new(ip).native
|
||||
type = ip.ipv6? ? 'AAAA' : 'A'
|
||||
|
@ -17,5 +17,25 @@ module Dyndnsd
|
||||
rescue ArgumentError
|
||||
return false
|
||||
end
|
||||
|
||||
def self.user_allowed?(username, password, users)
|
||||
(users.key? username) && (users[username]['password'] == password)
|
||||
end
|
||||
|
||||
def self.changed?(hostname, myips, hosts)
|
||||
# myips order is always deterministic
|
||||
(!hosts.include? hostname) || (hosts[hostname] != myips)
|
||||
end
|
||||
|
||||
def self.span(operation, &block)
|
||||
span = OpenTracing.start_span(operation)
|
||||
span.set_tag('component', 'dyndnsd')
|
||||
span.set_tag('span.kind', 'server')
|
||||
begin
|
||||
block.call(span)
|
||||
ensure
|
||||
span.finish
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -9,14 +9,19 @@ module Dyndnsd
|
||||
end
|
||||
|
||||
def update(zone)
|
||||
# write zone file in bind syntax
|
||||
File.open(@zone_file, 'w') { |f| f.write(@generator.generate(zone)) }
|
||||
# call user-defined command
|
||||
pid = fork do
|
||||
exec @command
|
||||
Helper.span('updater_update') do |span|
|
||||
span.set_tag('dyndnsd.updater.name', self.class.name.split('::').last)
|
||||
|
||||
# write zone file in bind syntax
|
||||
File.open(@zone_file, 'w') { |f| f.write(@generator.generate(zone)) }
|
||||
# call user-defined command
|
||||
pid = fork do
|
||||
exec @command
|
||||
end
|
||||
|
||||
# detach so children don't become zombies
|
||||
Process.detach(pid)
|
||||
end
|
||||
# detach so children don't become zombies
|
||||
Process.detach(pid)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user