-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: elastic filebeat adaptor * docs: elastic filebeat docs * fix: add ui for elastic backend * feat: http1 for elastic * docs: add link to filebeat docs * feat: default webhook value, add default field value changeset helper * chore: review comments * chore: only use Tesla.Mock for certain tesla clients * chore: fix documentation link, sidebar order * chore: fix failing test * chore: fix failing tests due to dynamic tesla client * chore: formatting
- Loading branch information
Showing
19 changed files
with
389 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
--- | ||
toc_max_heading_level: 3 | ||
sidebar_position: 1 | ||
--- | ||
|
||
# BigQuery | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
sidebar_position: 4 | ||
--- | ||
# Elastic | ||
|
||
The Elastic backend is **ingest-only** to a Filebeat HTTP server endpoint. | ||
|
||
See Filebeat HTTP input [configuration](https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-input-http_endpoint.html) for details on setting up the input server. | ||
|
||
## Behaviour and configurations | ||
### Configuration | ||
|
||
The following values are required when creating a webhook backend: | ||
|
||
- `url`: (`string`, required) a valid HTTP(S) endpoint. | ||
- `username`: (`string`, optional) used for basic auth. | ||
- `password`: (`string`, optional) used for basic auth. | ||
|
||
### Implementation Details | ||
|
||
Implementation is based on the [webhook backend](/backends/webhook). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
--- | ||
toc_max_heading_level: 3 | ||
sidebar_position: 2 | ||
--- | ||
|
||
# PostgreSQL | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
defmodule Logflare.Backends.Adaptor.ElasticAdaptor do | ||
@moduledoc """ | ||
Ingestion uses Filebeat HTTP input. | ||
https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-input-http_endpoint.html | ||
Basic auth implementation reference: | ||
https://datatracker.ietf.org/doc/html/rfc7617 | ||
""" | ||
|
||
use TypedStruct | ||
|
||
alias Logflare.Backends.Adaptor.WebhookAdaptor | ||
|
||
typedstruct enforce: true do | ||
field(:url, String.t()) | ||
# basic auth username and password | ||
field(:username, String.t()) | ||
field(:password, String.t()) | ||
end | ||
|
||
@behaviour Logflare.Backends.Adaptor | ||
|
||
def child_spec(arg) do | ||
%{ | ||
id: __MODULE__, | ||
start: {__MODULE__, :start_link, [arg]} | ||
} | ||
end | ||
|
||
@impl Logflare.Backends.Adaptor | ||
def start_link({source, backend}) do | ||
basic_auth = get_basic_auth(backend.config) | ||
|
||
backend = %{ | ||
backend | ||
| config: %{ | ||
url: backend.config.url, | ||
http: "http1", | ||
headers: | ||
if basic_auth do | ||
%{"Authorization" => "Basic #{basic_auth}"} | ||
else | ||
%{} | ||
end | ||
} | ||
} | ||
|
||
WebhookAdaptor.start_link({source, backend}) | ||
end | ||
|
||
defp get_basic_auth(%{username: username, password: password}) | ||
when is_binary(username) and is_binary(password) do | ||
Base.encode64(username <> ":" <> password) | ||
end | ||
|
||
defp get_basic_auth(_), do: nil | ||
|
||
@impl Logflare.Backends.Adaptor | ||
def ingest(pid, log_events, opts) do | ||
WebhookAdaptor.ingest(pid, log_events, opts) | ||
end | ||
|
||
@impl Logflare.Backends.Adaptor | ||
def execute_query(_ident, _query), do: {:error, :not_implemented} | ||
|
||
@impl Logflare.Backends.Adaptor | ||
def cast_config(params) do | ||
{%{}, %{url: :string, username: :string, password: :string}} | ||
|> Ecto.Changeset.cast(params, [:username, :password, :url]) | ||
|> validate_user_pass() | ||
end | ||
|
||
defp validate_user_pass(changeset) do | ||
user = Ecto.Changeset.get_field(changeset, :username) | ||
pass = Ecto.Changeset.get_field(changeset, :password) | ||
user_pass = [user, pass] | ||
|
||
if user_pass != [nil, nil] and Enum.any?(user_pass, &is_nil/1) do | ||
msg = "Both username and password must be provided for basic auth" | ||
|
||
changeset | ||
|> Ecto.Changeset.add_error(:username, msg) | ||
|> Ecto.Changeset.add_error(:password, msg) | ||
else | ||
changeset | ||
end | ||
end | ||
|
||
@impl Logflare.Backends.Adaptor | ||
def validate_config(changeset) do | ||
import Ecto.Changeset | ||
|
||
changeset | ||
|> validate_required([:url]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.