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

ecto_repo_init_status_info in umbrella apps #208

Open
woylie opened this issue Jun 23, 2023 · 2 comments
Open

ecto_repo_init_status_info in umbrella apps #208

woylie opened this issue Jun 23, 2023 · 2 comments

Comments

@woylie
Copy link

woylie commented Jun 23, 2023

We're having trouble making our Ecto repos appear in the dashboard in an umbrella application.

We have these apps:

  • my_app: includes MyApp.Repo
  • my_app_web: includes the Phoenix application

We put the prom_ex module into my_app_web, so that we can start it after the Phoenix endpoint. However, it seems that you are also expected to start prom_ex before the repo, so that it can get my_app_prom_ex_ecto_repo_init_status_info.

Is there a workaround for umbrella applications that we can use? Or would we have to add two separate prom_ex modules, one for each app?

Related issue: #190

@elvanja
Copy link

elvanja commented Apr 8, 2024

Have similar situation:

  • main_app - with MainApp.Repo
  • admin web - with Admin.Endpoint and router
  • user web - with User.Endpoint and router

I tried doing it like this (stuff omitted for brevity):

Main app

defmodule MainApp.Application do
  def start(_type, _args) do
    children = [
      # Telemetry supervisor
      MainApp.Telemetry,
      # Start before Ecto, to be able to capture init events
      MainApp.Observability.PromEx,
      MainApp.Repo
    ]

    OpentelemetryEcto.setup(MainApp.Repo.config()[:telemetry_prefix])
  end
end

defmodule MainApp.Observability.PromEx do
  use PromEx, otp_app: :main_app

  def plugins do
    [
      Plugins.Application,
      Plugins.Beam,
      Plugins.Ecto
    ]
  end

  def dashboards do
    [
      {:prom_ex, "application.json"},
      {:prom_ex, "beam.json"},
      {:prom_ex, "ecto.json"},
      {:prom_ex, "plug_cowboy.json"},
      {:prom_ex, "plug_router.json"},
      {:prom_ex, "phoenix.json"}
    ]
  end
end

Admin Web

defmodule AdminWeb.Application do
  def start(_type, _args) do
    children = [
      AdminWeb.Endpoint,
      # Start after the Endpoint, to avoid unnecessary error messages
      AdminWeb.Observability.PromEx
    ]

    OpentelemetryPhoenix.setup(adapter: :cowboy, endpoint_prefix: [:phoenix, :endpoint, :admin_web])
  end
end

defmodule AdminWeb.Observability.PromEx do
  use PromEx, otp_app: :admin_web

  def plugins do
    [
      {Plugins.PlugRouter, routers: [AdminWeb.Router], event_prefix: [:admin_web, :router], ignore_routes: ["/metrics"]},
      {Plugins.Phoenix, router: AdminWeb.Router, endpoint: AdminWeb.Endpoint},
      Plugins.PhoenixLiveView
    ]
  end

  def dashboards do
    [
      {:prom_ex, "application.json"},
      {:prom_ex, "beam.json"},
      {:prom_ex, "ecto.json"},
      {:prom_ex, "plug_cowboy.json"},
      {:prom_ex, "plug_router.json"},
      {:prom_ex, "phoenix.json"}
    ]
  end
end

User Web

defmodule UserWeb.Application do
  def start(_type, _args) do
    children = [
      UserWeb.Endpoint,
      # Start after the Endpoint, to avoid unnecessary error messages
      UserWeb.Observability.PromEx
    ]

    OpentelemetryPhoenix.setup(adapter: :cowboy, endpoint_prefix: [:phoenix, :endpoint, :user_web])
  end
end

defmodule UserWeb.Observability.PromEx do
  use PromEx, otp_app: :user_web

  def plugins do
    [
      {Plugins.PlugRouter, routers: [UserWeb.Router], event_prefix: [:user_web, :router], ignore_routes: ["/metrics"]},
      {Plugins.Phoenix, router: UserWeb.Router, endpoint: UserWeb.Endpoint},
      Plugins.PhoenixLiveView
    ]
  end

  def dashboards do
    [
      {:prom_ex, "application.json"},
      {:prom_ex, "beam.json"},
      {:prom_ex, "ecto.json"},
      {:prom_ex, "plug_cowboy.json"},
      {:prom_ex, "plug_router.json"},
      {:prom_ex, "phoenix.json"}
    ]
  end
end

Each PromEx is configured the same, with grafana host details and each it's own configuration block.
I see dashboard folders for each app.
However, data is empty. E.g. no repo to choose for Ecto dashboard, and no instance either.
I see only metrics for :user_web app and only phoenix and phoenix live ones.

Any ideas what may be wrong?
Is it even possible to set it up for such an umbrella setup?
Thank you 🙇🏼

@elvanja
Copy link

elvanja commented Apr 8, 2024

Update: the :user_web app indeed has option to choose e.g. the repo for Ecto dashboard, but again no data. Other Ecto dashboards totally empty, filters included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants