Skip to content

Commit

Permalink
ex/chore: rename to WarehouseEx (#30)
Browse files Browse the repository at this point in the history
* chore: rename to WarehouseEx

* chore: rename all modules post-rebase
  • Loading branch information
Ziinc authored Jun 12, 2024
1 parent 675d2fa commit 77ee8a8
Show file tree
Hide file tree
Showing 27 changed files with 167 additions and 189 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ex-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
if: github.event_name == 'push'
env:
HEX_API_KEY: ${{ secrets.HEX_AUTH_TOKEN }}
LOGFLARE_EX_PRERELEASE_VERSION: dev.${{env.timestamp}}.${{ env.short_sha }}
WAREHOUSE_EX_PRERELEASE_VERSION: dev.${{env.timestamp}}.${{ env.short_sha }}
- run: mix hex.publish --yes
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
env:
Expand Down
2 changes: 1 addition & 1 deletion ex/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ erl_crash.dump
*.ez

# Ignore package tarball (built via "mix hex.build").
logflare_ex-*.tar
warehouse_ex-*.tar

# Temporary files, for example, from tests.
/tmp/
26 changes: 2 additions & 24 deletions ex/README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
# LogflareEx

**TODO: Add description**
# WarehouseEx

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `logflare_ex` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[
{:logflare_ex, "~> 0.1.0"}
{:warehouse_ex, "~> 0.2.0"}
]
end
```

And add in to `application.ex`:
```elixir
def start(_type, _args) do
children = [
{Finch, name: LogflareEx.Finch}
]

opts = [strategy: :one_for_one, name: LogflareApiClient.Supervisor]
Supervisor.start_link(children, opts)
end
end
```

## Benchmarks

### Jason vs Bertex
Expand Down Expand Up @@ -63,7 +45,3 @@ jason encode large 57.26 - 10.73x slower +15.84 ms
jason decode large 47.24 - 13.01x slower +19.54 ms
```

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/logflare_ex](https://hexdocs.pm/logflare_ex).

2 changes: 1 addition & 1 deletion ex/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Config
# metadata: [:user_id]
#

config :logflare_ex,
config :warehouse_ex,
api_url: "https://api.logflare.app",
api_key: "some-key"

Expand Down
2 changes: 1 addition & 1 deletion ex/config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Config

config :logflare_ex,
config :warehouse_ex,
api_url: "https://api.logflare.app",
api_key: "some-key",
env: :test
2 changes: 1 addition & 1 deletion ex/config/test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Config

config :logflare_ex,
config :warehouse_ex,
env: :test,
api_url: "https://localhost:4006"
20 changes: 10 additions & 10 deletions ex/lib/application.ex
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
defmodule LogflareEx.Application do
defmodule WarehouseEx.Application do
@moduledoc false
use Application

@impl true
def start(_type, _args) do
env = Application.get_env(:logflare_ex, :env)
env = Application.get_env(:warehouse_ex, :env)

children = get_children(env)

# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: LogflareEx.Supervisor]
opts = [strategy: :one_for_one, name: WarehouseEx.Supervisor]
Supervisor.start_link(children, opts)
end

defp get_children(:test) do
[
LogflareEx.Repo,
{Registry, keys: :unique, name: LogflareEx.BatcherRegistry},
{Finch, name: LogflareEx.Finch}
WarehouseEx.Repo,
{Registry, keys: :unique, name: WarehouseEx.BatcherRegistry},
{Finch, name: WarehouseEx.Finch}
]
end

defp get_children(_) do
[
LogflareEx.Repo,
{DynamicSupervisor, name: LogflareEx.BatcherSup},
{Registry, keys: :unique, name: LogflareEx.BatcherRegistry},
{Finch, name: LogflareEx.Finch}
WarehouseEx.Repo,
{DynamicSupervisor, name: WarehouseEx.BatcherSup},
{Registry, keys: :unique, name: WarehouseEx.BatcherRegistry},
{Finch, name: WarehouseEx.Finch}
]
end
end
2 changes: 1 addition & 1 deletion ex/lib/batched_event.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule LogflareEx.BatchedEvent do
defmodule WarehouseEx.BatchedEvent do
@moduledoc false
use TypedEctoSchema

Expand Down
18 changes: 9 additions & 9 deletions ex/lib/batcher.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule LogflareEx.Batcher do
defmodule WarehouseEx.Batcher do
@moduledoc """
Batching cache is an Etso repo, `LogflareEx.Repo`, and stores all events to be sent to the Logflare service.
Batching cache is an Etso repo, `WarehouseEx.Repo`, and stores all events to be sent to the Logflare service.
There are 2 states that an event can be in:
- pending
Expand All @@ -11,10 +11,10 @@ defmodule LogflareEx.Batcher do
use GenServer

import Ecto.Query
alias LogflareEx.BatchedEvent
alias LogflareEx.BatcherRegistry
alias LogflareEx.Client
alias LogflareEx.Repo
alias WarehouseEx.BatchedEvent
alias WarehouseEx.BatcherRegistry
alias WarehouseEx.Client
alias WarehouseEx.Repo

# API

Expand Down Expand Up @@ -142,14 +142,14 @@ defmodule LogflareEx.Batcher do
end

@doc """
Returns the via for each partitioned Batcher. Accepts a `source_token` or `source_name` filter or a `%LogflareEx.Client{}` struct.
Returns the via for each partitioned Batcher. Accepts a `source_token` or `source_name` filter or a `%WarehouseEx.Client{}` struct.
### Example
```elixir
via(source_name: "my source")
via(source_token: "some-uuid")
via(%LogflareEx.Client{...})
via(%WarehouseEx.Client{...})
```
"""
@spec via(Client.t() | kw_filter()) :: identifier()
Expand Down Expand Up @@ -222,7 +222,7 @@ defmodule LogflareEx.Batcher do

# Task to send batch
Task.start_link(fn ->
LogflareEx.send_events(state.client, batch)
WarehouseEx.send_events(state.client, batch)
Repo.delete_all(from(e in BatchedEvent, where: e.id in ^event_ids))
end)

Expand Down
6 changes: 3 additions & 3 deletions ex/lib/batcher_sup.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defmodule LogflareEx.BatcherSup do
defmodule WarehouseEx.BatcherSup do
# Automatically defines child_spec/1
use DynamicSupervisor
alias LogflareEx.Batcher
alias LogflareEx.Client
alias WarehouseEx.Batcher
alias WarehouseEx.Client
require Logger

def start_link(_init_arg) do
Expand Down
34 changes: 17 additions & 17 deletions ex/lib/logflare_ex.ex
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
defmodule LogflareEx do
alias LogflareEx.Client
alias LogflareEx.Batcher
alias LogflareEx.BatchedEvent
alias LogflareEx.Repo
alias LogflareEx.BatcherSup
defmodule WarehouseEx do
alias WarehouseEx.Client
alias WarehouseEx.Batcher
alias WarehouseEx.BatchedEvent
alias WarehouseEx.Repo
alias WarehouseEx.BatcherSup

@moduledoc """
Documentation for `LogflareEx`.
Documentation for `WarehouseEx`.
"""

@doc """
Creates a client for interacting with Logflare.
See `LogflareEx.Client`.
See `WarehouseEx.Client`.
"""

defdelegate client(opts), to: __MODULE__.Client, as: :new
Expand All @@ -37,19 +37,19 @@ defmodule LogflareEx do
### Example
```elixir
iex> client = LogflareEx.client()
%LogflareEx.Client{...}
iex> client = WarehouseEx.client()
%WarehouseEx.Client{...}
# singular event
iex> LogflareEx.send_event(client, %{my: "event"})
iex> WarehouseEx.send_event(client, %{my: "event"})
{:ok, %{"message"=> "Logged!}}
# multiple events
iex> LogflareEx.send_events(client, [%{my: "event"}, ...])
iex> WarehouseEx.send_events(client, [%{my: "event"}, ...])
{:ok, %{"message"=> "Logged!}}
# a tesla result will be returned on error
iex> client |> LogflareEx.send_event(%{my: "event"})
iex> client |> WarehouseEx.send_event(%{my: "event"})
{:error, %Tesla.Env{...}}
```
Expand Down Expand Up @@ -110,15 +110,15 @@ defmodule LogflareEx do
```elixir
# create a client
iex> client = LogflareEx.client()
%LogflareEx.Client{...}
iex> client = WarehouseEx.client()
%WarehouseEx.Client{...}
# singular event
iex> LogflareEx.send_batched_event(client, %{...})
iex> WarehouseEx.send_batched_event(client, %{...})
:ok
# list of events
iex> LogflareEx.send_batched_event(client, [%{...}, ...])
iex> WarehouseEx.send_batched_event(client, [%{...}, ...])
:ok
```
"""
Expand Down
28 changes: 14 additions & 14 deletions ex/lib/logflare_ex/client.ex
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
defmodule LogflareEx.Client do
defmodule WarehouseEx.Client do
@moduledoc """
A `LogflareEx.Client` contains all configuration used for making API requests, whether batched or not.
A `WarehouseEx.Client` contains all configuration used for making API requests, whether batched or not.
### Application-level Configuration
Application-wide configuration can be set in `config.exs`:
```elixir
config :logflare_ex,
config :warehouse_ex,
api_key: "...",
source_token: "..."
```
### Runtime Configuration
All configuration options can be overridden at runtime. This is through the use of the `LogflareEx.Client` struct.
All configuration options can be overridden at runtime. This is through the use of the `WarehouseEx.Client` struct.
To create a new client with a custom configuration, use `LogflareEx.client/1`:
To create a new client with a custom configuration, use `WarehouseEx.client/1`:
```elixir
# To create a client from the application-level configuration.
iex> default_client = LogflareEx.client()
%LogflareEx.Client{...}
iex> default_client = WarehouseEx.client()
%WarehouseEx.Client{...}
# To create a client with runtime overrides
iex> client = LogflareEx.client(source_token: "...")
%LogflareEx.Client{...}
iex> client = WarehouseEx.client(source_token: "...")
%WarehouseEx.Client{...}
# use the runtime client
iex> LogflareEx.send_batched_event(client, %{...})
iex> WarehouseEx.send_batched_event(client, %{...})
:ok
```
Expand All @@ -37,17 +37,17 @@ defmodule LogflareEx.Client do
For every configuration, either `:source_token` or `:source_name` must be provided.
- `:api_key`: **Required**. Public API key.
- `:api_url`: Custom Logflare endpoint, for self-hosting. Defaults to `https//api.logflare.app`.
- `:api_url`: Custom server endpoint, for self-hosting. Defaults to `https//api.logflare.app`.
- `:source_token`: Source UUID. Mutually exclusive with `:source_name`
- `:source_name`: Source name. Mutually exclusive with `:source_token`
- `:on_error`: mfa callback for handling API errors. Must be 1 arity.
- `:on_prepare_payload`: mfa callback or anonymous function for preparing the final payload before sending to API. Must be 1 arity.
- `:auto_flush`: Used for batching. Enables automatic flushing. If disabled, `LogflareEx.flush/1` must be called.
- `:auto_flush`: Used for batching. Enables automatic flushing. If disabled, `WarehouseEx.flush/1` must be called.
- `:flush_interval`: Used for batching. Flushes cached events at the provided interval.
- `:batch_size`: Used for batching. It is the maximum number of events send per API request.
"""
@default_tesla_adapter {Tesla.Adapter.Finch, name: LogflareEx.Finch, receive_timeout: 30_000}
@default_tesla_adapter {Tesla.Adapter.Finch, name: WarehouseEx.Finch, receive_timeout: 30_000}
@default_batch_size 250
@default_flush_interval 1_500

Expand Down Expand Up @@ -116,7 +116,7 @@ defmodule LogflareEx.Client do
end

def get_config_value(key) do
Application.get_env(:logflare_ex, key)
Application.get_env(:warehouse_ex, key)
end

def validate_client(%__MODULE__{source_name: nil, source_token: nil}),
Expand Down
Loading

0 comments on commit 77ee8a8

Please sign in to comment.