Skip to content

Commit

Permalink
[featureflag] expose feature flag API via frontend
Browse files Browse the repository at this point in the history
Also:
* propagate the change from bool to float introduced in
  open-telemetry#1237
  more consistently via proto definitions by differentiating between
  the GetFlag operation (which evaluates the probabilty and therefore
  returns a bool) and all other operations, which need to operate with
  a float value/probability directly. To that end, the Flag grpc
  message has been split into two new types, FlagEvaluationResult
  and FlagDefinition.
* Rename the UpdateFlag operation to UpdateFlagProbability, as it
  actually only updates the enabled/probability value, but not the
  description or the name.
  • Loading branch information
basti1302 committed Jan 29, 2024
1 parent c9224a9 commit 3c7c5d7
Show file tree
Hide file tree
Showing 14 changed files with 1,369 additions and 807 deletions.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ services:
- CART_SERVICE_ADDR
- CHECKOUT_SERVICE_ADDR
- CURRENCY_SERVICE_ADDR
- FEATURE_FLAG_GRPC_SERVICE_ADDR
- PRODUCT_CATALOG_SERVICE_ADDR
- RECOMMENDATION_SERVICE_ADDR
- SHIPPING_SERVICE_ADDR
Expand Down
24 changes: 15 additions & 9 deletions pb/demo.proto
Original file line number Diff line number Diff line change
Expand Up @@ -266,46 +266,52 @@ message Ad {
service FeatureFlagService {
rpc GetFlag(GetFlagRequest) returns (GetFlagResponse) {}
rpc CreateFlag(CreateFlagRequest) returns (CreateFlagResponse) {}
rpc UpdateFlag(UpdateFlagRequest) returns (UpdateFlagResponse) {}
rpc UpdateFlagProbability(UpdateFlagProbabilityRequest) returns (UpdateFlagProbabilityResponse) {}
rpc ListFlags(ListFlagsRequest) returns (ListFlagsResponse) {}
rpc DeleteFlag(DeleteFlagRequest) returns (DeleteFlagResponse) {}
}

message Flag {
message FlagEvaluationResult {
string name = 1;
string description = 2;
bool enabled = 3;
}

message FlagDefinition {
string name = 1;
string description = 2;
float enabled = 3;
}

message GetFlagRequest {
string name = 1;
}

message GetFlagResponse {
Flag flag = 1;
FlagEvaluationResult flag = 1;
}

message CreateFlagRequest {
string name = 1;
string description = 2;
bool enabled = 3;
float enabled = 3;
}

message CreateFlagResponse {
Flag flag = 1;
FlagDefinition flag = 1;
}

message UpdateFlagRequest {
message UpdateFlagProbabilityRequest {
string name = 1;
bool enabled = 2;
float enabled = 2;
}

message UpdateFlagResponse {}
message UpdateFlagProbabilityResponse {}

message ListFlagsRequest {}

message ListFlagsResponse {
repeated Flag flag = 1;
repeated FlagDefinition flag = 1;
}

message DeleteFlagRequest {
Expand Down
92 changes: 92 additions & 0 deletions regenerate-grpc-code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/sh

set -euo pipefail

# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

# This script is used to update generated code after changing demo.proto.

cd -P -- "$(dirname -- "$0")"
pwd

command -v npm >/dev/null 2>&1 || {
cat <<EOF >&2
npm needs to be installed but it isn't.
Aborting.
EOF
exit 1
}

command -v go >/dev/null 2>&1 || {
cat <<EOF >&2
go needs to be installed but it isn't.
Aborting.
EOF
exit 1
}

command -v rebar3 >/dev/null 2>&1 || {
cat <<EOF >&2
rebar3 needs to be installed but it isn't.
Aborting.
EOF
exit 1
}


command -v protoc >/dev/null 2>&1 || {
cat <<EOF >&2
protoc needs to be installed but it isn't.
Aborting.
EOF
exit 1
}

echo "Regenerating typescript code in src/frontend based on demo.proto"
pushd src/frontend > /dev/null
# The npm script grpc:generate expects the pb directory to be available in the current directory (src/frontend) because it is
# intended to be used during Docker build, where pb is copied to the same working directory as src/frontend. To get around that
# difference, we temporarily create a symlink to pb and then remove it after the script is done.
ln -s ../../pb pb
npm run grpc:generate
rm pb
popd > /dev/null

echo "Regenerating Go code in src/accountingservice based on demo.proto"
pushd src/accountingservice > /dev/null
go generate
popd > /dev/null

echo "Regenerating Go code in src/checkoutservice based on demo.proto"
pushd src/checkoutservice > /dev/null
go generate
popd > /dev/null

echo "Regenerating Go code in src/productcatalogservice based on demo.proto"
pushd src/productcatalogservice > /dev/null
go generate
popd > /dev/null

echo "Regenerating Java code in src/adservice based on demo.proto"
pushd src/adservice > /dev/null
./gradlew generateProto
popd > /dev/null

echo "Recompiling Erlang code in src/featureflagservice based on demo.proto"
pushd src/featureflagservice > /dev/null
# The Erlang build expects the proto file to be available in src/featureflagservice/proto) because it is
# intended to be used during Docker build, where demo.proto is copied to the the proto directory in the same working directory
# as the Erlang source code. To get around that difference, we temporarily create a symlink to ../../pb as proto and then remove
# it after the script is done.
ln -s ../../pb proto
rebar3 grpc_regen
rm proto
popd > /dev/null


echo done
3 changes: 3 additions & 0 deletions restart-service.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/sh

set -euo pipefail

# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

Expand Down
Loading

0 comments on commit 3c7c5d7

Please sign in to comment.