From 58be1caea3091d888507caae56cd8d25496a3b69 Mon Sep 17 00:00:00 2001 From: simorenoh Date: Fri, 15 Mar 2024 17:00:45 -0700 Subject: [PATCH] move logging logic to policy --- sdk/data/azcosmos/cosmos_client.go | 3 --- sdk/data/azcosmos/cosmos_client_retry_policy.go | 3 +++ sdk/data/azcosmos/cosmos_client_retry_policy_test.go | 2 -- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/sdk/data/azcosmos/cosmos_client.go b/sdk/data/azcosmos/cosmos_client.go index ad95aa5cf45d..75ae70cd6eff 100644 --- a/sdk/data/azcosmos/cosmos_client.go +++ b/sdk/data/azcosmos/cosmos_client.go @@ -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 ( @@ -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 diff --git a/sdk/data/azcosmos/cosmos_client_retry_policy.go b/sdk/data/azcosmos/cosmos_client_retry_policy.go index 5cd09c9b66ac..183face6fbd5 100644 --- a/sdk/data/azcosmos/cosmos_client_retry_policy.go +++ b/sdk/data/azcosmos/cosmos_client_retry_policy.go @@ -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 { @@ -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 diff --git a/sdk/data/azcosmos/cosmos_client_retry_policy_test.go b/sdk/data/azcosmos/cosmos_client_retry_policy_test.go index c803905911d9..ad9b5a927660 100644 --- a/sdk/data/azcosmos/cosmos_client_retry_policy_test.go +++ b/sdk/data/azcosmos/cosmos_client_retry_policy_test.go @@ -6,7 +6,6 @@ package azcosmos import ( "context" "encoding/json" - "fmt" "net" "net/url" "testing" @@ -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(