Skip to content

Extend DBDRIVER to load from json_file or json_http and add EvalOnlyMode#247

Merged
zhouzhuojie merged 1 commit into
masterfrom
zz/add-eval-source
Apr 16, 2019
Merged

Extend DBDRIVER to load from json_file or json_http and add EvalOnlyMode#247
zhouzhuojie merged 1 commit into
masterfrom
zz/add-eval-source

Conversation

@zhouzhuojie
Copy link
Copy Markdown
Collaborator

@zhouzhuojie zhouzhuojie commented Apr 16, 2019

Description

Introduced two new sources of evaluation cache.

  • json_file
  • json_http

We can leverage FLAGR_DB_DBDRIVER and FLAGR_DB_DBCONNECTIONSTR and make flagr instances into EvalOnlyMode, which means it will only serve traffic for /api/v1/evaluation/*. It's the first attempt to separate Flagr into data plane and control plane. And EvalOnlyMode makes Flagr even easier to deploy with evaluation cache decoupled from the DB.

/**                                                                                  
DBDriver and DBConnectionStr define how we can write and read flags data.            
For databases, flagr supports sqlite3, mysql and postgres.                           
For read-only evaluation, flagr supports file and http.                              
                                                                                     
Examples:                                                                            
                                                                                     
FLAGR_DB_DBDRIVER     FLAGR_DB_DBCONNECTIONSTR                                       
=================     ===============================================================
"sqlite3"             "/tmp/file.db"                                                 
"sqlite3"             ":memory:"                                                     
"mysql"               "root:@tcp(127.0.0.1:18100)/flagr?parseTime=true"              
"postgres"            "host=myhost user=root dbname=flagr password=mypassword"       
                                                                                     
"json_file"           "/tmp/flags.json"                    # (sets EvalOnlyMode=true)
"json_http"           "https://example.com/flags.json"     # (sets EvalOnlyMode=true)
                                                                                     
*/                                                                                   

This PR also introduced

  • /api/v1/export/eval_cache/json endpoint
  • Adding back SnapshotID to flag's JSON serialization (because we need it to be included in the export, and thus json_file and json_http can load it as well)
  • Refactor eval_cache and adding refresh timeout support

How Has This Been Tested?

Tested locally.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@zhouzhuojie zhouzhuojie changed the title Add eval cache source Add eval cache source to load from json_file or json_http Apr 16, 2019
@zhouzhuojie zhouzhuojie changed the title Add eval cache source to load from json_file or json_http Extend DBDRIVER to load from json_file or json_http and add EvalOnlyMode Apr 16, 2019
Copy link
Copy Markdown

@ziru ziru left a comment

Choose a reason for hiding this comment

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

lgtm

@codecov-io
Copy link
Copy Markdown

codecov-io commented Apr 16, 2019

Codecov Report

Merging #247 into master will decrease coverage by 0.19%.
The diff coverage is 81.37%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #247     +/-   ##
=========================================
- Coverage   82.47%   82.27%   -0.2%     
=========================================
  Files          25       26      +1     
  Lines        1444     1518     +74     
=========================================
+ Hits         1191     1249     +58     
- Misses        193      202      +9     
- Partials       60       67      +7
Impacted Files Coverage Δ
pkg/entity/flag.go 94.28% <ø> (ø) ⬆️
pkg/handler/fixture.go 100% <100%> (ø) ⬆️
pkg/handler/export.go 69.09% <100%> (+2.42%) ⬆️
pkg/handler/handler.go 85.41% <42.85%> (-7.61%) ⬇️
pkg/config/config.go 83.33% <50%> (-2.39%) ⬇️
pkg/handler/eval_cache_fetcher.go 82.35% <82.35%> (ø)
pkg/handler/eval_cache.go 75% <94.11%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6ab20d5...0ec160c. Read the comment docs.

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