From 13125a46d926d90c29827f89bb1c09c9ed035288 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..1589e84b7 100644 --- a/pkg/common/oras/authprovider/azure/azureidentity.go +++ b/pkg/common/oras/authprovider/azure/azureidentity.go @@ -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" @@ -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{