Skip to content

Commit

Permalink
useless trace
Browse files Browse the repository at this point in the history
Signed-off-by: Charly Molter <[email protected]>
  • Loading branch information
lahabana committed Nov 15, 2024
1 parent 182b2a3 commit 7ebfa0a
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions app/internal/base/counter_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7ebfa0a

Please sign in to comment.