feat(configio): implement Builder#61
Merged
Merged
Conversation
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## main #61 +/- ##
==========================================
+ Coverage 81.16% 81.64% +0.47%
==========================================
Files 28 29 +1
Lines 945 1024 +79
==========================================
+ Hits 767 836 +69
- Misses 147 150 +3
- Partials 31 38 +7
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
f2850a8 to
5d5465f
Compare
efba581 to
e163977
Compare
5d5465f to
1dbd54e
Compare
This was referenced Nov 6, 2022
840c662 to
5e9268f
Compare
400f89e to
61ff33c
Compare
1dbd54e to
5f1ed58
Compare
…ilder" This reverts commit 731547e.
Previous benchmarks showed 2.5x better performance over piped modifier.
- Builder.Into -> Builder.Mutate - Builder.modifiers -> Builder.mutations
- configio.Representation -> configio.representation - make all representation methods private
- remove Decode methods from interface Decoder and its implementations - rename DecodeRunner methods to Decode - remove UnmarshalXXXX functions - rename UnmarshalXXXXRunner functions to UnmarshalXXXX
e865353 to
39fb4a6
Compare
Write -> Decode
moreirathomas
approved these changes
Mar 28, 2023
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Meant to replace configio.Representation for external use. configio.Representation is hardly usable because of nested structs and pointers: it should remain an internal unmarshaling/marshaling structure only.
Problem statement
A common use-case we have is the need to combine benchttp configuration, by overriding successively different sources (e.g. in benchttp/cli: DefaultRunner <- configuration file <- cli flags).
To do this, we need to know which fields are set and which are not for each override. However, due to Go initializing unset fields with zero values, it's impossible to determine whether a zero-value field was actually set or defaulted by Go.
Consecutive solutions
➡️ Solution 1:
runner.Config.OverrideTo overcome this we first added memorizing capabilities to
runner.Config, which used with its methodOverrideallowed to perform this kind of selective override.This solution was far from ideal: it was cumbersome to use for the consumer (having to keep track of set fields), it polluted package
runnerwith manyConfigFieldXxxdeclarations and added undesirable complexity to the package.➡️ Solution 2:
configio.Representation(previously
configparse.Representation)In #58, we nuke the
runner.Configstructure and its overriding logics.Instead we take advantage of
configio.Representation: previously used as a decoding structure only, it uses pointer fields to distinguish zero values from undefined values. This combined with the adoptions ofMarshal-like signature provides a functional overriding logic:Overriding a
benchttp.Runnerwith json config usingconfigio.RepresentationThis works well for what it was initially intended for: decoding bytes. Other than that it turns out to be extremely painful to manipulate, due to nested structs and pointer fields. As such, it ties overriding logics to the action of decoding. Let's try to assign a value to
configio.Representation.Body(e.g. in a testing context or from anybenchttpconsumer point of view):Cumbersome manipulation of
configio.RepresentationThis shows how unadapted
configio.Representationis for the general purpose of building a config. It is tied to the purpose of decoding a JSON/YAML config and as such it must remain an internal decoding structure.➡️ Solution 3:
configio.BuilderThe purpose of
configio.Builderis to provide a building API forbenchttp.Runner.strings.Builders) using write and setter methods (b.WriteJSON,b.SetConcurrency)configio.Representationfor that matterThis makes
configio.Representationobsolete as an exported value, but still needed as an internal decoding structure.That's why we also unexport
configio.Representationand update all related public function to work withconfigio.Builderinstead.Changes
configio.Builderconfigio.Builderinstead ofconfigio.Representationconfigio.RepresentationNotes