Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ the release.
([#2644](https://github.com/open-telemetry/opentelemetry-demo/pull/2644))
* [frontend] fix item calculation and shipping
([#2684](https://github.com/open-telemetry/opentelemetry-demo/pull/2684))
* [flagd-ui] add back legacy REST APIs to empower programmatic usage ([#2720](https://github.com/open-telemetry/opentelemetry-demo/pull/2720))

## 2.1.3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ defmodule FlagdUiWeb.FeatureController do

json(conn, %{"flags" => flags})
end

def write(conn, %{"data" => data}) do
payload = Jason.encode!(data)
GenServer.cast(Storage, {:replace, payload})

json(conn, %{})
end
end
3 changes: 3 additions & 0 deletions src/flagd-ui/lib/flagd_ui_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ defmodule FlagdUiWeb.Router do
pipe_through :api

get "/read", FeatureController, :read
get "/read-file", FeatureController, :read
post "/write", FeatureController, :write
post "/write-to-file", FeatureController, :write
end

# Enable LiveDashboard and Swoosh mailbox preview in development
Expand Down
2 changes: 1 addition & 1 deletion src/flagd-ui/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule FlagdUi.MixProject do
def project do
[
app: :flagd_ui,
version: "0.1.0",
version: "0.1.1",
elixir: "~> 1.15",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

defmodule FlagdUiWeb.FeatureControllerTest do
use FlagdUiWeb.ConnCase

setup do
file_content = GenServer.call(Storage, :read)

on_exit(fn ->
GenServer.cast(Storage, {:replace, Jason.encode!(file_content)})
end)
end

test "GET /api/read", %{conn: conn} do
conn = get(conn, ~p"/api/read")

assert %{
"flags" => %{
"adFailure" => %{
"defaultVariant" => "off",
"description" => "Fail ad service",
"state" => "ENABLED",
"variants" => %{"off" => false, "on" => true}
},
"adHighCpu" => %{
"defaultVariant" => "off",
"description" => "Triggers high cpu load in the ad service",
"state" => "ENABLED",
"variants" => %{"off" => false, "on" => true}
}
}
} = json_response(conn, 200)
end

test "GET /api/read-file (legacy API)", %{conn: conn} do
conn = get(conn, ~p"/api/read-file")

assert %{
"flags" => %{
"adFailure" => %{
"defaultVariant" => "off",
"description" => "Fail ad service",
"state" => "ENABLED",
"variants" => %{"off" => false, "on" => true}
},
"adHighCpu" => %{
"defaultVariant" => "off",
"description" => "Triggers high cpu load in the ad service",
"state" => "ENABLED",
"variants" => %{"off" => false, "on" => true}
}
}
} = json_response(conn, 200)
end

test "POST /api/write", %{conn: conn} do
data = %{
"flags" => %{
"adFailure" => %{
"defaultVariant" => "off",
"description" => "Fail ad service",
"state" => "ENABLED",
"variants" => %{"off" => true, "on" => false}
},
"adHighCpu" => %{
"defaultVariant" => "off",
"description" => "Triggers high cpu load in the ad service",
"state" => "ENABLED",
"variants" => %{"off" => true, "on" => false}
}
}
}

conn = post(conn, ~p"/api/write", %{"data" => data})

conn = get(conn, ~p"/api/read")

assert %{
"flags" => %{
"adFailure" => %{
"defaultVariant" => "off",
"description" => "Fail ad service",
"state" => "ENABLED",
"variants" => %{"off" => true, "on" => false}
},
"adHighCpu" => %{
"defaultVariant" => "off",
"description" => "Triggers high cpu load in the ad service",
"state" => "ENABLED",
"variants" => %{"off" => true, "on" => false}
}
}
} = json_response(conn, 200)
end

test "POST /api/write-to-file (legacy API)", %{conn: conn} do
data = %{
"flags" => %{
"adFailure" => %{
"defaultVariant" => "off",
"description" => "Fail ad service",
"state" => "ENABLED",
"variants" => %{"off" => true, "on" => false}
},
"adHighCpu" => %{
"defaultVariant" => "off",
"description" => "Triggers high cpu load in the ad service",
"state" => "ENABLED",
"variants" => %{"off" => true, "on" => false}
}
}
}

conn = post(conn, ~p"/api/write-to-file", %{"data" => data})

conn = get(conn, ~p"/api/read-file")

assert %{
"flags" => %{
"adFailure" => %{
"defaultVariant" => "off",
"description" => "Fail ad service",
"state" => "ENABLED",
"variants" => %{"off" => true, "on" => false}
},
"adHighCpu" => %{
"defaultVariant" => "off",
"description" => "Triggers high cpu load in the ad service",
"state" => "ENABLED",
"variants" => %{"off" => true, "on" => false}
}
}
} = json_response(conn, 200)
end
end