Telemetry check service (#771)

This commit is contained in:
Jamil
2022-06-30 09:34:03 -07:00
committed by GitHub
parent f461ef84c6
commit 6442439378
3 changed files with 29 additions and 2 deletions

View File

@@ -36,6 +36,7 @@ defmodule FzHttp.Application do
{Phoenix.PubSub, name: FzHttp.PubSub},
FzHttpWeb.Presence,
FzHttp.ConnectivityCheckService,
FzHttp.TelemetryPingService,
FzHttp.VpnSessionScheduler,
{OpenIDConnect.Worker, openid_connect_providers},
{DynamicSupervisor, name: FzHttp.RefresherSupervisor, strategy: :one_for_one},

View File

@@ -7,7 +7,7 @@ defmodule FzHttp.ConnectivityCheckService do
require Logger
alias FzHttp.{ConnectivityChecks, Telemetry}
alias FzHttp.ConnectivityChecks
def start_link(_) do
http_client().start()
@@ -26,7 +26,6 @@ defmodule FzHttp.ConnectivityCheckService do
# XXX: Consider passing state here to implement exponential backoff in case of errors.
@impl GenServer
def handle_info(:perform, _state) do
Telemetry.ping()
{:noreply, post_request()}
end

View File

@@ -0,0 +1,27 @@
defmodule FzHttp.TelemetryPingService do
@moduledoc """
Periodic service for sending `ping` telemetry
events.
"""
use GenServer
alias FzHttp.Telemetry
@interval 3_600
def start_link(_) do
GenServer.start_link(__MODULE__, %{})
end
@impl GenServer
def init(state) do
# Send ping every hour
:timer.send_interval(@interval * 1000, :perform)
{:ok, state}
end
@impl GenServer
def handle_info(:perform, state) do
Telemetry.ping()
{:noreply, state}
end
end