-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add measurements for app deployment
- Loading branch information
1 parent
1ee023d
commit ea066c8
Showing
2 changed files
with
53 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
defmodule Lenra.Monitor do | ||
@moduledoc """ | ||
This module is monitoring requests at different places | ||
Lenra's monitor executes the following events: | ||
* `[:lenra, :app_deployment, :start]` - Executed when the app's deployment is triggered. | ||
#### Measurements | ||
* start_time. | ||
#### Metadata | ||
* `:application_id` - The id of the application which is deploying. | ||
* `[:lenra, :app_deployment, :stop]` - Executed when the `available_replicas` parameter is not 0 or null on OpenFaaS. | ||
#### Measurements | ||
* end_time. | ||
* `:duration` - The time took by the openfaas function in `:native` unit of time. | ||
""" | ||
|
||
alias Lenra.Repo | ||
|
||
def setup do | ||
events = [ | ||
[:lenra, :app_deployment, :start], | ||
[:lenra, :app_deployment, :stop], | ||
] | ||
|
||
:telemetry.attach_many( | ||
"lenra.monitor", | ||
events, | ||
&Lenra.Monitor.handle_event/4, | ||
nil | ||
) | ||
end | ||
|
||
def handle_event([:lenra, :app_deployment, :start], measurements, metadata, _config) do | ||
application_id = Map.get(metadata, :application_id) | ||
|
||
Repo.insert(ApplicationDeploymentMeasurement.new(application_id, measurements)) | ||
end | ||
|
||
def handle_event([:lenra, :app_deployment, :stop], measurements, metadata, _config) do | ||
application_id = Map.get(metadata, :application_id) | ||
|
||
Repo.get_by!(ApplicationDeploymentMeasurement, uuid: application_id) | ||
|> ApplicationDeploymentMeasurement.update(measurements) | ||
|> Repo.update() | ||
end | ||
end |