Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
0.2.0 (February XX, 2025):
- BREAKING CHANGES:
- Removed the `fallback_enabled` option from the `Split.Supervisor.start_link/1` function. The fallback behavior is now always enabled, so `Split` functions will never return `{:error, _}` tuples. Instead, they will use the fallback value when an error occurs.
- Updated the return types of `Split.get_treatment/3` and `Split.get_treatments/3` to return the treatment string value and a map of treatment string values, respectively.
- Updated the `Split` struct: renamed the `configurations` field to `configs`, the `flag_sets` field to `sets`, and added the `impressions_disabled` field.
- Updated the signature of all `get_treatment` functions: removed the 3rd argument (`bucketing_key`) and extended the first argument (`key`) to accept a union, allowing a string or a map with the key and optional bucketing key (`{:matching_key, String.t(), :bucketing_key, String.t() | nil}`).
- Removed the `fallback_enabled` option from `Split.Supervisor.start_link/1`. Fallback behavior is now always enabled, so `Split` functions no longer return `{:error, _}` tuples but instead use the fallback value when an error occurs.
- Moved the `Split` struct to the new `Split.SplitView` module and updated some fields: renamed `configurations` to `configs`, `flag_sets` to `sets`, and added the `impressions_disabled` field.
- Updated the return types of `Split.get_treatment/3` and `Split.get_treatments/3` to return a treatment string and a map of treatment strings, respectively.
- Updated all `get_treatment` function signatures: removed the third argument (`bucketing_key`) and expanded the first argument (`key`) to accept a union, allowing either a string or a map with a key and optional bucketing key (`{:matching_key, String.t(), :bucketing_key, String.t() | nil}`).

0.1.0 (January 27, 2025):
- BREAKING CHANGES:
Expand Down
29 changes: 3 additions & 26 deletions lib/split.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,10 @@ defmodule Split do
alias Split.Telemetry
alias Split.Sockets.Pool
alias Split.Treatment
alias Split.SplitView
alias Split.RPC.Message
alias Split.RPC.ResponseParser

@type t :: %Split{
name: String.t(),
traffic_type: String.t(),
killed: boolean(),
treatments: [String.t()],
change_number: integer(),
configs: map(),
default_treatment: String.t(),
sets: [String.t()],
impressions_disabled: boolean()
}

@typedoc "An option that can be provided when starting `Split`."
@type option ::
{:socket_path, String.t()}
Expand All @@ -77,18 +66,6 @@ defmodule Split do

@type split_key :: String.t() | {:matching_key, String.t(), :bucketing_key, String.t() | nil}

defstruct [
:name,
:traffic_type,
:killed,
:treatments,
:change_number,
:configs,
:default_treatment,
:sets,
:impressions_disabled
]

@doc """
Builds a child specification to use in a Supervisor.

Expand Down Expand Up @@ -164,14 +141,14 @@ defmodule Split do
execute_rpc(request)
end

@spec split(String.t()) :: Split.t() | nil
@spec split(String.t()) :: SplitView.t() | nil
def split(name) do
request = Message.split(name)

execute_rpc(request)
end

@spec splits() :: [Split.t()]
@spec splits() :: [SplitView.t()]
def splits do
request = Message.splits()
execute_rpc(request)
Expand Down
5 changes: 3 additions & 2 deletions lib/split/rpc/response_parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule Split.RPC.ResponseParser do
alias Split.RPC.Message
alias Split.Telemetry
alias Split.Treatment
alias Split.SplitView

@type splitd_response :: {:ok, map()} | {:error, term()}

Expand All @@ -17,7 +18,7 @@ defmodule Split.RPC.ResponseParser do
"""
@spec parse_response(response :: splitd_response(), request :: Message.t(), [
{:span_context, reference()} | {:span_context, nil}
]) :: map() | list() | Treatment.t() | Split.t() | boolean() | nil
]) :: map() | list() | Treatment.t() | SplitView.t() | boolean() | nil

def parse_response(response, original_request, opts \\ [])

Expand Down Expand Up @@ -151,7 +152,7 @@ defmodule Split.RPC.ResponseParser do
end

defp parse_split(payload) do
%Split{
%SplitView{
name: Map.get(payload, "n", nil),
traffic_type: payload["t"],
killed: payload["k"],
Expand Down
25 changes: 25 additions & 0 deletions lib/split/split_view.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
defmodule Split.SplitView do
defstruct [
:name,
:traffic_type,
:killed,
:treatments,
:change_number,
:configs,
:default_treatment,
:sets,
:impressions_disabled
]

@type t :: %__MODULE__{
name: String.t(),
traffic_type: String.t(),
killed: boolean(),
treatments: [String.t()],
change_number: integer(),
configs: map(),
default_treatment: String.t(),
sets: [String.t()],
impressions_disabled: boolean()
}
end
7 changes: 4 additions & 3 deletions test/rpc/response_parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule Split.RPC.ResponseParserTest do
alias Split.RPC.ResponseParser
alias Split.RPC.Message
alias Split.Treatment
alias Split.SplitView

import ExUnit.CaptureLog

Expand Down Expand Up @@ -166,7 +167,7 @@ defmodule Split.RPC.ResponseParserTest do
}}

assert ResponseParser.parse_response(response, message) ==
%Split{
%SplitView{
name: "feature_name",
traffic_type: "user",
killed: false,
Expand Down Expand Up @@ -222,7 +223,7 @@ defmodule Split.RPC.ResponseParserTest do
# Order of splits is not guaranteed
assert ResponseParser.parse_response(response, message) |> Enum.sort_by(& &1.name) ==
[
%Split{
%SplitView{
name: "feature_a",
traffic_type: "user",
killed: false,
Expand All @@ -233,7 +234,7 @@ defmodule Split.RPC.ResponseParserTest do
sets: [],
impressions_disabled: false
},
%Split{
%SplitView{
name: "feature_b",
traffic_type: "user",
killed: false,
Expand Down
5 changes: 3 additions & 2 deletions test/split_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule SplitThinElixirTest do

alias Split.Impression
alias Split.Treatment
alias Split.SplitView

setup_all context do
test_id = :erlang.phash2(context.case)
Expand Down Expand Up @@ -104,12 +105,12 @@ defmodule SplitThinElixirTest do
end

test "split/1" do
assert %Split{name: "test-split"} =
assert %SplitView{name: "test-split"} =
Split.split("test-split")
end

test "splits/0" do
assert [%Split{name: "test-split"}] = Split.splits()
assert [%SplitView{name: "test-split"}] = Split.splits()
end

describe "telemetry" do
Expand Down