Skip to content

Commit

Permalink
Add ReportMetrics to azureidentity.go
Browse files Browse the repository at this point in the history
  • Loading branch information
SpongeBob0318 committed Oct 15, 2024
1 parent 1ecd21f commit e34ab64
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 @@ -19,6 +19,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/ratify-project/ratify/pkg/metrics"
"os"
"time"

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()
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)

expiresOn := getACRExpiryIfEarlier(d.identityToken.ExpiresOn)

authConfig := provider.AuthConfig{
Expand Down

0 comments on commit e34ab64

Please sign in to comment.