Skip to content

Commit

Permalink
Merge pull request #31 from GameAnalytics/rename-to-panoramix
Browse files Browse the repository at this point in the history
Rename to Panoramix
  • Loading branch information
lastres authored Apr 3, 2019
2 parents ea01bff + 161c8c0 commit 6d5d38e
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ erl_crash.dump
*.ez

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

22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ElixirDruid
=====
[![Build Status](https://travis-ci.com/GameAnalytics/elixir_druid.svg?token=7iC72mSUZcJMSAvPBsAL&branch=master)](https://travis-ci.com/GameAnalytics/elixir_druid)
# Panoramix

[![Build Status](https://travis-ci.com/GameAnalytics/panoramix.svg?token=7iC72mSUZcJMSAvPBsAL&branch=master)](https://travis-ci.com/GameAnalytics/panoramix)

An open-source client library for sending requests to [Apache Druid][druid] from applications written in Elixir. The project uses [HTTPoison][httpoison] as an HTTP client for sending queries.

Expand All @@ -9,24 +9,24 @@ An open-source client library for sending requests to [Apache Druid][druid] from

## Getting Started

Add ElixirDruid as a dependency to your project.
Add Panoramix as a dependency to your project.

[//]: # (TODO - Replace GitHub dep with Hex.pm below)

```elixir
defp deps do
[
{:elixir_druid, github: "GameAnalytics/elixir_druid"}
{:panoramix, github: "GameAnalytics/panoramix"}
]
end
```

## Configuration

ElixirDruid requires a Druid Broker profile to be defined in the configuration of your application.
Panoramix requires a Druid Broker profile to be defined in the configuration of your application.

```elixir
config :elixir_druid,
config :panoramix,
request_timeout: 120_000,
query_priority: 0,
broker_profiles: [
Expand All @@ -49,7 +49,7 @@ config :elixir_druid,
Build a query like this:

```elixir
use ElixirDruid
use Panoramix

q = from "my_datasource",
query_type: "timeseries",
Expand All @@ -63,7 +63,7 @@ q = from "my_datasource",
And then send it:

```elixir
ElixirDruid.post_query(q, :default)
Panoramix.post_query(q, :default)
```

Where `:default` is a configuration profile pointing to your Druid server.
Expand All @@ -72,7 +72,7 @@ The default value for the profile argument is `:default`, so if you
only need a single configuration you can omit it:

```elixir
ElixirDruid.post_query(q)
Panoramix.post_query(q)
```

Response example:
Expand Down Expand Up @@ -108,7 +108,7 @@ Response example:
You can check correctness of your configuration by requesting status from Druid Broker. A successfull response will look like this.

```elixir
iex(1)> ElixirDruid.status(:default)
iex(1)> Panoramix.status(:default)
{:ok,
%{
"memory" => %{...},
Expand Down
6 changes: 3 additions & 3 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use Mix.Config

# You can configure your application as:
#
# config :elixir_druid, key: :value
# config :panoramix, key: :value
#
# and access this configuration in your application as:
#
# Application.get_env(:elixir_druid, :key)
# Application.get_env(:panoramix, :key)
#
# You can also configure a 3rd-party app:
#
Expand All @@ -29,7 +29,7 @@ use Mix.Config
#
# import_config "#{Mix.env}.exs"

config :elixir_druid,
config :panoramix,
request_timeout: 120_000,
query_priority: 0,
broker_profiles: [
Expand Down
36 changes: 18 additions & 18 deletions lib/elixir_druid.ex → lib/panoramix.ex
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
defmodule ElixirDruid.Error do
defmodule Panoramix.Error do
defexception [:message]
@type t :: %__MODULE__{}
end

defmodule ElixirDruid do
defmodule Panoramix do

@moduledoc """
Post a query to Druid Broker or request its status.
Use ElixirDruid.Query to build a query.
Use Panoramix.Query to build a query.
## Examples
Build a query like this:
```elixir
use ElixirDruid
use Panoramix
q = from "my_datasource",
query_type: "timeseries",
Expand All @@ -29,7 +29,7 @@ defmodule ElixirDruid do
And then send it:
```elixir
ElixirDruid.post_query(q, :default)
Panoramix.post_query(q, :default)
```
Where `:default` is a configuration profile pointing to your Druid server.
Expand All @@ -38,7 +38,7 @@ defmodule ElixirDruid do
only need a single configuration you can omit it:
```elixir
ElixirDruid.post_query(q)
Panoramix.post_query(q)
```
Response example:
Expand Down Expand Up @@ -71,23 +71,23 @@ defmodule ElixirDruid do
To request status from Broker run
```elixir
ElixirDruid.status(:default)
Panoramix.status(:default)
```
"""
@moduledoc since: "1.0.0"

@spec post_query(%ElixirDruid.Query{}, atom()) :: {:ok, term()} |
{:error, HTTPoison.Error.t() | Jason.DecodeError.t() | ElixirDruid.Error.t()}
@spec post_query(%Panoramix.Query{}, atom()) :: {:ok, term()} |
{:error, HTTPoison.Error.t() | Jason.DecodeError.t() | Panoramix.Error.t()}
def post_query(query, profile \\ :default) do
url_path = "/druid/v2"
body = ElixirDruid.Query.to_json query
body = Panoramix.Query.to_json query
headers = [{"Content-Type", "application/json"}]

request_and_decode(profile, :post, url_path, body, headers)
end

@spec post_query!(%ElixirDruid.Query{}, atom()) :: term()
@spec post_query!(%Panoramix.Query{}, atom()) :: term()
def post_query!(query, profile \\ :default) do
case post_query(query, profile) do
{:ok, response} -> response
Expand All @@ -96,7 +96,7 @@ defmodule ElixirDruid do
end

@spec status(atom) :: {:ok, term()} |
{:error, HTTPoison.Error.t() | Jason.DecodeError.t() | ElixirDruid.Error.t()}
{:error, HTTPoison.Error.t() | Jason.DecodeError.t() | Panoramix.Error.t()}
def status(profile \\ :default) do
url_path = "/status"
body = ""
Expand All @@ -114,7 +114,7 @@ defmodule ElixirDruid do
end

defp request_and_decode(profile, method, url_path, body, headers) do
broker_profiles = Application.get_env(:elixir_druid, :broker_profiles)
broker_profiles = Application.get_env(:panoramix, :broker_profiles)
broker_profile = broker_profiles[profile] ||
raise ArgumentError, "no broker profile with name #{profile}"
url = broker_profile[:base_url] <> url_path
Expand Down Expand Up @@ -153,7 +153,7 @@ defmodule ElixirDruid do

defp timeout_options() do
# Default to 120 seconds
request_timeout = Application.get_env(:elixir_druid, :request_timeout, 120_000)
request_timeout = Application.get_env(:panoramix, :request_timeout, 120_000)
[recv_timeout: request_timeout]
end

Expand All @@ -178,17 +178,17 @@ defmodule ElixirDruid do
_ ->
"undecodable error: " <> body
end
{:error, %ElixirDruid.Error{message: message}}
{:error, %Panoramix.Error{message: message}}
end

@doc ~S"""
Format a date or a datetime into a format that Druid expects.
## Examples
iex> ElixirDruid.format_time! ~D[2018-07-20]
iex> Panoramix.format_time! ~D[2018-07-20]
"2018-07-20"
iex> ElixirDruid.format_time!(
iex> Panoramix.format_time!(
...> Timex.to_datetime({{2018,07,20},{1,2,3}}))
"2018-07-20T01:02:03+00:00"
"""
Expand All @@ -201,7 +201,7 @@ defmodule ElixirDruid do

defmacro __using__(_params) do
quote do
import ElixirDruid.Query, only: [from: 2]
import Panoramix.Query, only: [from: 2]
end
end

Expand Down
20 changes: 10 additions & 10 deletions lib/elixir_druid/query.ex → lib/panoramix/query.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ElixirDruid.Query do
defmodule Panoramix.Query do
@moduledoc """
Provides functions for building Druid query requests.
"""
Expand All @@ -9,7 +9,7 @@ defmodule ElixirDruid.Query do
bound: nil, virtual_columns: nil, limit: nil, search_dimensions: nil,
query: nil, sort: nil]

# A query has type ElixirDruid.query.t()
# A query has type Panoramix.query.t()
@type t :: %__MODULE__{}

@doc """
Expand All @@ -19,16 +19,16 @@ defmodule ElixirDruid.Query do
## Examples
```elixir
iex(1)> use ElixirDruid
ElixirDruid.Query
iex(1)> use Panoramix
Panoramix.Query
iex(2)> q = from "my_datasource",
...(2)> query_type: "timeseries",
...(2)> intervals: ["2019-03-01T00:00:00+00:00/2019-03-04T00:00:00+00:00"],
...(2)> granularity: :day,
...(2)> filter: dimensions.foo == "bar",
...(2)> aggregations: [event_count: count(),
...(2)> unique_id_count: hyperUnique(:user_unique)]
%ElixirDruid.Query{
%Panoramix.Query{
aggregations: [
%{name: :event_count, type: "count"},
%{fieldName: :user_unique, name: :unique_id_count, type: :hyperUnique}
Expand Down Expand Up @@ -71,14 +71,14 @@ defmodule ElixirDruid.Query do
# tell Druid to cancel the query if it takes too long.
# We're going to close the HTTP connection on our end, so
# there is no point in Druid keeping processing.
timeout = Application.get_env(:elixir_druid, :request_timeout, 120_000)
timeout = Application.get_env(:panoramix, :request_timeout, 120_000)
# Also set the configured priority. 0 is what Druid picks if you
# don't specify a priority, so that seems to be a sensible default.
priority = Application.get_env(:elixir_druid, :query_priority, 0)
%ElixirDruid.Query{
priority = Application.get_env(:panoramix, :query_priority, 0)
%Panoramix.Query{
data_source: datasource,
context: %{timeout: timeout, priority: priority}}
%ElixirDruid.Query{} ->
%Panoramix.Query{} ->
# Or are we extending an existing query?
source
end
Expand Down Expand Up @@ -145,7 +145,7 @@ defmodule ElixirDruid.Query do
# Already a string - pass it on unchanged
interval_string
{from, to} ->
ElixirDruid.format_time!(from) <> "/" <> ElixirDruid.format_time!(to)
Panoramix.format_time!(from) <> "/" <> Panoramix.format_time!(to)
end
end
end
Expand Down
16 changes: 8 additions & 8 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
defmodule ElixirDruid.MixProject do
defmodule Panoramix.MixProject do
use Mix.Project

def project do
[
app: :elixir_druid,
app: :panoramix,
version: System.cmd("git", ["describe", "--tags"]) |> elem(0) |> String.trim_trailing |> String.trim_leading("v"),
elixir: "~> 1.8.1",
start_permanent: Mix.env() == :prod,
description: "Client library for sending requests to Druid.",
source_url: "https://github.com/gameanalytics/elixir_druid",
source_url: "https://github.com/GameAnalytics/panoramix",
package: package(),
deps: deps(),

# Docs
name: "ElixirDruid",
source_url: "https://github.com/GameAnalytics/elixir_druid",
homepage_url: "https://github.com/GameAnalytics/elixir_druid",
name: "Panoramix",
source_url: "https://github.com/GameAnalytics/panoramix",
homepage_url: "https://github.com/GameAnalytics/panoramix",
docs: [
main: "ElixirDruid", # The main page in the docs
main: "Panoramix", # The main page in the docs
extras: ["README.md"]
]
]
Expand All @@ -28,7 +28,7 @@ defmodule ElixirDruid.MixProject do
files: ["config", "lib", "mix.exs", "README*", "LICENSE*"],
maintainers: ["Magnus Henoch"],
licenses: ["Apache-2.0"],
links: %{github: "https://github.com/gameanalytics/elixir_druid"}
links: %{github: "https://github.com/GameAnalytics/panoramix"}
]
end

Expand Down
Loading

0 comments on commit 6d5d38e

Please sign in to comment.