diff --git a/.env b/.env
index cf2b1bed25..1f4049bf50 100644
--- a/.env
+++ b/.env
@@ -47,3 +47,6 @@ RECOMMENDATION_SERVICE_ADDR=recommendationservice:${RECOMMENDATION_SERVICE_PORT}
SHIPPING_SERVICE_PORT=50051
SHIPPING_SERVICE_ADDR=shippingservice:${SHIPPING_SERVICE_PORT}
+
+FEATURE_FLAG_SERVICE_PORT=50052
+FEATURE_FLAG_GRPC_SERVICE_PORT=50053
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dbfd016e99..0884c0df1e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,3 +17,5 @@ release.
([#26](https://github.com/open-telemetry/opentelemetry-demo-webstore/pull/26))
* Added span attributes to frontend service
([#82](https://github.com/open-telemetry/opentelemetry-demo-webstore/pull/82))
+* Added feature flag service implementation
+ ([#141](https://github.com/open-telemetry/opentelemetry-demo-webstore/pull/141))
diff --git a/docker-compose.yml b/docker-compose.yml
index 7077f7f346..84db8dc268 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -25,6 +25,7 @@ services:
- ./src/otelcollector/otelcol-config.yml:/etc/otelcol-config.yml
ports:
- "4317"
+ - "4318"
depends_on:
- jaeger
@@ -198,6 +199,29 @@ services:
- OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
- OTEL_RESOURCE_ATTRIBUTES=service.name=shippingservice
+ # FeatureFlagService
+ featureflagservice:
+ build:
+ context: ./src/featureflagservice
+ ports:
+ - "${FEATURE_FLAG_SERVICE_PORT}"
+ - "${FEATURE_FLAG_GRPC_SERVICE_PORT}"
+ environment:
+ - PORT=${FEATURE_FLAG_SERVICE_PORT}
+ - GRPC_PORT=${FEATURE_FLAG_GRPC_SERVICE_PORT}
+ - OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
+ - OTEL_RESOURCE_ATTRIBUTES=service.name=featureflagservice
+ - DATABASE_URL=ecto://ffs:ffs@ffs_postgres:5432/ffs
+ depends_on:
+ - ffs_postgres
+
+ ffs_postgres:
+ image: cimg/postgres:14.2
+ environment:
+ - POSTGRES_USER=ffs
+ - POSTGRES_DB=ffs
+ - POSTGRES_PASSWORD=ffs
+
# LoadGenerator
loadgenerator:
image: ${IMAGE_NAME}:${IMAGE_VERSION}-loadgenerator
diff --git a/src/featureflagservice/.dockerignore b/src/featureflagservice/.dockerignore
new file mode 100644
index 0000000000..61a73933c8
--- /dev/null
+++ b/src/featureflagservice/.dockerignore
@@ -0,0 +1,45 @@
+# This file excludes paths from the Docker build context.
+#
+# By default, Docker's build context includes all files (and folders) in the
+# current directory. Even if a file isn't copied into the container it is still sent to
+# the Docker daemon.
+#
+# There are multiple reasons to exclude files from the build context:
+#
+# 1. Prevent nested folders from being copied into the container (ex: exclude
+# /assets/node_modules when copying /assets)
+# 2. Reduce the size of the build context and improve build time (ex. /build, /deps, /doc)
+# 3. Avoid sending files containing sensitive information
+#
+# More information on using .dockerignore is available here:
+# https://docs.docker.com/engine/reference/builder/#dockerignore-file
+
+.dockerignore
+
+# Ignore git, but keep git HEAD and refs to access current commit hash if needed:
+#
+# $ cat .git/HEAD | awk '{print ".git/"$2}' | xargs cat
+# d0b8727759e1e0e7aa3d41707d12376e373d5ecc
+.git
+!.git/HEAD
+!.git/refs
+
+# Common development/test artifacts
+/cover/
+/doc/
+/test/
+/tmp/
+.elixir_ls
+
+# Mix artifacts
+/_build/
+/deps/
+*.ez
+
+# Generated on crash by the VM
+erl_crash.dump
+
+# Static artifacts - These should be fetched and built inside the Docker image
+/assets/node_modules/
+/priv/static/assets/
+/priv/static/cache_manifest.json
diff --git a/src/featureflagservice/.formatter.exs b/src/featureflagservice/.formatter.exs
new file mode 100644
index 0000000000..8a6391c6a6
--- /dev/null
+++ b/src/featureflagservice/.formatter.exs
@@ -0,0 +1,5 @@
+[
+ import_deps: [:ecto, :phoenix],
+ inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"],
+ subdirectories: ["priv/*/migrations"]
+]
diff --git a/src/featureflagservice/.gitignore b/src/featureflagservice/.gitignore
new file mode 100644
index 0000000000..b76e6cf3af
--- /dev/null
+++ b/src/featureflagservice/.gitignore
@@ -0,0 +1,35 @@
+# The directory Mix will write compiled artifacts to.
+/_build/
+ffs_grpc/_build/
+# If you run "mix test --cover", coverage assets end up here.
+/cover/
+
+# The directory Mix downloads your dependencies sources to.
+/deps/
+
+# Where 3rd-party dependencies like ExDoc output generated docs.
+/doc/
+
+# Ignore .fetch files in case you like to edit your project deps locally.
+/.fetch
+
+# If the VM crashes, it generates a dump, let's ignore it too.
+erl_crash.dump
+
+# Also ignore archive artifacts (built via "mix archive.build").
+*.ez
+
+# Ignore package tarball (built via "mix hex.build").
+featureflagservice-*.tar
+
+# Ignore assets that are produced by build tools.
+/priv/static/assets/
+
+# Ignore digested assets cache.
+/priv/static/cache_manifest.json
+
+# In case you use Node.js/npm, you want to ignore these.
+npm-debug.log
+/assets/node_modules/
+
+/assets/vendor/
diff --git a/src/featureflagservice/Dockerfile b/src/featureflagservice/Dockerfile
new file mode 100644
index 0000000000..66ea291ea1
--- /dev/null
+++ b/src/featureflagservice/Dockerfile
@@ -0,0 +1,93 @@
+# Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian instead of
+# Alpine to avoid DNS resolution issues in production.
+#
+# https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu
+# https://hub.docker.com/_/ubuntu?tab=tags
+#
+#
+# This file is based on these images:
+#
+# - https://hub.docker.com/r/hexpm/elixir/tags - for the build image
+# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20210902-slim - for the release image
+# - https://pkgs.org/ - resource for finding needed packages
+# - Ex: hexpm/elixir:1.13.3-erlang-25.0-debian-bullseye-20210902-slim
+#
+ARG ELIXIR_VERSION=1.13.3
+ARG OTP_VERSION=25.0
+ARG DEBIAN_VERSION=bullseye-20210902-slim
+
+ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
+ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"
+
+FROM ${BUILDER_IMAGE} as builder
+
+# install build dependencies
+RUN apt-get update -y && apt-get install -y build-essential git \
+ && apt-get clean && rm -f /var/lib/apt/lists/*_*
+
+# prepare build dir
+WORKDIR /app
+
+# install hex + rebar
+RUN mix local.hex --force && \
+ mix local.rebar --force
+
+# set build ENV
+ENV MIX_ENV="prod"
+
+# install mix dependencies
+COPY mix.exs mix.lock ./
+RUN mix deps.get --only $MIX_ENV
+RUN mkdir config
+
+# copy compile-time config files before we compile dependencies
+# to ensure any relevant config change will trigger the dependencies
+# to be re-compiled.
+COPY config/config.exs config/${MIX_ENV}.exs config/
+RUN mix deps.compile
+
+COPY priv priv
+
+COPY lib lib
+
+COPY assets assets
+
+# compile assets
+RUN mix assets.deploy
+
+# Compile the release
+RUN mix compile
+
+# Changes to config/runtime.exs don't require recompiling the code
+COPY config/runtime.exs config/
+
+COPY rel rel
+RUN mix release
+
+# start a new build stage so that the final image will only contain
+# the compiled release and other runtime necessities
+FROM ${RUNNER_IMAGE}
+
+RUN apt-get update -y && apt-get install -y libstdc++6 openssl libncurses5 locales \
+ && apt-get clean && rm -f /var/lib/apt/lists/*_*
+
+# Set the locale
+RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
+
+ENV LANG en_US.UTF-8
+ENV LANGUAGE en_US:en
+ENV LC_ALL en_US.UTF-8
+
+WORKDIR "/app"
+RUN chown nobody /app
+
+# set runner ENV
+ENV MIX_ENV="prod"
+ENV SECRET_KEY_BASE="mNhoOKKxgyvBIwbtw0P23waQcvUOmusb2U1moG2I7JQ3Bt6+MlGb5ZTrHwqbqy7j"
+
+# Only copy the final release from the build stage
+COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/featureflagservice ./
+
+USER nobody
+
+CMD ["/app/bin/server"]
diff --git a/src/featureflagservice/README.md b/src/featureflagservice/README.md
new file mode 100644
index 0000000000..9503485ea1
--- /dev/null
+++ b/src/featureflagservice/README.md
@@ -0,0 +1,45 @@
+# Feature Flag Service
+
+This project provides an web interface for creating and updating feature flags
+and a GRPC service for fetching the status of flags by their name. Each runs on
+their own port but are in the same Release.
+
+## Running
+
+To run individually and not part of the demo the Release can be built with
+`mix`:
+
+``` shell
+$ MIX_ENV=prod mix release
+```
+
+Then start Postgres with `docker compose`
+
+``` shell
+$ docker compose up
+```
+
+And run the Release:
+
+``` shell
+$ PHX_SERVER=1 PORT=4000 GRPC_PORT=4001 _build/prod/rel/featureflagservice/bin/featureflagservice start_iex
+```
+
+## Instrumentation
+
+Traces of interaction with the web interface is provided by the OpenTelemetry
+[Phoenix
+instrumentation](https://github.com/open-telemetry/opentelemetry-erlang-contrib/tree/main/instrumentation/opentelemetry_phoenix)
+with Spans for database queries added through the [Ecto
+instrumentation](https://github.com/open-telemetry/opentelemetry-erlang-contrib/tree/main/instrumentation/opentelemetry_ecto).
+
+The GRPC service uses [grpcbox](https://github.com/tsloughter/grpcbox) and uses
+the [grpcbox
+interceptor](https://github.com/open-telemetry/opentelemetry-erlang-contrib/tree/main/instrumentation/opentelemetry_grpcbox)
+for instrumentation.
+
+## Building Protos
+
+A copy of the `FeatureFlagService` protos from `demo.proto` are kept in
+`proto/featureflag.proto` and `rebar3 grpc gen` will update the corresponding
+Erlang module `src/ffs_featureflag_pb.erl`.
diff --git a/src/featureflagservice/assets/css/app.css b/src/featureflagservice/assets/css/app.css
new file mode 100644
index 0000000000..19c2e51edc
--- /dev/null
+++ b/src/featureflagservice/assets/css/app.css
@@ -0,0 +1,120 @@
+/* This file is for your main application CSS */
+@import "./phoenix.css";
+
+/* Alerts and form errors used by phx.new */
+.alert {
+ padding: 15px;
+ margin-bottom: 20px;
+ border: 1px solid transparent;
+ border-radius: 4px;
+}
+.alert-info {
+ color: #31708f;
+ background-color: #d9edf7;
+ border-color: #bce8f1;
+}
+.alert-warning {
+ color: #8a6d3b;
+ background-color: #fcf8e3;
+ border-color: #faebcc;
+}
+.alert-danger {
+ color: #a94442;
+ background-color: #f2dede;
+ border-color: #ebccd1;
+}
+.alert p {
+ margin-bottom: 0;
+}
+.alert:empty {
+ display: none;
+}
+.invalid-feedback {
+ color: #a94442;
+ display: block;
+ margin: -1rem 0 2rem;
+}
+
+/* LiveView specific classes for your customization */
+.phx-no-feedback.invalid-feedback,
+.phx-no-feedback .invalid-feedback {
+ display: none;
+}
+
+.phx-click-loading {
+ opacity: 0.5;
+ transition: opacity 1s ease-out;
+}
+
+.phx-loading{
+ cursor: wait;
+}
+
+.phx-modal {
+ opacity: 1!important;
+ position: fixed;
+ z-index: 1;
+ left: 0;
+ top: 0;
+ width: 100%;
+ height: 100%;
+ overflow: auto;
+ background-color: rgba(0,0,0,0.4);
+}
+
+.phx-modal-content {
+ background-color: #fefefe;
+ margin: 15vh auto;
+ padding: 20px;
+ border: 1px solid #888;
+ width: 80%;
+}
+
+.phx-modal-close {
+ color: #aaa;
+ float: right;
+ font-size: 28px;
+ font-weight: bold;
+}
+
+.phx-modal-close:hover,
+.phx-modal-close:focus {
+ color: black;
+ text-decoration: none;
+ cursor: pointer;
+}
+
+.fade-in-scale {
+ animation: 0.2s ease-in 0s normal forwards 1 fade-in-scale-keys;
+}
+
+.fade-out-scale {
+ animation: 0.2s ease-out 0s normal forwards 1 fade-out-scale-keys;
+}
+
+.fade-in {
+ animation: 0.2s ease-out 0s normal forwards 1 fade-in-keys;
+}
+.fade-out {
+ animation: 0.2s ease-out 0s normal forwards 1 fade-out-keys;
+}
+
+@keyframes fade-in-scale-keys{
+ 0% { scale: 0.95; opacity: 0; }
+ 100% { scale: 1.0; opacity: 1; }
+}
+
+@keyframes fade-out-scale-keys{
+ 0% { scale: 1.0; opacity: 1; }
+ 100% { scale: 0.95; opacity: 0; }
+}
+
+@keyframes fade-in-keys{
+ 0% { opacity: 0; }
+ 100% { opacity: 1; }
+}
+
+@keyframes fade-out-keys{
+ 0% { opacity: 1; }
+ 100% { opacity: 0; }
+}
diff --git a/src/featureflagservice/assets/css/phoenix.css b/src/featureflagservice/assets/css/phoenix.css
new file mode 100644
index 0000000000..0d59050f89
--- /dev/null
+++ b/src/featureflagservice/assets/css/phoenix.css
@@ -0,0 +1,101 @@
+/* Includes some default style for the starter application.
+ * This can be safely deleted to start fresh.
+ */
+
+/* Milligram v1.4.1 https://milligram.github.io
+ * Copyright (c) 2020 CJ Patoilo Licensed under the MIT license
+ */
+
+*,*:after,*:before{box-sizing:inherit}html{box-sizing:border-box;font-size:62.5%}body{color:#000000;font-family:'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;font-size:1.6em;font-weight:300;letter-spacing:.01em;line-height:1.6}blockquote{border-left:0.3rem solid #d1d1d1;margin-left:0;margin-right:0;padding:1rem 1.5rem}blockquote *:last-child{margin-bottom:0}.button,button,input[type='button'],input[type='reset'],input[type='submit']{background-color:#0069d9;border:0.1rem solid #0069d9;border-radius:.4rem;color:#fff;cursor:pointer;display:inline-block;font-size:1.1rem;font-weight:700;height:3.8rem;letter-spacing:.1rem;line-height:3.8rem;padding:0 3.0rem;text-align:center;text-decoration:none;text-transform:uppercase;white-space:nowrap}.button:focus,.button:hover,button:focus,button:hover,input[type='button']:focus,input[type='button']:hover,input[type='reset']:focus,input[type='reset']:hover,input[type='submit']:focus,input[type='submit']:hover{background-color:#606c76;border-color:#606c76;color:#fff;outline:0}.button[disabled],button[disabled],input[type='button'][disabled],input[type='reset'][disabled],input[type='submit'][disabled]{cursor:default;opacity:.5}.button[disabled]:focus,.button[disabled]:hover,button[disabled]:focus,button[disabled]:hover,input[type='button'][disabled]:focus,input[type='button'][disabled]:hover,input[type='reset'][disabled]:focus,input[type='reset'][disabled]:hover,input[type='submit'][disabled]:focus,input[type='submit'][disabled]:hover{background-color:#0069d9;border-color:#0069d9}.button.button-outline,button.button-outline,input[type='button'].button-outline,input[type='reset'].button-outline,input[type='submit'].button-outline{background-color:transparent;color:#0069d9}.button.button-outline:focus,.button.button-outline:hover,button.button-outline:focus,button.button-outline:hover,input[type='button'].button-outline:focus,input[type='button'].button-outline:hover,input[type='reset'].button-outline:focus,input[type='reset'].button-outline:hover,input[type='submit'].button-outline:focus,input[type='submit'].button-outline:hover{background-color:transparent;border-color:#606c76;color:#606c76}.button.button-outline[disabled]:focus,.button.button-outline[disabled]:hover,button.button-outline[disabled]:focus,button.button-outline[disabled]:hover,input[type='button'].button-outline[disabled]:focus,input[type='button'].button-outline[disabled]:hover,input[type='reset'].button-outline[disabled]:focus,input[type='reset'].button-outline[disabled]:hover,input[type='submit'].button-outline[disabled]:focus,input[type='submit'].button-outline[disabled]:hover{border-color:inherit;color:#0069d9}.button.button-clear,button.button-clear,input[type='button'].button-clear,input[type='reset'].button-clear,input[type='submit'].button-clear{background-color:transparent;border-color:transparent;color:#0069d9}.button.button-clear:focus,.button.button-clear:hover,button.button-clear:focus,button.button-clear:hover,input[type='button'].button-clear:focus,input[type='button'].button-clear:hover,input[type='reset'].button-clear:focus,input[type='reset'].button-clear:hover,input[type='submit'].button-clear:focus,input[type='submit'].button-clear:hover{background-color:transparent;border-color:transparent;color:#606c76}.button.button-clear[disabled]:focus,.button.button-clear[disabled]:hover,button.button-clear[disabled]:focus,button.button-clear[disabled]:hover,input[type='button'].button-clear[disabled]:focus,input[type='button'].button-clear[disabled]:hover,input[type='reset'].button-clear[disabled]:focus,input[type='reset'].button-clear[disabled]:hover,input[type='submit'].button-clear[disabled]:focus,input[type='submit'].button-clear[disabled]:hover{color:#0069d9}code{background:#f4f5f6;border-radius:.4rem;font-size:86%;margin:0 .2rem;padding:.2rem .5rem;white-space:nowrap}pre{background:#f4f5f6;border-left:0.3rem solid #0069d9;overflow-y:hidden}pre>code{border-radius:0;display:block;padding:1rem 1.5rem;white-space:pre}hr{border:0;border-top:0.1rem solid #f4f5f6;margin:3.0rem 0}input[type='color'],input[type='date'],input[type='datetime'],input[type='datetime-local'],input[type='email'],input[type='month'],input[type='number'],input[type='password'],input[type='search'],input[type='tel'],input[type='text'],input[type='url'],input[type='week'],input:not([type]),textarea,select{-webkit-appearance:none;background-color:transparent;border:0.1rem solid #d1d1d1;border-radius:.4rem;box-shadow:none;box-sizing:inherit;height:3.8rem;padding:.6rem 1.0rem .7rem;width:100%}input[type='color']:focus,input[type='date']:focus,input[type='datetime']:focus,input[type='datetime-local']:focus,input[type='email']:focus,input[type='month']:focus,input[type='number']:focus,input[type='password']:focus,input[type='search']:focus,input[type='tel']:focus,input[type='text']:focus,input[type='url']:focus,input[type='week']:focus,input:not([type]):focus,textarea:focus,select:focus{border-color:#0069d9;outline:0}select{background:url('data:image/svg+xml;utf8,') center right no-repeat;padding-right:3.0rem}select:focus{background-image:url('data:image/svg+xml;utf8,')}select[multiple]{background:none;height:auto}textarea{min-height:6.5rem}label,legend{display:block;font-size:1.6rem;font-weight:700;margin-bottom:.5rem}fieldset{border-width:0;padding:0}input[type='checkbox'],input[type='radio']{display:inline}.label-inline{display:inline-block;font-weight:normal;margin-left:.5rem}.container{margin:0 auto;max-width:112.0rem;padding:0 2.0rem;position:relative;width:100%}.row{display:flex;flex-direction:column;padding:0;width:100%}.row.row-no-padding{padding:0}.row.row-no-padding>.column{padding:0}.row.row-wrap{flex-wrap:wrap}.row.row-top{align-items:flex-start}.row.row-bottom{align-items:flex-end}.row.row-center{align-items:center}.row.row-stretch{align-items:stretch}.row.row-baseline{align-items:baseline}.row .column{display:block;flex:1 1 auto;margin-left:0;max-width:100%;width:100%}.row .column.column-offset-10{margin-left:10%}.row .column.column-offset-20{margin-left:20%}.row .column.column-offset-25{margin-left:25%}.row .column.column-offset-33,.row .column.column-offset-34{margin-left:33.3333%}.row .column.column-offset-40{margin-left:40%}.row .column.column-offset-50{margin-left:50%}.row .column.column-offset-60{margin-left:60%}.row .column.column-offset-66,.row .column.column-offset-67{margin-left:66.6666%}.row .column.column-offset-75{margin-left:75%}.row .column.column-offset-80{margin-left:80%}.row .column.column-offset-90{margin-left:90%}.row .column.column-10{flex:0 0 10%;max-width:10%}.row .column.column-20{flex:0 0 20%;max-width:20%}.row .column.column-25{flex:0 0 25%;max-width:25%}.row .column.column-33,.row .column.column-34{flex:0 0 33.3333%;max-width:33.3333%}.row .column.column-40{flex:0 0 40%;max-width:40%}.row .column.column-50{flex:0 0 50%;max-width:50%}.row .column.column-60{flex:0 0 60%;max-width:60%}.row .column.column-66,.row .column.column-67{flex:0 0 66.6666%;max-width:66.6666%}.row .column.column-75{flex:0 0 75%;max-width:75%}.row .column.column-80{flex:0 0 80%;max-width:80%}.row .column.column-90{flex:0 0 90%;max-width:90%}.row .column .column-top{align-self:flex-start}.row .column .column-bottom{align-self:flex-end}.row .column .column-center{align-self:center}@media (min-width: 40rem){.row{flex-direction:row;margin-left:-1.0rem;width:calc(100% + 2.0rem)}.row .column{margin-bottom:inherit;padding:0 1.0rem}}a{color:#0069d9;text-decoration:none}a:focus,a:hover{color:#606c76}dl,ol,ul{list-style:none;margin-top:0;padding-left:0}dl dl,dl ol,dl ul,ol dl,ol ol,ol ul,ul dl,ul ol,ul ul{font-size:90%;margin:1.5rem 0 1.5rem 3.0rem}ol{list-style:decimal inside}ul{list-style:circle inside}.button,button,dd,dt,li{margin-bottom:1.0rem}fieldset,input,select,textarea{margin-bottom:1.5rem}blockquote,dl,figure,form,ol,p,pre,table,ul{margin-bottom:2.5rem}table{border-spacing:0;display:block;overflow-x:auto;text-align:left;width:100%}td,th{border-bottom:0.1rem solid #e1e1e1;padding:1.2rem 1.5rem}td:first-child,th:first-child{padding-left:0}td:last-child,th:last-child{padding-right:0}@media (min-width: 40rem){table{display:table;overflow-x:initial}}b,strong{font-weight:bold}p{margin-top:0}h1,h2,h3,h4,h5,h6{font-weight:300;letter-spacing:-.1rem;margin-bottom:2.0rem;margin-top:0}h1{font-size:4.6rem;line-height:1.2}h2{font-size:3.6rem;line-height:1.25}h3{font-size:2.8rem;line-height:1.3}h4{font-size:2.2rem;letter-spacing:-.08rem;line-height:1.35}h5{font-size:1.8rem;letter-spacing:-.05rem;line-height:1.5}h6{font-size:1.6rem;letter-spacing:0;line-height:1.4}img{max-width:100%}.clearfix:after{clear:both;content:' ';display:table}.float-left{float:left}.float-right{float:right}
+
+/* General style */
+h1{font-size: 3.6rem; line-height: 1.25}
+h2{font-size: 2.8rem; line-height: 1.3}
+h3{font-size: 2.2rem; letter-spacing: -.08rem; line-height: 1.35}
+h4{font-size: 1.8rem; letter-spacing: -.05rem; line-height: 1.5}
+h5{font-size: 1.6rem; letter-spacing: 0; line-height: 1.4}
+h6{font-size: 1.4rem; letter-spacing: 0; line-height: 1.2}
+pre{padding: 1em;}
+
+.container{
+ margin: 0 auto;
+ max-width: 80.0rem;
+ padding: 0 2.0rem;
+ position: relative;
+ width: 100%
+}
+select {
+ width: auto;
+}
+
+/* Phoenix promo and logo */
+.phx-hero {
+ text-align: center;
+ border-bottom: 1px solid #e3e3e3;
+ background: #eee;
+ border-radius: 6px;
+ padding: 3em 3em 1em;
+ margin-bottom: 3rem;
+ font-weight: 200;
+ font-size: 120%;
+}
+.phx-hero input {
+ background: #ffffff;
+}
+.phx-logo {
+ min-width: 300px;
+ margin: 1rem;
+ display: block;
+}
+.phx-logo img {
+ width: auto;
+ display: block;
+}
+
+/* Headers */
+header {
+ width: 100%;
+ background: #fdfdfd;
+ border-bottom: 1px solid #eaeaea;
+ margin-bottom: 2rem;
+}
+header section {
+ align-items: center;
+ display: flex;
+ flex-direction: column;
+ justify-content: space-between;
+}
+header section :first-child {
+ order: 2;
+}
+header section :last-child {
+ order: 1;
+}
+header nav ul,
+header nav li {
+ margin: 0;
+ padding: 0;
+ display: block;
+ text-align: right;
+ white-space: nowrap;
+}
+header nav ul {
+ margin: 1rem;
+ margin-top: 0;
+}
+header nav a {
+ display: block;
+}
+
+@media (min-width: 40.0rem) { /* Small devices (landscape phones, 576px and up) */
+ header section {
+ flex-direction: row;
+ }
+ header nav ul {
+ margin: 1rem;
+ }
+ .phx-logo {
+ flex-basis: 527px;
+ margin: 2rem 1rem;
+ }
+}
diff --git a/src/featureflagservice/assets/js/app.js b/src/featureflagservice/assets/js/app.js
new file mode 100644
index 0000000000..2ca06a5664
--- /dev/null
+++ b/src/featureflagservice/assets/js/app.js
@@ -0,0 +1,45 @@
+// We import the CSS which is extracted to its own file by esbuild.
+// Remove this line if you add a your own CSS build pipeline (e.g postcss).
+import "../css/app.css"
+
+// If you want to use Phoenix channels, run `mix help phx.gen.channel`
+// to get started and then uncomment the line below.
+// import "./user_socket.js"
+
+// You can include dependencies in two ways.
+//
+// The simplest option is to put them in assets/vendor and
+// import them using relative paths:
+//
+// import "../vendor/some-package.js"
+//
+// Alternatively, you can `npm install some-package --prefix assets` and import
+// them using a path starting with the package name:
+//
+// import "some-package"
+//
+
+// Include phoenix_html to handle method=PUT/DELETE in forms and buttons.
+import "phoenix_html"
+// Establish Phoenix Socket and LiveView configuration.
+import {Socket} from "phoenix"
+import {LiveSocket} from "phoenix_live_view"
+import topbar from "../vendor/topbar"
+
+let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
+let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}})
+
+// Show progress bar on live navigation and form submits
+topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
+window.addEventListener("phx:page-loading-start", info => topbar.show())
+window.addEventListener("phx:page-loading-stop", info => topbar.hide())
+
+// connect if there are any LiveViews on the page
+liveSocket.connect()
+
+// expose liveSocket on window for web console debug logs and latency simulation:
+// >> liveSocket.enableDebug()
+// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
+// >> liveSocket.disableLatencySim()
+window.liveSocket = liveSocket
+
diff --git a/src/featureflagservice/config/config.exs b/src/featureflagservice/config/config.exs
new file mode 100644
index 0000000000..24a34818ca
--- /dev/null
+++ b/src/featureflagservice/config/config.exs
@@ -0,0 +1,55 @@
+# This file is responsible for configuring your application
+# and its dependencies with the aid of the Config module.
+#
+# This configuration file is loaded before any dependency and
+# is restricted to this project.
+
+# General application configuration
+import Config
+
+config :featureflagservice,
+ ecto_repos: [Featureflagservice.Repo]
+
+# Configures the endpoint
+config :featureflagservice, FeatureflagserviceWeb.Endpoint,
+ url: [host: "localhost"],
+ render_errors: [view: FeatureflagserviceWeb.ErrorView, accepts: ~w(html json), layout: false],
+ pubsub_server: Featureflagservice.PubSub,
+ live_view: [signing_salt: "T88WPl/Q"]
+
+# Configures the mailer
+#
+# By default it uses the "Local" adapter which stores the emails
+# locally. You can see the emails in your browser, at "/dev/mailbox".
+#
+# For production it's recommended to configure a different adapter
+# at the `config/runtime.exs`.
+config :featureflagservice, Featureflagservice.Mailer, adapter: Swoosh.Adapters.Local
+
+# Swoosh API client is needed for adapters other than SMTP.
+config :swoosh, :api_client, false
+
+# Configure esbuild (the version is required)
+config :esbuild,
+ version: "0.14.29",
+ default: [
+ args:
+ ~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*),
+ cd: Path.expand("../assets", __DIR__),
+ env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
+ ]
+
+# Configures Elixir's Logger
+config :logger, :console,
+ format: "$time $metadata[$level] $message\n",
+ metadata: [:request_id]
+
+config :logger,
+ level: :debug
+
+# Use Jason for JSON parsing in Phoenix
+config :phoenix, :json_library, Jason
+
+# Import environment specific config. This must remain at the bottom
+# of this file so it overrides the configuration defined above.
+import_config "#{config_env()}.exs"
diff --git a/src/featureflagservice/config/dev.exs b/src/featureflagservice/config/dev.exs
new file mode 100644
index 0000000000..6312e977fa
--- /dev/null
+++ b/src/featureflagservice/config/dev.exs
@@ -0,0 +1,76 @@
+import Config
+
+# Configure your database
+config :featureflagservice, Featureflagservice.Repo,
+ username: "postgres",
+ password: "postgres",
+ hostname: "localhost",
+ database: "featureflagservice_dev",
+ stacktrace: true,
+ show_sensitive_data_on_connection_error: true,
+ pool_size: 10
+
+# For development, we disable any cache and enable
+# debugging and code reloading.
+#
+# The watchers configuration can be used to run external
+# watchers to your application. For example, we use it
+# with esbuild to bundle .js and .css sources.
+config :featureflagservice, FeatureflagserviceWeb.Endpoint,
+ # Binding to loopback ipv4 address prevents access from other machines.
+ # Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
+ http: [ip: {127, 0, 0, 1}, port: 4000],
+ check_origin: false,
+ code_reloader: true,
+ debug_errors: true,
+ secret_key_base: "GH1AJrEOJEVmzyUE+5kgz2cfBEOg5qPBlTYVive++6s/QS0BE3xjNoRCd7xI3zSv",
+ watchers: [
+ # Start the esbuild watcher by calling Esbuild.install_and_run(:default, args)
+ esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]}
+ ]
+
+# ## SSL Support
+#
+# In order to use HTTPS in development, a self-signed
+# certificate can be generated by running the following
+# Mix task:
+#
+# mix phx.gen.cert
+#
+# Note that this task requires Erlang/OTP 20 or later.
+# Run `mix help phx.gen.cert` for more information.
+#
+# The `http:` config above can be replaced with:
+#
+# https: [
+# port: 4001,
+# cipher_suite: :strong,
+# keyfile: "priv/cert/selfsigned_key.pem",
+# certfile: "priv/cert/selfsigned.pem"
+# ],
+#
+# If desired, both `http:` and `https:` keys can be
+# configured to run both http and https servers on
+# different ports.
+
+# Watch static and templates for browser reloading.
+config :featureflagservice, FeatureflagserviceWeb.Endpoint,
+ live_reload: [
+ patterns: [
+ ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
+ ~r"priv/gettext/.*(po)$",
+ ~r"lib/featureflagservice_web/(live|views)/.*(ex)$",
+ ~r"lib/featureflagservice_web/templates/.*(eex)$"
+ ]
+ ]
+
+# Do not include metadata nor timestamps in development logs
+config :logger, :console, format: "[$level] $message\n"
+config :logger, level: :debug
+
+# Set a higher stacktrace during development. Avoid configuring such
+# in production as building large stacktraces may be expensive.
+config :phoenix, :stacktrace_depth, 20
+
+# Initialize plugs at runtime for faster development compilation
+config :phoenix, :plug_init_mode, :runtime
diff --git a/src/featureflagservice/config/prod.exs b/src/featureflagservice/config/prod.exs
new file mode 100644
index 0000000000..b14f480d67
--- /dev/null
+++ b/src/featureflagservice/config/prod.exs
@@ -0,0 +1,49 @@
+import Config
+
+# For production, don't forget to configure the url host
+# to something meaningful, Phoenix uses this information
+# when generating URLs.
+#
+# Note we also include the path to a cache manifest
+# containing the digested version of static files. This
+# manifest is generated by the `mix phx.digest` task,
+# which you should run after static files are built and
+# before starting your production server.
+config :featureflagservice, FeatureflagserviceWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json"
+
+# Do not print debug messages in production
+config :logger, level: :info
+
+# ## SSL Support
+#
+# To get SSL working, you will need to add the `https` key
+# to the previous section and set your `:url` port to 443:
+#
+# config :featureflagservice, FeatureflagserviceWeb.Endpoint,
+# ...,
+# url: [host: "example.com", port: 443],
+# https: [
+# ...,
+# port: 443,
+# cipher_suite: :strong,
+# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
+# certfile: System.get_env("SOME_APP_SSL_CERT_PATH")
+# ]
+#
+# The `cipher_suite` is set to `:strong` to support only the
+# latest and more secure SSL ciphers. This means old browsers
+# and clients may not be supported. You can set it to
+# `:compatible` for wider support.
+#
+# `:keyfile` and `:certfile` expect an absolute path to the key
+# and cert in disk or a relative path inside priv, for example
+# "priv/ssl/server.key". For all supported SSL configuration
+# options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
+#
+# We also recommend setting `force_ssl` in your endpoint, ensuring
+# no data is ever sent via http, always redirecting to https:
+#
+# config :featureflagservice, FeatureflagserviceWeb.Endpoint,
+# force_ssl: [hsts: true]
+#
+# Check `Plug.SSL` for all available options in `force_ssl`.
diff --git a/src/featureflagservice/config/runtime.exs b/src/featureflagservice/config/runtime.exs
new file mode 100644
index 0000000000..407ab5e01b
--- /dev/null
+++ b/src/featureflagservice/config/runtime.exs
@@ -0,0 +1,61 @@
+import Config
+
+if System.get_env("PHX_SERVER") do
+ config :featureflagservice, FeatureflagserviceWeb.Endpoint, server: true
+end
+
+grpc_port = String.to_integer(System.get_env("GRPC_PORT") || "4001")
+
+config :grpcbox,
+ servers: [%{:grpc_opts => %{:service_protos => [:ffs_featureflag_pb],
+ :unary_interceptor => {:otel_grpcbox_interceptor, :unary},
+ :services => %{:FeatureFlagService => :ffs_service}},
+ :listen_opts => %{:port => grpc_port}}]
+
+if config_env() == :prod do
+ config :opentelemetry_exporter,
+ otlp_endpoint: "http://otelcol:4317",
+ otlp_protocol: :grpc
+
+ database_url =
+ System.get_env("DATABASE_URL") ||
+ raise """
+ environment variable DATABASE_URL is missing.
+ For example: ecto://USER:PASS@HOST/DATABASE
+ """
+
+ maybe_ipv6 = if System.get_env("ECTO_IPV6"), do: [:inet6], else: []
+
+ config :featureflagservice, Featureflagservice.Repo,
+ # ssl: true,
+ url: database_url,
+ pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
+ socket_options: maybe_ipv6
+
+ # The secret key base is used to sign/encrypt cookies and other secrets.
+ # A default value is used in config/dev.exs and config/test.exs but you
+ # want to use a different value for prod and you most likely don't want
+ # to check this value into version control, so we use an environment
+ # variable instead.
+ secret_key_base =
+ System.get_env("SECRET_KEY_BASE") ||
+ raise """
+ environment variable SECRET_KEY_BASE is missing.
+ You can generate one by calling: mix phx.gen.secret
+ """
+
+ host = System.get_env("PHX_HOST") || "localhost"
+ port = String.to_integer(System.get_env("PORT") || "4000")
+
+ config :featureflagservice, FeatureflagserviceWeb.Endpoint,
+ url: [host: host, port: 443, scheme: "https"],
+ http: [
+ # Enable IPv6 and bind on all interfaces.
+ # Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
+ # See the documentation on https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html
+ # for details about using IPv6 vs IPv4 and loopback vs public addresses.
+ ip: {0, 0, 0, 0, 0, 0, 0, 0},
+ port: port
+ ],
+ secret_key_base: secret_key_base
+end
diff --git a/src/featureflagservice/config/test.exs b/src/featureflagservice/config/test.exs
new file mode 100644
index 0000000000..73df68955f
--- /dev/null
+++ b/src/featureflagservice/config/test.exs
@@ -0,0 +1,30 @@
+import Config
+
+# Configure your database
+#
+# The MIX_TEST_PARTITION environment variable can be used
+# to provide built-in test partitioning in CI environment.
+# Run `mix help test` for more information.
+config :featureflagservice, Featureflagservice.Repo,
+ username: "postgres",
+ password: "postgres",
+ hostname: "localhost",
+ database: "featureflagservice_test#{System.get_env("MIX_TEST_PARTITION")}",
+ pool: Ecto.Adapters.SQL.Sandbox,
+ pool_size: 10
+
+# We don't run a server during test. If one is required,
+# you can enable the server option below.
+config :featureflagservice, FeatureflagserviceWeb.Endpoint,
+ http: [ip: {127, 0, 0, 1}, port: 4002],
+ secret_key_base: "HcCBiW6WwFO9llsQig9V6rxpIwlHoKC722YEs/ANSl+w6uJG1aAbeSZOcR/3sA57",
+ server: false
+
+# In test we don't send emails.
+config :featureflagservice, Featureflagservice.Mailer, adapter: Swoosh.Adapters.Test
+
+# Print only warnings and errors during test
+config :logger, level: :warn
+
+# Initialize plugs at runtime for faster test compilation
+config :phoenix, :plug_init_mode, :runtime
diff --git a/src/featureflagservice/docker-compose.yml b/src/featureflagservice/docker-compose.yml
new file mode 100644
index 0000000000..15909dd201
--- /dev/null
+++ b/src/featureflagservice/docker-compose.yml
@@ -0,0 +1,13 @@
+version: '3.7'
+
+services:
+ postgres:
+ image: cimg/postgres:14.2
+ environment:
+ - POSTGRES_USER=postgres
+ - POSTGRES_DB=featureflagservice_dev
+ - POSTGRES_PASSWORD=postgres
+ - POSTGRES_HOST_AUTH_METHOD=scram-sha-256
+ ports:
+ - 5432:5432
+
diff --git a/src/featureflagservice/lib/featureflagservice.ex b/src/featureflagservice/lib/featureflagservice.ex
new file mode 100644
index 0000000000..971a698267
--- /dev/null
+++ b/src/featureflagservice/lib/featureflagservice.ex
@@ -0,0 +1,9 @@
+defmodule Featureflagservice do
+ @moduledoc """
+ Featureflagservice keeps the contexts that define your domain
+ and business logic.
+
+ Contexts are also responsible for managing your data, regardless
+ if it comes from the database, an external API or others.
+ """
+end
diff --git a/src/featureflagservice/lib/featureflagservice/application.ex b/src/featureflagservice/lib/featureflagservice/application.ex
new file mode 100644
index 0000000000..24417f1ab7
--- /dev/null
+++ b/src/featureflagservice/lib/featureflagservice/application.ex
@@ -0,0 +1,39 @@
+defmodule Featureflagservice.Application do
+ # See https://hexdocs.pm/elixir/Application.html
+ # for more information on OTP Applications
+ @moduledoc false
+
+ use Application
+
+ @impl true
+ def start(_type, _args) do
+ OpentelemetryEcto.setup([:featureflagservice, :repo])
+ OpentelemetryPhoenix.setup()
+
+ children = [
+ # Start the Ecto repository
+ Featureflagservice.Repo,
+ # Start the Telemetry supervisor
+ FeatureflagserviceWeb.Telemetry,
+ # Start the PubSub system
+ {Phoenix.PubSub, name: Featureflagservice.PubSub},
+ # Start the Endpoint (http/https)
+ FeatureflagserviceWeb.Endpoint
+ # Start a worker by calling: Featureflagservice.Worker.start_link(arg)
+ # {Featureflagservice.Worker, arg}
+ ]
+
+ # See https://hexdocs.pm/elixir/Supervisor.html
+ # for other strategies and supported options
+ opts = [strategy: :one_for_one, name: Featureflagservice.Supervisor]
+ Supervisor.start_link(children, opts)
+ end
+
+ # Tell Phoenix to update the endpoint configuration
+ # whenever the application is updated.
+ @impl true
+ def config_change(changed, _new, removed) do
+ FeatureflagserviceWeb.Endpoint.config_change(changed, removed)
+ :ok
+ end
+end
diff --git a/src/featureflagservice/lib/featureflagservice/feature_flags.ex b/src/featureflagservice/lib/featureflagservice/feature_flags.ex
new file mode 100644
index 0000000000..827682e565
--- /dev/null
+++ b/src/featureflagservice/lib/featureflagservice/feature_flags.ex
@@ -0,0 +1,118 @@
+defmodule Featureflagservice.FeatureFlags do
+ @moduledoc """
+ The FeatureFlags context.
+ """
+
+ import Ecto.Query, warn: false
+ alias Featureflagservice.Repo
+
+ alias Featureflagservice.FeatureFlags.FeatureFlag
+
+ @doc """
+ Returns the list of featureflags.
+
+ ## Examples
+
+ iex> list_featureflags()
+ [%FeatureFlag{}, ...]
+
+ """
+ def list_featureflags do
+ Repo.all(FeatureFlag)
+ end
+
+ @doc """
+ Gets a single feature_flag.
+
+ Raises `Ecto.NoResultsError` if the Feature flag does not exist.
+
+ ## Examples
+
+ iex> get_feature_flag!(123)
+ %FeatureFlag{}
+
+ iex> get_feature_flag!(456)
+ ** (Ecto.NoResultsError)
+
+ """
+ def get_feature_flag!(id), do: Repo.get!(FeatureFlag, id)
+
+ @doc """
+ Gets a single feature_flag by name.
+
+ ## Examples
+
+ iex> get_feature_flag_by_name("feature-1")
+ %FeatureFlag{}
+
+ iex> get_feature_flag_by_name("not-a-feature-flag")
+ nil
+
+ """
+ def get_feature_flag_by_name(name), do: Repo.get_by(FeatureFlag, name: name)
+
+ @doc """
+ Creates a feature_flag.
+
+ ## Examples
+
+ iex> create_feature_flag(%{field: value})
+ {:ok, %FeatureFlag{}}
+
+ iex> create_feature_flag(%{field: bad_value})
+ {:error, %Ecto.Changeset{}}
+
+ """
+ def create_feature_flag(attrs \\ %{}) do
+ %FeatureFlag{}
+ |> FeatureFlag.changeset(attrs)
+ |> Repo.insert()
+ end
+
+ @doc """
+ Updates a feature_flag.
+
+ ## Examples
+
+ iex> update_feature_flag(feature_flag, %{field: new_value})
+ {:ok, %FeatureFlag{}}
+
+ iex> update_feature_flag(feature_flag, %{field: bad_value})
+ {:error, %Ecto.Changeset{}}
+
+ """
+ def update_feature_flag(%FeatureFlag{} = feature_flag, attrs) do
+ feature_flag
+ |> FeatureFlag.changeset(attrs)
+ |> Repo.update()
+ end
+
+ @doc """
+ Deletes a feature_flag.
+
+ ## Examples
+
+ iex> delete_feature_flag(feature_flag)
+ {:ok, %FeatureFlag{}}
+
+ iex> delete_feature_flag(feature_flag)
+ {:error, %Ecto.Changeset{}}
+
+ """
+ def delete_feature_flag(%FeatureFlag{} = feature_flag) do
+ Repo.delete(feature_flag)
+ end
+
+ @doc """
+ Returns an `%Ecto.Changeset{}` for tracking feature_flag changes.
+
+ ## Examples
+
+ iex> change_feature_flag(feature_flag)
+ %Ecto.Changeset{data: %FeatureFlag{}}
+
+ """
+ def change_feature_flag(%FeatureFlag{} = feature_flag, attrs \\ %{}) do
+ FeatureFlag.changeset(feature_flag, attrs)
+ end
+end
diff --git a/src/featureflagservice/lib/featureflagservice/feature_flags/feature_flag.ex b/src/featureflagservice/lib/featureflagservice/feature_flags/feature_flag.ex
new file mode 100644
index 0000000000..29ab530163
--- /dev/null
+++ b/src/featureflagservice/lib/featureflagservice/feature_flags/feature_flag.ex
@@ -0,0 +1,20 @@
+defmodule Featureflagservice.FeatureFlags.FeatureFlag do
+ use Ecto.Schema
+ import Ecto.Changeset
+
+ schema "featureflags" do
+ field :description, :string
+ field :enabled, :boolean, default: false
+ field :name, :string
+
+ timestamps()
+ end
+
+ @doc false
+ def changeset(feature_flag, attrs) do
+ feature_flag
+ |> cast(attrs, [:name, :description, :enabled])
+ |> validate_required([:name, :description, :enabled])
+ |> unique_constraint(:name)
+ end
+end
diff --git a/src/featureflagservice/lib/featureflagservice/mailer.ex b/src/featureflagservice/lib/featureflagservice/mailer.ex
new file mode 100644
index 0000000000..51e635fabc
--- /dev/null
+++ b/src/featureflagservice/lib/featureflagservice/mailer.ex
@@ -0,0 +1,3 @@
+defmodule Featureflagservice.Mailer do
+ use Swoosh.Mailer, otp_app: :featureflagservice
+end
diff --git a/src/featureflagservice/lib/featureflagservice/release.ex b/src/featureflagservice/lib/featureflagservice/release.ex
new file mode 100644
index 0000000000..9adad2960e
--- /dev/null
+++ b/src/featureflagservice/lib/featureflagservice/release.ex
@@ -0,0 +1,28 @@
+defmodule Featureflagservice.Release do
+ @moduledoc """
+ Used for executing DB release tasks when run in production without Mix
+ installed.
+ """
+ @app :featureflagservice
+
+ def migrate do
+ load_app()
+
+ for repo <- repos() do
+ {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
+ end
+ end
+
+ def rollback(repo, version) do
+ load_app()
+ {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
+ end
+
+ defp repos do
+ Application.fetch_env!(@app, :ecto_repos)
+ end
+
+ defp load_app do
+ Application.load(@app)
+ end
+end
diff --git a/src/featureflagservice/lib/featureflagservice/repo.ex b/src/featureflagservice/lib/featureflagservice/repo.ex
new file mode 100644
index 0000000000..b18e85d08e
--- /dev/null
+++ b/src/featureflagservice/lib/featureflagservice/repo.ex
@@ -0,0 +1,5 @@
+defmodule Featureflagservice.Repo do
+ use Ecto.Repo,
+ otp_app: :featureflagservice,
+ adapter: Ecto.Adapters.Postgres
+end
diff --git a/src/featureflagservice/lib/featureflagservice_web.ex b/src/featureflagservice/lib/featureflagservice_web.ex
new file mode 100644
index 0000000000..c2ad9a8ca2
--- /dev/null
+++ b/src/featureflagservice/lib/featureflagservice_web.ex
@@ -0,0 +1,110 @@
+defmodule FeatureflagserviceWeb do
+ @moduledoc """
+ The entrypoint for defining your web interface, such
+ as controllers, views, channels and so on.
+
+ This can be used in your application as:
+
+ use FeatureflagserviceWeb, :controller
+ use FeatureflagserviceWeb, :view
+
+ The definitions below will be executed for every view,
+ controller, etc, so keep them short and clean, focused
+ on imports, uses and aliases.
+
+ Do NOT define functions inside the quoted expressions
+ below. Instead, define any helper function in modules
+ and import those modules here.
+ """
+
+ def controller do
+ quote do
+ use Phoenix.Controller, namespace: FeatureflagserviceWeb
+
+ import Plug.Conn
+ import FeatureflagserviceWeb.Gettext
+ alias FeatureflagserviceWeb.Router.Helpers, as: Routes
+ end
+ end
+
+ def view do
+ quote do
+ use Phoenix.View,
+ root: "lib/featureflagservice_web/templates",
+ namespace: FeatureflagserviceWeb
+
+ # Import convenience functions from controllers
+ import Phoenix.Controller,
+ only: [get_flash: 1, get_flash: 2, view_module: 1, view_template: 1]
+
+ # Include shared imports and aliases for views
+ unquote(view_helpers())
+ end
+ end
+
+ def live_view do
+ quote do
+ use Phoenix.LiveView,
+ layout: {FeatureflagserviceWeb.LayoutView, "live.html"}
+
+ unquote(view_helpers())
+ end
+ end
+
+ def live_component do
+ quote do
+ use Phoenix.LiveComponent
+
+ unquote(view_helpers())
+ end
+ end
+
+ def component do
+ quote do
+ use Phoenix.Component
+
+ unquote(view_helpers())
+ end
+ end
+
+ def router do
+ quote do
+ use Phoenix.Router
+
+ import Plug.Conn
+ import Phoenix.Controller
+ import Phoenix.LiveView.Router
+ end
+ end
+
+ def channel do
+ quote do
+ use Phoenix.Channel
+ import FeatureflagserviceWeb.Gettext
+ end
+ end
+
+ defp view_helpers do
+ quote do
+ # Use all HTML functionality (forms, tags, etc)
+ use Phoenix.HTML
+
+ # Import LiveView and .heex helpers (live_render, live_patch, <.form>, etc)
+ import Phoenix.LiveView.Helpers
+
+ # Import basic rendering functionality (render, render_layout, etc)
+ import Phoenix.View
+
+ import FeatureflagserviceWeb.ErrorHelpers
+ import FeatureflagserviceWeb.Gettext
+ alias FeatureflagserviceWeb.Router.Helpers, as: Routes
+ end
+ end
+
+ @doc """
+ When used, dispatch to the appropriate controller/view/etc.
+ """
+ defmacro __using__(which) when is_atom(which) do
+ apply(__MODULE__, which, [])
+ end
+end
diff --git a/src/featureflagservice/lib/featureflagservice_web/controllers/feature_flag_controller.ex b/src/featureflagservice/lib/featureflagservice_web/controllers/feature_flag_controller.ex
new file mode 100644
index 0000000000..b0fbe40c0a
--- /dev/null
+++ b/src/featureflagservice/lib/featureflagservice_web/controllers/feature_flag_controller.ex
@@ -0,0 +1,62 @@
+defmodule FeatureflagserviceWeb.FeatureFlagController do
+ use FeatureflagserviceWeb, :controller
+
+ alias Featureflagservice.FeatureFlags
+ alias Featureflagservice.FeatureFlags.FeatureFlag
+
+ def index(conn, _params) do
+ featureflags = FeatureFlags.list_featureflags()
+ render(conn, "index.html", featureflags: featureflags)
+ end
+
+ def new(conn, _params) do
+ changeset = FeatureFlags.change_feature_flag(%FeatureFlag{})
+ render(conn, "new.html", changeset: changeset)
+ end
+
+ def create(conn, %{"feature_flag" => feature_flag_params}) do
+ case FeatureFlags.create_feature_flag(feature_flag_params) do
+ {:ok, feature_flag} ->
+ conn
+ |> put_flash(:info, "Feature flag created successfully.")
+ |> redirect(to: Routes.feature_flag_path(conn, :show, feature_flag))
+
+ {:error, %Ecto.Changeset{} = changeset} ->
+ render(conn, "new.html", changeset: changeset)
+ end
+ end
+
+ def show(conn, %{"id" => id}) do
+ feature_flag = FeatureFlags.get_feature_flag!(id)
+ render(conn, "show.html", feature_flag: feature_flag)
+ end
+
+ def edit(conn, %{"id" => id}) do
+ feature_flag = FeatureFlags.get_feature_flag!(id)
+ changeset = FeatureFlags.change_feature_flag(feature_flag)
+ render(conn, "edit.html", feature_flag: feature_flag, changeset: changeset)
+ end
+
+ def update(conn, %{"id" => id, "feature_flag" => feature_flag_params}) do
+ feature_flag = FeatureFlags.get_feature_flag!(id)
+
+ case FeatureFlags.update_feature_flag(feature_flag, feature_flag_params) do
+ {:ok, feature_flag} ->
+ conn
+ |> put_flash(:info, "Feature flag updated successfully.")
+ |> redirect(to: Routes.feature_flag_path(conn, :show, feature_flag))
+
+ {:error, %Ecto.Changeset{} = changeset} ->
+ render(conn, "edit.html", feature_flag: feature_flag, changeset: changeset)
+ end
+ end
+
+ def delete(conn, %{"id" => id}) do
+ feature_flag = FeatureFlags.get_feature_flag!(id)
+ {:ok, _feature_flag} = FeatureFlags.delete_feature_flag(feature_flag)
+
+ conn
+ |> put_flash(:info, "Feature flag deleted successfully.")
+ |> redirect(to: Routes.feature_flag_path(conn, :index))
+ end
+end
diff --git a/src/featureflagservice/lib/featureflagservice_web/controllers/page_controller.ex b/src/featureflagservice/lib/featureflagservice_web/controllers/page_controller.ex
new file mode 100644
index 0000000000..1d8dd37650
--- /dev/null
+++ b/src/featureflagservice/lib/featureflagservice_web/controllers/page_controller.ex
@@ -0,0 +1,11 @@
+defmodule FeatureflagserviceWeb.PageController do
+ use FeatureflagserviceWeb, :controller
+
+ alias Featureflagservice.FeatureFlags
+ alias Featureflagservice.FeatureFlags.FeatureFlag
+
+ def index(conn, _params) do
+ featureflags = FeatureFlags.list_featureflags()
+ render(conn, "index.html", featureflags: featureflags)
+ end
+end
diff --git a/src/featureflagservice/lib/featureflagservice_web/endpoint.ex b/src/featureflagservice/lib/featureflagservice_web/endpoint.ex
new file mode 100644
index 0000000000..57413f9747
--- /dev/null
+++ b/src/featureflagservice/lib/featureflagservice_web/endpoint.ex
@@ -0,0 +1,50 @@
+defmodule FeatureflagserviceWeb.Endpoint do
+ use Phoenix.Endpoint, otp_app: :featureflagservice
+
+ # The session will be stored in the cookie and signed,
+ # this means its contents can be read but not tampered with.
+ # Set :encryption_salt if you would also like to encrypt it.
+ @session_options [
+ store: :cookie,
+ key: "_featureflagservice_key",
+ signing_salt: "B7PAq71f"
+ ]
+
+ socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]]
+
+ # Serve at "/" the static files from "priv/static" directory.
+ #
+ # You should set gzip to true if you are running phx.digest
+ # when deploying your static files in production.
+ plug Plug.Static,
+ at: "/",
+ from: :featureflagservice,
+ gzip: false,
+ only: ~w(assets fonts images favicon.ico robots.txt)
+
+ # Code reloading can be explicitly enabled under the
+ # :code_reloader configuration of your endpoint.
+ if code_reloading? do
+ socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
+ plug Phoenix.LiveReloader
+ plug Phoenix.CodeReloader
+ plug Phoenix.Ecto.CheckRepoStatus, otp_app: :featureflagservice
+ end
+
+ plug Phoenix.LiveDashboard.RequestLogger,
+ param_key: "request_logger",
+ cookie_key: "request_logger"
+
+ plug Plug.RequestId
+ plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]
+
+ plug Plug.Parsers,
+ parsers: [:urlencoded, :multipart, :json],
+ pass: ["*/*"],
+ json_decoder: Phoenix.json_library()
+
+ plug Plug.MethodOverride
+ plug Plug.Head
+ plug Plug.Session, @session_options
+ plug FeatureflagserviceWeb.Router
+end
diff --git a/src/featureflagservice/lib/featureflagservice_web/gettext.ex b/src/featureflagservice/lib/featureflagservice_web/gettext.ex
new file mode 100644
index 0000000000..4e8f23c287
--- /dev/null
+++ b/src/featureflagservice/lib/featureflagservice_web/gettext.ex
@@ -0,0 +1,24 @@
+defmodule FeatureflagserviceWeb.Gettext do
+ @moduledoc """
+ A module providing Internationalization with a gettext-based API.
+
+ By using [Gettext](https://hexdocs.pm/gettext),
+ your module gains a set of macros for translations, for example:
+
+ import FeatureflagserviceWeb.Gettext
+
+ # Simple translation
+ gettext("Here is the string to translate")
+
+ # Plural translation
+ ngettext("Here is the string to translate",
+ "Here are the strings to translate",
+ 3)
+
+ # Domain-based translation
+ dgettext("errors", "Here is the error message to translate")
+
+ See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage.
+ """
+ use Gettext, otp_app: :featureflagservice
+end
diff --git a/src/featureflagservice/lib/featureflagservice_web/router.ex b/src/featureflagservice/lib/featureflagservice_web/router.ex
new file mode 100644
index 0000000000..5ba5b70c8b
--- /dev/null
+++ b/src/featureflagservice/lib/featureflagservice_web/router.ex
@@ -0,0 +1,57 @@
+defmodule FeatureflagserviceWeb.Router do
+ use FeatureflagserviceWeb, :router
+
+ pipeline :browser do
+ plug :accepts, ["html"]
+ plug :fetch_session
+ plug :fetch_live_flash
+ plug :put_root_layout, {FeatureflagserviceWeb.LayoutView, :root}
+ plug :protect_from_forgery
+ plug :put_secure_browser_headers
+ end
+
+ pipeline :api do
+ plug :accepts, ["json"]
+ end
+
+ scope "/", FeatureflagserviceWeb do
+ pipe_through :browser
+
+ get "/", PageController, :index
+ resources "/featureflags", FeatureFlagController
+ end
+
+ # Other scopes may use custom stacks.
+ # scope "/api", FeatureflagserviceWeb do
+ # pipe_through :api
+ # end
+
+ # Enables LiveDashboard only for development
+ #
+ # If you want to use the LiveDashboard in production, you should put
+ # it behind authentication and allow only admins to access it.
+ # If your application does not have an admins-only section yet,
+ # you can use Plug.BasicAuth to set up some basic authentication
+ # as long as you are also using SSL (which you should anyway).
+ if Mix.env() in [:dev, :test] do
+ import Phoenix.LiveDashboard.Router
+
+ scope "/" do
+ pipe_through :browser
+
+ live_dashboard "/dashboard", metrics: FeatureflagserviceWeb.Telemetry
+ end
+ end
+
+ # Enables the Swoosh mailbox preview in development.
+ #
+ # Note that preview only shows emails that were sent by the same
+ # node running the Phoenix server.
+ if Mix.env() == :dev do
+ scope "/dev" do
+ pipe_through :browser
+
+ forward "/mailbox", Plug.Swoosh.MailboxPreview
+ end
+ end
+end
diff --git a/src/featureflagservice/lib/featureflagservice_web/telemetry.ex b/src/featureflagservice/lib/featureflagservice_web/telemetry.ex
new file mode 100644
index 0000000000..c9e4298d3a
--- /dev/null
+++ b/src/featureflagservice/lib/featureflagservice_web/telemetry.ex
@@ -0,0 +1,71 @@
+defmodule FeatureflagserviceWeb.Telemetry do
+ use Supervisor
+ import Telemetry.Metrics
+
+ def start_link(arg) do
+ Supervisor.start_link(__MODULE__, arg, name: __MODULE__)
+ end
+
+ @impl true
+ def init(_arg) do
+ children = [
+ # Telemetry poller will execute the given period measurements
+ # every 10_000ms. Learn more here: https://hexdocs.pm/telemetry_metrics
+ {:telemetry_poller, measurements: periodic_measurements(), period: 10_000}
+ # Add reporters as children of your supervision tree.
+ # {Telemetry.Metrics.ConsoleReporter, metrics: metrics()}
+ ]
+
+ Supervisor.init(children, strategy: :one_for_one)
+ end
+
+ def metrics do
+ [
+ # Phoenix Metrics
+ summary("phoenix.endpoint.stop.duration",
+ unit: {:native, :millisecond}
+ ),
+ summary("phoenix.router_dispatch.stop.duration",
+ tags: [:route],
+ unit: {:native, :millisecond}
+ ),
+
+ # Database Metrics
+ summary("featureflagservice.repo.query.total_time",
+ unit: {:native, :millisecond},
+ description: "The sum of the other measurements"
+ ),
+ summary("featureflagservice.repo.query.decode_time",
+ unit: {:native, :millisecond},
+ description: "The time spent decoding the data received from the database"
+ ),
+ summary("featureflagservice.repo.query.query_time",
+ unit: {:native, :millisecond},
+ description: "The time spent executing the query"
+ ),
+ summary("featureflagservice.repo.query.queue_time",
+ unit: {:native, :millisecond},
+ description: "The time spent waiting for a database connection"
+ ),
+ summary("featureflagservice.repo.query.idle_time",
+ unit: {:native, :millisecond},
+ description:
+ "The time the connection spent waiting before being checked out for the query"
+ ),
+
+ # VM Metrics
+ summary("vm.memory.total", unit: {:byte, :kilobyte}),
+ summary("vm.total_run_queue_lengths.total"),
+ summary("vm.total_run_queue_lengths.cpu"),
+ summary("vm.total_run_queue_lengths.io")
+ ]
+ end
+
+ defp periodic_measurements do
+ [
+ # A module, function and arguments to be invoked periodically.
+ # This function must call :telemetry.execute/3 and a metric must be added above.
+ # {FeatureflagserviceWeb, :count_users, []}
+ ]
+ end
+end
diff --git a/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/edit.html.heex b/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/edit.html.heex
new file mode 100644
index 0000000000..c8f96e7140
--- /dev/null
+++ b/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/edit.html.heex
@@ -0,0 +1,5 @@
+
Edit Feature flag
+
+<%= render "form.html", Map.put(assigns, :action, Routes.feature_flag_path(@conn, :update, @feature_flag)) %>
+
+<%= link "Back", to: Routes.feature_flag_path(@conn, :index) %>
diff --git a/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/form.html.heex b/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/form.html.heex
new file mode 100644
index 0000000000..81ebee96ba
--- /dev/null
+++ b/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/form.html.heex
@@ -0,0 +1,23 @@
+<.form let={f} for={@changeset} action={@action}>
+ <%= if @changeset.action do %>
+
+
Oops, something went wrong! Please check the errors below.
+
diff --git a/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/index.html.heex b/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/index.html.heex
new file mode 100644
index 0000000000..10ab76ec53
--- /dev/null
+++ b/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/index.html.heex
@@ -0,0 +1,30 @@
+
Listing Featureflags
+
+
+
+
+
Name
+
Description
+
Enabled
+
+
+
+
+
+<%= for feature_flag <- @featureflags do %>
+
+
<%= feature_flag.name %>
+
<%= feature_flag.description %>
+
<%= feature_flag.enabled %>
+
+
+ <%= link "Show", to: Routes.feature_flag_path(@conn, :show, feature_flag) %>
+ <%= link "Edit", to: Routes.feature_flag_path(@conn, :edit, feature_flag) %>
+ <%= link "Delete", to: Routes.feature_flag_path(@conn, :delete, feature_flag), method: :delete, data: [confirm: "Are you sure?"] %>
+
+
+<% end %>
+
+
+
+<%= link "New Feature flag", to: Routes.feature_flag_path(@conn, :new) %>
diff --git a/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/new.html.heex b/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/new.html.heex
new file mode 100644
index 0000000000..e95b4e0985
--- /dev/null
+++ b/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/new.html.heex
@@ -0,0 +1,5 @@
+
New Feature flag
+
+<%= render "form.html", Map.put(assigns, :action, Routes.feature_flag_path(@conn, :create)) %>
+
+<%= link "Back", to: Routes.feature_flag_path(@conn, :index) %>
diff --git a/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/show.html.heex b/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/show.html.heex
new file mode 100644
index 0000000000..493650b5a5
--- /dev/null
+++ b/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/show.html.heex
@@ -0,0 +1,23 @@
+
+
+
+<%= for feature_flag <- @featureflags do %>
+
+
<%= feature_flag.name %>
+
<%= feature_flag.description %>
+
<%= feature_flag.enabled %>
+
+
+ <%= link "Show", to: Routes.feature_flag_path(@conn, :show, feature_flag) %>
+ <%= link "Edit", to: Routes.feature_flag_path(@conn, :edit, feature_flag) %>
+ <%= link "Delete", to: Routes.feature_flag_path(@conn, :delete, feature_flag), method: :delete, data: [confirm: "Are you sure?"] %>
+