-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure start options take precedence
- Loading branch information
Showing
2 changed files
with
39 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,33 @@ | ||
# Changelog | ||
|
||
* Fixed prefix building when start options provided. | ||
* Dropped support for Elixir v1.2. | ||
|
||
## v0.8.1 | ||
|
||
* Fixed port command for OTP versions that support ancillary data sending. | ||
|
||
## v0.8.0 | ||
|
||
* Added support for module, function, arguments tuple in `Fluxter.measure/4`. | ||
* Added support for module, function, arguments tuple in `measure/4`. | ||
|
||
## v0.7.1 | ||
|
||
* Fixed Elixir v1.6 warnings. | ||
|
||
## v0.7.0 | ||
|
||
* Added the `Fluxter.start_link/1` callback to support runtime configuration. | ||
* Added the `c:Fluxter.start_link/1` callback to support runtime configuration. | ||
|
||
__Deprecations:__ | ||
|
||
* Passing child specification options to `Fluxter.child_spec/1` is deprecated. | ||
* Passing child specification options to `child_spec/1` is deprecated. | ||
|
||
## v0.6.1 | ||
|
||
* Fixed a bug in the `Fluxter.child_spec/1` callback. | ||
* Fixed a bug in the `c:Fluxter.child_spec/1` callback. | ||
|
||
## v0.6.0 | ||
|
||
* Added the `Fluxter.child_spec/1` callback. | ||
* Added the `c:Fluxter.child_spec/1` callback. | ||
* Started flushing counters synchronously when calling `Fluxter.flush_counter/1`. |
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 |
---|---|---|
|
@@ -307,11 +307,15 @@ defmodule Fluxter do | |
def start_link(options \\ []) do | ||
import Supervisor.Spec | ||
|
||
{host, port, prefix} = Fluxter.load_config(__MODULE__, options) | ||
conn = Fluxter.Conn.new(host, port) | ||
conn = %{conn | header: [conn.header | prefix]} | ||
config = Fluxter.get_config(__MODULE__, options) | ||
|
||
Enum.map(@worker_names, &worker(Fluxter.Conn, [conn, &1], id: &1)) | ||
conn = | ||
config.host | ||
|> Fluxter.Conn.new(config.port) | ||
|> Map.update!(:header, &[&1 | config.prefix]) | ||
|
||
@worker_names | ||
|> Enum.map(&worker(Fluxter.Conn, [conn, &1], id: &1)) | ||
|> Supervisor.start_link(strategy: :one_for_one) | ||
end | ||
|
||
|
@@ -325,7 +329,8 @@ defmodule Fluxter do | |
def write(measurement, tags \\ [], fields) | ||
|
||
def write(measurement, tags, fields) when is_list(fields) do | ||
System.unique_integer([:positive]) | ||
[:positive] | ||
|> System.unique_integer() | ||
|> rem(@pool_size) | ||
|> worker_name() | ||
|> Fluxter.Conn.write(measurement, tags, fields) | ||
|
@@ -366,19 +371,31 @@ defmodule Fluxter do | |
end | ||
|
||
@doc false | ||
def load_config(module, options) do | ||
{loc_env, glob_env} = | ||
Application.get_all_env(:fluxter) | ||
def get_config(module, overrides) do | ||
{module_env, global_env} = | ||
:fluxter | ||
|> Application.get_all_env() | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
lexmag
Author
Owner
|
||
|> Keyword.pop(module, []) | ||
|
||
host = options[:host] || loc_env[:host] || glob_env[:host] | ||
port = options[:port] || loc_env[:port] || glob_env[:port] | ||
prefix = build_prefix(glob_env[:prefix], loc_env[:prefix], options[:prefix]) | ||
env = module_env ++ global_env | ||
options = overrides ++ env | ||
|
||
{host, port, prefix} | ||
%{ | ||
prefix: build_prefix(env, overrides), | ||
host: Keyword.get(options, :host, "127.0.0.1"), | ||
port: Keyword.get(options, :port, 8125) | ||
} | ||
end | ||
|
||
defp build_prefix(part1, part2, part3) do | ||
Enum.map_join([part1, part2, part3], &(&1 && [&1, ?_])) | ||
defp build_prefix(env, overrides) do | ||
case Keyword.fetch(overrides, :prefix) do | ||
{:ok, prefix} -> | ||
[prefix, ?_] | ||
|
||
:error -> | ||
env | ||
|> Keyword.get_values(:prefix) | ||
|> Enum.map_join(&(&1 && [&1, ?_])) | ||
end | ||
end | ||
end |
Maybe let's deprecate global config altogether?