Skip to content
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

feat: support yaml evaluator #206

Merged
merged 16 commits into from
Jan 4, 2023

Conversation

vadasambar
Copy link
Contributor

@vadasambar vadasambar commented Nov 2, 2022

This PR

  • adds support for YAML evaluator

Related Issues

Fixes #180

Notes

I have added extra notes as comments in the code.

Follow-up Tasks

TBD

How to test

Not sure what would be a good test for this.

To try it out, you can run the example yaml config

go run main.go start -f config/samples/example_flags.yaml  -e=yaml

@vadasambar vadasambar force-pushed the feat/180/add-yaml-evaluator branch from a51f64d to 19a66fb Compare November 2, 2022 18:41
@vadasambar
Copy link
Contributor Author

vadasambar commented Nov 2, 2022

This PR is WIP. I will request review once I am done by mentioning the reviewer in a comment on this issue.

@toddbaert
Copy link
Member

Hey @vadasambar ! Since it tends to be trivial to convert yaml <=> json, I would suggest somehow approaching the problem with that in mind. You can leverage the existing JSON evaluator's logic and state storage and just change the parsing, I think. Perhaps composition could help here?

@vadasambar vadasambar force-pushed the feat/180/add-yaml-evaluator branch 2 times, most recently from e832622 to cef8463 Compare November 11, 2022 19:05
@vadasambar vadasambar force-pushed the feat/180/add-yaml-evaluator branch 3 times, most recently from 1afef7d to 07e75c5 Compare November 22, 2022 18:42
@vadasambar vadasambar changed the title feat: wip support yaml evaluator feat: support yaml evaluator Nov 22, 2022
@vadasambar vadasambar marked this pull request as ready for review November 22, 2022 18:56
@vadasambar vadasambar requested review from AlexsJones and removed request for toddbaert, skyerus and james-milligan November 22, 2022 18:57
@vadasambar vadasambar force-pushed the feat/180/add-yaml-evaluator branch 2 times, most recently from 62ef1b0 to 3daacc1 Compare November 30, 2022 18:19
Copy link
Member

@beeme1mr beeme1mr left a comment

Choose a reason for hiding this comment

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

Could you please also update the configuration documentation?

https://github.com/open-feature/flagd/blob/main/docs/configuration.md

pkg/sync/filepath_sync.go Outdated Show resolved Hide resolved
@vadasambar
Copy link
Contributor Author

Could you please also update the configuration documentation?

https://github.com/open-feature/flagd/blob/main/docs/configuration.md

@beeme1mr slipped my mind. I will do it. Thanks for pointing it out. 🙏

@beeme1mr
Copy link
Member

beeme1mr commented Dec 6, 2022

Hi @vadasambar, could you please fix the conflicts and resolve the issue with the test?

Copy link
Member

@toddbaert toddbaert left a comment

Choose a reason for hiding this comment

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

Approving with #206 (comment)

Thanks again for all your effort, @vadasambar

@beeme1mr beeme1mr requested a review from AlexsJones January 3, 2023 12:37
@vadasambar
Copy link
Contributor Author

@vadasambar ./flagd start --uri file://home/todd/git/flagd/config/samples/example_flags.yaml -e=yaml works as expected, but

./flagd start --uri file://home/todd/git/flagd/config/samples/example_flags.yaml errors (I believe because in that case it anticipates JSON). I think it would improve usability to default to the evaluator matching the file extension. Do you agree?

What do you think @Kavindu-Dodan ?

Makes sense to me. 👍

@vadasambar
Copy link
Contributor Author

vadasambar

Detecting flag configuration format based on file extension is a great usability improvement. However, I think this require substantial code change as well as proper documentation.

I created a follow-up issue #240, where we could have dedicated focus on this

Thank you for creating the issue 🙏

@vadasambar
Copy link
Contributor Author

Approving with #206 (comment)

Thanks again for all your effort, @vadasambar

Not at all. Thank you for the feedback and review 🙏

@vadasambar
Copy link
Contributor Author

I think we need review from @AlexsJones to merge this PR (not sure if we want to keep it open until #240 is done)

@vadasambar
Copy link
Contributor Author

I think we need review from @AlexsJones
image

@toddbaert
Copy link
Member

I think we need review from @AlexsJones to merge this PR (not sure if we want to keep it open until #240 is done)

I don't think we need to include that in this PR, it seems like something we can roll in later, but feel free to start working on it if you are interested.

vadasambar and others added 16 commits January 3, 2023 15:35
Signed-off-by: Suraj Banakar <surajrbanakar@gmail.com>

feat: wip try replacing json evaluator with a generic file type evaluator
- TODO:
 - still need a way to make the json_evaluator_model more composable
 - replace instances of `json` with the `MUaler` interface
 - implement `MUaler` interface for yaml and json

Signed-off-by: Suraj Banakar <surajrbanakar@gmail.com>

feat: wip pass `yaml` as filetype to `FilePathSync`
- check `yaml.Unmarshal` not able to `Unmarshal` to `json.rawMessage` which is just `[]byte` with `MarshalJSON` and `UnmarshalJSON`
- `FileTypeEvaluator` didn't turn out to be such a good idea because we are reliant on `gojsonschema` to test json schema
- add `example_flags.yaml` file based on `examples_flags.json`
refactor: remove traces of `FileTypeEvaluator`

Signed-off-by: Suraj Banakar <surajrbanakar@gmail.com>

feat: wip try yaml->map->json conversion
- the code compiles and the converted json seems to look good but flagd throws error
- need to look into this ^

Signed-off-by: Suraj Banakar <surajrbanakar@gmail.com>

feat: wip remove yaml annotationt and redundant code
- yaml config -> json config -> json.Unmarshal (<- error here)

Signed-off-by: Suraj Banakar <surajrbanakar@gmail.com>

feat: wip add indentations in the json converted from yaml
- because the evaluator transposer function doesn't understand json without indentations well
- needs more testing

Signed-off-by: Suraj Banakar <surajrbanakar@gmail.com>

feat: refactor

Signed-off-by: Suraj Banakar <surajrbanakar@gmail.com>

feat: add `yaml` and `yml` in evaluator switch case

feat: fix go.mod
- add json-iterator package

Signed-off-by: Suraj Banakar <surajrbanakar@gmail.com>
Signed-off-by: Suraj Banakar <surajrbanakar@gmail.com>
Signed-off-by: Suraj Banakar <surajrbanakar@gmail.com>
- yaml.v2 has a bug where the sub-maps are converted to `map[interface]interface{}` instead of `map[string]interface{}`

Signed-off-by: Suraj Banakar <surajrbanakar@gmail.com>
- update go.mod and go.sum

Signed-off-by: Suraj Banakar <surajrbanakar@gmail.com>
- didn't make a lot of sense to me

Signed-off-by: Suraj Banakar <surajrbanakar@gmail.com>
Signed-off-by: Suraj Banakar <surajrbanakar@gmail.com>
- don't check the file type in when fetching file in filepathsync

Signed-off-by: Suraj Banakar <surajrbanakar@gmail.com>
Signed-off-by: Suraj Banakar <surajrbanakar@gmail.com>
This reverts commit a2efb06.

Signed-off-by: Suraj Banakar <surajrbanakar@gmail.com>
- not sure if this is the best way to do this

Signed-off-by: Suraj Banakar <surajrbanakar@gmail.com>
Signed-off-by: Suraj Banakar <surajrbanakar@gmail.com>
Co-authored-by: Michael Beemer <beeme1mr@users.noreply.github.com>
Signed-off-by: Suraj Banakar(बानकर) | スラジ <34534103+vadasambar@users.noreply.github.com>
- use case X,Y instead of case X -> fallthrough -> case Y
- former is cleaner than latter

Signed-off-by: vadasambar <surajrbanakar@gmail.com>
Signed-off-by: vadasambar <surajrbanakar@gmail.com>
Signed-off-by: vadasambar <surajrbanakar@gmail.com>
@toddbaert toddbaert force-pushed the feat/180/add-yaml-evaluator branch from c11e0df to ecd7eff Compare January 3, 2023 20:35
@beeme1mr beeme1mr merged commit 2dbace5 into open-feature:main Jan 4, 2023
beeme1mr pushed a commit that referenced this pull request Jan 6, 2023
🤖 I have created a release *beep* *boop*
---


##
[0.3.0](v0.2.7...v0.3.0)
(2023-01-06)


### ⚠ BREAKING CHANGES

* consolidated configuration change events into one event
([#241](#241))

### Features

* consolidated configuration change events into one event
([#241](#241))
([f9684b8](f9684b8))
* support yaml evaluator
([#206](#206))
([2dbace5](2dbace5))


### Bug Fixes

* changed eventing configuration mutex to rwmutex and added missing lock
([#220](#220))
([5bbef9e](5bbef9e))
* omitempty targeting field in Flag structure
([#247](#247))
([3f406b5](3f406b5))

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

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.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.

[FEATURE] YAML Evaluator Support
6 participants