All Projects → mwitkow → Go Flagz

mwitkow / Go Flagz

Licence: apache-2.0
Dynamic flag management for Go.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Go Flagz

Konfig
Composable, observable and performant config handling for Go for the distributed processing era
Stars: ✭ 597 (+212.57%)
Mutual labels:  etcd, configuration
flagga
An extensible Go library for handling program configuration using flags.
Stars: ✭ 28 (-85.34%)
Mutual labels:  configuration, flags
Magento2 Configurator
Magento 2 Configurator
Stars: ✭ 158 (-17.28%)
Mutual labels:  configuration
Microconfig
Modern tool for microservice configuration management
Stars: ✭ 180 (-5.76%)
Mutual labels:  configuration
Dot Hammerspoon
My personal Hammerspoon configuration - mirrored from GitLab
Stars: ✭ 165 (-13.61%)
Mutual labels:  configuration
Config
Configuration module for Nest framework (node.js) 🍓
Stars: ✭ 161 (-15.71%)
Mutual labels:  configuration
Glow
mpv Config File Generator for Windows
Stars: ✭ 167 (-12.57%)
Mutual labels:  configuration
Dotnet Etcd
A C# .NET (dotnet) GRPC client for etcd v3 +
Stars: ✭ 157 (-17.8%)
Mutual labels:  etcd
Aconfig
Simple, useful and opinionated config loader.
Stars: ✭ 187 (-2.09%)
Mutual labels:  configuration
Apollo.net
Apollo配置中心.Net客户端
Stars: ✭ 165 (-13.61%)
Mutual labels:  configuration
Countrycode
🎯 Swift country and phone code Picker
Stars: ✭ 175 (-8.38%)
Mutual labels:  flags
Configs
Scala wrapper for Typesafe config
Stars: ✭ 164 (-14.14%)
Mutual labels:  configuration
Pifpaf
Python fixtures and daemon managing tools for functional testing
Stars: ✭ 161 (-15.71%)
Mutual labels:  etcd
Config
Various program configuration files and scripts
Stars: ✭ 173 (-9.42%)
Mutual labels:  configuration
Discovery.etcd.io
etcd discovery service
Stars: ✭ 160 (-16.23%)
Mutual labels:  etcd
Swarmstack
A Docker swarm-based starting point for operating highly-available containerized applications.
Stars: ✭ 181 (-5.24%)
Mutual labels:  etcd
Etcd Watcher
Etcd watcher for Casbin
Stars: ✭ 157 (-17.8%)
Mutual labels:  etcd
Docker Compose
一些基础服务的docker-compose配置文件,方便在一台新电脑上快速开始工作
Stars: ✭ 163 (-14.66%)
Mutual labels:  etcd
Simple Settings
A simple way to manage your project settings.
Stars: ✭ 165 (-13.61%)
Mutual labels:  configuration
Knobs
A reasonable configuration library for Scala
Stars: ✭ 188 (-1.57%)
Mutual labels:  configuration

Go FlagZ

Travis Build Go Report Card GoDoc SourceGraph codecov Apache 2.0 License

Dynamic, thread-safe flag variables that can be modified at runtime through etcd or Kubernetes.

For a similar project for JVM languages (Java, scala) see java-flagz

This sounds crazy. Why?

File-based or command-line configuration can only be changed when a service restarts. Dynamic flags provide flexibility in normal operations and emergencies. Two examples:

  • A new feature launches that you want to A/B test. You want to gradually enable it for a certain fraction of user requests (1%, 5%, 20%, 50%, 100%) without the need to restart servers.
  • Your service is getting overloaded and you want to disable certain costly features. You can't afford restarting because you'd lose important capacity.

All of this can be done simultaneously across a whole shard of your services.

Features

  • compatible with popular flag replacement spf13/pflag (e.g. ones using spf13/cobra)
  • dynamic flag that are thread-safe and efficient:
    • DynInt64
    • DynFloat64
    • DynString
    • DynDuration
    • DynStringSlice
    • DynJSON - a flag that takes an arbitrary JSON struct
    • DynProto3 - a flag that takes a proto3 struct in JSONpb or binary form
  • validator functions for each flag, allows the user to provide checks for newly set values
  • notifier functions allow user code to be subscribed to flag changes
  • Kubernetes ConfigMap watcher, see configmap/README.md.
  • etcd based watcher that syncs values from a distributed Key-Value store into the program's memory
  • Prometheus metric for checksums of the current flag configuration
  • a /debug/flagz HandlerFunc endpoint that allows for easy inspection of the service's runtime configuration

Here's a teaser of the debug endpoint:

Status Endpoint

Examples

Declare a single pflag.FlagSet in some public package (e.g. common.SharedFlagSet) that you'll use throughout your server.

Dynamic JSON flag with a validator and notifier

var (
  limitsConfigFlag = flagz.DynJSON(
    common.SharedFlagSet, 
    "rate_limiting_config", 
    &rateLimitConfig{ DefaultRate: 10, Policy: "allow"},
    "Config for service's rate limit",
  ).WithValidator(rateLimitConfigValidator).WithNotifier(onRateLimitChange)
)

This declares a JSON flag of type rateLimitConfig with a default value. Whenever the config changes (statically or dynamically) the rateLimitConfigValidator will be called. If it returns no errors, the flag will be updated and onRateLimitChange will be called with both old and new, allowing the rate-limit mechanism to re-tune.

Dynamic feature flags

var (
  featuresFlag = flagz.DynStringSlice(common.SharedFlagSet, "enabled_features", []string{"fast_index"}, "list of enabled feature markers")
)
...
func MyHandler(resp http.ResponseWriter, req *http.Request) {
   ...
   if existsInStringSlice("fast_index", featuresFlag.Get()) {
     doFastIndex(req)
   }
   ...
}

All access to featuresFlag, which is a []string flag, is synchronised across go-routines using atomic pointer swaps.

Watching for changes from etcd

// First parse the flags from the command line, as normal.
common.SharedFlagSet.Parse(os.Args[1:])
w, err := watcher.New(common.SharedFlagSet, etcdClient, "/my_service/flagz", logger)
if err != nil {
  logger.Fatalf("failed setting up %v", err)
}
// Read flagz from etcd and update their values in common.SharedFlagSet
if err := w.Initialize(); err != nil {
	log.Fatalf("failed setting up %v", err)
}
// Start listening of dynamic flags from etcd.
w.Start()

The watcher's go-routine will watch for etcd value changes and synchronise them with values in memory. In case a value fails parsing or the user-specified validator, the key in etcd will be atomically rolled back.

More examples:

Status

This code is production quality. It's been running happily in production at Improbable for a few months.

Features planned:

  • [x] - #11 monitoring of FlagSet checksus using a Prometheus handler
  • [ ] - #12 support for standard flag (requires changes in spf13/pflag interfaces)

License

go-flagz is released under the Apache 2.0 license. See the LICENSE file for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].