-
Notifications
You must be signed in to change notification settings - Fork 3
fix: Store configuration atomically #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
614d2a2
DTO traits for create and packout
typotter cf0292b
Config wire types and trait tests
typotter 9562182
ignore tmp cache directory
typotter e7aaf09
Configuration Class
typotter 4860aac
move UFCParser logic to Flag
typotter f2d7479
Config class tests
typotter 3ca697c
refactor reloadIfExpired out of getFlag
typotter 16e7e66
Tests for Configuration class
typotter ba24b15
DTO updates
typotter f187884
new config store
typotter 42ffe2b
new config store
typotter f29a3a0
Tests for the new config store
typotter cdc93ad
rip out changes
typotter d2dc794
fixed more tests
typotter 7de70f9
more tests
typotter ad85819
even more tests. feat complete possibly
typotter 40ac12d
last test
typotter 9969444
finish configuration store swap out
typotter d513987
rename create trait
typotter be8f682
polish
typotter 898ccc1
polish
typotter bffb17b
fix timing for cache test.
typotter 674c5ad
lint
typotter 04b2bcc
don't evaluate bandit for default value
typotter bde87bb
log cache errors
typotter c603bf3
Merge branch 'main' into tp/config-wire
typotter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,4 @@ vendor | |
| tests/data | ||
| .phpunit.result.cache | ||
| .vscode | ||
| cache | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| <?php | ||
|
|
||
| namespace Eppo\Config; | ||
|
|
||
| use Eppo\DTO\Bandit\Bandit; | ||
| use Eppo\DTO\BanditParametersResponse; | ||
| use Eppo\DTO\BanditReference; | ||
| use Eppo\DTO\ConfigurationWire\ConfigResponse; | ||
| use Eppo\DTO\ConfigurationWire\ConfigurationWire; | ||
| use Eppo\DTO\Flag; | ||
| use Eppo\DTO\FlagConfigResponse; | ||
|
|
||
| class Configuration | ||
| { | ||
| private array $parsedFlags = []; | ||
| private readonly FlagConfigResponse $flags; | ||
| private readonly BanditParametersResponse $bandits; | ||
|
|
||
|
|
||
| private function __construct( | ||
| private readonly ConfigResponse $flagsConfig, | ||
| private readonly ?ConfigResponse $banditsConfig | ||
| ) { | ||
| $flagJson = json_decode($this->flagsConfig->response, true); | ||
| $banditsJson = json_decode($this->banditsConfig?->response ?? "", true); | ||
| $this->flags = FlagConfigResponse::fromJson($flagJson ?? []); | ||
| $this->bandits = BanditParametersResponse::fromJson($banditsJson ?? []); | ||
| } | ||
|
|
||
| public static function fromUfcResponses(ConfigResponse $flagsConfig, ?ConfigResponse $banditsConfig): Configuration | ||
| { | ||
| return new self($flagsConfig, $banditsConfig); | ||
| } | ||
|
|
||
| public static function fromConfigurationWire(ConfigurationWire $configurationWire): self | ||
| { | ||
| return new self($configurationWire?->config ?? null, $configurationWire?->bandits ?? null); | ||
| } | ||
|
|
||
| public static function fromFlags(array $flags, ?array $bandits = null) | ||
| { | ||
| $fcr = FlagConfigResponse::fromJson(["flags" => $flags]); | ||
| $flagsConfig = new ConfigResponse(response: json_encode($fcr)); | ||
| $banditsConfig = $bandits ? new ConfigResponse( | ||
| response: json_encode(BanditParametersResponse::fromJson(["bandits" => $bandits])) | ||
| ) : null; | ||
| return new self($flagsConfig, $banditsConfig); | ||
| } | ||
|
|
||
| public static function emptyConfig(): self | ||
| { | ||
| return self::fromFlags([]); | ||
| } | ||
|
|
||
| public function getFlag(string $key): ?Flag | ||
| { | ||
| if (!isset($this->parsedFlags[$key])) { | ||
| $flagObj = $this->flags->flags[$key] ?? null; | ||
| if ($flagObj !== null) { | ||
| $this->parsedFlags[$key] = Flag::fromJson($flagObj); | ||
| } | ||
| } | ||
| return $this->parsedFlags[$key] ?? null; | ||
| } | ||
|
|
||
| public function getBandit(string $banditKey): ?Bandit | ||
| { | ||
| if (!isset($this->bandits->bandits[$banditKey])) { | ||
| return null; | ||
| } | ||
| return Bandit::fromJson($this->bandits?->bandits[$banditKey]) ?? null; | ||
| } | ||
|
|
||
| public function getBanditByVariation(string $flagKey, string $variation): ?string | ||
| { | ||
| foreach ($this->flags->banditReferences as $banditKey => $banditReferenceObj) { | ||
| $banditReference = BanditReference::fromJson($banditReferenceObj); | ||
| foreach ($banditReference->flagVariations as $flagVariation) { | ||
| if ($flagVariation->flagKey === $flagKey && $flagVariation->variationKey === $variation) { | ||
| return $banditKey; | ||
| } | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| public function toConfigurationWire(): ConfigurationWire | ||
| { | ||
| return ConfigurationWire::fromResponses( | ||
| flags: $this->flagsConfig, | ||
| bandits: $this->banditsConfig | ||
| ); | ||
| } | ||
|
|
||
| public function getFetchedAt(): ?string | ||
| { | ||
| return $this?->flagsConfig?->fetchedAt ?? null; | ||
| } | ||
|
|
||
| public function getFlagETag(): ?string | ||
| { | ||
| return $this->flagsConfig?->eTag ?? null; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.