Skip to content

chore: refactor configuration handling for startup#551

Merged
toddbaert merged 4 commits intoopen-feature:mainfrom
Kavindu-Dodan:chore/refactor-config-handling
Mar 23, 2023
Merged

chore: refactor configuration handling for startup#551
toddbaert merged 4 commits intoopen-feature:mainfrom
Kavindu-Dodan:chore/refactor-config-handling

Conversation

@Kavindu-Dodan
Copy link
Copy Markdown
Contributor

@Kavindu-Dodan Kavindu-Dodan commented Mar 22, 2023

This PR

No logic changes - Pure refactoring[1] to untangle startup argument-based configurations from runtime.

Consider the simple sequence diagram below,

sequenceDiagram
    participant start
    participant from_config
    participant runtime
    start-->>from_config: ParseSyncProviderURIs()
    start-->>from_config: ParseSources()
    start-->>from_config: FromConfig()
    Note left of from_config: This parse & build the runtime.
    from_config-->>start: Runtime
    Note left of from_config: Runtime structure is self-contained & <br/> does not rely on the startup configuration
    start-->>runtime: rt.Start()
    loop Run
        runtime->>runtime: flagd runtime
    end
Loading

The core idea was to isolate startup configuration & get rid of the unwanted Config [2] structure parsing to the Runtime layer.

This change

  • Helps to isolate startup arguments & runtime (low coupling)
  • Improves testability by removing unused/unwanted pointer receivers
  • Improves readability as we have a clear logic flow

[1] Note - Had to change this faulty log line :

default:
return nil, fmt.Errorf("invalid sync provider: %s, must be one of with '%s', '%s', '%s' or '%s'",
syncProvider.Provider, syncProviderFile, syncProviderKubernetes, syncProviderHTTP, syncProviderKubernetes)

[2] - https://github.com/open-feature/flagd/blob/main/core/pkg/runtime/runtime.go#L30

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 22, 2023

Codecov Report

Merging #551 (00f2da8) into main (c7b29ed) will increase coverage by 2.62%.
The diff coverage is 41.17%.

@@            Coverage Diff             @@
##             main     #551      +/-   ##
==========================================
+ Coverage   66.77%   69.40%   +2.62%     
==========================================
  Files          19       19              
  Lines        2125     2121       -4     
==========================================
+ Hits         1419     1472      +53     
+ Misses        646      589      -57     
  Partials       60       60              
Impacted Files Coverage Δ
core/pkg/runtime/runtime.go 0.00% <0.00%> (ø)
core/pkg/runtime/from_config.go 58.92% <43.07%> (+31.04%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Kavindu-Dodan Kavindu-Dodan force-pushed the chore/refactor-config-handling branch 2 times, most recently from 3ad9c86 to 0f171eb Compare March 23, 2023 13:28
Signed-off-by: Kavindu Dodanduwa <kavindudodanduwa@gmail.com>
Signed-off-by: Kavindu Dodanduwa <kavindudodanduwa@gmail.com>
Signed-off-by: Kavindu Dodanduwa <kavindudodanduwa@gmail.com>
@Kavindu-Dodan Kavindu-Dodan force-pushed the chore/refactor-config-handling branch from 0f171eb to 9975c90 Compare March 23, 2023 14:20
Signed-off-by: Kavindu Dodanduwa <kavindudodanduwa@gmail.com>
@Kavindu-Dodan Kavindu-Dodan force-pushed the chore/refactor-config-handling branch from 9975c90 to 00f2da8 Compare March 23, 2023 14:29
Copy link
Copy Markdown
Contributor

@odubajDT odubajDT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! :)

syncProvidersParsed := []sync.SourceConfig{}
if err := json.Unmarshal([]byte(syncProviders), &syncProvidersParsed); err != nil {
// ParseSources parse a json formatted SourceConfig array string and performs validations on the content
func ParseSources(sourcesFlag string) ([]SourceConfig, error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better names, thanks.

Comment on lines +150 to +151
return nil, fmt.Errorf("invalid sync provider: %s, must be one of with '%s', '%s', '%s' or '%s'",
syncProvider.Provider, syncProviderFile, syncProviderKubernetes, syncProviderHTTP, syncProviderKubernetes)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is the incorrect log you were mentioning.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. Here the switch work on syncProvider.Provider & not the URI :)

@toddbaert toddbaert self-requested a review March 23, 2023 14:57
@toddbaert toddbaert merged commit 8dfbde5 into open-feature:main Mar 23, 2023
@github-actions github-actions Bot mentioned this pull request Mar 23, 2023
toddbaert added a commit that referenced this pull request Mar 30, 2023
🤖 I have created a release *beep* *boop*
---


<details><summary>flagd: 0.5.0</summary>

##
[0.5.0](flagd/v0.4.5...flagd/v0.5.0)
(2023-03-30)


### ⚠ BREAKING CHANGES

* unify sources configuration handling
([#560](#560))

### 🐛 Bug Fixes

* benchmark pipeline
([#538](#538))
([62cc0fc](62cc0fc))
* **deps:** update module github.com/open-feature/flagd/core to v0.4.5
([#552](#552))
([41799f6](41799f6))


### 🧹 Chore

* refactor configuration handling for startup
([#551](#551))
([8dfbde5](8dfbde5))
</details>

<details><summary>flagd-proxy: 0.2.0</summary>

##
[0.2.0](flagd-proxy-v0.1.2...flagd-proxy/v0.2.0)
(2023-03-30)


### ⚠ BREAKING CHANGES

* rename `kube-flagd-proxy` to `flagd-proxy`
([#576](#576))

### ✨ New Features

* rename `kube-flagd-proxy` to `flagd-proxy`
([#576](#576))
([223de99](223de99))
</details>

<details><summary>core: 0.5.0</summary>

##
[0.5.0](core/v0.4.5...core/v0.5.0)
(2023-03-30)


### ⚠ BREAKING CHANGES

* rename `kube-flagd-proxy` to `flagd-proxy`
([#576](#576))
* unify sources configuration handling
([#560](#560))

### 🧹 Chore

* move credential builder for grpc sync into seperate component
([#536](#536))
([7314fee](7314fee))
* refactor configuration handling for startup
([#551](#551))
([8dfbde5](8dfbde5))
* refactor middleware setup in server
([#554](#554))
([01016c7](01016c7))
* refactor service configuration objects
([#545](#545))
([c7b29ed](c7b29ed)),
closes [#524](#524)
* unify sources configuration handling
([#560](#560))
([7f4888a](7f4888a))


### 🐛 Bug Fixes

* **deps:** update module google.golang.org/grpc to v1.54.0
([#548](#548))
([99ba5ec](99ba5ec))
* **deps:** update module sigs.k8s.io/controller-runtime to v0.14.6
([#572](#572))
([bed9458](bed9458))
* fixing silent lint failures
([#550](#550))
([30c8022](30c8022))
* nil pointer fix + export constructors
([#555](#555))
([78adb81](78adb81))


### ✨ New Features

* expose Impression metric
([#556](#556))
([77e0a33](77e0a33))
* Introduce kube-proxy-metrics
([#558](#558))
([ad0baeb](ad0baeb))
* rename `kube-flagd-proxy` to `flagd-proxy`
([#576](#576))
([223de99](223de99))
* refactor core module into multiple packages
([#530](#530))
([9d68d0b](9d68d0b))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Signed-off-by: Todd Baert <toddbaert@gmail.com>
Co-authored-by: Todd Baert <toddbaert@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants