prometheus-ecto
                                
                                
                                
                                    prometheus-ecto copied to clipboard
                            
                            
                            
                        Argument error during migration with Ecto.Repo.delete_all/1
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
                                    
                                    
                                    
                                
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 wrote:
We had a similar problem with
ottersome days ago.:ets.lookup/2fails with anArgumentErrorwhen the ETS tables does not exist. You may need to startprometheus_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