Skip to content

Remove env_config dependency #2

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

Open
wants to merge 5 commits into
base: mix-format
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
*Currently no unreleased changes*

## [1.0.0] - 2019-11-12
### Changed
- removed EnvConfig dependency. Replaced `EnvConfig.get/2` with `Application.get_env/2`

## [0.4.4] - 2018-12-14
### Added
- This changelog!
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
```elixir
def deps do
[
{:stats_doggo, "~> 0.4.0",
{:stats_doggo, "~> 1.0.0",
]
end
```
Expand All @@ -19,9 +19,9 @@ Configuration in your `config.exs`
```
config :stats_doggo,
app_name: "YOUR_APP_NAME",
override_statix_host: {:system, "STATSD_HOST"},
app_env: {:system, "RAILS_ENV", "dev"},
enabled: {:system, "STATS_ENABLED", "false"},
override_statix_host: System.fetch_env!("STATSD_HOST"),
app_env: System.get_env("RAILS_ENV", "dev"),
enabled: System.get_env("STATS_ENABLED", "false"),
impl: StatsDoggo.Connection
```

Expand Down
7 changes: 0 additions & 7 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
use Mix.Config

config :stats_doggo,
app_name: "stats_doggo",
override_statix_host: {:system, "STATSD_HOST"},
app_env: {:system, "RAILS_ENV", "dev"},
enabled: {:system, "STATS_ENABLED", "false"},
impl: StatsDoggo.Connection

if File.regular?("config/#{Mix.env()}.exs") do
import_config "#{Mix.env()}.exs"
end
6 changes: 6 additions & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
use Mix.Config

config :logger, level: :warn

config :stats_doggo,
app_name: "stats_doggo",
app_env: "dev",
enabled: "false",
impl: StatsDoggo.Connection
7 changes: 3 additions & 4 deletions lib/stats_doggo/plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ defmodule StatsDoggo.Plug do
@behaviour Plug
import Plug.Conn, only: [register_before_send: 2]

@app_name EnvConfig.get(:stats_doggo, :app_name)
@timing_key "#{@app_name}.web.response_time"

def init(opts), do: opts

def call(conn, _config) do
before_time = :os.timestamp()

timing_key = Application.get_env(:stats_doggo, :app_name) <> ".web.response_time"

register_before_send(conn, fn conn ->
after_time = :os.timestamp()
diff = :timer.now_diff(after_time, before_time)

StatsDoggo.timing(@timing_key, diff / 1_000)
StatsDoggo.timing(timing_key, diff / 1_000)
conn
end)
end
Expand Down
3 changes: 2 additions & 1 deletion lib/stats_doggo/vmstats.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ defmodule StatsDoggo.Vmstats do
end

defp prev_sched do
:erlang.statistics(:scheduler_wall_time)
:scheduler_wall_time
|> :erlang.statistics()
|> Enum.sort()
end

Expand Down
18 changes: 9 additions & 9 deletions lib/stats_doggo/worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@ defmodule StatsDoggo.Worker do
require Logger
use GenServer

@app_tag "app:#{EnvConfig.get(:stats_doggo, :app_name)}"
@env_tag "env:#{EnvConfig.get(:stats_doggo, :app_env)}"

@default_tags [@env_tag, @app_tag]

def init(:ok) do
set_up_config()

connection =
case EnvConfig.get(:stats_doggo, :enabled) do
case Application.get_env(:stats_doggo, :enabled) do
"false" ->
Logger.info("StatsDoggo disabled, using StatsDoggo.ConnectionMock")
StatsDoggo.ConnectionMock
Expand All @@ -42,14 +37,19 @@ defmodule StatsDoggo.Worker do
end

defp default_opts(opts) do
opts |> Keyword.merge(tags: Keyword.get(opts, :tags, []) |> default_tags())
Keyword.merge(opts, tags: default_tags(opts[:tags]))
end

defp default_tags(nil), do: []

defp default_tags(tags) do
@default_tags ++ tags
app_tag = "app:" <> Application.get_env(:stats_doggo, :app_name)
env_tag = "env:" <> Application.get_env(:stats_doggo, :app_env)

[env_tag, app_tag | tags]
end

defp set_up_config do
Application.put_env(:statix, :host, EnvConfig.get(:stats_doggo, :override_statix_host))
Application.put_env(:statix, :host, Application.get_env(:stats_doggo, :override_statix_host))
end
end
3 changes: 1 addition & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ defmodule StatsDoggo.Mixfile do
use Mix.Project

@name :stats_doggo
@version "0.4.4"
@version "1.0.0"

@deps [
{:env_config, ">= 0.1.0"},
{:plug, ">= 1.3.0"},
{:statix, ">= 1.0.0"},
{:ex_doc, "~> 0.16", only: [:dev, :test]}
Expand Down
2 changes: 0 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
%{
"earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], [], "hexpm"},
"env_config": {:hex, :env_config, "0.2.0", "d12640aa1cff012803e51f9be25f9a6c420c717d0da2bf9b3495cc039ad802b1", [:mix], [], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.19.1", "519bb9c19526ca51d326c060cb1778d4a9056b190086a8c6c115828eaccea6cf", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.7", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
"ex_vmstats": {:git, "https://github.com/dplummer/ex_vmstats.git", "318789bb401105b79a9deb9750481cce8b9797c0", [branch: "worker-config"]},
"makeup": {:hex, :makeup, "0.5.6", "da47b331b1fe0a5f0380cc3a6967200eac5e1daaa9c6bff4b0310b3fcc12b98f", [:mix], [{:nimble_parsec, "~> 0.4.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
"makeup_elixir": {:hex, :makeup_elixir, "0.10.0", "0f09c2ddf352887a956d84f8f7e702111122ca32fbbc84c2f0569b8b65cbf7fa", [:mix], [{:makeup, "~> 0.5.5", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"},
"mime": {:hex, :mime, "1.1.0", "01c1d6f4083d8aa5c7b8c246ade95139620ef8effb009edde934e0ec3b28090a", [:mix], [], "hexpm"},
Expand Down