Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not start telemetry_poller when no metric exported is configured #2190

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/sync-service/lib/electric/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ defmodule Electric.Config do
Application.fetch_env!(:electric, key)
end

@doc """
True when at least one metric exporter is configured.

This function is used to skip starting the Electric.Telemetry supervisor when there's no need
to capture periodic measurements. Useful in the dev and test environments.
"""
def telemetry_export_enabled? do
not is_nil(Electric.Config.get_env(:telemetry_statsd_host)) or
not is_nil(Electric.Config.get_env(:prometheus_port)) or
Electric.Config.get_env(:call_home_telemetry?)
end

@doc ~S"""
Parse a PostgreSQL URI into a keyword list.

Expand Down
12 changes: 8 additions & 4 deletions packages/sync-service/lib/electric/telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ defmodule Electric.Telemetry do
import Telemetry.Metrics

def start_link(init_arg) do
Supervisor.start_link(__MODULE__, init_arg, name: __MODULE__)
if Electric.Config.telemetry_export_enabled?() do
Supervisor.start_link(__MODULE__, init_arg, name: __MODULE__)
else
# Avoid starting the telemetry supervisor and its telemetry_poller child if we're not
# intending to export periodic measurements metrics anywhere.
:ignore
end
end

def init(opts) do
system_metrics_poll_interval =
Electric.Config.get_env(:system_metrics_poll_interval)

system_metrics_poll_interval = Electric.Config.get_env(:system_metrics_poll_interval)
statsd_host = Electric.Config.get_env(:telemetry_statsd_host)
prometheus? = not is_nil(Electric.Config.get_env(:prometheus_port))
call_home_telemetry? = Electric.Config.get_env(:call_home_telemetry?)
Expand Down
Loading