<commit_before>
Dynamic Flags For Go (golang)
=============================

This is a **work in progress** to implement dynamic setting of `flag` or `spf13/pflag` values by reading them from
some configuration store (like etcd).

Watch this space for more:
 * unit tests
 * integration tests
 * unicorns


Author: <EMAIL><commit_msg>Updated readme.<commit_after>
# Go FlagZ - Dynamic Flag Management

** work in progress **

The purpose of this project is to provide the ability to change `flag` or `spf13/pflag` values in runtime across many 
services based on a distributed configuration store (etcd, Consul).
 
## This sounds crazy. Why?

Dynamic configuration allows for fast iteration cycles, and provides valuable flexibility in emergencies. Two examples:
 
 * You want to enable a new feature for a certain fraction of user requests in granular fashion (1%, 5%, 20%, 50%, 
 100%) without a need to restart servers.
 * Your service is getting overloaded and you want to disable certain costly features, and you can't afford 
 restarting because you'd lose important capacity.
 
All of these unformly across a shard of your services. Of course with great power comes great responsibility :)

## How?

Declare a single `flag.FlagSet` compatible variable in some package of your codebase (e.g. `common.DynamicFlagSet`) 
that you'll use throughout to declare your flags. Then:

```go
    // First parse the flags from the command line, as normal.
    common.DynamicFlagSet.Parse(os.Args[1:])
	updater, err := flagz_etcd.New(common.DynamicFlagSet, 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.DynamicFlagSet
	err = updater.Initialize()
	if err != nil {
		log.Fatalf("failed setting up %v", err)
	}
	// Start listening for dynamic updates of flags.
	updater.Start()
```

In case of errors (parsing, disallowed values) flagz will atomically roll back the bad state in etcd.

# Status

This is a proof of concept. Integration tests pending.

Features planned:
 
  * HTTP `Handler` for displaying state of flags.
  * Monitoring of checksum of flags.
  * Implementation of flags that implement complicated types: maps, JSON Marshalled structs, protocol buffers.

Author: <EMAIL>
{'fraction_non_alphanumeric': 0.08932461873638345, 'fraction_numerical': 0.006100217864923747, 'mean_word_length': 4.290322580645161, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3969272', 'n_tokens_mistral': 648, 'n_tokens_neox': 613, 'n_words': 302}