Skip to content

Commit

Permalink
move logging logic to policy
Browse files Browse the repository at this point in the history
  • Loading branch information
simorenoh committed Mar 16, 2024
1 parent 2d8fee0 commit 58be1ca
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
3 changes: 0 additions & 3 deletions sdk/data/azcosmos/cosmos_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
azlog "github.com/Azure/azure-sdk-for-go/sdk/azcore/log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
azruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming"
"github.com/Azure/azure-sdk-for-go/sdk/internal/log"
)

const (
Expand Down Expand Up @@ -472,7 +470,6 @@ func (c *Client) attachContent(content interface{}, req *policy.Request) error {
}

func (c *Client) executeAndEnsureSuccessResponse(request *policy.Request) (*http.Response, error) {
log.Write(azlog.EventResponse, fmt.Sprintf("\n===== Client preferred regions:\n%v\n=====\n", c.gem.preferredLocations))
response, err := c.pipeline.Do(request)
if err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions sdk/data/azcosmos/cosmos_client_retry_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import (
"net/http"
"time"

azlog "github.com/Azure/azure-sdk-for-go/sdk/azcore/log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
azruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
"github.com/Azure/azure-sdk-for-go/sdk/internal/errorinfo"
"github.com/Azure/azure-sdk-for-go/sdk/internal/log"
)

type clientRetryPolicy struct {
Expand All @@ -32,6 +34,7 @@ func (p *clientRetryPolicy) Do(req *policy.Request) (*http.Response, error) {
if !req.OperationValue(&o) {
return nil, fmt.Errorf("failed to obtain request options, please check request being sent: %s", req.Body())
}
log.Write(azlog.EventResponse, fmt.Sprintf("\n===== Client preferred regions:\n%v\n=====\n", p.gem.preferredLocations))
for {
resolvedEndpoint := p.gem.ResolveServiceEndpoint(p.retryCount, o.isWriteOperation, p.useWriteEndpoint)
req.Raw().Host = resolvedEndpoint.Host
Expand Down
2 changes: 0 additions & 2 deletions sdk/data/azcosmos/cosmos_client_retry_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package azcosmos
import (
"context"
"encoding/json"
"fmt"
"net"
"net/url"
"testing"
Expand Down Expand Up @@ -366,7 +365,6 @@ func TestReadServiceUnavailable(t *testing.T) {
// Request should retry twice and then succeed (2 preferred regions)
assert.NoError(t, err)
assert.True(t, retryPolicy.retryCount == 2)
fmt.Println("we here 1")

// Setting up responses for retrying and failing
srv.AppendResponse(
Expand Down

0 comments on commit 58be1ca

Please sign in to comment.