Skip to content

Commit

Permalink
Merge pull request #173 from artemis-platform/dashboard-sync
Browse files Browse the repository at this point in the history
Platform Sync
  • Loading branch information
chrislaskey authored Apr 16, 2021
2 parents d941d5f + 6ff7196 commit e66079c
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .env.demo
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ ARTEMIS_CLUSTER_NODES=artemis01@0.0.0.0,artemis02@0.0.0.0
# The recomended value is 10. Higher values may cause performance issues.
#
ARTEMIS_INTERVAL_WORKER_DEFAULT_LOG_LIMIT=10
ARTEMIS_INTERVAL_WORKER_DEFAULT_LOG_LEVEL=info
ARTEMIS_BENCHMARK_DEFAULT_LOG_LEVEL=info

# Actions

Expand Down
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ ARTEMIS_CLUSTER_NODES=artemis01@0.0.0.0,artemis02@0.0.0.0
# The recomended value is 10. Higher values may cause performance issues.
#
ARTEMIS_INTERVAL_WORKER_DEFAULT_LOG_LIMIT=10
ARTEMIS_INTERVAL_WORKER_DEFAULT_LOG_LEVEL=info
ARTEMIS_BENCHMARK_DEFAULT_LOG_LEVEL=info

# Actions
#
Expand Down
2 changes: 2 additions & 0 deletions .env.travis
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ ARTEMIS_CLUSTER_NODES=artemis01@0.0.0.0,artemis02@0.0.0.0
# The recomended value is 10. Higher values may cause performance issues.
#
ARTEMIS_INTERVAL_WORKER_DEFAULT_LOG_LIMIT=10
ARTEMIS_INTERVAL_WORKER_DEFAULT_LOG_LEVEL=info
ARTEMIS_BENCHMARK_DEFAULT_LOG_LEVEL=info

# Actions

Expand Down
6 changes: 5 additions & 1 deletion apps/artemis/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ config :artemis, :cache,
username: System.get_env("ARTEMIS_CACHE_REDIS_USERNAME")
]

config :artemis, :benchmark, default_log_level: System.get_env("ARTEMIS_BENCHMARK_DEFAULT_LOG_LEVEL")

config :artemis, :event, system_events_to_not_broadcast: []

config :artemis, :users,
Expand Down Expand Up @@ -103,7 +105,9 @@ config :artemis, :ibm_cloudant,
]
]

config :artemis, :interval_worker, default_log_limit: System.get_env("ARTEMIS_INTERVAL_WORKER_DEFAULT_LOG_LIMIT")
config :artemis, :interval_worker,
default_log_limit: System.get_env("ARTEMIS_INTERVAL_WORKER_DEFAULT_LOG_LIMIT"),
default_log_level: System.get_env("ARTEMIS_INTERVAL_WORKER_DEFAULT_LOG_LEVEL")

config :artemis, :pager_duty,
api_token: System.get_env("ARTEMIS_PAGER_DUTY_API_TOKEN"),
Expand Down
78 changes: 71 additions & 7 deletions apps/artemis/lib/artemis/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -850,33 +850,58 @@ defmodule Artemis.Helpers do
end

@doc """
Print entire value without truncation
Benchmark execution time
Options:
log_level -> when not set, uses default value set in an env variable
Example:
Artemis.Helpers.benchmark("Sleep Performance", fn ->
:timer.sleep(5_000)
end, log_level: :info)
"""
def benchmark(key \\ nil, callback) do
def benchmark(callback), do: benchmark(nil, callback)

def benchmark(callback, options) when is_list(options), do: benchmark(nil, callback, options)

def benchmark(key, callback, options \\ []) do
start_time = Timex.now()
result = callback.()
end_time = Timex.now()
duration = Timex.diff(end_time, start_time, :milliseconds)

log(
default_log_level = Artemis.Helpers.AppConfig.fetch!(:artemis, :benchmark, :default_log_level)
options = Keyword.put_new(options, :log_level, default_log_level)

message = [
type: "Benchmark",
key: key,
duration: "#{duration}ms"
)
]

log(message, options)

result
end

@doc """
Send values to Logger
"""
def log(values) when is_list(values) do
def log(values, options \\ [])

def log(values, options) when is_list(values) do
message = format_log_message(values)

Logger.info(message)
log(message, options)
end

def log(message), do: Logger.info(message)
def log(message, options) do
log_level = get_log_level(options)

Logger.log(log_level, message)
end

defp format_log_message(values) do
values
Expand All @@ -890,6 +915,27 @@ defmodule Artemis.Helpers do
|> Enum.join(" ")
end

defp get_log_level(options) do
default_log_level = :info

log_level =
options
|> Keyword.get(:log_level, Keyword.get(options, :level))
|> Kernel.||(default_log_level)
|> Artemis.Helpers.to_string()

case log_level do
"emergency" -> :emergency
"alert" -> :alert
"critical" -> :critical
"error" -> :error
"warning" -> :warning
"notice" -> :notice
"info" -> :info
_ -> :debug
end
end

@doc """
Log application start
"""
Expand Down Expand Up @@ -939,4 +985,22 @@ defmodule Artemis.Helpers do
end

def error(message), do: Logger.error(message: message)

@doc """
Convert an Ecto Query into SQL
Example:
Customer
|> distinct_query(params, default: false)
|> order_query(params)
|> Artemis.Helpers.print_to_sql(Artemis.Repo)
|> Repo.all()
"""
def print_to_sql(query, repo) do
IO.inspect(Ecto.Adapters.SQL.to_sql(:all, repo, query))

query
end
end
10 changes: 8 additions & 2 deletions apps/artemis/lib/artemis/workers/interval_worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,18 @@ defmodule Artemis.IntervalWorker do
start = Timex.format!(entry.started_at, "{h24}:{m}:{s}{ss}")
duration = entry.duration / 1000

Artemis.Helpers.log(
message = [
type: "IntervalWorker",
key: module,
start: start,
duration: "#{duration}ms"
)
]

options = [
log_level: Artemis.Helpers.AppConfig.fetch!(:artemis, :interval_worker, :default_log_level)
]

Artemis.Helpers.log(message, options)
end

defp get_log_limit() do
Expand Down
2 changes: 2 additions & 0 deletions apps/artemis/lib/mix/task_helpers/strings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ defmodule Mix.TaskHelpers.Strings do
def modulecase(value) do
value
|> String.downcase()
|> String.replace("_", " ")
|> String.replace("-", " ")
|> String.split(" ")
|> Enum.map(&String.capitalize/1)
|> Enum.join("")
Expand Down
10 changes: 8 additions & 2 deletions apps/artemis_log/lib/artemis_log/workers/interval_worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,18 @@ defmodule ArtemisLog.IntervalWorker do
start = Timex.format!(entry.started_at, "{h24}:{m}:{s}{ss}")
duration = entry.duration / 1000

Artemis.Helpers.log(
message = [
type: "IntervalWorker",
key: module,
start: start,
duration: "#{duration}ms"
)
]

options = [
log_level: Artemis.Helpers.AppConfig.fetch!(:artemis, :interval_worker, :default_log_level)
]

Artemis.Helpers.log(message, options)
end

defp get_log_limit() do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,18 @@ defmodule ArtemisNotify.IntervalWorker do
start = Timex.format!(entry.started_at, "{h24}:{m}:{s}{ss}")
duration = entry.duration / 1000

Artemis.Helpers.log(
message = [
type: "IntervalWorker",
key: module,
start: start,
duration: "#{duration}ms"
)
]

options = [
log_level: Artemis.Helpers.AppConfig.fetch!(:artemis, :interval_worker, :default_log_level)
]

Artemis.Helpers.log(message, options)
end

defp get_log_limit() do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ defmodule ArtemisWeb.AuthController do
{:ok, _} <- Event.broadcast(session, "session:created:web", user) do
Logger.debug("Log In with Auth Provider Session: " <> inspect(session))

redirect = Artemis.Helpers.deep_get(data, [:extra, :raw_info, :state]) || "/"
state_query_param = Artemis.Helpers.deep_get(data, [:extra, :raw_info, :state])

redirect =
case Artemis.Helpers.present?(state_query_param) do
true -> state_query_param
false -> "/"
end

conn
|> sign_in(user)
Expand Down
2 changes: 1 addition & 1 deletion bin/docker-prod/build-release
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export MIX_ENV=prod
# Enables dynamic environmental variables within distillery releases using
# the ConfigTuples plugin.
#
find apps/*/config/* -type f | xargs sed -i"" -e 's/System.get_env.*(\(.*\))/{:system, \1}/g'
sed -r -i -e "s/System.get_env[(]([\"a-zA-Z0-9_]+)[)]/{:system, \1}/g" apps/**/config/*.exs config/*.exs

# Build Release
MIX_ENV=${MIX_ENV} mix release artemis
Expand Down

0 comments on commit e66079c

Please sign in to comment.