Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Remove Mixfile from the main project, replace with example Elixir pro…
Browse files Browse the repository at this point in the history
…ject (#22)

A dual-language build doesn't seem to be working for me, so this
uses only Erlang for the library and creates an example Elixir
project to verify that functionality.
  • Loading branch information
waisbrot authored Nov 21, 2016
1 parent 2b9d338 commit 8fd1755
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 98 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ dogstatsd:gauge("users.active", UserCount, #{ shard => ShardId, version => Vsn }

### Elixir

For more details, see the example application in (examples/elixir)[examples/elixir]

1. List dogstatsd dependency in your `mix.exs` file

```elixir
Expand All @@ -63,7 +65,7 @@ dogstatsd:gauge("users.active", UserCount, #{ shard => ShardId, version => Vsn }
5. For custom metrics:

```elixir
Dogstatsd.gauge("users.active", user_count, %{ :shard => shard_id, :version => vsn })
:dogstatsd.gauge("users.active", user_count, %{ :shard => shard_id, :version => vsn })
```

### VM Stats
Expand Down
19 changes: 19 additions & 0 deletions examples/elixir/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# The directory Mix will write compiled artifacts to.
/_build

# If you run "mix test --cover", coverage assets end up here.
/cover

# The directory Mix downloads your dependencies sources to.
/deps

# Where 3rd-party dependencies like ExDoc output generated docs.
/doc

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez
elixir_example
mix.lock
23 changes: 23 additions & 0 deletions examples/elixir/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# ElixirExample

Example of some Elixir code using the Dogstatsd library

## Mix.exs

`:dogstatsd` is listed as an application dependency so it will start before your application.

```
def application do
[applications: [:logger, :dogstatsd]]
end
```

`:dogstatsd` is listed as a dependency so Mix will fetch it. (You will actually want to depend on `{:dogstatsd, "~> <version>", hex: :dogstatsde}`, not a relative path!)

```
defp deps do
[
{:dogstatsd, path: "../../"}
]
end
```
30 changes: 30 additions & 0 deletions examples/elixir/config/config.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config

# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
# file won't be loaded nor affect the parent project. For this reason,
# if you want to provide default values for your application for
# 3rd-party users, it should be done in your "mix.exs" file.

# You can configure for your application as:
#
# config :elixir_example, key: :value
#
# And access this configuration in your application as:
#
# Application.get_env(:elixir_example, :key)
#
# Or configure a 3rd-party app:
#
# config :logger, level: :info
#

# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
#
# import_config "#{Mix.env}.exs"
12 changes: 12 additions & 0 deletions examples/elixir/lib/elixir_example.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
defmodule ElixirExample do
require Logger

def main(_) do
Logger.info "Example dogstatsd calls"
:dogstatsd.event("Test", "Testing dogstatsd library", :info, :low)
:dogstatsd.gauge("connection.active", 5)
:dogstatsd.increment("requests.image", 1, %{:file_type => "png"})
:dogstatsd.timer("connection.latency", 35, %{:path => "/hello/world.png"})
:dogstatsd.set("user.recent_ids", 2054)
end
end
35 changes: 35 additions & 0 deletions examples/elixir/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
defmodule Elixir.Mixfile do
use Mix.Project

def project do
[app: :elixir_example,
version: "0.1.0",
elixir: "~> 1.3",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
escript: [main_module: ElixirExample],
deps: deps()]
end

# Configuration for the OTP application
#
# Type "mix help compile.app" for more information
def application do
[applications: [:logger, :dogstatsd]]
end

# Dependencies can be Hex packages:
#
# {:mydep, "~> 0.3.0"}
#
# Or git/path repositories:
#
# {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"}
#
# Type "mix help deps" for more examples and options
defp deps do
[
{:dogstatsd, path: "../../"}
]
end
end
8 changes: 8 additions & 0 deletions examples/elixir/test/elixir_example_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule ElixirExampleTest do
use ExUnit.Case
doctest ElixirExample

test "the truth" do
assert 1 + 1 == 2
end
end
1 change: 1 addition & 0 deletions examples/elixir/test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ExUnit.start()
73 changes: 0 additions & 73 deletions mix.exs

This file was deleted.

2 changes: 0 additions & 2 deletions rebar.lock

This file was deleted.

1 change: 0 additions & 1 deletion scripts/install-deps.bash
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ elif [ $ELIXIR_VSN ]; then
source $HOME/.kiex/elixirs/elixir-${ELIXIR_VSN}.env
mix local.hex --force
mix local.rebar --force
mix deps.get
else
echo Unknown rebar version requested: $REBAR_VSN
exit 1
Expand Down
5 changes: 4 additions & 1 deletion scripts/run-tests.bash
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ elif [ $REBAR_VSN -eq 3 ]; then
./vendor/rebar3 eunit
elif [ $ELIXIR_VSN ]; then
source $HOME/.kiex/elixirs/elixir-${ELIXIR_VSN}.env
cd examples/elixir
mix deps.get
mix compile
mix test
mix escript.build
./elixir_example
else
echo Unknown rebar version requested: $REBAR_VSN
exit 1
Expand Down
2 changes: 1 addition & 1 deletion src/dogstatsd.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
{links, [{"GitHub", "https://github.com/WhoopInc/dogstatsde"}]},
{pkg_name, "dogstatsde"},
{include_files, ["mix.exs"]},
{build_tools, [<<"rebar3">>, <<"mix">>]}
{build_tools, [<<"rebar3">>]}
]}.
10 changes: 0 additions & 10 deletions test/basic_test.exs

This file was deleted.

9 changes: 0 additions & 9 deletions test/test_helper.exs

This file was deleted.

0 comments on commit 8fd1755

Please sign in to comment.