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: Allow to force update the internal cache #1878

Merged
merged 12 commits into from
May 14, 2024
Merged

Conversation

thomaspoignant
Copy link
Owner

Description

This PR adds functionality to force the call to the retrievers when we know that a change has happened in the configuration of your flag, it will call the retrievers without having to wait for the next polling interval to happen.

A good example of when to call this new API?
We set the polling interval to a high value (~15 minutes) BUT in the CI process of our flag config file, we explicitly call a function (or API) to refresh the flags configuration.

In the relay proxy

A new endpoint has been added and allows to force refresh the call to the retrievers.

⚠️ This endpoint requires having an admin token because we want to avoid any DDOS on this endpoint. You need to configure an admin authorized key inside you relay-proxy configuration under the key authorizedKeys.admin.

example:

curl -X 'POST' \
  'http://<your_domain>:1031/admin/v1/retriever/refresh' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <your_admin_api_key>' \
  -d ''

In the go module

If you are using the go module, a new function is available and is called ffclient.ForceRefresh().
example:

goff, _ := ffclient.New(ffclient.Config{
	PollingInterval: 10 * time.Minute,
	Retriever: &fileretriever.Retriever{
		Path: "xxxx.yaml",
	},
})

// ...
goff.ForceRefresh()
// ...

⚠️ Deprecations / Breaking changes

Before this version, the way to configure your API Keys for the relay proxy was by setting the key apiKeys in the relay-proxy configuration file.

| `apiKeys` | []string | **none** | List of authorized API keys. Each request will need to provide one of authorized key inside `Authorization` header with format `Bearer <api-key>`.<br /><br />_Note: there will be no authorization when this config is not set._ |

Now this way of configuring the authorized API keys is deprecated and we are using a key called authorizedKeys.

| `authorizedKeys` | [authorizedKeys](#type-authorizedkeys) | **none** | List of authorized API keys. |

## type `authorizedKeys`
To be able to control who can access your relay proxy, you can set a list of authorized keys.
| Field name | Type | Default | Description |
|--------------|----------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `evaluation` | []string | **none** | If set, we will check for each evaluation if an authorized key is provided.<br/>Each request will need to provide one of authorized key inside `Authorization` header with format `Bearer <api-key>`.<br /><br />_Note: there will be no authorization when this config is not set._ |
| `admin` | []string | **none** | You need to set API keys in this field if you want to access the `/v1/admin/*` endpoints.<br/> If no api key is configured the endpoint will be unreachable.<br/>Each request will need to provide one of authorized key inside `Authorization` header with format `Bearer <api-key>`. |

Closes issue(s)

Resolve #1858

Checklist

  • I have tested this code
  • I have added unit test to cover this code
  • I have updated the documentation (README.md and /website/docs)
  • I have followed the contributing guide

Copy link

netlify bot commented May 13, 2024

Deploy Preview for go-feature-flag-doc-preview canceled.

Name Link
🔨 Latest commit 4344470
🔍 Latest deploy log https://app.netlify.com/sites/go-feature-flag-doc-preview/deploys/6642841bce966200081e4fe8

Copy link

codecov bot commented May 13, 2024

Codecov Report

Attention: Patch coverage is 82.08955% with 24 lines in your changes are missing coverage. Please review.

Project coverage is 86.80%. Comparing base (c048469) to head (4344470).

Files Patch % Lines
cmd/relayproxy/api/routes_ofrep.go 35.29% 9 Missing and 2 partials ⚠️
cmd/relayproxy/api/routes_goff.go 41.66% 5 Missing and 2 partials ⚠️
cmd/relayproxy/api/routes_admin.go 57.14% 2 Missing and 1 partial ⚠️
feature_flag.go 80.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1878      +/-   ##
==========================================
+ Coverage   86.72%   86.80%   +0.07%     
==========================================
  Files          89       95       +6     
  Lines        3368     3433      +65     
==========================================
+ Hits         2921     2980      +59     
- Misses        345      349       +4     
- Partials      102      104       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

sonarcloud bot commented May 13, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@thomaspoignant thomaspoignant merged commit 6873eaa into main May 14, 2024
21 of 22 checks passed
@thomaspoignant thomaspoignant deleted the force-refresh-cache branch May 14, 2024 07:48
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) Force call to the retrievers
1 participant