diff --git a/app/internal/base/counter_api.go b/app/internal/base/counter_api.go index b5888e2..f31b1d8 100644 --- a/app/internal/base/counter_api.go +++ b/app/internal/base/counter_api.go @@ -6,9 +6,6 @@ import ( "encoding/json" "fmt" "github.com/kumahq/kuma-counter-demo/pkg/api" - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/trace" "io" "math/rand" "net/http" @@ -115,19 +112,21 @@ func (s *ServerImpl) PostCounter(w http.ResponseWriter, r *http.Request) { s.writeErrorResponse(w, r, http.StatusInternalServerError, api.INTERNAL_ERROR, err, "failed to retrieve zone") return } - ctx, span := otel.Tracer("").Start(r.Context(), "POST-KV") - for i := 0; i < 5; i++ { - span.AddEvent("try", trace.WithAttributes(attribute.Int("try-count", i))) - if s.tryIncrementCounter(ctx, w, r, zone) { + for i := 0; ; i++ { + if s.tryIncrementCounter(w, r, zone) { + return + } + if i == 5 { + s.writeErrorResponse(w, r, http.StatusConflict, api.KV_CONFLICT, nil, "out of retries without success") return } time.Sleep(time.Duration(int64(rand.Intn(50)+50)) * time.Millisecond) } - s.writeErrorResponse(w, r, http.StatusConflict, api.KV_CONFLICT, nil, "out of retries without success") } -func (s *ServerImpl) tryIncrementCounter(ctx context.Context, w http.ResponseWriter, r *http.Request, zone string) bool { +func (s *ServerImpl) tryIncrementCounter(w http.ResponseWriter, r *http.Request, zone string) bool { + ctx := r.Context() counter, err := s.getKey(ctx, COUNTER_KEY) if err != nil { s.logger.InfoContext(ctx, "failed to retrieve counter", "error", err)