From c38b2168e4ffe412c7722de15ffc844e2b897f7f Mon Sep 17 00:00:00 2001 From: wang jiabao <204268140@qq.com> Date: Tue, 15 Oct 2024 15:01:16 +0800 Subject: [PATCH] Add ReportMetrics to azureidentity.go Signed-off-by: wang jiabao <204268140@qq.com> --- pkg/common/oras/authprovider/azure/azureidentity.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/common/oras/authprovider/azure/azureidentity.go b/pkg/common/oras/authprovider/azure/azureidentity.go index 0a5a00e5c..17df572d9 100644 --- a/pkg/common/oras/authprovider/azure/azureidentity.go +++ b/pkg/common/oras/authprovider/azure/azureidentity.go @@ -19,6 +19,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/ratify-project/ratify/pkg/metrics" "os" "time" @@ -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{