archethic-foundation / archethic-node

Official Archethic Blockchain node, written in Elixir
GNU Affero General Public License v3.0
74 stars 22 forks source link

Add telemetry for embedded database #327

Closed ghost closed 2 years ago

ghost commented 2 years ago

Problem to solve

We want to have a better monitoring of the database, to detect bottlenecks or area of improvements

Solution

We have to leverage telemetry for:

apoorv-2204 commented 2 years ago

hello Team, I think , we might have to add this only ,maybe. It might also cause regression in Metrics.Poller. Whaty'all think?

 start =System.monotonic_time()
:telemetry.execute([:archethic, :db], %{duration: System.monotonic_time() - start}, %{
        query: "write_transaction_chain"
      })

@spec write_transaction_chain(list(Transaction.t())) :: :ok
  def write_transaction_chain(chain) do
    start =System.monotonic_time()

    sorted_chain = Enum.sort_by(chain, & &1.validation_stamp.timestamp, {:asc, DateTime})

    first_tx = List.first(sorted_chain)
    genesis_address = Transaction.previous_address(first_tx)

    Enum.each(sorted_chain, fn tx ->
      unless ChainIndex.transaction_exists?(tx.address, db_path()) do
        ChainWriter.append_transaction(genesis_address, tx)
      end
    end)
:telemetry.execute([:archethic, :db], %{duration: System.monotonic_time() - start}, %{
        query: "write_transaction_chain"
      })
  end
AmodD commented 2 years ago

Hey team! Please add your planning poker estimate with ZenHub @apoorv-2204 @blackode @Neylix @samuel-uniris @nilesh-uniris