Skip to content

Commit

Permalink
Add ReportMetrics to azureidentity.go
Browse files Browse the repository at this point in the history
Signed-off-by: wang jiabao <[email protected]>
  • Loading branch information
SpongeBob0318 committed Oct 16, 2024
1 parent 1ecd21f commit 13125a4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/common/oras/authprovider/azure/azureidentity.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
re "github.com/ratify-project/ratify/errors"
"github.com/ratify-project/ratify/internal/logger"
provider "github.com/ratify-project/ratify/pkg/common/oras/authprovider"
"github.com/ratify-project/ratify/pkg/metrics"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
Expand Down Expand Up @@ -136,11 +137,16 @@ func (d *azureManagedIdentityAuthProvider) Provide(ctx context.Context, artifact

// create registry client and exchange AAD token for registry refresh token
refreshTokenClient := containerregistry.NewRefreshTokensClient(serverURL)
// The time to start recording the token exchange process
startTime := time.Now()

Check warning on line 141 in pkg/common/oras/authprovider/azure/azureidentity.go

View check run for this annotation

Codecov / codecov/patch

pkg/common/oras/authprovider/azure/azureidentity.go#L140-L141

Added lines #L140 - L141 were not covered by tests
rt, err := refreshTokenClient.GetFromExchange(ctx, "access_token", artifactHostName, d.tenantID, "", d.identityToken.Token)
if err != nil {
return provider.AuthConfig{}, re.ErrorCodeAuthDenied.NewError(re.AuthProvider, "", re.AzureManagedIdentityLink, err, "failed to get refresh token for container registry by azure managed identity token", re.HideStackTrace)
}

// Report the duration of the token exchange to the metrics system
metrics.ReportACRExchangeDuration(ctx, time.Since(startTime).Milliseconds(), artifactHostName)

Check warning on line 149 in pkg/common/oras/authprovider/azure/azureidentity.go

View check run for this annotation

Codecov / codecov/patch

pkg/common/oras/authprovider/azure/azureidentity.go#L148-L149

Added lines #L148 - L149 were not covered by tests
expiresOn := getACRExpiryIfEarlier(d.identityToken.ExpiresOn)

authConfig := provider.AuthConfig{
Expand Down

0 comments on commit 13125a4

Please sign in to comment.