Packages
prom_ex
0.1.13-beta
1.12.0
1.11.0
1.10.0
1.9.0
1.8.0
1.7.1
1.7.0
retired
1.6.0
1.5.0
1.4.1
1.4.0
1.3.0
1.2.2
1.2.1
1.2.0
1.1.1
1.1.0
1.0.1
1.0.0
0.1.15-beta
0.1.14-beta
0.1.13-beta
0.1.12-beta
0.1.11-alpha
0.1.10-alpha
0.1.9-alpha
0.1.8-alpha
0.1.7-alpha
0.1.6-alpha
0.1.5-alpha
0.1.4-alpha
0.1.3-alpha
0.1.2-alpha
0.1.1-alpha
0.1.0-alpha
Prometheus metrics and Grafana dashboards for all of your favorite Elixir libraries
Current section
Files
Jump to
Current section
Files
lib/prom_ex/grafana_client/connection.ex
defmodule PromEx.GrafanaClient.Connection do
@moduledoc """
This struct encapsulates all of the data necessary
to connect to a Grafana instance.
"""
@type t :: %__MODULE__{
finch_process: module(),
base_url: String.t(),
auth_token: String.t()
}
defstruct finch_process: nil, base_url: nil, auth_token: nil
@doc """
Build a connection struct for connecting to Grafana.
"""
@spec build(finch_process :: module(), base_url :: String.t(), auth_token :: String.t()) :: __MODULE__.t()
def build(finch_process, base_url, auth_token) do
%__MODULE__{
finch_process: finch_process,
base_url: normalize_host(base_url),
auth_token: "Bearer #{auth_token}"
}
end
defp normalize_host(host_string) do
host_string
|> URI.parse()
|> Map.put(:path, nil)
|> Map.put(:query, nil)
|> URI.to_string()
end
end