8000 feat: allow to pass mfa for git sha, git author and app version to lifecycle annotator by yordis · Pull Request #163 · akoutmos/prom_ex · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: allow to pass mfa for git sha, git author and app version to lifecycle annotator #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions lib/prom_ex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,12 @@ defmodule PromEx do
)
|> PromEx.lifecycle_annotator_child_spec(
grafana_config,
__MODULE__,
unquote(otp_app),
unquote(lifecycle_annotator_name)
name: unquote(lifecycle_annotator_name),
prom_ex_module: __MODULE__,
otp_app: unquote(otp_app),
git_sha_mfa: nil,
git_author_mfa: nil,
app_version_mfa: nil
)
|> Enum.reverse()

Expand Down Expand Up @@ -458,20 +461,15 @@ defmodule PromEx do
end

@doc false
def lifecycle_annotator_child_spec(acc, %{annotate_app_lifecycle: true}, prom_ex_module, otp_app, process_name) do
spec = {
PromEx.LifecycleAnnotator,
name: process_name, prom_ex_module: prom_ex_module, otp_app: otp_app
}

[spec | acc]
def lifecycle_annotator_child_spec(acc, %{annotate_app_lifecycle: true}, opts) do
[{PromEx.LifecycleAnnotator, opts} | acc]
end

def lifecycle_annotator_child_spec(acc, :disabled, _, _, _) do
def lifecycle_annotator_child_spec(acc, :disabled, _) do
acc
end

def lifecycle_annotator_child_spec(acc, %{annotate_app_lifecycle: false}, _, _, _) do
def lifecycle_annotator_child_spec(acc, %{annotate_app_lifecycle: false}, _) do
acc
end

Expand Down
61 changes: 35 additions & 26 deletions lib/prom_ex/lifecycle_annotator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,12 @@ defmodule PromEx.LifecycleAnnotator do
|> elem(1)
|> :erlang.list_to_binary()

app_version =
otp_app
|> Application.spec(:vsn)
|> to_string()

git_sha =
case System.fetch_env("GIT_SHA") do
{:ok, git_sha} ->
git_sha

:error ->
"Not available"
end

git_author =
case System.fetch_env("GIT_AUTHOR") do
{:ok, git_sha} ->
git_sha

:error ->
"Not available"
end

state =
state
|> Map.put(:hostname, hostname)
|> Map.put(:app_version, app_version)
|> Map.put(:git_sha, git_sha)
|> Map.put(:git_author, git_author)
|> Map.put(:app_version, get_app_version(state[:git_sha_mfa], otp_app))
|> Map.put(:git_sha, get_git_sha(state[:git_sha_mfa]))
|> Map.put(:git_author, get_git_sha(state[:git_author_mfa]))

grafana_conn = GrafanaClient.build_conn(prom_ex_module)

Expand Down Expand Up @@ -123,4 +100,36 @@ defmodule PromEx.LifecycleAnnotator do
"Git Author - #{git_author}"
]
end

defp get_app_version({m, f, a}, _), do: apply(m, f, a)

defp get_app_version(_, otp_app) do
otp_app
|> Application.spec(:vsn)
|> to_string()
end

defp get_git_sha({m, f, a}), do: apply(m, f, a)

defp get_git_sha(_) do
case System.fetch_env("GIT_SHA") do
{:ok, git_sha} ->
git_sha

:error ->
"Git SHA not available"
end
end

defp get_git_author({m, f, a}), do: apply(m, f, a)

def get_git_author(_) do
case System.fetch_env("GIT_AUTHOR") do
{:ok, git_sha} ->
git_sha

:error ->
"Git author not available"
end
end
end
0