From ddcdf64f7032f1de8650c4f26f155c295e1c261e Mon Sep 17 00:00:00 2001 From: TzeYiing Date: Tue, 11 Jun 2024 15:11:37 +0800 Subject: [PATCH 1/2] chore: rename to WarehouseEx --- .github/workflows/ex-publish.yml | 2 +- ex/.gitignore | 2 +- ex/README.md | 26 +------- ex/config/config.exs | 2 +- ex/config/dev.exs | 2 +- ex/config/test.exs | 2 +- ex/lib/application.ex | 20 +++--- ex/lib/batched_event.ex | 2 +- ex/lib/batcher.ex | 18 +++--- ex/lib/batcher_sup.ex | 6 +- ex/lib/logflare_ex.ex | 34 +++++----- ex/lib/logflare_ex/client.ex | 28 ++++----- ex/lib/logflare_ex/logger_backend.ex | 26 ++++---- .../logflare_ex/logger_backend/formatter.ex | 4 +- .../logflare_ex/logger_backend/stacktrace.ex | 2 +- ex/lib/logflare_ex/repo.ex | 4 +- ex/lib/logflare_ex/telemetry_reporter.ex | 20 +++--- ex/mix.exs | 8 +-- ex/test/batcher_test.exs | 12 ++-- ex/test/logflare_ex_test.exs | 62 +++++++++---------- ex/test/logger_backend_test.exs | 20 +++--- ex/test/support/batcher_case.ex | 6 +- ex/test/support/factory.ex | 6 +- ex/test/support/test_utils.ex | 2 +- ex/test/telemetry_reporter_test.exs | 22 +++---- ex/test/test_helper.exs | 2 +- js/src/main.ts | 4 +- 27 files changed, 161 insertions(+), 183 deletions(-) diff --git a/.github/workflows/ex-publish.yml b/.github/workflows/ex-publish.yml index 1ac1b1c..f30cc3b 100644 --- a/.github/workflows/ex-publish.yml +++ b/.github/workflows/ex-publish.yml @@ -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: diff --git a/ex/.gitignore b/ex/.gitignore index aff2e43..0604fb3 100644 --- a/ex/.gitignore +++ b/ex/.gitignore @@ -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/ diff --git a/ex/README.md b/ex/README.md index f2a806b..e505d1c 100644 --- a/ex/README.md +++ b/ex/README.md @@ -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 @@ -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). - diff --git a/ex/config/config.exs b/ex/config/config.exs index c33342f..27c3780 100644 --- a/ex/config/config.exs +++ b/ex/config/config.exs @@ -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" diff --git a/ex/config/dev.exs b/ex/config/dev.exs index 4598e62..b1a55b4 100644 --- a/ex/config/dev.exs +++ b/ex/config/dev.exs @@ -1,6 +1,6 @@ import Config -config :logflare_ex, +config :warehouse_ex, api_url: "https://api.logflare.app", api_key: "some-key", env: :test diff --git a/ex/config/test.exs b/ex/config/test.exs index c2a175a..84af5a2 100644 --- a/ex/config/test.exs +++ b/ex/config/test.exs @@ -1,5 +1,5 @@ import Config -config :logflare_ex, +config :warehouse_ex, env: :test, api_url: "https://localhost:4006" diff --git a/ex/lib/application.ex b/ex/lib/application.ex index 26aca4d..b17cdd7 100644 --- a/ex/lib/application.ex +++ b/ex/lib/application.ex @@ -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 diff --git a/ex/lib/batched_event.ex b/ex/lib/batched_event.ex index 439f447..e7a8278 100644 --- a/ex/lib/batched_event.ex +++ b/ex/lib/batched_event.ex @@ -1,4 +1,4 @@ -defmodule LogflareEx.BatchedEvent do +defmodule WarehouseEx.BatchedEvent do @moduledoc false use TypedEctoSchema diff --git a/ex/lib/batcher.ex b/ex/lib/batcher.ex index 1d6f4b4..06be176 100644 --- a/ex/lib/batcher.ex +++ b/ex/lib/batcher.ex @@ -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 @@ -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 @@ -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() @@ -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) diff --git a/ex/lib/batcher_sup.ex b/ex/lib/batcher_sup.ex index 33a4dc0..b5c9b4e 100644 --- a/ex/lib/batcher_sup.ex +++ b/ex/lib/batcher_sup.ex @@ -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 diff --git a/ex/lib/logflare_ex.ex b/ex/lib/logflare_ex.ex index 31f1152..1d44a92 100644 --- a/ex/lib/logflare_ex.ex +++ b/ex/lib/logflare_ex.ex @@ -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 @@ -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{...}} ``` @@ -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 ``` """ diff --git a/ex/lib/logflare_ex/client.ex b/ex/lib/logflare_ex/client.ex index 390e951..12081a6 100644 --- a/ex/lib/logflare_ex/client.ex +++ b/ex/lib/logflare_ex/client.ex @@ -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 ``` @@ -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 @@ -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}), diff --git a/ex/lib/logflare_ex/logger_backend.ex b/ex/lib/logflare_ex/logger_backend.ex index ba70999..e071a03 100644 --- a/ex/lib/logflare_ex/logger_backend.ex +++ b/ex/lib/logflare_ex/logger_backend.ex @@ -1,4 +1,4 @@ -defmodule LogflareEx.LoggerBackend do +defmodule WarehouseEx.LoggerBackend do @moduledoc """ Implements `:gen_event` behaviour, handles incoming Logger messages. @@ -8,7 +8,7 @@ defmodule LogflareEx.LoggerBackend do Add the following to your config.exs: ```elixir config :logger - backends: [..., LogflareEx.LoggerBackend] + backends: [..., WarehouseEx.LoggerBackend] ``` You can then log as per normal: @@ -22,8 +22,8 @@ defmodule LogflareEx.LoggerBackend do There are 3 levels of configuration available, and these are listed in priority order: 1. Runtime Logger configuration, such as `Logger.configure(...)` - 2. Module level configuration via `config.exs`, such as `config :logflare_ex, #{__MODULE__}, source_token: ...` - 3. Application level configuration via `config.exs`, such as`config :logflare_ex, source_token: ...` + 2. Module level configuration via `config.exs`, such as `config :warehouse_ex, #{__MODULE__}, source_token: ...` + 3. Application level configuration via `config.exs`, such as`config :warehouse_ex, source_token: ...` Options will then be merged together, with each level overriding the previous. @@ -67,7 +67,7 @@ defmodule LogflareEx.LoggerBackend do alias __MODULE__.Formatter require Logger - @app :logflare_ex + @app :warehouse_ex @behaviour :gen_event @type level :: Logger.level() @@ -84,7 +84,7 @@ defmodule LogflareEx.LoggerBackend do @spec handle_event(log_msg, Config.t()) :: {:ok, Config.t()} def handle_event(:flush, config) do - LogflareEx.flush(config.client) + WarehouseEx.flush(config.client) {:ok, config} end @@ -103,7 +103,7 @@ defmodule LogflareEx.LoggerBackend do if log_level_matches?(level, config.level) do # TODO: add default context formatting for backwards compat payload = Formatter.format(level, msg, datetime, metadata) - LogflareEx.send_batched_event(config.client, payload) + WarehouseEx.send_batched_event(config.client, payload) end {:ok, config} @@ -115,7 +115,7 @@ defmodule LogflareEx.LoggerBackend do end def handle_info(:flush, state) do - LogflareEx.flush(state.client) + WarehouseEx.flush(state.client) {:ok, state} end @@ -133,7 +133,7 @@ defmodule LogflareEx.LoggerBackend do def terminate(_reason, _state), do: :ok defp maybe_start(config) do - with :ok <- LogflareEx.Client.validate_client(config.client) do + with :ok <- WarehouseEx.Client.validate_client(config.client) do msg = "[#{__MODULE__}] v#{Application.spec(@app, :vsn)} started." log_after(:info, msg) :ok @@ -146,7 +146,7 @@ defmodule LogflareEx.LoggerBackend do # delayed logging to ensure applications are started defp log_after(level, message, delay \\ 5_000) do - if Application.get_env(:logflare_ex, :env) != :test do + if Application.get_env(:warehouse_ex, :env) != :test do Process.send_after(self(), {:log_after, level, message}, delay) end end @@ -158,12 +158,12 @@ defmodule LogflareEx.LoggerBackend do defp log_level_matches?(lvl, min), do: Logger.compare_levels(lvl, min) != :lt defp build_default_config(options \\ []) do - config_file_opts = (Application.get_env(:logflare_ex, __MODULE__) || []) |> Map.new() + config_file_opts = (Application.get_env(:warehouse_ex, __MODULE__) || []) |> Map.new() opts = Enum.into(options, config_file_opts) - client = LogflareEx.client(opts) + client = WarehouseEx.client(opts) client = - if :ok == LogflareEx.Client.validate_client(client) do + if :ok == WarehouseEx.Client.validate_client(client) do client else nil diff --git a/ex/lib/logflare_ex/logger_backend/formatter.ex b/ex/lib/logflare_ex/logger_backend/formatter.ex index 46bba8d..1eb6e50 100644 --- a/ex/lib/logflare_ex/logger_backend/formatter.ex +++ b/ex/lib/logflare_ex/logger_backend/formatter.ex @@ -1,6 +1,6 @@ -defmodule LogflareEx.LoggerBackend.Formatter do +defmodule WarehouseEx.LoggerBackend.Formatter do @moduledoc false - alias LogflareEx.LoggerBackend.Stacktrace + alias WarehouseEx.LoggerBackend.Stacktrace require Logger def format(level, message, ts, metadata) do diff --git a/ex/lib/logflare_ex/logger_backend/stacktrace.ex b/ex/lib/logflare_ex/logger_backend/stacktrace.ex index 3ff8e46..2970c3b 100644 --- a/ex/lib/logflare_ex/logger_backend/stacktrace.ex +++ b/ex/lib/logflare_ex/logger_backend/stacktrace.ex @@ -1,4 +1,4 @@ -defmodule LogflareEx.LoggerBackend.Stacktrace do +defmodule WarehouseEx.LoggerBackend.Stacktrace do @moduledoc """ Handles stacktrace formatting for logged exceptions """ diff --git a/ex/lib/logflare_ex/repo.ex b/ex/lib/logflare_ex/repo.ex index 1259029..b73af48 100644 --- a/ex/lib/logflare_ex/repo.ex +++ b/ex/lib/logflare_ex/repo.ex @@ -1,3 +1,3 @@ -defmodule LogflareEx.Repo do - use Ecto.Repo, otp_app: :logflare_ex, adapter: Etso.Adapter +defmodule WarehouseEx.Repo do + use Ecto.Repo, otp_app: :warehouse_ex, adapter: Etso.Adapter end diff --git a/ex/lib/logflare_ex/telemetry_reporter.ex b/ex/lib/logflare_ex/telemetry_reporter.ex index 76c57d2..b6d7791 100644 --- a/ex/lib/logflare_ex/telemetry_reporter.ex +++ b/ex/lib/logflare_ex/telemetry_reporter.ex @@ -1,4 +1,4 @@ -defmodule LogflareEx.TelemetryReporter do +defmodule WarehouseEx.TelemetryReporter do @moduledoc """ A TelemetryReporter for attaching to metrics created from `:telemetry_metrics`. Telemetry events are sent to the Logflare API as is. @@ -15,26 +15,26 @@ defmodule LogflareEx.TelemetryReporter do end ``` - Thereafter, add the `LogflareEx.TelemetryReporter` to your supervision tree: + Thereafter, add the `WarehouseEx.TelemetryReporter` to your supervision tree: ```elixir # application.ex children = [ - {LogflareEx.TelemetryReporter, metrics: [ + {WarehouseEx.TelemetryReporter, metrics: [ last_value("some.event.stop.duration") ]} ] ... ``` - The `LogflareEx.TelemetryReporter` will attach to all provided metrics. + The `WarehouseEx.TelemetryReporter` will attach to all provided metrics. ### Configuration There are 2 levels of configuration available, and these are listed in priority order: - 1. Module level configuration via `config.exs`, such as `config :logflare_ex, #{__MODULE__}, source_token: ...` - 2. Application level configuration via `config.exs`, such as`config :logflare_ex, source_token: ...` + 1. Module level configuration via `config.exs`, such as `config :warehouse_ex, #{__MODULE__}, source_token: ...` + 2. Application level configuration via `config.exs`, such as`config :warehouse_ex, source_token: ...` Client options will then be merged together, with each level overriding the previous. @@ -48,7 +48,7 @@ defmodule LogflareEx.TelemetryReporter do @doc """ `:telemetry.attach/4` callback for allowing attaching to telemetry events. - Telemetry events attached this way are batched to Logflare. + Telemetry events attached this way are batched to the server. Options: - `:include` - dot syntax fields to be included. @@ -59,7 +59,7 @@ defmodule LogflareEx.TelemetryReporter do def handle_attach(event, measurements, metadata, config) when is_list(config) do # merge configuration - config_file_opts = (Application.get_env(:logflare_ex, __MODULE__) || []) |> Map.new() + config_file_opts = (Application.get_env(:warehouse_ex, __MODULE__) || []) |> Map.new() opts = Enum.into(config, config_file_opts) @@ -87,7 +87,7 @@ defmodule LogflareEx.TelemetryReporter do end message = "#{event_str} | #{measurements_str}" - client = LogflareEx.client(opts) + client = WarehouseEx.client(opts) payload = Map.merge( @@ -98,7 +98,7 @@ defmodule LogflareEx.TelemetryReporter do filtered_payload ) - LogflareEx.send_batched_event(client, payload) + WarehouseEx.send_batched_event(client, payload) :ok end diff --git a/ex/mix.exs b/ex/mix.exs index c48ce32..f433ae9 100644 --- a/ex/mix.exs +++ b/ex/mix.exs @@ -1,12 +1,12 @@ -defmodule LogflareEx.MixProject do +defmodule WarehouseEx.MixProject do use Mix.Project @source_url "https://github.com/Logflare/warehouse-sdk" - @prerelease System.get_env("LOGFLARE_EX_PRERELEASE_VERSION") + @prerelease System.get_env("WAREHOUSE_EX_PRERELEASE_VERSION") @version_suffix if(@prerelease, do: "-#{@prerelease}", else: "") def project do [ - app: :logflare_ex, + app: :warehouse_ex, version: "0.2.0#{@version_suffix}", build_path: "./_build", config_path: "./config/config.exs", @@ -34,7 +34,7 @@ defmodule LogflareEx.MixProject do def application do [ extra_applications: if(Mix.env() != :test, do: [:logger], else: [:logger, :runtime_tools]), - mod: {LogflareEx.Application, []} + mod: {WarehouseEx.Application, []} ] end diff --git a/ex/test/batcher_test.exs b/ex/test/batcher_test.exs index e1a10b1..bad9291 100644 --- a/ex/test/batcher_test.exs +++ b/ex/test/batcher_test.exs @@ -1,9 +1,9 @@ -defmodule LogflareEx.BatcherTest do - use LogflareEx.BatcherCase - alias LogflareEx.Batcher - alias LogflareEx.BatcherSup - alias LogflareEx.BatchedEvent - alias LogflareEx.Client +defmodule WarehouseEx.BatcherTest do + use WarehouseEx.BatcherCase + alias WarehouseEx.Batcher + alias WarehouseEx.BatcherSup + alias WarehouseEx.BatchedEvent + alias WarehouseEx.Client use Mimic describe "BatcherSup" do diff --git a/ex/test/logflare_ex_test.exs b/ex/test/logflare_ex_test.exs index a713cc1..6dce6cc 100644 --- a/ex/test/logflare_ex_test.exs +++ b/ex/test/logflare_ex_test.exs @@ -1,7 +1,7 @@ defmodule LogflareExTest do - use LogflareEx.BatcherCase + use WarehouseEx.BatcherCase use Mimic - alias LogflareEx.BatcherSup + alias WarehouseEx.BatcherSup test "send_event/2" do Tesla @@ -10,23 +10,23 @@ defmodule LogflareExTest do end) # send with source token - client = LogflareEx.client(api_key: "123", source_token: "12313") - assert %LogflareEx.Client{api_key: "123"} = client + client = WarehouseEx.client(api_key: "123", source_token: "12313") + assert %WarehouseEx.Client{api_key: "123"} = client - assert {:ok, %{"message" => "server msg"}} = LogflareEx.send_event(client, %{some: "event"}) + assert {:ok, %{"message" => "server msg"}} = WarehouseEx.send_event(client, %{some: "event"}) # send with source name - client = LogflareEx.client(api_key: "123", source_name: "12313") - assert %LogflareEx.Client{api_key: "123"} = client + client = WarehouseEx.client(api_key: "123", source_name: "12313") + assert %WarehouseEx.Client{api_key: "123"} = client - assert {:ok, %{"message" => "server msg"}} = LogflareEx.send_event(client, %{some: "event"}) + assert {:ok, %{"message" => "server msg"}} = WarehouseEx.send_event(client, %{some: "event"}) Tesla |> expect(:post, fn _client, _path, _body -> {:ok, %Tesla.Env{status: 500, body: "server err"}} end) - assert {:error, %Tesla.Env{}} = LogflareEx.send_event(client, %{some: "event"}) + assert {:error, %Tesla.Env{}} = WarehouseEx.send_event(client, %{some: "event"}) end test "send_events/2" do @@ -35,16 +35,16 @@ defmodule LogflareExTest do {:ok, %Tesla.Env{status: 201, body: Jason.encode!(%{"message" => "server msg"})}} end) - client = LogflareEx.client(api_key: "123", source_token: "123") - assert %LogflareEx.Client{api_key: "123"} = client + client = WarehouseEx.client(api_key: "123", source_token: "123") + assert %WarehouseEx.Client{api_key: "123"} = client assert {:ok, %{"message" => "server msg"}} = - LogflareEx.send_events(client, [%{some: "event"}]) + WarehouseEx.send_events(client, [%{some: "event"}]) - assert {:error, :no_events} = LogflareEx.send_events(client, []) + assert {:error, :no_events} = WarehouseEx.send_events(client, []) assert {:error, :no_source} = - LogflareEx.client(api_key: "123") |> LogflareEx.send_events([%{some: "event"}]) + WarehouseEx.client(api_key: "123") |> WarehouseEx.send_events([%{some: "event"}]) end describe "on_error" do @@ -54,15 +54,15 @@ defmodule LogflareExTest do {:ok, %Tesla.Env{status: 500, body: "some server error"}} end) - LogflareEx.TestUtils + WarehouseEx.TestUtils |> expect(:stub_function, 2, fn %{status: 500} -> :ok end) for cb <- [ - {LogflareEx.TestUtils, :stub_function, 1}, - &LogflareEx.TestUtils.stub_function/1 + {WarehouseEx.TestUtils, :stub_function, 1}, + &WarehouseEx.TestUtils.stub_function/1 ] do - client = LogflareEx.client(api_key: "123", source_token: "123", on_error: cb) - assert {:error, %Tesla.Env{}} = LogflareEx.send_events(client, [%{some: "event"}]) + client = WarehouseEx.client(api_key: "123", source_token: "123", on_error: cb) + assert {:error, %Tesla.Env{}} = WarehouseEx.send_events(client, [%{some: "event"}]) end end @@ -72,15 +72,15 @@ defmodule LogflareExTest do {:error, %Tesla.Env{status: 500, body: "some server error"}} end) - LogflareEx.TestUtils + WarehouseEx.TestUtils |> expect(:stub_function, 2, fn %{status: 500} -> :ok end) for cb <- [ - {LogflareEx.TestUtils, :stub_function, 1}, - &LogflareEx.TestUtils.stub_function/1 + {WarehouseEx.TestUtils, :stub_function, 1}, + &WarehouseEx.TestUtils.stub_function/1 ] do - client = LogflareEx.client(api_key: "123", source_token: "123", on_error: cb) - assert {:error, %Tesla.Env{}} = LogflareEx.send_events(client, [%{some: "event"}]) + client = WarehouseEx.client(api_key: "123", source_token: "123", on_error: cb) + assert {:error, %Tesla.Env{}} = WarehouseEx.send_events(client, [%{some: "event"}]) end end end @@ -126,13 +126,13 @@ defmodule LogflareExTest do test "send_batched_events/2 queues events to be batched" do reject(Tesla, :post, 2) - client = LogflareEx.client(api_key: "123", source_token: "12313", auto_flush: false) + client = WarehouseEx.client(api_key: "123", source_token: "12313", auto_flush: false) assert :ok = - LogflareEx.send_batched_events(client, [%{some: "event"}, %{some_other: "event"}]) + WarehouseEx.send_batched_events(client, [%{some: "event"}, %{some_other: "event"}]) assert BatcherSup.count_batchers() == 1 - assert LogflareEx.count_queued_events() == 2 + assert WarehouseEx.count_queued_events() == 2 end end @@ -191,12 +191,12 @@ defmodule LogflareExTest do BencheeAsync.run( %{ "no batching" => fn -> - LogflareEx.client(source_name: "somename") - |> LogflareEx.send_event(event) + WarehouseEx.client(source_name: "somename") + |> WarehouseEx.send_event(event) end, "batching" => fn -> - LogflareEx.client(source_name: "some-batched-name", flush_interval: 500) - |> LogflareEx.send_batched_event(event) + WarehouseEx.client(source_name: "some-batched-name", flush_interval: 500) + |> WarehouseEx.send_batched_event(event) end }, time: 2, diff --git a/ex/test/logger_backend_test.exs b/ex/test/logger_backend_test.exs index b179fe9..1cd068d 100644 --- a/ex/test/logger_backend_test.exs +++ b/ex/test/logger_backend_test.exs @@ -1,9 +1,9 @@ -defmodule LogflareEx.LoggerBackendTest do - use LogflareEx.BatcherCase +defmodule WarehouseEx.LoggerBackendTest do + use WarehouseEx.BatcherCase use Mimic setup :set_mimic_global - alias LogflareEx.BatcherSup - alias LogflareEx.LoggerBackend + alias WarehouseEx.BatcherSup + alias WarehouseEx.LoggerBackend require Logger import ExUnit.CaptureLog import ExUnit.CaptureIO @@ -42,7 +42,7 @@ defmodule LogflareEx.LoggerBackendTest do {:ok, %Tesla.Env{status: 201, body: Jason.encode!(%{"message" => "server msg"})}} end) - assert LogflareEx.count_queued_events() == 0 + assert WarehouseEx.count_queued_events() == 0 capture_log(fn -> Logger.emergency("a log event") @@ -58,10 +58,10 @@ defmodule LogflareEx.LoggerBackendTest do Process.sleep(80) end) =~ "a log event" - assert LogflareEx.count_queued_events() == 10 + assert WarehouseEx.count_queued_events() == 10 Process.sleep(300) # should clear cache - assert LogflareEx.count_queued_events() == 0 + assert WarehouseEx.count_queued_events() == 0 end test "exception and stacktrace" do @@ -279,11 +279,11 @@ defmodule LogflareEx.LoggerBackendTest do describe "Configuration" do setup do - env = Application.get_env(:logflare_ex, LoggerBackend) - Application.put_env(:logflare_ex, LoggerBackend, api_url: "http://custom-url.com") + env = Application.get_env(:warehouse_ex, LoggerBackend) + Application.put_env(:warehouse_ex, LoggerBackend, api_url: "http://custom-url.com") on_exit(fn -> - Application.put_env(:logflare_ex, LoggerBackend, env) + Application.put_env(:warehouse_ex, LoggerBackend, env) end) :ok diff --git a/ex/test/support/batcher_case.ex b/ex/test/support/batcher_case.ex index 35df9e9..79ba161 100644 --- a/ex/test/support/batcher_case.ex +++ b/ex/test/support/batcher_case.ex @@ -1,11 +1,11 @@ -defmodule LogflareEx.BatcherCase do +defmodule WarehouseEx.BatcherCase do use ExUnit.CaseTemplate, async: false - alias LogflareEx.Batcher + alias WarehouseEx.Batcher using do quote do use Mimic - import LogflareEx.Factory + import WarehouseEx.Factory setup :set_mimic_global setup :verify_on_exit! end diff --git a/ex/test/support/factory.ex b/ex/test/support/factory.ex index e98545d..48a241b 100644 --- a/ex/test/support/factory.ex +++ b/ex/test/support/factory.ex @@ -1,7 +1,7 @@ -defmodule LogflareEx.Factory do +defmodule WarehouseEx.Factory do # with Ecto - use ExMachina.Ecto, repo: LogflareEx.Repo - alias LogflareEx.BatchedEvent + use ExMachina.Ecto, repo: WarehouseEx.Repo + alias WarehouseEx.BatchedEvent def pending_event_factory(attrs) do %BatchedEvent{ diff --git a/ex/test/support/test_utils.ex b/ex/test/support/test_utils.ex index 8d8c0bc..0344c89 100644 --- a/ex/test/support/test_utils.ex +++ b/ex/test/support/test_utils.ex @@ -1,4 +1,4 @@ -defmodule LogflareEx.TestUtils do +defmodule WarehouseEx.TestUtils do @moduledoc false def stub_function(_env), do: nil diff --git a/ex/test/telemetry_reporter_test.exs b/ex/test/telemetry_reporter_test.exs index ab379cf..99d2fc6 100644 --- a/ex/test/telemetry_reporter_test.exs +++ b/ex/test/telemetry_reporter_test.exs @@ -1,19 +1,19 @@ -defmodule LogflareEx.TelemetryReporterTest do - use LogflareEx.BatcherCase +defmodule WarehouseEx.TelemetryReporterTest do + use WarehouseEx.BatcherCase use Mimic - alias LogflareEx.BatcherSup - alias LogflareEx.TelemetryReporter + alias WarehouseEx.BatcherSup + alias WarehouseEx.TelemetryReporter import Telemetry.Metrics describe "telemtry" do setup do start_supervised!(BatcherSup) - source_name = Application.get_env(:logflare_ex, :source_name) - Application.put_env(:logflare_ex, :source_name, "some name") + source_name = Application.get_env(:warehouse_ex, :source_name) + Application.put_env(:warehouse_ex, :source_name, "some name") on_exit(fn -> :telemetry.detach("my-id") - Application.put_env(:logflare_ex, :source_name, source_name) + Application.put_env(:warehouse_ex, :source_name, source_name) end) end @@ -44,7 +44,7 @@ defmodule LogflareEx.TelemetryReporterTest do Process.sleep(300) # should clear cache - assert LogflareEx.count_queued_events() == 0 + assert WarehouseEx.count_queued_events() == 0 assert_received {^ref, %{"batch" => [event]}} # include option will only add @@ -193,11 +193,11 @@ defmodule LogflareEx.TelemetryReporterTest do describe "Configuration" do setup do start_supervised!(BatcherSup) - env = Application.get_env(:logflare_ex, TelemetryReporter) - Application.put_env(:logflare_ex, TelemetryReporter, api_url: "http://custom-url.com") + env = Application.get_env(:warehouse_ex, TelemetryReporter) + Application.put_env(:warehouse_ex, TelemetryReporter, api_url: "http://custom-url.com") on_exit(fn -> - Application.put_env(:logflare_ex, TelemetryReporter, env) + Application.put_env(:warehouse_ex, TelemetryReporter, env) :telemetry.detach("my-id") end) diff --git a/ex/test/test_helper.exs b/ex/test/test_helper.exs index 136bd49..6d47a99 100644 --- a/ex/test/test_helper.exs +++ b/ex/test/test_helper.exs @@ -1,5 +1,5 @@ {:ok, _} = Application.ensure_all_started(:ex_machina) Mimic.copy(Tesla) -Mimic.copy(LogflareEx.TestUtils) +Mimic.copy(WarehouseEx.TestUtils) ExUnit.start(exclude: [:benchmark]) diff --git a/js/src/main.ts b/js/src/main.ts index 89e655d..87cff6d 100644 --- a/js/src/main.ts +++ b/js/src/main.ts @@ -3,9 +3,9 @@ export interface ClientOptions { sourceToken: string; // api key retrieved from service apiKey: string; - // configurable url for the logflare endpoint + // configurable url for the server endpoint apiUrl?: string; - // onError is an optional callback function to handle any errors returned by logflare + // onError is an optional callback function to handle any errors returned by server onError?: ( payload: { batch: object[]; From e87b24eaf4793959ca72db8211eab4bd0780abe6 Mon Sep 17 00:00:00 2001 From: TzeYiing Date: Wed, 12 Jun 2024 18:51:44 +0800 Subject: [PATCH 2/2] chore: rename all modules post-rebase --- ex/test/logflare_ex_test.exs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ex/test/logflare_ex_test.exs b/ex/test/logflare_ex_test.exs index 6dce6cc..41c61df 100644 --- a/ex/test/logflare_ex_test.exs +++ b/ex/test/logflare_ex_test.exs @@ -1,4 +1,4 @@ -defmodule LogflareExTest do +defmodule WarehouseExTest do use WarehouseEx.BatcherCase use Mimic alias WarehouseEx.BatcherSup @@ -96,21 +96,21 @@ defmodule LogflareExTest do {:ok, %Tesla.Env{status: 500, body: "some server error"}} end) - LogflareEx.TestUtils + WarehouseEx.TestUtils |> expect(:stub_function, 2, fn data -> %{different: "value", ref: data.ref} end) for cb <- [ - {LogflareEx.TestUtils, :stub_function, 1}, - &LogflareEx.TestUtils.stub_function/1, + {WarehouseEx.TestUtils, :stub_function, 1}, + &WarehouseEx.TestUtils.stub_function/1, fn data -> %{different: "value", ref: data.ref} end ] do - client = LogflareEx.client(api_key: "123", source_token: "123", on_prepare_payload: cb) + client = WarehouseEx.client(api_key: "123", source_token: "123", on_prepare_payload: cb) ref = make_ref() assert {:error, %Tesla.Env{}} = - LogflareEx.send_events(client, [%{some: "event", ref: ref}]) + WarehouseEx.send_events(client, [%{some: "event", ref: ref}]) assert_receive {^ref, %{different: "value", ref: _}} end