|
4 | 4 | "context"
|
5 | 5 | "encoding/json"
|
6 | 6 | "fmt"
|
| 7 | + "github.com/frain-dev/convoy/internal/pkg/fflag" |
7 | 8 | "github.com/frain-dev/convoy/pkg/circuit_breaker"
|
8 | 9 | "github.com/frain-dev/convoy/pkg/msgpack"
|
9 | 10 | "net/http"
|
@@ -211,29 +212,31 @@ func (h *Handler) GetEndpoints(w http.ResponseWriter, r *http.Request) {
|
211 | 212 | return
|
212 | 213 | }
|
213 | 214 |
|
214 |
| - // fetch keys from redis and mutate endpoints slice |
215 |
| - keys := make([]string, len(endpoints)) |
216 |
| - for i := 0; i < len(endpoints); i++ { |
217 |
| - keys[i] = fmt.Sprintf("breaker:%s", endpoints[i].UID) |
218 |
| - } |
| 215 | + if h.A.FFlag.CanAccessFeature(fflag.CircuitBreaker) && h.A.Licenser.CircuitBreaking() && len(endpoints) > 0 { |
| 216 | + // fetch keys from redis and mutate endpoints slice |
| 217 | + keys := make([]string, len(endpoints)) |
| 218 | + for i := 0; i < len(endpoints); i++ { |
| 219 | + keys[i] = fmt.Sprintf("breaker:%s", endpoints[i].UID) |
| 220 | + } |
219 | 221 |
|
220 |
| - cbs, err := h.A.Redis.MGet(r.Context(), keys...).Result() |
221 |
| - if err != nil { |
222 |
| - _ = render.Render(w, r, util.NewServiceErrResponse(err)) |
223 |
| - return |
224 |
| - } |
| 222 | + cbs, err := h.A.Redis.MGet(r.Context(), keys...).Result() |
| 223 | + if err != nil { |
| 224 | + _ = render.Render(w, r, util.NewServiceErrResponse(err)) |
| 225 | + return |
| 226 | + } |
225 | 227 |
|
226 |
| - for i := 0; i < len(cbs); i++ { |
227 |
| - if cbs[i] != nil { |
228 |
| - str, ok := cbs[i].(string) |
229 |
| - if ok { |
230 |
| - var c circuit_breaker.CircuitBreaker |
231 |
| - asBytes := []byte(str) |
232 |
| - innerErr := msgpack.DecodeMsgPack(asBytes, &c) |
233 |
| - if innerErr != nil { |
234 |
| - continue |
| 228 | + for i := 0; i < len(cbs); i++ { |
| 229 | + if cbs[i] != nil { |
| 230 | + str, ok := cbs[i].(string) |
| 231 | + if ok { |
| 232 | + var c circuit_breaker.CircuitBreaker |
| 233 | + asBytes := []byte(str) |
| 234 | + innerErr := msgpack.DecodeMsgPack(asBytes, &c) |
| 235 | + if innerErr != nil { |
| 236 | + continue |
| 237 | + } |
| 238 | + endpoints[i].FailureRate = c.FailureRate |
235 | 239 | }
|
236 |
| - endpoints[i].FailureRate = c.FailureRate |
237 | 240 | }
|
238 | 241 | }
|
239 | 242 | }
|
@@ -505,6 +508,11 @@ func (h *Handler) PauseEndpoint(w http.ResponseWriter, r *http.Request) {
|
505 | 508 | // @Security ApiKeyAuth
|
506 | 509 | // @Router /v1/projects/{projectID}/endpoints/{endpointID}/activate [post]
|
507 | 510 | func (h *Handler) ActivateEndpoint(w http.ResponseWriter, r *http.Request) {
|
| 511 | + if !h.A.Licenser.CircuitBreaking() || !h.A.FFlag.CanAccessFeature(fflag.CircuitBreaker) { |
| 512 | + _ = render.Render(w, r, util.NewErrorResponse("feature not enabled", http.StatusBadRequest)) |
| 513 | + return |
| 514 | + } |
| 515 | + |
508 | 516 | project, err := h.retrieveProject(r)
|
509 | 517 | if err != nil {
|
510 | 518 | _ = render.Render(w, r, util.NewErrorResponse(err.Error(), http.StatusBadRequest))
|
|
0 commit comments