Skip to content

Commit

Permalink
Merge 15212c1 into e56ec36
Browse files Browse the repository at this point in the history
  • Loading branch information
nbriar committed Jun 10, 2019
2 parents e56ec36 + 15212c1 commit fea6d91
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 72 deletions.
157 changes: 157 additions & 0 deletions .credo.exs
@@ -0,0 +1,157 @@
# This file contains the configuration for Credo and you are probably reading
# this after creating it with `mix credo.gen.config`.
#
# If you find anything wrong or unclear in this file, please report an
# issue on GitHub: https://github.com/rrrene/credo/issues
#
%{
#
# You can have as many configs as you like in the `configs:` field.
configs: [
%{
#
# Run any exec using `mix credo -C <name>`. If no exec name is given
# "default" is used.
#
name: "default",
#
# These are the files included in the analysis:
files: %{
#
# You can give explicit globs or simply directories.
# In the latter case `**/*.{ex,exs}` will be used.
#
included: ["lib/"],
excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
},
#
# If you create your own checks, you must specify the source files for
# them here, so they can be loaded by Credo before running the analysis.
#
requires: [],
#
# If you want to enforce a style guide and need a more traditional linting
# experience, you can change `strict` to `true` below:
#
strict: true,
#
# If you want to use uncolored output by default, you can change `color`
# to `false` below:
#
color: true,
#
# You can customize the parameters of any check by adding a second element
# to the tuple.
#
# To disable a check put `false` as second element:
#
# {Credo.Check.Design.DuplicatedCode, false}
#
checks: [
#
## Consistency Checks
#
{Credo.Check.Consistency.ExceptionNames, []},
{Credo.Check.Consistency.LineEndings, []},
{Credo.Check.Consistency.ParameterPatternMatching, []},
{Credo.Check.Consistency.SpaceAroundOperators, []},
{Credo.Check.Consistency.SpaceInParentheses, []},
{Credo.Check.Consistency.TabsOrSpaces, []},

#
## Design Checks
#
# You can customize the priority of any check
# Priority values are: `low, normal, high, higher`
#
{Credo.Check.Design.AliasUsage,
[priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]},
# You can also customize the exit_status of each check.
# If you don't want TODO comments to cause `mix credo` to fail, just
# set this value to 0 (zero).
#
{Credo.Check.Design.TagTODO, [exit_status: 2]},
{Credo.Check.Design.TagFIXME, []},

#
## Readability Checks
#
{Credo.Check.Readability.AliasOrder, []},
{Credo.Check.Readability.FunctionNames, []},
{Credo.Check.Readability.LargeNumbers, []},
{Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]},
{Credo.Check.Readability.ModuleAttributeNames, []},
{Credo.Check.Readability.ModuleDoc, []},
{Credo.Check.Readability.ModuleNames, []},
{Credo.Check.Readability.ParenthesesInCondition, []},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
{Credo.Check.Readability.PredicateFunctionNames, []},
{Credo.Check.Readability.PreferImplicitTry, []},
{Credo.Check.Readability.RedundantBlankLines, []},
{Credo.Check.Readability.Semicolons, []},
{Credo.Check.Readability.SpaceAfterCommas, []},
{Credo.Check.Readability.StringSigils, []},
{Credo.Check.Readability.TrailingBlankLine, []},
{Credo.Check.Readability.TrailingWhiteSpace, []},
{Credo.Check.Readability.VariableNames, []},

#
## Refactoring Opportunities
#
{Credo.Check.Refactor.CondStatements, []},
{Credo.Check.Refactor.CyclomaticComplexity, []},
{Credo.Check.Refactor.FunctionArity, []},
{Credo.Check.Refactor.LongQuoteBlocks, []},
{Credo.Check.Refactor.MapInto, []},
{Credo.Check.Refactor.MatchInCondition, []},
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
{Credo.Check.Refactor.Nesting, []},
{Credo.Check.Refactor.PipeChainStart,
[
excluded_argument_types: [:atom, :binary, :fn, :keyword, :number],
excluded_functions: []
]},
{Credo.Check.Refactor.UnlessWithElse, []},

#
## Warnings
#
{Credo.Check.Warning.BoolOperationOnSameValues, []},
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
{Credo.Check.Warning.IExPry, []},
{Credo.Check.Warning.IoInspect, []},
{Credo.Check.Warning.LazyLogging, []},
{Credo.Check.Warning.OperationOnSameValues, []},
{Credo.Check.Warning.OperationWithConstantResult, []},
{Credo.Check.Warning.RaiseInsideRescue, []},
{Credo.Check.Warning.UnusedEnumOperation, []},
{Credo.Check.Warning.UnusedFileOperation, []},
{Credo.Check.Warning.UnusedKeywordOperation, []},
{Credo.Check.Warning.UnusedListOperation, []},
{Credo.Check.Warning.UnusedPathOperation, []},
{Credo.Check.Warning.UnusedRegexOperation, []},
{Credo.Check.Warning.UnusedStringOperation, []},
{Credo.Check.Warning.UnusedTupleOperation, []},

#
# Controversial and experimental checks (opt-in, just replace `false` with `[]`)
#
{Credo.Check.Consistency.MultiAliasImportRequireUse, false},
{Credo.Check.Design.DuplicatedCode, false},
{Credo.Check.Readability.Specs, false},
{Credo.Check.Refactor.ABCSize, false},
{Credo.Check.Refactor.AppendSingleItem, false},
{Credo.Check.Refactor.DoubleBooleanNegation, false},
{Credo.Check.Refactor.ModuleDependencies, false},
{Credo.Check.Refactor.VariableRebinding, false},
{Credo.Check.Warning.MapGetUnsafePass, false},
{Credo.Check.Warning.UnsafeToAtom, false}

#
# Custom checks can be created using `mix credo.gen.check`.
#
]
}
]
}
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
/_build
/.elixir_ls
/deps
erl_crash.dump
*.ez
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
@@ -1,9 +1,9 @@
sudo: false
language: elixir
elixir:
- 1.4.0
- 1.8.2
otp_release:
- 19.1
- 22.0
notifications:
recipients:
- adam@apathydrive.com
Expand Down
2 changes: 1 addition & 1 deletion VERSION.yml
@@ -1,5 +1,5 @@
---
major: 0
minor: 0
patch: 4
patch: 5
pre:
61 changes: 36 additions & 25 deletions lib/dogstatsd.ex
@@ -1,4 +1,6 @@
defmodule DogStatsd do
@moduledoc false

use GenServer
use DogStatsd.Statsd

Expand All @@ -10,17 +12,20 @@ defmodule DogStatsd do
end

def new(host, port, opts \\ %{}) do
config = opts
|> Map.put_new(:host, host)
|> Map.put_new(:port, port)
config =
opts
|> Map.put_new(:host, host)
|> Map.put_new(:port, port)

start_link(config)
end

def start_link(config, options \\ []) do
config = config
|> Map.take([:host, :port, :namespace, :tags, :max_buffer_size])
|> Map.put_new(:max_buffer_size, 50)
|> Map.put_new(:buffer, [])
config =
config
|> Map.take([:host, :port, :namespace, :tags, :max_buffer_size])
|> Map.put_new(:max_buffer_size, 50)
|> Map.put_new(:buffer, [])

GenServer.start_link(__MODULE__, config, options)
end
Expand Down Expand Up @@ -53,6 +58,7 @@ defmodule DogStatsd do
case GenServer.call(dogstatsd, :get_port) || System.get_env("DD_AGENT_PORT") || @default_port do
port when is_binary(port) ->
String.to_integer(port)

port ->
port
end
Expand All @@ -74,6 +80,7 @@ defmodule DogStatsd do
case GenServer.call(dogstatsd, :get_namespace) do
nil ->
nil

namespace ->
"#{namespace}."
end
Expand All @@ -84,12 +91,13 @@ defmodule DogStatsd do
end

def flush_buffer(dogstatsd) do
buffer = dogstatsd
|> GenServer.call(:flush_buffer)
|> Enum.join("\n")
send_to_socket dogstatsd, buffer
end
buffer =
dogstatsd
|> GenServer.call(:flush_buffer)
|> Enum.join("\n")

send_to_socket(dogstatsd, buffer)
end

###################
# Server Callbacks
Expand All @@ -103,8 +111,9 @@ defmodule DogStatsd do
end

def handle_call({:set_max_buffer_size, buffer_size}, _from, config) do
config = config
|> Map.put(:max_buffer_size, buffer_size)
config =
config
|> Map.put(:max_buffer_size, buffer_size)

{:reply, config[:max_buffer_size], config}
end
Expand All @@ -114,15 +123,17 @@ defmodule DogStatsd do
end

def handle_call({:set_namespace, nil}, _from, config) do
config = config
|> Map.put(:namespace, nil)
config =
config
|> Map.put(:namespace, nil)

{:reply, config[:namespace], config}
end

def handle_call({:set_namespace, namespace}, _from, config) do
config = config
|> Map.put(:namespace, namespace)
config =
config
|> Map.put(:namespace, namespace)

{:reply, config[:namespace], config}
end
Expand All @@ -132,8 +143,9 @@ defmodule DogStatsd do
end

def handle_call({:set_host, host}, _from, config) do
config = config
|> Map.put(:host, host)
config =
config
|> Map.put(:host, host)

{:reply, config[:host], config}
end
Expand All @@ -143,8 +155,7 @@ defmodule DogStatsd do
end

def handle_call({:set_port, port}, _from, config) do
config = config
|> Map.put(:port, port)
config = config |> Map.put(:port, port)

{:reply, config[:port], config}
end
Expand All @@ -154,8 +165,9 @@ defmodule DogStatsd do
end

def handle_call({:set_tags, tags}, _from, config) do
config = config
|> Map.put(:tags, tags)
config =
config
|> Map.put(:tags, tags)

{:reply, config[:tags], config}
end
Expand All @@ -169,5 +181,4 @@ defmodule DogStatsd do
def handle_call(:flush_buffer, _from, config) do
{:reply, config[:buffer], Map.put(config, :buffer, [])}
end

end
7 changes: 5 additions & 2 deletions lib/dogstatsd/batched.ex
@@ -1,10 +1,13 @@
defmodule DogStatsd.Batched do
@moduledoc false

use DogStatsd.Statsd

def send_to_socket(dogstatsd, message) do
buffer = DogStatsd.add_to_buffer(dogstatsd, message)
if length(buffer) == DogStatsd.max_buffer_size(dogstatsd) do

if length(buffer) == DogStatsd.max_buffer_size(dogstatsd) do
DogStatsd.flush_buffer(dogstatsd)
end
end
end
end

0 comments on commit fea6d91

Please sign in to comment.