Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Bump go feature flag to add reason and errorcode (#35)
Browse files Browse the repository at this point in the history
* Bump goff to deal with reason and error codes

Signed-off-by: Thomas Poignant <thomas.poignant@gofeatureflag.org>

* add new dev file

Signed-off-by: Thomas Poignant <thomas.poignant@gofeatureflag.org>

* adding errorCode and reason into the tests

Signed-off-by: Thomas Poignant <thomas.poignant@gofeatureflag.org>
  • Loading branch information
thomaspoignant authored Jul 19, 2022
1 parent 2053961 commit aa058af
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 54 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ tmp/

# Local dev files
goff-proxy.yaml
flags.yaml


# release folders
dist/
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ GOTEST=$(GOCMD) test
GOVET=$(GOCMD) vet
BINARY_NAME=go-feature-flag-relay-proxy
VERSION?=0.0.0
SERVICE_PORT?=3000
SERVICE_PORT?=1031
DOCKER_REGISTRY?= #if set it should finished by /
EXPORT_RESULT?=false # for CI please set EXPORT_RESULT to true

Expand Down Expand Up @@ -37,7 +37,7 @@ watch: ## Run the code with cosmtrek/air to have automatic reload on changes

swagger: ## Build swagger documentation
$(GOCMD) install github.com/swaggo/swag/cmd/swag@latest
swag init --parseDependency --parseDepth 2
swag init

## Test:
test: ## Run the tests of the project
Expand Down
4 changes: 2 additions & 2 deletions controller/all_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func NewAllFlags(goFF *ffclient.GoFeatureFlag) Controller {
// @Accept json
// @Param data body model.RelayProxyRequest true "Payload of the user we want to challenge against the flag."
// @Success 200 {object} modeldocs.AllFlags "Success"
// @Failure 400 {object} echo.HTTPError "Bad Request"
// @Failure 500 {object} echo.HTTPError "Internal server error"
// @Failure 400 {object} modeldocs.HTTPError "Bad Request"
// @Failure 500 {object} modeldocs.HTTPError "Internal server error"
// @Router /v1/allflags [post]
func (h *allFlags) Handler(c echo.Context) error {
reqBody := new(model.RelayProxyRequest)
Expand Down
4 changes: 2 additions & 2 deletions controller/flag_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ func NewFlagEval(goFF *ffclient.GoFeatureFlag) Controller {
// @Param data body model.RelayProxyRequest true "Payload of the user we want to get all the flags from."
// @Param flag_key path string true "Name of your feature flag"
// @Success 200 {object} model.FlagEval "Success"
// @Failure 400 {object} echo.HTTPError "Bad Request"
// @Failure 500 {object} echo.HTTPError "Internal server error"
// @Failure 400 {object} modeldocs.HTTPError "Bad Request"
// @Failure 500 {object} modeldocs.HTTPError "Internal server error"
// @Router /v1/feature/{flag_key}/eval [post]
func (h *flagEval) Handler(c echo.Context) error {
reqBody := new(model.RelayProxyRequest)
Expand Down
30 changes: 20 additions & 10 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ const docTemplate = `{
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/echo.HTTPError"
"$ref": "#/definitions/modeldocs.HTTPError"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/echo.HTTPError"
"$ref": "#/definitions/modeldocs.HTTPError"
}
}
}
Expand Down Expand Up @@ -150,26 +150,20 @@ const docTemplate = `{
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/echo.HTTPError"
"$ref": "#/definitions/modeldocs.HTTPError"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/echo.HTTPError"
"$ref": "#/definitions/modeldocs.HTTPError"
}
}
}
}
}
},
"definitions": {
"echo.HTTPError": {
"type": "object",
"properties": {
"message": {}
}
},
"model.FlagEval": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -240,6 +234,16 @@ const docTemplate = `{
"modeldocs.FlagState": {
"type": "object",
"properties": {
"errorCode": {
"description": "ErrorCode In cases of abnormal execution indicate an error",
"type": "string",
"example": "FLAG_NOT_FOUND"
},
"reason": {
"description": "Reason indicates the semantic reason for the returned flag value.",
"type": "string",
"example": "TARGETING_MATCH"
},
"timestamp": {
"description": "Timestamp is the time when the flag was evaluated.",
"type": "integer",
Expand All @@ -259,6 +263,12 @@ const docTemplate = `{
"example": "variation-A"
}
}
},
"modeldocs.HTTPError": {
"type": "object",
"properties": {
"message": {}
}
}
}
}`
Expand Down
30 changes: 20 additions & 10 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/echo.HTTPError"
"$ref": "#/definitions/modeldocs.HTTPError"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/echo.HTTPError"
"$ref": "#/definitions/modeldocs.HTTPError"
}
}
}
Expand Down Expand Up @@ -141,26 +141,20 @@
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/echo.HTTPError"
"$ref": "#/definitions/modeldocs.HTTPError"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/echo.HTTPError"
"$ref": "#/definitions/modeldocs.HTTPError"
}
}
}
}
}
},
"definitions": {
"echo.HTTPError": {
"type": "object",
"properties": {
"message": {}
}
},
"model.FlagEval": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -231,6 +225,16 @@
"modeldocs.FlagState": {
"type": "object",
"properties": {
"errorCode": {
"description": "ErrorCode In cases of abnormal execution indicate an error",
"type": "string",
"example": "FLAG_NOT_FOUND"
},
"reason": {
"description": "Reason indicates the semantic reason for the returned flag value.",
"type": "string",
"example": "TARGETING_MATCH"
},
"timestamp": {
"description": "Timestamp is the time when the flag was evaluated.",
"type": "integer",
Expand All @@ -250,6 +254,12 @@
"example": "variation-A"
}
}
},
"modeldocs.HTTPError": {
"type": "object",
"properties": {
"message": {}
}
}
}
}
24 changes: 16 additions & 8 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
basePath: /
definitions:
echo.HTTPError:
properties:
message: {}
type: object
model.FlagEval:
properties:
value: {}
Expand Down Expand Up @@ -55,6 +51,14 @@ definitions:
type: object
modeldocs.FlagState:
properties:
errorCode:
description: ErrorCode In cases of abnormal execution indicate an error
example: FLAG_NOT_FOUND
type: string
reason:
description: Reason indicates the semantic reason for the returned flag value.
example: TARGETING_MATCH
type: string
timestamp:
description: Timestamp is the time when the flag was evaluated.
example: 1652113076
Expand All @@ -71,6 +75,10 @@ definitions:
example: variation-A
type: string
type: object
modeldocs.HTTPError:
properties:
message: {}
type: object
info:
contact:
name: GO feature flag relay proxy
Expand Down Expand Up @@ -136,11 +144,11 @@ paths:
"400":
description: Bad Request
schema:
$ref: '#/definitions/echo.HTTPError'
$ref: '#/definitions/modeldocs.HTTPError'
"500":
description: Internal server error
schema:
$ref: '#/definitions/echo.HTTPError'
$ref: '#/definitions/modeldocs.HTTPError'
summary: allflags returns all the flag for a specific user.
tags:
- flags
Expand Down Expand Up @@ -175,11 +183,11 @@ paths:
"400":
description: Bad Request
schema:
$ref: '#/definitions/echo.HTTPError'
$ref: '#/definitions/modeldocs.HTTPError'
"500":
description: Internal server error
schema:
$ref: '#/definitions/echo.HTTPError'
$ref: '#/definitions/modeldocs.HTTPError'
summary: Evaluate the users with the corresponding flag and return the value
for the user.
tags:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/stretchr/testify v1.8.0
github.com/swaggo/echo-swagger v1.3.3
github.com/swaggo/swag v1.8.3
github.com/thomaspoignant/go-feature-flag v0.26.1
github.com/thomaspoignant/go-feature-flag v0.27.1
go.uber.org/zap v1.21.0
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e
k8s.io/client-go v0.24.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ github.com/swaggo/files v0.0.0-20220610200504-28940afbdbfe/go.mod h1:lKJPbtWzJ9J
github.com/swaggo/swag v1.8.1/go.mod h1:ugemnJsPZm/kRwFUnzBlbHRd0JY9zE1M4F+uy2pAaPQ=
github.com/swaggo/swag v1.8.3 h1:3pZSSCQ//gAH88lfmxM3Cd1+JCsxV8Md6f36b9hrZ5s=
github.com/swaggo/swag v1.8.3/go.mod h1:jMLeXOOmYyjk8PvHTsXBdrubsNd9gUJTTCzL5iBnseg=
github.com/thomaspoignant/go-feature-flag v0.26.1 h1:sWFPAEUJd/KPYl9iZo2+fjtP+oGMBIL/122/LvfLp0c=
github.com/thomaspoignant/go-feature-flag v0.26.1/go.mod h1:jeYNUrwdma2NIZeb/CSdRve6NBMgcGP+ehe3YC2coNI=
github.com/thomaspoignant/go-feature-flag v0.27.1 h1:HcXKbVf9+VE4b91VPPqbpD0WR0YH53XxCY6rp6/MAl0=
github.com/thomaspoignant/go-feature-flag v0.27.1/go.mod h1:jeYNUrwdma2NIZeb/CSdRve6NBMgcGP+ehe3YC2coNI=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
Expand Down
6 changes: 6 additions & 0 deletions modeldocs/allflags_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ type FlagState struct {
// TrackEvents this flag is trackable.
TrackEvents bool `json:"trackEvents" example:"false"`
Failed bool `json:"-"`

// ErrorCode In cases of abnormal execution indicate an error
ErrorCode string `json:"errorCode" example:"FLAG_NOT_FOUND"`

// Reason indicates the semantic reason for the returned flag value.
Reason string `json:"reason" example:"TARGETING_MATCH"`
}
8 changes: 8 additions & 0 deletions modeldocs/http_error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package modeldocs

// HTTPError represents an error that occurred while handling a request.
type HTTPError struct {
Code int `json:"-"`
Message interface{} `json:"message"`
Internal error `json:"-"` // Stores the error returned by an external dependency
}
36 changes: 26 additions & 10 deletions testdata/controller/all_flags/valid_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,71 @@
],
"timestamp": 1652273630,
"variationType": "Default",
"trackEvents": true
"trackEvents": true,
"errorCode":"",
"reason":"DEFAULT"
},
"disable-flag": {
"value": "default",
"value": null,
"timestamp": 1652273630,
"variationType": "Default",
"trackEvents": true
"variationType": "",
"trackEvents": true,
"errorCode":"",
"reason":"DISABLED"
},
"flag-only-for-admin": {
"value": false,
"timestamp": 1652273630,
"variationType": "Default",
"trackEvents": true
"trackEvents": true,
"errorCode":"",
"reason":"DEFAULT"
},
"new-admin-access": {
"value": true,
"timestamp": 1652273630,
"variationType": "True",
"trackEvents": true
"trackEvents": true,
"errorCode":"",
"reason":"SPLIT"
},
"number-flag": {
"value": 1,
"timestamp": 1652273630,
"variationType": "Default",
"trackEvents": true
"trackEvents": true,
"errorCode":"",
"reason":"DEFAULT"
},
"test-flag-rule-apply": {
"value": {
"test": "test"
},
"timestamp": 1652273630,
"variationType": "Default",
"trackEvents": true
"trackEvents": true,
"errorCode":"",
"reason":"DEFAULT"
},
"test-flag-rule-apply-false": {
"value": {
"test": "test"
},
"timestamp": 1652273630,
"variationType": "Default",
"trackEvents": true
"trackEvents": true,
"errorCode":"",
"reason":"DEFAULT"
},
"test-flag-rule-not-apply": {
"value": {
"test": "test"
},
"timestamp": 1652273630,
"variationType": "Default",
"trackEvents": true
"trackEvents": true,
"errorCode":"",
"reason":"DEFAULT"
}
},
"valid": true
Expand Down
6 changes: 4 additions & 2 deletions testdata/controller/flag_eval/disable_flag_response.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"failed": true,
"failed": false,
"trackEvents": true,
"value": "mydefaultFlagValue",
"variationType": "SdkDefault",
"version": 0
"version": 0,
"reason":"DISABLED",
"errorCode": ""
}
Loading

0 comments on commit aa058af

Please sign in to comment.