The amazing sentry-options is Sentry's internal option/feature flag management platform. It offers a reusable way to easily get configuration at run-time into your Kubernetes service.
Backed by volume mounted ConfigMaps, sentry-options provides hot-reloadable options with no database overhead.
sentry-options consists of several components:
The CLI tool typically run in CI to help validate and generate ConfigMaps.
A library with common code used in both the CLI and client libraries.
To make ingesting options as simple as possible, sentry-options comes with client libraries in two different languages: Rust and Python, hosted on crates.io and our internal pypi respectively.
A composite GitHub action that ensures
- Your schema definition is valid
- Any changes you make to the schema follow the schema evolution rules
Import this into your repo to ensure your schema is valid before it fails in CI much later on (when you start changing values)
For a detailed guide on how to set up sentry-options in your repo, refer to the integration guide. This will require changes in:
- Defining your schema (what options do we have?)
- Importing the
validate-schemasaction - Using the client library in your code
- An update to
repos.json, so values can be validated against the schema - Defining the values for your option
- Updating your k8 cluster to mount your config map
If you already have sentry-options set up in your repo, you only need to import the client library and use it:
# index.py
from sentry_options import init, options
# Initialize the library
# Do this *once* early on
init()
# Get options for a specified namespace
opts = options('seer')
# Read the values
# If the option value is not set in the automator repo, it will just use the default
if opts.get('feature.enabled'):
rate = opts.get('feature.rate_limit')
print(f"The global rate limit is {rate}")// main.rs
use sentry_options::{init, options};
fn main() -> anyhow::Result<()> {
// Initialize the library
// Do this *once* early on
init()?;
// Get options for a specified namespace
let opts = options("seer");
// Read the values
// If the option value is not set in the automator repo, it will just use the default
if opts.get("feature.enabled")?.as_bool().unwrap() {
let rate = opts.get("feature.rate_limit")?;
println!("The global rate limit is {}", rate);
}
}To test behaviour when an option value change, you can override your default values with local values.
In a new file in the same directory as your schemas, e.g. sentry-options/values/{namespace}/, create a values.json:
// values.json
{
"options": {
"feature.enabled": true,
"feature.rate_limit": 200
}
}Your client libraries will automatically pick up the new values.