prometheus-ecto icon indicating copy to clipboard operation
prometheus-ecto copied to clipboard

Argument error during migration with Ecto.Repo.delete_all/1

Open alex-knowles opened this issue 7 years ago • 2 comments

Using prometheus_ecto version 1.3.0, I observe the following stack trace:

** (ArgumentError) argument error
    (stdlib) :ets.lookup(:prometheus_histogram_table, {:default, :ecto_db_query_duration_microseconds, [:ok], 3})
    src/metrics/prometheus_histogram.erl:196: :prometheus_histogram.observe/4
    lib/core/repo_instrumenter.ex:5: Core.RepoInstrumenter.log/1
    lib/core/repo.ex:2: Core.Repo.__log__/1
    (db_connection) lib/db_connection.ex:1186: DBConnection.log/6
    (ecto) lib/ecto/adapters/postgres/connection.ex:73: Ecto.Adapters.Postgres.Connection.prepare_execute/5
    (ecto) lib/ecto/adapters/sql.ex:256: Ecto.Adapters.SQL.sql_call/6
    (ecto) lib/ecto/adapters/sql.ex:426: Ecto.Adapters.SQL.execute_and_cache/7

The Core.RepoInstrumenter module refers to my instrumenter (MyApp.Repo.Instrumenter in the README).

The migration starts by dropping all the rows in a table using Ecto.Repo.delete_all/1. Something like:

MyRepo.delete_all(MySchema)

I can work-around the error by using Ecto.Migration.drop/1 and Ecto.Migration.create/1 in place of delete_all/1:

drop table(:my_table_name)
create table(:my_table_name, primary_key: false) do
  add :foo, :string, null: false
  add :bar, :string, null: false
 # ...
end

alex-knowles avatar Oct 25 '18 15:10 alex-knowles

We had a similar problem with otter some days ago. :ets.lookup/2 fails with an ArgumentError when the ETS tables does not exist. You may need to start prometheus_ecto.

janpieper avatar Oct 26 '18 20:10 janpieper

@janpieper wrote:

We had a similar problem with otter some days ago. :ets.lookup/2 fails with an ArgumentError when the ETS tables does not exist. You may need to start prometheus_ecto.

I am pretty new to ETS, but I suspect that the prometheus tables do exist prior to the migration.

For example, when I invoke :ets.all/0, I see :prometheus_histogram_table in the results. Also, if I start Observer from an iex -S mix session and select the Table Viewer I see a number of prometheus tables in the list:

  • prometheus_boolean_table
  • prometheus_counter_table
  • prometheus_gauge_table
  • prometheus_histogram_table
  • prometheus_instrumenter_tests
  • prometheus_registry_table
  • prometheus_summary_table

alex-knowles avatar Oct 29 '18 15:10 alex-knowles