-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1190 from OpenFn/1178-load-tests-production-telem…
…etry Crude logging of telemetry events for load testing
- Loading branch information
Showing
3 changed files
with
88 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
defmodule TelemetryCSVLogger do | ||
require Logger | ||
|
||
def handle_event( | ||
[:lightning, :workorder, :webhook, :stop] = event, | ||
%{duration: duration} = measurements, | ||
_metadata, | ||
output_file: file | ||
) do | ||
log_received(event, measurements) | ||
|
||
IO.binwrite(file, "lightning.create_webhook_workorder.stop, #{duration}\n") | ||
end | ||
|
||
def handle_event(event, _measurements, _metadata, _config) do | ||
log_received(event) | ||
end | ||
|
||
defp native_to_microsecond(duration) do | ||
System.convert_time_unit(duration, :native, :microsecond) | ||
end | ||
|
||
defp log_received(event, %{duration: duration}) do | ||
duration = native_to_microsecond(duration) | ||
|
||
Logger.info( | ||
"Received #{event |> Enum.join(".")} event. Duration: #{duration}µs" | ||
) | ||
end | ||
|
||
defp log_received(event) do | ||
Logger.info("Received #{event |> Enum.join(".")} event.") | ||
end | ||
end | ||
|
||
defmodule LoadTestingPrep do | ||
def init(output_file) do | ||
telemetry_events = [ | ||
[:lightning, :workorder, :webhook, :stop], | ||
] | ||
|
||
:ok = | ||
:telemetry.attach_many( | ||
"lightning-load-testing-events", | ||
telemetry_events, | ||
&TelemetryCSVLogger.handle_event/4, | ||
output_file: output_file | ||
) | ||
end | ||
|
||
def fin(file) do | ||
File.close(file) | ||
end | ||
end |