### Start flagd with Binary Installation Source: https://github.com/open-feature/flagd/wiki/Examples-using-cURL Start the flagd service using the downloaded configuration file when installed as a binary. ```shell flagd start -f example_flags.json ``` -------------------------------- ### Example Static Context Configuration Source: https://github.com/open-feature/flagd/blob/main/docs/reference/flag-definitions.md Shows how to start flagd with static context values using the -X flag. These values are included in all evaluations. ```shell flagd start \ --uri file:./flags.json \ -X environment=production \ -X region=us-east-1 \ -X service=payment-api ``` -------------------------------- ### Start flagd with Docker Installation Source: https://github.com/open-feature/flagd/wiki/Examples-using-cURL Start the flagd service using Docker, mounting the configuration file and exposing the necessary port. ```shell docker run -p 8013:8013 -v $(pwd)/:/etc/flagd/ -it --pull=always ghcr.io/open-feature/flagd:latest start --uri file:./etc/flagd/example_flags.json ``` -------------------------------- ### Download flagd example flags locally Source: https://github.com/open-feature/flagd/blob/main/README.md Download the example flags configuration file locally using wget. This allows for local modifications before starting flagd. ```sh wget https://raw.githubusercontent.com/open-feature/flagd/main/samples/example_flags.flagd.json ``` -------------------------------- ### Source Selector Examples Source: https://github.com/open-feature/flagd/blob/main/docs/reference/selector-syntax.md Examples showing how to select flags originating from specific sources using the source key. ```text source=config/flags.json ``` ```text source=http://flag-server/config ``` ```text source=./local-flags.yaml ``` -------------------------------- ### Full Flag Configuration Example Source: https://github.com/open-feature/flagd/blob/main/docs/reference/flag-definitions.md A comprehensive example of a fully configured flag, including state, variants, defaultVariant, targeting, and metadata. ```jsonc { "$schema": "https://flagd.dev/schema/v0/flags.json", "flags": { "new-welcome-banner": { "state": "ENABLED", "variants": { "on": true, "off": false }, "defaultVariant": "off", "targeting": { "if": [ { "ends_with": [{ "var": "email" }, "@example.com"] }, "on", "off" ] }, "metadata": { "version": "17" } } }, "metadata": { "team": "user-experience", "flagSetId": "ecommerce" } } ``` -------------------------------- ### flagd SEE ALSO Source: https://github.com/open-feature/flagd/blob/main/docs/reference/flagd-cli/flagd.md Lists related flagd subcommands. Use 'flagd start' to run the agent and 'flagd version' to check the installed version. ```bash * [flagd start](flagd_start.md) - Start flagd * [flagd version](flagd_version.md) - Print the version number of flagd ``` -------------------------------- ### Starting flagd with multiple flag sources Source: https://github.com/open-feature/flagd/blob/main/docs/architecture-decisions/multiple-flag-set-support(rejected).md Demonstrates how to start the flagd service and configure it to load flag configurations from multiple sources using the `--uri` flag. ```shell flagd start \ --port 8013 \ --uri file:etc/flagd/my-flags-1.json \ --uri https://my-flags-2.com/flags ``` -------------------------------- ### Starts-With Example Flag Configuration Source: https://github.com/open-feature/flagd/blob/main/docs/reference/custom-operations/string-comparison-operation.md Example of a flag configuration using the 'starts_with' operation to determine the 'headerColor' variant. Returns 'red' if the email starts with 'user@faas', otherwise 'green'. ```json { "$schema": "https://flagd.dev/schema/v0/flags.json", "flags": { "headerColor": { "variants": { "red": "#FF0000", "blue": "#0000FF", "green": "#00FF00" }, "defaultVariant": "blue", "state": "ENABLED", "targeting": { "if": [ { "starts_with": [{"var": "email"}, "user@faas"] }, "red", "green" ] } } } } ``` -------------------------------- ### Install flagd Go Binary Source: https://github.com/open-feature/flagd/wiki/Home Install the flagd Go binary using the go install command. Requires Go version 1.18 or above. ```bash go install github.com/open-feature/flagd@latest ``` -------------------------------- ### Run flagd Playground Development Environment Source: https://github.com/open-feature/flagd/blob/main/playground-app/README.md Execute this command from the project root to start the development server for the flagd playground. Ensure Node.js version 18 or newer is installed. ```bash make playground-dev ``` -------------------------------- ### Starting flagd with multiple sync sources Source: https://github.com/open-feature/flagd/blob/main/docs/reference/sync-configuration.md Demonstrates how to start the flagd daemon with a complex configuration of multiple sync sources using command-line arguments. This includes file, HTTP, and Kubernetes providers with various authentication and configuration options. ```sh ./bin/flagd start --sources='[{"uri":"config/samples/example_flags.json","provider":"file"}, {"uri":"config/samples/example_flags.json","provider":"fsnotify"}, {"uri":"config/samples/example_flags.json","provider":"fileinfo"}, {"uri":"http://my-flag-source/flags.json","provider":"http","authHeader":"Bearer bearer-dji34ld2l"}, {"uri":"https://secure-remote/bearer-auth/flags.json","provider":"http","authHeader":"Bearer bearer-dji34ld2l"}, {"uri":"https://secure-remote/basic-auth/flags.json","provider":"http","authHeader":"Basic dXNlcjpwYXNz"}, {"uri":"default/my-flag-config","provider":"kubernetes"}, {"uri":"grpc-source:8080","provider":"grpc"}, {"uri":"my-flag-source:8080","provider":"grpc", "maxMsgSize": 5242880}, {"uri":"envoy://localhost:9211/test.service", "provider":"grpc"}, {"uri":"my-flag-source:8080","provider":"grpc", "certPath": "/certs/ca.cert", "tls": true, "providerID": "flagd-weatherapp-sidecar", "selector": "flagSetId=weatherapp"}, {"uri":"gs://my-bucket/my-flag.json","provider":"gcs"}, {"uri":"azblob://my-container/my-flag.json","provider":"azblob"}, {"uri":"s3://my-bucket/my-flag.json","provider":"s3"}]' ``` -------------------------------- ### Start flagd Service Source: https://github.com/open-feature/flagd/blob/main/README.md Instructions on how to start the flagd service using the command line or Docker, with options for specifying flag sources. ```APIDOC ## Start flagd flagd can be started using the `flagd start` command. You can specify the port and the URI for the flag source. ### Command Line ```sh flagd start \ --port 8013 \ --uri https://raw.githubusercontent.com/open-feature/flagd/main/samples/example_flags.flagd.json ``` ### Docker ```sh docker run \ --rm -it \ --name flagd \ -p 8013:8013 \ ghcr.io/open-feature/flagd:latest start \ --uri https://raw.githubusercontent.com/open-feature/flagd/main/samples/example_flags.flagd.json ``` ### Local File URI To use a local file as the flag source, prefix the file path with `file:`. ```sh flagd start \ --port 8013 \ --uri file:./example_flags.flagd.json ``` Or using Docker: ```sh docker run \ --rm -it \ --name flagd \ -p 8013:8013 \ -v $(pwd):/etc/flagd \ ghcr.io/open-feature/flagd:latest start \ --uri file:./etc/flagd/example_flags.flagd.json ``` Multiple `--uri` parameters can be specified to retrieve flags from multiple sources simultaneously. ``` -------------------------------- ### Kubernetes Sync Provider Configuration Source: https://github.com/open-feature/flagd/wiki/Options Example command to start flagd using the Kubernetes sync provider. This configuration requires specifying the sync provider and its arguments, including the FeatureFlagConfiguration resource name and namespace. ```shell flagd start --sync-provider=kubernetes --sync-provider-args=featureflagconfiguration=my-example --sync-provider-args=namespace=default ``` -------------------------------- ### flagd Start Command Help Source: https://github.com/open-feature/flagd/wiki/Options Lists all available command-line flags for starting the flagd service. These flags control various aspects of flagd's behavior, including ports, security, and sync providers. ```bash -b, --bearer-token string Set a bearer token to use for remote sync -e, --evaluator string Set an evaluator e.g. json (default "json") -h, --help help for start -p, --port int32 Port to listen on (default 8013) -m, --metrics-port int32 Port to set up metrics listener on (default 8014) -c, --server-cert-path string Server side tls certificate path -k, --server-key-path string Server side tls key path -a, --sync-provider-args Sync provider arguments as key values separated by = -d, --socket-path string Set the flagd socket path. -y, --sync-provider string Set a sync provider e.g. filepath, remote or kubernetes (default "filepath") -f, --uri strings Set a sync provider uri to read data from this can be a filepath or url. Using multiple providers is supported where collisions between flags with the same key, the later will be used. -C, --cors-origin strings Set a CORS allow origin header, setting "*" will allow all origins (by default CORS headers are not set) ``` -------------------------------- ### Starting flagd with CLI-based OAuth configuration Source: https://github.com/open-feature/flagd/blob/main/docs/reference/sync-configuration.md Demonstrates how to start flagd using the command line with OAuth enabled for HTTP synchronization. It includes client ID, client secret, and token URL configuration. ```sh ./bin/flagd start --sources='[{ "uri": "http://localhost:8180/flags", "provider": "http", "interval": 1, "timeoutS": 10, "oauth": { "clientID": "test", "clientSecret": "test", "tokenURL": "http://localhost:8180/sso/oauth2/token" }}]' ``` -------------------------------- ### Start flagd with a local configuration file Source: https://github.com/open-feature/flagd/blob/main/CONTRIBUTING.md Manually start the flagd service using a local JSON file for flag configurations. Requires Go and curl. ```shell go run main.go start -f file:../config/samples/example_flags.flagd.json ``` -------------------------------- ### Source Selection Example (Legacy) Source: https://github.com/open-feature/flagd/blob/main/docs/reference/selector-syntax.md Example using curl to select flags from a specific source file, demonstrating backward compatibility. ```APIDOC ### Source Selection (Legacy) ```bash # Select flags from a specific source (backward compatibility) curl -H "Flagd-Selector: source=config/prod-flags.json" \ http://localhost:8014/ofrep/v1/evaluate/flags ``` ``` -------------------------------- ### Start flagd with Docker Compose Source: https://github.com/open-feature/flagd/blob/main/docs/quick-start.md Execute the Docker Compose configuration to start the flagd service. ```shell docker compose up ``` -------------------------------- ### flagSetId Selector Examples Source: https://github.com/open-feature/flagd/blob/main/docs/reference/selector-syntax.md Examples demonstrating how to select flags belonging to specific flag sets using the flagSetId key. ```text flagSetId=project-42 ``` ```text flagSetId=dev-environment ``` ```text flagSetId=team-payments ``` -------------------------------- ### Example Context Merge Priority Configuration Source: https://github.com/open-feature/flagd/blob/main/docs/reference/flag-definitions.md Demonstrates a scenario where static context and header-mapped context are configured, illustrating merge priority. ```shell flagd start \ --uri file:./flags.json \ -X tier=basic \ -H "X-User-Tier=tier" ``` -------------------------------- ### Download Sample Flag Configuration Source: https://github.com/open-feature/flagd/wiki/Examples-using-cURL Use cURL to download the example flag configuration file. ```shell curl https://raw.githubusercontent.com/open-feature/flagd/main/config/samples/example_flags.json -o example_flags.json ``` -------------------------------- ### Start flagd command Source: https://github.com/open-feature/flagd/blob/main/docs/reference/flagd-cli/flagd_start.md This is the base command to start the flagd service. Various flags can be appended to configure its behavior. ```bash flagd start [flags] ``` -------------------------------- ### Initialize flagd workspace Source: https://github.com/open-feature/flagd/blob/main/CONTRIBUTING.md Run this command to set up the Go workspace for the flagd project. Ensure you have Go and make installed. ```shell make workspace-init ``` -------------------------------- ### Running flagd with Binary Source: https://github.com/open-feature/flagd/blob/main/docs/reference/cheat-sheet.md Examples for running flagd directly using the binary with different flag source configurations. ```APIDOC ## Running flagd with Binary ### Single flag source (local file) ```shell flagd start --uri file:./cheat-sheet-flags.json ``` ### Multiple flag sources ```shell flagd start \ --uri file:./cheat-sheet-flags.json \ --uri file:./cheat-sheet-flags-payments.json ``` ### HTTP source ```shell flagd start --uri https://flagd.dev/assets/cheat-sheet-flags.json ``` ``` -------------------------------- ### Provider SDK Usage Source: https://github.com/open-feature/flagd/blob/main/docs/reference/selector-syntax.md Examples of how to configure the selector in various OpenFeature provider SDKs. ```APIDOC ### Provider SDK Usage #### Go Provider ```go import "github.com/open-feature/go-sdk-contrib/providers/flagd" provider := flagd.NewProvider( flagd.WithHost("localhost"), flagd.WithPort(8013), flagd.WithSelector("flagSetId=user-service"), ) ``` #### Java Provider ```java FlagdProvider provider = new FlagdProvider( FlagdOptions.builder() .host("localhost") .port(8013) .selector("flagSetId=payment-service") .build() ); ``` #### JavaScript Provider ```javascript const provider = new FlagdProvider({ host: 'localhost', port: 8013, selector: 'flagSetId=frontend-features' }); ``` ``` -------------------------------- ### Example flagd Service Status Output Source: https://github.com/open-feature/flagd/wiki/systemd-Service This is an example output from the `systemctl status flagd` command, showing the service details including its loaded status, active state, main process information, and recent log lines. ```text flagd.service - "A generic feature flag daemon" Loaded: loaded (/etc/systemd/system/flagd.service; disabled; vendor preset: enabled) Active: active (running) since Mon 2022-05-30 12:19:55 BST; 5min ago Main PID: 64610 (flagd) Tasks: 7 (limit: 4572) Memory: 1.4M CGroup: /system.slice/flagd.service └─64610 /usr/local/bin/flagd start -f=/etc/flagd/flags.json May 30 12:19:55 foo systemd[1]: Started "A generic feature flag daemon". ``` -------------------------------- ### Flagd Sync Selector Examples Source: https://github.com/open-feature/flagd/blob/main/docs/architecture-decisions/decouple-flag-source-and-set.md These examples demonstrate the extended selector syntax for selecting flags based on source and flag set ID. The semantic can be extended later for more complex filtering. ```yaml selector: override ``` ```yaml selector: source=override ``` ```yaml selector: flagsetID=project-42 ``` -------------------------------- ### Provider Configuration: Source-Based Selector Source: https://github.com/open-feature/flagd/blob/main/docs/guides/migrating-to-flag-sets.md Example of a provider configuration using a source-based selector. ```yaml selector: "config/my-flags.json" ``` -------------------------------- ### Starts-With Operation Configuration Source: https://github.com/open-feature/flagd/blob/main/docs/reference/specifications/custom-operations/string-comparison-operation-spec.md Example of how the 'starts_with' property is configured within a targeting rule. It specifies the evaluation context property to check and the prefix to match. ```json { "starts_with": [ {"var": "email"}, "user@faas" ] } ``` -------------------------------- ### Run flagd Binary (Multiple Local Flag Sources) Source: https://github.com/open-feature/flagd/blob/main/docs/reference/cheat-sheet.md Starts flagd directly from the binary with multiple local JSON files as flag sources. ```shell flagd start \ --uri file:./cheat-sheet-flags.json \ --uri file:./cheat-sheet-flags-payments.json ``` -------------------------------- ### Run flagd Binary (Single Local Flag Source) Source: https://github.com/open-feature/flagd/blob/main/docs/reference/cheat-sheet.md Starts flagd directly from the binary with a single local JSON file as the flag source. ```shell flagd start --uri file:./cheat-sheet-flags.json ``` -------------------------------- ### Rollout Operator Syntax Examples Source: https://github.com/open-feature/flagd/blob/main/docs/architecture-decisions/rollout-operator.md Demonstrates the different ways to define the 'rollout' operator, including shorthand, longhand, and with a custom 'bucketBy' expression. ```jsonc // shorthand: roll from defaultVariant to "new" {"rollout": [1704067200, 1706745600, "new"]} // longhand: explicit from and to - from "old" to "new" {"rollout": [1704067200, 1706745600, "old", "new"]} // with custom bucketBy {"rollout": [{"var": "email"}, 1704067200, 1706745600, "old", "new"]} ``` -------------------------------- ### Run flagd Binary (HTTP Flag Source) Source: https://github.com/open-feature/flagd/blob/main/docs/reference/cheat-sheet.md Starts flagd directly from the binary, fetching flag definitions from a remote HTTP URL. ```shell flagd start --uri https://flagd.dev/assets/cheat-sheet-flags.json ``` -------------------------------- ### Start flagd with Envoy gRPC resolution Source: https://github.com/open-feature/flagd/blob/main/docs/reference/sync-configuration.md Use this command to start flagd with a custom gRPC target URI for Envoy proxy resolution. Ensure flagd is built with the appropriate flags enabled. ```shell ./bin/flagd start -x --uri envoy://localhost:9211/test.service ``` -------------------------------- ### Running flagd with Docker Source: https://github.com/open-feature/flagd/blob/main/docs/reference/cheat-sheet.md Examples for running flagd using Docker with different flag source configurations (local file, multiple files, HTTP). ```APIDOC ## Running flagd with Docker ### Single flag source (local file) ```shell docker run --rm -it \ -p 8013:8013 \ -p 8015:8015 \ -p 8016:8016 \ -v $(pwd):/flags \ ghcr.io/open-feature/flagd:latest start \ --uri file:./flags/cheat-sheet-flags.json ``` ### Multiple flag sources ```shell docker run --rm -it \ -p 8013:8013 \ -p 8015:8015 \ -p 8016:8016 \ -v $(pwd):/flags \ ghcr.io/open-feature/flagd:latest start \ --uri file:./flags/cheat-sheet-flags.json \ --uri file:./flags/cheat-sheet-flags-payments.json ``` ### HTTP source ```shell docker run --rm -it \ -p 8013:8013 \ -p 8015:8015 \ -p 8016:8016 \ -v $(pwd):/flags \ ghcr.io/open-feature/flagd:latest start \ --uri https://flagd.dev/assets/cheat-sheet-flags.json ``` ``` -------------------------------- ### Example Header-Mapped Context Configuration Source: https://github.com/open-feature/flagd/blob/main/docs/reference/flag-definitions.md Illustrates configuring flagd to map HTTP/gRPC request headers to evaluation context keys using the -H flag. ```shell flagd start \ --uri file:./flags.json \ -H "X-User-Id=userId" \ -H "X-User-Tier=tier" ``` -------------------------------- ### Flag Configuration: After Flag Set IDs Source: https://github.com/open-feature/flagd/blob/main/docs/guides/migrating-to-flag-sets.md Example of a flag configuration with a flagSetId added to metadata. ```json { "metadata": { "flagSetId": "my-application" }, "flags": { "feature-a": { "state": "ENABLED", "variants": {"on": true, "off": false}, "defaultVariant": "on" } } } ``` -------------------------------- ### Configure Git for DCO Sign-off Source: https://github.com/open-feature/flagd/blob/main/CONTRIBUTING.md Set up your Git client with your legal name and email for DCO sign-offs. This is a one-time setup. ```shell git config user.name git config user.email ``` ```shell git config --global user.name git config --global user.email ``` -------------------------------- ### Rollout Operator Example Source: https://github.com/open-feature/flagd/blob/main/docs/architecture-decisions/rollout-operator.md Defines a linear rollout from 'off' to 'on' over a specified time window using the 'rollout' operator. ```jsonc {"rollout": [1740000000, 1800000000, "off", "on"]} ``` -------------------------------- ### Provider Configuration: Flag Set-Based Selector Source: https://github.com/open-feature/flagd/blob/main/docs/guides/migrating-to-flag-sets.md Example of a provider configuration using a flag set-based selector. ```yaml selector: "flagSetId=my-application" ``` -------------------------------- ### Starts-With ResolveString Command and Result (No Match) Source: https://github.com/open-feature/flagd/blob/main/docs/reference/custom-operations/string-comparison-operation.md Example command to resolve a string flag using 'starts_with' with a non-matching email, and its expected JSON result. ```shell curl -X POST "localhost:8013/flagd.evaluation.v1.Service/ResolveString" -d '{"flagKey":"headerColor","context":{"email": "foo@bar.com"}}' -H "Content-Type: application/json" ``` ```json {"value":"#0000FF","reason":"TARGETING_MATCH","variant":"green"} ``` -------------------------------- ### Starts-With ResolveString Command and Result (Match) Source: https://github.com/open-feature/flagd/blob/main/docs/reference/custom-operations/string-comparison-operation.md Example command to resolve a string flag using 'starts_with' with a matching email, and its expected JSON result. ```shell curl -X POST "localhost:8013/flagd.evaluation.v1.Service/ResolveString" -d '{"flagKey":"headerColor","context":{"email": "user@faas.com"}}' -H "Content-Type: application/json" ``` ```json {"value":"#00FF00","reason":"TARGETING_MATCH","variant":"red"} ``` -------------------------------- ### Run flagd-proxy Locally Source: https://github.com/open-feature/flagd/blob/main/flagd-proxy/tests/loadtest/README.md Starts the flagd-proxy service on port 8080. This is a prerequisite for running the load tests. ```bash go run flagd-proxy/main.go start --port 8080 ``` -------------------------------- ### Return flag not found error Source: https://github.com/open-feature/flagd/wiki/Examples-using-cURL This example demonstrates the error response when the requested flag key does not exist in the configuration. ```APIDOC ## POST /schema.v1.Service/ResolveBoolean (Flag Not Found Error) ### Description This scenario triggers a 'flag not found' error when the provided flag key does not match any configured flags. ### Method POST ### Endpoint `localhost:8013/schema.v1.Service/ResolveBoolean` ### Request Body - **flagKey** (string) - Required - The key of a flag that does not exist (e.g., `aMissingFlag`). - **context** (object) - Optional - The evaluation context. ### Request Example ```json { "flagKey": "aMissingFlag", "context": {} } ``` ### Response #### Error Response (404 Not Found) - **code** (string) - Error code, e.g., `not_found`. - **message** (string) - Error message, e.g., `FLAG_NOT_FOUND`. #### Response Example ```json { "code": "not_found", "message": "FLAG_NOT_FOUND" } ``` ``` -------------------------------- ### Conventional PR Title Example Source: https://github.com/open-feature/flagd/blob/main/CONTRIBUTING.md Format your Pull Request titles according to conventional commit standards, starting with a type like 'docs:'. ```text docs: some PR title here... ``` -------------------------------- ### gRPC Header Precedence Example Source: https://github.com/open-feature/flagd/blob/main/docs/reference/selector-syntax.md Demonstrates how the gRPC metadata header takes precedence over the request body selector when both are provided. ```bash grpcurl -H "Flagd-Selector: flagSetId=production" \ -d '{"selector": "flagSetId=development"}' \ localhost:8013 flagd.sync.v1.FlagSyncService/FetchAllFlags ``` -------------------------------- ### Rollback Operator Example Source: https://github.com/open-feature/flagd/blob/main/docs/architecture-decisions/rollout-operator.md Implements a 'first in, last out' rollback initiated at the 50% mark using the 'rollback' operator. Requires a pivot time to define the rollback start. ```jsonc {"rollback": [1740000000, 1800000000, 1770000000, "on", "off"]} ``` -------------------------------- ### Setup grpcurl with flagd Proto Files Source: https://github.com/open-feature/flagd/blob/main/docs/reference/cheat-sheet.md Prepare to interact with the flagd gRPC API by cloning the repository to access the necessary proto files for serialization and deserialization. ```shell # Clone the repo for proto files git clone git@github.com:open-feature/flagd-schemas.git PROTO_DIR="flagd-schemas/protobuf/" ``` -------------------------------- ### Variants Property Example (String) Source: https://github.com/open-feature/flagd/blob/main/docs/reference/flag-definitions.md Example of the 'variants' property with string values. All variant values must be of the same type. ```jsonc "variants": { "red": "c05543", "green": "2f5230", "blue": "0d507b" } ``` -------------------------------- ### Variants Property Example (Boolean) Source: https://github.com/open-feature/flagd/blob/main/docs/reference/flag-definitions.md Example of the 'variants' property with boolean values. All variant values must be of the same type. ```jsonc "variants": { "on": true, "off": false } ``` -------------------------------- ### No Flag Set Selection Example Source: https://github.com/open-feature/flagd/blob/main/docs/reference/selector-syntax.md Example using curl to select flags that do not belong to any named flag set. ```APIDOC ### No Flag Set Selection ```bash # Select flags that don't belong to any named flag set curl -H "Flagd-Selector: flagSetId=" \ http://localhost:8014/ofrep/v1/evaluate/flags ``` ``` -------------------------------- ### Start flagd with a local flag configuration file Source: https://github.com/open-feature/flagd/blob/main/README.md Run flagd as a standalone binary, using a local file for flag configurations. The `--uri` parameter should be prefixed with `file:`. ```sh flagd start \ --port 8013 \ --uri file:./example_flags.flagd.json ``` -------------------------------- ### Publish flagd Playground to Docs Source: https://github.com/open-feature/flagd/blob/main/playground-app/README.md Run this command from the project root to build the playground app and copy its output to the documentation directory. ```bash make playground-publish ``` -------------------------------- ### Current Fractional Calculation (Go) Source: https://github.com/open-feature/flagd/blob/main/docs/architecture-decisions/high-precision-fractional-bucketing.md Illustrates the current implementation of fractional bucketing in Go, which limits granularity to 1% increments. ```go bucket := hashRatio * 100 // in range [0, 100] ``` -------------------------------- ### Run flagd with TLS Configuration Source: https://github.com/open-feature/flagd/blob/main/test/integration/README.md Start the flagd binary with TLS enabled, specifying the certificate and key files. This prepares flagd to accept TLS connections. ```shell ./bin/flagd start -f file:test-harness/symlink_testing-flags.json -c ./localhost.crt -k ./localhost.key ``` -------------------------------- ### Flag Set Selection Example Source: https://github.com/open-feature/flagd/blob/main/docs/reference/selector-syntax.md Example using curl to select flags from the 'payments' flag set via the Flagd-Selector header. ```APIDOC ### Flag Set Selection ```bash # Select flags from the "payments" flag set curl -H "Flagd-Selector: flagSetId=payments" \ http://localhost:8014/ofrep/v1/evaluate/flags ``` ``` -------------------------------- ### State Property Example Source: https://github.com/open-feature/flagd/blob/main/docs/reference/flag-definitions.md Example of the 'state' property, which must be either 'ENABLED' or 'DISABLED'. When disabled, flagd returns a successful evaluation with reason=DISABLED. ```jsonc "state": "ENABLED" ``` -------------------------------- ### Default Variant Example (String) Source: https://github.com/open-feature/flagd/blob/main/docs/reference/flag-definitions.md Example of 'defaultVariant' set to 'red' for a flag with string variants. This variant is used unless targeting rules override it. ```jsonc "variants": { "red": "c05543", "green": "2f5230", "blue": "0d507b" }, "defaultVariant": "red" ``` -------------------------------- ### Default Variant Example (Boolean) Source: https://github.com/open-feature/flagd/blob/main/docs/reference/flag-definitions.md Example of 'defaultVariant' set to 'off' for a flag with boolean variants. This variant is used unless targeting rules override it. ```jsonc "variants": { "on": true, "off": false }, "defaultVariant": "off" ``` -------------------------------- ### ResolveString Command Example Source: https://github.com/open-feature/flagd/blob/main/docs/reference/custom-operations/fractional-operation.md Example curl commands to resolve a string flag using fractional evaluation. The context, specifically the 'email' field, determines the variant. ```shell curl -X POST "localhost:8013/flagd.evaluation.v1.Service/ResolveString" -d '{"flagKey":"headerColor","context":{"email": "foo@bar.com"}}' -H "Content-Type: application/json" ``` ```json {"value":"#0000FF","reason":"TARGETING_MATCH","variant":"blue"} ``` ```shell curl -X POST "localhost:8013/flagd.evaluation.v1.Service/ResolveString" -d '{"flagKey":"headerColor","context":{"email": "foo@test.com"}}' -H "Content-Type: application/json" ``` ```json {"value":"#00FF00","reason":"TARGETING_MATCH","variant":"green"} ``` -------------------------------- ### flagd ResolveString API Response Example Source: https://github.com/open-feature/flagd/blob/main/README.md Example JSON response when resolving a string flag. It includes the resolved value, the reason for the resolution, and the specific variant returned. ```json { "value": "val1", "reason": "DEFAULT", "variant":"key1" } ``` -------------------------------- ### Ends-With Example Flag Configuration Source: https://github.com/open-feature/flagd/blob/main/docs/reference/custom-operations/string-comparison-operation.md Example of a flag configuration using the 'ends_with' operation to determine the 'headerColor' variant. Returns 'red' if the email ends with 'faas.com', otherwise 'green'. ```json { "$schema": "https://flagd.dev/schema/v0/flags.json", "flags": { "headerColor": { "variants": { "red": "#FF0000", "blue": "#0000FF", "green": "#00FF00" }, "defaultVariant": "blue", "state": "ENABLED", "targeting": { "if": [ { "ends_with": [{"var": "email"}, "faas.com"] }, "red", "green" ] } } } } ``` -------------------------------- ### Docker Compose for Local OTEL Collector Setup Source: https://github.com/open-feature/flagd/blob/main/docs/reference/monitoring.md A docker-compose configuration to set up a local OpenTelemetry collector with Jaeger and Prometheus. This setup allows for local testing and development of telemetry export and visualization. ```yaml services: jaeger: image: cr.jaegertracing.io/jaegertracing/jaeger:2.8.0 restart: always ports: - "16686:16686" - "14268" - "14250" # Collector otel-collector: image: otel/opentelemetry-collector:0.129.1 restart: always command: [ "--config=/etc/otel-collector-config.yaml" ] volumes: - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml ports: - "1888:1888" # pprof extension - "8888:8888" # Prometheus metrics exposed by the collector - "8889:8889" # Prometheus exporter metrics - "13133:13133" # health_check extension - "4317:4317" # OTLP gRPC receiver - "55679:55679" # zpages extension depends_on: - jaeger prometheus: container_name: prometheus image: prom/prometheus:v2.53.5 restart: always volumes: - ./prometheus.yaml:/etc/prometheus/prometheus.yml ports: - "9090:9090" ``` -------------------------------- ### Start flagd using Docker with a local flag configuration Source: https://github.com/open-feature/flagd/blob/main/README.md Run flagd as a Docker container, mounting the current directory to `/etc/flagd` and using a local file for flag configurations. This requires WSL on Windows. ```sh docker run \ --rm -it \ --name flagd \ -p 8013:8013 \ -v $(pwd):/etc/flagd \ ghcr.io/open-feature/flagd:latest start \ --uri file:./etc/flagd/example_flags.flagd.json ``` -------------------------------- ### OFREP Response Metadata Example Source: https://github.com/open-feature/flagd/blob/main/docs/reference/specifications/providers.md Example JSON structure for an OFREP response, illustrating the 'metadata' field which includes reflected selector information such as 'flagSetId', 'team', and 'version'. This provides transparency on how flags were queried. ```json { "value": true, "reason": "TARGETING_MATCH", "variant": "on", "metadata": { "flagSetId": "payment-service", "team": "payments", "version": "1.2.0" } } ``` -------------------------------- ### Start flagd with Filepath Sync Source: https://github.com/open-feature/flagd/blob/main/docs/concepts/syncs.md Use the file path sync provider to read and watch a local file for feature flag updates. For production, a symbolic link is recommended for atomic modifications. ```shell flagd start --uri file:etc/featureflags.json ``` -------------------------------- ### Example Custom Target String for Envoy Source: https://github.com/open-feature/flagd/blob/main/docs/reference/specifications/proposal/rfc-grpc-custom-name-resolver.md This example shows a custom target string format that utilizes an Envoy sidecar proxy for name resolution. The provider uses the endpoint name as the authority and connects to a specified host and port. ```text envoy://localhost:9211/flagd-sync.service ``` -------------------------------- ### Go Implementation of Fractional Evaluation Source: https://github.com/open-feature/flagd/blob/main/docs/reference/specifications/custom-operations/fractional-operation-spec.md A simplified Go implementation demonstrating the logic for fractional evaluation distribution. The 'values' parameter contains the targeting rule, and 'data' holds the evaluation context. ```go type fractionalEvaluationDistribution struct { variant string weight int } /* values: contains the targeting rule object; e.g.: [ {"var":"email"}, [ "red", 50 ], [ "blue", 20 ], [ "green", 30 ] ] data: contains the evaluation context; e.g.: { ``` -------------------------------- ### JavaScript Fractional Bucketing Example Source: https://github.com/open-feature/flagd/blob/main/docs/architecture-decisions/high-precision-fractional-bucketing.md This JavaScript example shows how to perform fractional bucketing using `BigInt` to handle potentially large numbers resulting from the multiplication. It converts the hash to `BigInt` and uses `BigInt` arithmetic for the calculation. Ensure `totalWeight` is a `BigInt` and the sum of variant weights does not exceed `Number.MAX_SAFE_INTEGER`. ```javascript const hash = murmur3_32(value); // Number const bucket = (BigInt(hash) * BigInt(totalWeight)) >> 32n; ``` -------------------------------- ### Invalid Variants Configuration Source: https://github.com/open-feature/flagd/blob/main/docs/reference/flag-definitions.md An example of an invalid 'variants' configuration where values are of mixed types. ```jsonc "variants": { "on": true, "off": "false" } ``` -------------------------------- ### Run flagd with Docker (Single Local Flag Source) Source: https://github.com/open-feature/flagd/blob/main/docs/reference/cheat-sheet.md Starts flagd using Docker with a single local JSON file as the flag source. Ensure the flag file is mounted into the container. ```shell docker run --rm -it \ -p 8013:8013 \ -p 8015:8015 \ -p 8016:8016 \ -v $(pwd):/flags \ ghcr.io/open-feature/flagd:latest start \ --uri file:./flags/cheat-sheet-flags.json ``` -------------------------------- ### Configuring FlagdProvider with a selector Source: https://github.com/open-feature/flagd/blob/main/docs/architecture-decisions/multiple-flag-set-support(rejected).md Shows how to instantiate the `FlagdProvider` with options, including specifying a `selector` for a flag set. The `selector` argument will be used to pass the `flagSetId` instead of a source file name. ```java final FlagdProvider flagdProvider = new FlagdProvider(FlagdOptions.builder() .resolverType(Config.Evaluator.IN_PROCESS) .host("localhost") .port(8015) .selector("myFlags.json") .build()); ``` -------------------------------- ### Flag Configuration: Before Flag Set IDs Source: https://github.com/open-feature/flagd/blob/main/docs/guides/migrating-to-flag-sets.md Example of a flag configuration without a flagSetId. ```json { "flags": { "feature-a": { "state": "ENABLED", "variants": {"on": true, "off": false}, "defaultVariant": "on" } } } ``` -------------------------------- ### Invalid Default Variant Configuration Source: https://github.com/open-feature/flagd/blob/main/docs/reference/flag-definitions.md An example of an invalid 'defaultVariant' configuration where the specified variant does not exist. ```jsonc "variants": { "red": "c05543", "green": "2f5230", "blue": "0d507b" }, "defaultVariant": "purple" ``` -------------------------------- ### Configure sync provider sources Source: https://github.com/open-feature/flagd/blob/main/docs/reference/flagd-cli/flagd_start.md Use the -s or --sources flag to provide a JSON array of SourceConfig objects, defining where flagd should fetch feature flags from. Each source requires a 'uri' and 'provider'. ```bash flagd start -s "[{ \"uri\": \"file:///path/to/flags.yaml\", \"provider\": \"local\" }]" ``` -------------------------------- ### Flag Set Organization: By Team Source: https://github.com/open-feature/flagd/blob/main/docs/guides/migrating-to-flag-sets.md Example YAML showing flag set organization by team. ```yaml flagSetId: "frontend-team" # Frontend features flagSetId: "backend-team" # Backend features ``` -------------------------------- ### Flag Set Organization: By Environment Source: https://github.com/open-feature/flagd/blob/main/docs/guides/migrating-to-flag-sets.md Example YAML showing flag set organization by environment. ```yaml flagSetId: "development" # Dev-specific flags flagSetId: "production" # Production flags ``` -------------------------------- ### Invalid Default Variant Configuration Source: https://github.com/open-feature/flagd/wiki/Feature-Flag-Configurations An example of an invalid configuration where the defaultVariant does not match any of the defined variants. ```json "variants": { "red": "c05543", "green": "2f5230", "blue": "0d507b" }, "defaultVariant": "purple" ``` -------------------------------- ### Analyze Heap Profile in UI Mode Source: https://github.com/open-feature/flagd/blob/main/test/loadtest/README.MD Use the go pprof tool to analyze the heap profile data from the running flagd instance via its pprof endpoint. This command starts a web server for UI-based analysis. ```bash go tool pprof --http=:9090 http://localhost:6060/debug/pprof/heap ``` -------------------------------- ### YAML configuration for flagd sync sources Source: https://github.com/open-feature/flagd/blob/main/docs/reference/sync-configuration.md An example of configuring flagd synchronization sources using a YAML file. This demonstrates various providers like file, http, kubernetes, grpc, gcs, azblob, and s3, along with specific configurations for each. ```yaml sources: - uri: config/samples/example_flags.json provider: file - uri: config/samples/example_flags.json provider: fsnotify - uri: config/samples/example_flags.json provider: fileinfo - uri: http://my-flag-source/flags.json provider: http authHeader: "Bearer bearer-dji34ld2l" - uri: default/my-flag-config provider: kubernetes - uri: my-flag-source:8080 provider: grpc - uri: my-flag-source:8080 provider: grpc maxMsgSize: 5242880 - uri: envoy://localhost:9211/test.service provider: grpc - uri: my-flag-source:8080 provider: grpc certPath: /certs/ca.cert tls: true providerID: flagd-weatherapp-sidecar selector: "flagSetId=weatherapp" - uri: gs://my-bucket/my-flag.json provider: gcs - uri: azblob://my-container/my-flags.json provider: azblob - uri: s3://my-bucket/my-flags.json provider: s3 ``` -------------------------------- ### Flag Configuration with SemVer Targeting Source: https://github.com/open-feature/flagd/blob/main/docs/reference/custom-operations/semver-operation.md Example flag configuration demonstrating how to use the semver operation within targeting rules to conditionally serve variants based on a version string. The 'red' variant is served if the 'version' property is >= '1.0.0'. ```json { "$schema": "https://flagd.dev/schema/v0/flags.json", "flags": { "headerColor": { "variants": { "red": "#FF0000", "blue": "#0000FF", "green": "#00FF00" }, "defaultVariant": "blue", "state": "ENABLED", "targeting": { "if": [ { "sem_ver": [{"var": "version"}, ">=", "1.0.0"] }, "red", "green" ] } } } } ``` -------------------------------- ### Flag Set Organization: By Application/Service Source: https://github.com/open-feature/flagd/blob/main/docs/guides/migrating-to-flag-sets.md Example YAML showing flag set organization by application or service. ```yaml flagSetId: "user-service" # All user-related flags flagSetId: "payment-service" # All payment-related flags ``` -------------------------------- ### Resolve an integer value Source: https://github.com/open-feature/flagd/wiki/Examples-using-cURL This example demonstrates resolving an integer flag. Note that the response value is a string. ```APIDOC ## POST /schema.v1.Service/ResolveInt ### Description Resolves an integer flag. Note: The resolved value is returned as a string. ### Method POST ### Endpoint `localhost:8013/schema.v1.Service/ResolveInt` ### Request Body - **flagKey** (string) - Required - The key of the flag to resolve. - **context** (object) - Optional - The evaluation context. ### Request Example ```json { "flagKey": "myIntFlag", "context": {} } ``` ### Response #### Success Response (200) - **value** (string) - The resolved integer value of the flag, returned as a string. - **reason** (string) - The reason for the resolution. - **variant** (string) - The variant of the flag that was resolved. #### Response Example ```json { "value": "1", "reason": "DEFAULT", "variant": "one" } ``` ```