From 320d19c34ea6c45c0e91b3de15c9bac1f9fe9a4d Mon Sep 17 00:00:00 2001 From: Alessio Biancalana Date: Sun, 9 Nov 2025 11:28:15 +0100 Subject: [PATCH 1/3] [flagd-ui] add back legacy REST APIs to empower programmatic usage --- .../controllers/feature_controller.ex | 7 + src/flagd-ui/lib/flagd_ui_web/router.ex | 3 + .../controllers/feature_controller_test.exs | 136 ++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 src/flagd-ui/test/flagd_ui_web/controllers/feature_controller_test.exs diff --git a/src/flagd-ui/lib/flagd_ui_web/controllers/feature_controller.ex b/src/flagd-ui/lib/flagd_ui_web/controllers/feature_controller.ex index 551f225c2f..906971aef9 100644 --- a/src/flagd-ui/lib/flagd_ui_web/controllers/feature_controller.ex +++ b/src/flagd-ui/lib/flagd_ui_web/controllers/feature_controller.ex @@ -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 diff --git a/src/flagd-ui/lib/flagd_ui_web/router.ex b/src/flagd-ui/lib/flagd_ui_web/router.ex index df7d8bae18..b32e66136d 100644 --- a/src/flagd-ui/lib/flagd_ui_web/router.ex +++ b/src/flagd-ui/lib/flagd_ui_web/router.ex @@ -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 diff --git a/src/flagd-ui/test/flagd_ui_web/controllers/feature_controller_test.exs b/src/flagd-ui/test/flagd_ui_web/controllers/feature_controller_test.exs new file mode 100644 index 0000000000..8d24cc3d81 --- /dev/null +++ b/src/flagd-ui/test/flagd_ui_web/controllers/feature_controller_test.exs @@ -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 From 35414ac0c4b11784a7f5a61e3dd7b1bf8c2e93d2 Mon Sep 17 00:00:00 2001 From: Alessio Biancalana Date: Sun, 9 Nov 2025 11:31:52 +0100 Subject: [PATCH 2/3] [flagd-ui] bump version --- src/flagd-ui/mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flagd-ui/mix.exs b/src/flagd-ui/mix.exs index 7fa0130066..a8fb490851 100644 --- a/src/flagd-ui/mix.exs +++ b/src/flagd-ui/mix.exs @@ -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, From 648b132a337c5896ffdd089fd44e072d1c740671 Mon Sep 17 00:00:00 2001 From: Alessio Biancalana Date: Sun, 9 Nov 2025 11:34:00 +0100 Subject: [PATCH 3/3] [chore]: update the CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd4efc51c1..f2f847fa4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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