diff --git a/lib/dpul_collections/indexing_pipeline/dashboard_page.ex b/lib/dpul_collections/indexing_pipeline/dashboard_page.ex index a555ca24..003ab459 100644 --- a/lib/dpul_collections/indexing_pipeline/dashboard_page.ex +++ b/lib/dpul_collections/indexing_pipeline/dashboard_page.ex @@ -58,7 +58,9 @@ defmodule DpulCollections.IndexingPipeline.DashboardPage do rows_name="metrics" > <:col field={:updated_at} sortable={:desc} /> - <:col field={:duration} header="Duration (s)" /> + <:col :let={record} field={:duration} header="Duration (hh:mm:ss)"> + <%= to_hh_mm_ss(record.duration) %> + <:col field={:records_acked} header="Record Count" /> <:col :let={record} field={:per_second} header="Records per Second"> <%= per_second(record) %> @@ -73,7 +75,9 @@ defmodule DpulCollections.IndexingPipeline.DashboardPage do rows_name="metrics" > <:col field={:updated_at} sortable={:desc} /> - <:col field={:duration} header="Duration (s)" /> + <:col :let={record} field={:duration} header="Duration (hh:mm:ss)"> + <%= to_hh_mm_ss(record.duration) %> + <:col field={:records_acked} header="Record Count" /> <:col :let={record} field={:per_second} header="Records per Second"> <%= per_second(record) %> @@ -88,7 +92,9 @@ defmodule DpulCollections.IndexingPipeline.DashboardPage do rows_name="metrics" > <:col field={:updated_at} sortable={:desc} /> - <:col field={:duration} header="Duration (s)" /> + <:col :let={record} field={:duration} header="Duration (hh:mm:ss)"> + <%= to_hh_mm_ss(record.duration) %> + <:col field={:records_acked} header="Record Count" /> <:col :let={record} field={:per_second} header="Records per Second"> <%= per_second(record) %> @@ -104,4 +110,20 @@ defmodule DpulCollections.IndexingPipeline.DashboardPage do defp per_second(%{duration: duration, records_acked: records_acked}) do records_acked / duration end + + # Pulled from + # https://nickjanetakis.com/blog/formatting-seconds-into-hh-mm-ss-with-elixir-and-python + # and modified to be consistently hh:mm:ss + defp to_hh_mm_ss(0), do: "00:00:00" + + defp to_hh_mm_ss(seconds) do + units = [3600, 60, 1] + # Returns a list of how many hours, minutes, and seconds there are, reducing + # the total seconds by that amount if it's greater than 1. + t = + Enum.map_reduce(units, seconds, fn unit, val -> {div(val, unit), rem(val, unit)} end) + |> elem(0) + + Enum.map_join(t, ":", fn x -> x |> Integer.to_string() |> String.pad_leading(2, "0") end) + end end diff --git a/test/dpul_collections/indexing_pipeline/dashboard_page_test.exs b/test/dpul_collections/indexing_pipeline/dashboard_page_test.exs new file mode 100644 index 00000000..7519e199 --- /dev/null +++ b/test/dpul_collections/indexing_pipeline/dashboard_page_test.exs @@ -0,0 +1,48 @@ +defmodule DpuLCollections.IndexingPipeline.DashboardPageTest do + alias DpulCollections.IndexingPipeline.Figgy.IndexingProducerSource + alias DpulCollections.IndexingPipeline.Figgy.TransformationProducerSource + alias DpulCollections.IndexingPipeline.Figgy.HydrationProducerSource + alias DpulCollections.IndexingPipeline.Metrics + use DpulCollectionsWeb.ConnCase + import Phoenix.LiveViewTest + @endpoint DpulCollectionsWeb.Endpoint + + test "GET /dev/dashboard/index_metrics", %{conn: conn} do + Metrics.create_index_metric(%{ + type: HydrationProducerSource.processor_marker_key(), + measurement_type: "full_index", + duration: 0, + records_acked: 20 + }) + + Metrics.create_index_metric(%{ + type: TransformationProducerSource.processor_marker_key(), + measurement_type: "full_index", + duration: 10, + records_acked: 20 + }) + + Metrics.create_index_metric(%{ + type: IndexingProducerSource.processor_marker_key(), + measurement_type: "full_index", + duration: 200, + records_acked: 60 + }) + + {:ok, view, html} = + conn + |> put_req_header("authorization", "Basic " <> Base.encode64("admin:test")) + |> get(~p"/dev/dashboard/index_metrics") + |> live + + assert html =~ "Hydration Metric Times" + assert html =~ "Transformation Metric Times" + assert html =~ "Indexing Metric Times" + assert has_element?(view, "td.hydration-table-per_second", "20") + assert has_element?(view, "td.hydration-table-duration", "00:00:00") + assert has_element?(view, "td.transformation-table-per_second", "2") + assert has_element?(view, "td.transformation-table-duration", "00:00:10") + assert has_element?(view, "td.indexing-table-per_second", "0.3") + assert has_element?(view, "td.indexing-table-duration", "00:03:20") + end +end