Skip to content

Commit

Permalink
Adding test + fixing OFREP issue (#1760)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Poignant <thomas.poignant@gofeatureflag.org>
  • Loading branch information
thomaspoignant committed Apr 15, 2024
1 parent 2a35d96 commit add7232
Show file tree
Hide file tree
Showing 28 changed files with 512 additions and 29 deletions.
1 change: 1 addition & 0 deletions cmd/relayproxy/controller/all_flags.go
Expand Up @@ -26,6 +26,7 @@ func NewAllFlags(goFF *ffclient.GoFeatureFlag, metrics metric.Metrics) Controlle

// Handler is the entry point for the allFlags endpoint
// @Summary All flags variations for a user
// @Tags GO Feature Flag Evaluation API
// @Description Making a **POST** request to the URL `/v1/allflags` will give you the values of all the flags for
// @Description this user.
// @Description
Expand Down
1 change: 1 addition & 0 deletions cmd/relayproxy/controller/collect_eval_data.go
Expand Up @@ -28,6 +28,7 @@ func NewCollectEvalData(goFF *ffclient.GoFeatureFlag, metrics metric.Metrics) Co

// Handler is the entry point for the data/collector endpoint
// @Summary Endpoint to send usage of your flags to be collected
// @Tags GO Feature Flag Evaluation API
// @Description This endpoint is receiving the events of your flags usage to send them in the data collector.
// @Description
// @Description It is used by the different Open Feature providers to send in bulk all the cached events to avoid
Expand Down
1 change: 1 addition & 0 deletions cmd/relayproxy/controller/flag_eval.go
Expand Up @@ -27,6 +27,7 @@ func NewFlagEval(goFF *ffclient.GoFeatureFlag, metrics metric.Metrics) Controlle

// Handler is the entry point for the flag eval endpoint
// @Summary Evaluate a feature flag
// @Tags GO Feature Flag Evaluation API
// @Description Making a **POST** request to the URL `/v1/feature/<your_flag_name>/eval` will give you the value of the
// @Description flag for this user.
// @Description
Expand Down
1 change: 1 addition & 0 deletions cmd/relayproxy/controller/health.go
Expand Up @@ -20,6 +20,7 @@ func NewHealth(monitoring service.Monitoring) Controller {

// Handler is the entry point for this API
// @Summary Health
// @Tags Monitoring
// @Description Making a **GET** request to the URL path `/health` will tell you if the relay proxy is ready to serve
// @Description traffic.
// @Description
Expand Down
1 change: 1 addition & 0 deletions cmd/relayproxy/controller/info.go
Expand Up @@ -19,6 +19,7 @@ func NewInfo(monitoring service.Monitoring) Controller {

// Handler is the entry point for the Info API
// @Summary Info
// @Tags Monitoring
// @Description Making a **GET** request to the URL path `/info` will give you information about the actual state
// @Description of the relay proxy.
// @Description
Expand Down
1 change: 1 addition & 0 deletions cmd/relayproxy/controller/ws_flag_change.go
Expand Up @@ -32,6 +32,7 @@ type wsFlagChange struct {

// Handler is the entry point for the websocket endpoint to get notified when a flag has been edited
// @Summary Websocket endpoint to be notified about flag changes
// @Tags GO Feature Flag Evaluation API
// @Description This endpoint is a websocket endpoint to be notified about flag changes, every change
// @Description will send a request to the client with a model.DiffCache format.
// @Description
Expand Down
27 changes: 27 additions & 0 deletions cmd/relayproxy/docs/docs.go
Expand Up @@ -32,6 +32,9 @@ const docTemplate = `{
"produces": [
"application/json"
],
"tags": [
"Monitoring"
],
"summary": "Health",
"responses": {
"200": {
Expand All @@ -49,6 +52,9 @@ const docTemplate = `{
"produces": [
"application/json"
],
"tags": [
"Monitoring"
],
"summary": "Info",
"responses": {
"200": {
Expand All @@ -66,6 +72,9 @@ const docTemplate = `{
"produces": [
"text/plain"
],
"tags": [
"Monitoring"
],
"summary": "Prometheus endpoint",
"responses": {
"200": {
Expand All @@ -91,6 +100,9 @@ const docTemplate = `{
"produces": [
"application/json"
],
"tags": [
"OpenFeature Remote Evaluation Protocol (OFREP)"
],
"summary": "Open-Feature Remote Evaluation Protocol bulk evaluation API.",
"parameters": [
{
Expand Down Expand Up @@ -157,6 +169,9 @@ const docTemplate = `{
"produces": [
"application/json"
],
"tags": [
"OpenFeature Remote Evaluation Protocol (OFREP)"
],
"summary": "Evaluate a feature flag using the OpenFeature Remote Evaluation Protocol",
"parameters": [
{
Expand Down Expand Up @@ -224,6 +239,9 @@ const docTemplate = `{
"produces": [
"application/json"
],
"tags": [
"GO Feature Flag Evaluation API"
],
"summary": "All flags variations for a user",
"parameters": [
{
Expand Down Expand Up @@ -272,6 +290,9 @@ const docTemplate = `{
"produces": [
"application/json"
],
"tags": [
"GO Feature Flag Evaluation API"
],
"summary": "Endpoint to send usage of your flags to be collected",
"parameters": [
{
Expand Down Expand Up @@ -320,6 +341,9 @@ const docTemplate = `{
"produces": [
"application/json"
],
"tags": [
"GO Feature Flag Evaluation API"
],
"summary": "Evaluate a feature flag",
"parameters": [
{
Expand Down Expand Up @@ -370,6 +394,9 @@ const docTemplate = `{
"produces": [
"application/json"
],
"tags": [
"GO Feature Flag Evaluation API"
],
"summary": "Websocket endpoint to be notified about flag changes",
"parameters": [
{
Expand Down
27 changes: 27 additions & 0 deletions cmd/relayproxy/docs/swagger.json
Expand Up @@ -24,6 +24,9 @@
"produces": [
"application/json"
],
"tags": [
"Monitoring"
],
"summary": "Health",
"responses": {
"200": {
Expand All @@ -41,6 +44,9 @@
"produces": [
"application/json"
],
"tags": [
"Monitoring"
],
"summary": "Info",
"responses": {
"200": {
Expand All @@ -58,6 +64,9 @@
"produces": [
"text/plain"
],
"tags": [
"Monitoring"
],
"summary": "Prometheus endpoint",
"responses": {
"200": {
Expand All @@ -83,6 +92,9 @@
"produces": [
"application/json"
],
"tags": [
"OpenFeature Remote Evaluation Protocol (OFREP)"
],
"summary": "Open-Feature Remote Evaluation Protocol bulk evaluation API.",
"parameters": [
{
Expand Down Expand Up @@ -149,6 +161,9 @@
"produces": [
"application/json"
],
"tags": [
"OpenFeature Remote Evaluation Protocol (OFREP)"
],
"summary": "Evaluate a feature flag using the OpenFeature Remote Evaluation Protocol",
"parameters": [
{
Expand Down Expand Up @@ -216,6 +231,9 @@
"produces": [
"application/json"
],
"tags": [
"GO Feature Flag Evaluation API"
],
"summary": "All flags variations for a user",
"parameters": [
{
Expand Down Expand Up @@ -264,6 +282,9 @@
"produces": [
"application/json"
],
"tags": [
"GO Feature Flag Evaluation API"
],
"summary": "Endpoint to send usage of your flags to be collected",
"parameters": [
{
Expand Down Expand Up @@ -312,6 +333,9 @@
"produces": [
"application/json"
],
"tags": [
"GO Feature Flag Evaluation API"
],
"summary": "Evaluate a feature flag",
"parameters": [
{
Expand Down Expand Up @@ -362,6 +386,9 @@
"produces": [
"application/json"
],
"tags": [
"GO Feature Flag Evaluation API"
],
"summary": "Websocket endpoint to be notified about flag changes",
"parameters": [
{
Expand Down
18 changes: 18 additions & 0 deletions cmd/relayproxy/docs/swagger.yaml
Expand Up @@ -386,6 +386,8 @@ paths:
schema:
$ref: '#/definitions/model.HealthResponse'
summary: Health
tags:
- Monitoring
/info:
get:
description: |-
Expand All @@ -402,6 +404,8 @@ paths:
schema:
$ref: '#/definitions/model.InfoResponse'
summary: Info
tags:
- Monitoring
/metrics:
get:
description: This endpoint is providing metrics about the relay proxy in the
Expand All @@ -414,6 +418,8 @@ paths:
schema:
type: string
summary: Prometheus endpoint
tags:
- Monitoring
/ofrep/v1/evaluate/flags:
post:
consumes:
Expand Down Expand Up @@ -460,6 +466,8 @@ paths:
security:
- ApiKeyAuth: []
summary: Open-Feature Remote Evaluation Protocol bulk evaluation API.
tags:
- OpenFeature Remote Evaluation Protocol (OFREP)
/ofrep/v1/evaluate/flags/{flag_key}:
post:
consumes:
Expand Down Expand Up @@ -505,6 +513,8 @@ paths:
security:
- ApiKeyAuth: []
summary: Evaluate a feature flag using the OpenFeature Remote Evaluation Protocol
tags:
- OpenFeature Remote Evaluation Protocol (OFREP)
/v1/allflags:
post:
consumes:
Expand Down Expand Up @@ -540,6 +550,8 @@ paths:
security:
- ApiKeyAuth: []
summary: All flags variations for a user
tags:
- GO Feature Flag Evaluation API
/v1/data/collector:
post:
consumes:
Expand Down Expand Up @@ -574,6 +586,8 @@ paths:
security:
- ApiKeyAuth: []
summary: Endpoint to send usage of your flags to be collected
tags:
- GO Feature Flag Evaluation API
/v1/feature/{flag_key}/eval:
post:
consumes:
Expand Down Expand Up @@ -619,6 +633,8 @@ paths:
security:
- ApiKeyAuth: []
summary: Evaluate a feature flag
tags:
- GO Feature Flag Evaluation API
/ws/v1/flag/change:
post:
consumes:
Expand Down Expand Up @@ -647,6 +663,8 @@ paths:
schema:
$ref: '#/definitions/modeldocs.HTTPErrorDoc'
summary: Websocket endpoint to be notified about flag changes
tags:
- GO Feature Flag Evaluation API
securityDefinitions:
ApiKeyAuth:
description: Use configured APIKeys in yaml config as authorization keys, disabled
Expand Down
9 changes: 8 additions & 1 deletion cmd/relayproxy/model/ofrep_error_response.go
@@ -1,6 +1,9 @@
package model

import "github.com/thomaspoignant/go-feature-flag/internal/flag"
import (
"fmt"
"github.com/thomaspoignant/go-feature-flag/internal/flag"
)

type OFREPEvaluateErrorResponse struct {
OFREPCommonErrorResponse `json:",inline" yaml:",inline" toml:",inline"`
Expand All @@ -11,3 +14,7 @@ type OFREPCommonErrorResponse struct {
ErrorCode flag.ErrorCode `json:"errorCode"`
ErrorDetails string `json:"errorDetails"`
}

func (o *OFREPCommonErrorResponse) Error() string {
return fmt.Sprintf("[%s] %s", o.ErrorCode, o.ErrorDetails)
}
2 changes: 1 addition & 1 deletion cmd/relayproxy/model/ofrep_success_response.go
Expand Up @@ -5,5 +5,5 @@ type OFREPEvaluateSuccessResponse struct {
Value any `json:"value"`
Reason string `json:"reason"`
Variant string `json:"variant"`
Metadata map[string]any `json:"metadata"`
Metadata map[string]any `json:"metadata,omitempty"`
}
1 change: 1 addition & 0 deletions cmd/relayproxy/modeldocs/metricsController.go
Expand Up @@ -5,6 +5,7 @@ import "github.com/labstack/echo/v4"
// FakeMetricsController is the entry point for the allFlags endpoint
//
// @Summary Prometheus endpoint
// @Tags Monitoring
// @Description This endpoint is providing metrics about the relay proxy in the prometheus format.
// @Produce plain
// @Success 200 {object} string
Expand Down

0 comments on commit add7232

Please sign in to comment.