-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2617 capture editor metrics serverside (#2868)
* Config to allow disabling of logging * Allow for logging of JobEditor merics * Pass through metrics from JobEditor * Implement logging for workflow editor metrics * Refactor UiMetrics * Wire up WorkflowEditor metrics * Fix test name typo * Formatting changes * Docs and CHANGELOG * Test coverage on liveview * Trying out retrying when all the components haven't mounted yet --------- Co-authored-by: Stuart Corbishley <[email protected]>
- Loading branch information
1 parent
adba8f6
commit 6439637
Showing
14 changed files
with
516 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
defmodule LightningWeb.UiMetrics do | ||
@moduledoc """ | ||
A temporary measure to allow WorkflowEditor and JobEditor UI components to | ||
report selected metrics and have these logged. | ||
""" | ||
require Logger | ||
|
||
def log_job_editor_metrics(job, metrics) do | ||
if Lightning.Config.ui_metrics_tracking_enabled?() do | ||
Enum.each(metrics, fn metric -> | ||
metric | ||
|> enrich_job_editor_metric(job) | ||
|> create_job_editor_log_line() | ||
|> Logger.info() | ||
end) | ||
end | ||
end | ||
|
||
defp enrich_job_editor_metric(metric, job) do | ||
%{id: job_id, workflow_id: workflow_id} = job | ||
|
||
metric | ||
|> common_enrichment() | ||
|> Map.merge(%{ | ||
"workflow_id" => workflow_id, | ||
"job_id" => job_id | ||
}) | ||
end | ||
|
||
defp create_job_editor_log_line(metric) do | ||
%{ | ||
"event" => event, | ||
"workflow_id" => workflow_id, | ||
"job_id" => job_id, | ||
"start_time" => start_time, | ||
"end_time" => end_time, | ||
"duration" => duration | ||
} = metric | ||
|
||
"UiMetrics: [JobEditor] " <> | ||
"event=`#{event}` " <> | ||
"workflow_id=#{workflow_id} " <> | ||
"job_id=#{job_id} " <> | ||
"start_time=#{start_time} " <> | ||
"end_time=#{end_time} " <> | ||
"duration=#{duration} ms" | ||
end | ||
|
||
def log_workflow_editor_metrics(workflow, metrics) do | ||
if Lightning.Config.ui_metrics_tracking_enabled?() do | ||
Enum.each(metrics, fn metric -> | ||
metric | ||
|> enrich_workflow_editor_metric(workflow) | ||
|> create_workflow_editor_log_line() | ||
|> Logger.info() | ||
end) | ||
end | ||
end | ||
|
||
defp enrich_workflow_editor_metric(metric, %{id: workflow_id}) do | ||
metric |> common_enrichment() |> Map.put("workflow_id", workflow_id) | ||
end | ||
|
||
defp create_workflow_editor_log_line(metric) do | ||
%{ | ||
"event" => event, | ||
"workflow_id" => workflow_id, | ||
"start_time" => start_time, | ||
"end_time" => end_time, | ||
"duration" => duration | ||
} = metric | ||
|
||
"UiMetrics: [WorkflowEditor] " <> | ||
"event=`#{event}` " <> | ||
"workflow_id=#{workflow_id} " <> | ||
"start_time=#{start_time} " <> | ||
"end_time=#{end_time} " <> | ||
"duration=#{duration} ms" | ||
end | ||
|
||
defp common_enrichment(%{"start" => start_ts, "end" => end_ts} = metric) do | ||
metric | ||
|> Map.merge(%{ | ||
"start_time" => convert_ts(start_ts), | ||
"end_time" => convert_ts(end_ts), | ||
"duration" => end_ts - start_ts | ||
}) | ||
end | ||
|
||
defp convert_ts(ts) do | ||
ts |> DateTime.from_unix!(:millisecond) |> DateTime.to_iso8601() | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.