Skip to content

Commit

Permalink
Pid is in log output already
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Nov 12, 2023
1 parent 6034d65 commit 0d054c6
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/flipper/cloud/telemetry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,33 @@ def record(name, payload)

# Start all the tasks and setup new metric storage.
def start
logger.info "pid=#{@pid} name=flipper_telemetry action=start"
logger.info "name=flipper_telemetry action=start"
@metric_storage = MetricStorage.new
@pool = Concurrent::FixedThreadPool.new(5, pool_options)
@timer = Concurrent::TimerTask.execute(timer_options) { post_to_pool }
end

# Shuts down all the tasks and tries to flush any remaining info to Cloud.
def stop
logger.info "pid=#{@pid} name=flipper_telemetry action=stop"
logger.info "name=flipper_telemetry action=stop"

if @timer
logger.debug "pid=#{@pid} name=flipper_telemetry action=timer_shutdown_start"
logger.debug "name=flipper_telemetry action=timer_shutdown_start"
@timer.shutdown
# no need to wait long for timer, all it does is drain in memory metric
# storage and post to the pool of background workers
timer_termination_result = @timer.wait_for_termination(1)
@timer.kill unless timer_termination_result
logger.debug "pid=#{@pid} name=flipper_telemetry action=timer_shutdown_end result=#{timer_termination_result}"
logger.debug "name=flipper_telemetry action=timer_shutdown_end result=#{timer_termination_result}"
end

if @pool
post_to_pool # one last drain
logger.debug "pid=#{@pid} name=flipper_telemetry action=pool_shutdown_start"
logger.debug "name=flipper_telemetry action=pool_shutdown_start"
@pool.shutdown
pool_termination_result = @pool.wait_for_termination(@cloud_configuration.telemetry_shutdown_timeout)
@pool.kill unless pool_termination_result
logger.debug "pid=#{@pid} name=flipper_telemetry action=pool_shutdown_end result=#{pool_termination_result}"
logger.debug "name=flipper_telemetry action=pool_shutdown_end result=#{pool_termination_result}"
end
end

Expand All @@ -95,22 +95,22 @@ def restart

def detect_forking
if @pid != $$
logger.info "pid=#{@pid} name=flipper_telemetry action=fork_detected pid_was#{@pid} pid_is=#{$$}"
logger.info "name=flipper_telemetry action=fork_detected pid_was#{@pid} pid_is=#{$$}"
restart
@pid = $$
end
end

def post_to_pool
logger.debug "pid=#{@pid} name=flipper_telemetry action=post_to_pool"
logger.debug "name=flipper_telemetry action=post_to_pool"
drained = @metric_storage.drain
return if drained.empty?
@pool.post { post_to_cloud(drained) }
end

def post_to_cloud(drained)
return if drained.empty?
logger.debug "pid=#{@pid} name=flipper_telemetry action=post_to_cloud"
logger.debug "name=flipper_telemetry action=post_to_cloud"

enabled_metrics = drained.map { |metric, value|
metric.as_json(with: {"value" => value})
Expand Down

0 comments on commit 0d054c6

Please sign in to comment.