From f7b32e4fa38bb52dd43eab4b7f295ba6adc873db Mon Sep 17 00:00:00 2001 From: Pragyesh Mishra Date: Mon, 23 Feb 2026 20:34:12 +0530 Subject: [PATCH 1/5] [fix]: [AH-2686]: error handling --- registry/app/pkg/nuget/local.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/registry/app/pkg/nuget/local.go b/registry/app/pkg/nuget/local.go index 9258c46fda..1196491df3 100644 --- a/registry/app/pkg/nuget/local.go +++ b/registry/app/pkg/nuget/local.go @@ -25,6 +25,7 @@ import ( "strconv" "strings" + "github.com/harness/gitness/app/api/usererror" urlprovider "github.com/harness/gitness/app/url" apicontract "github.com/harness/gitness/registry/app/api/openapi/contracts/artifact" nugetmetadata "github.com/harness/gitness/registry/app/metadata/nuget" @@ -266,7 +267,7 @@ func (c *localRegistry) UploadPackage( metadata, err = c.buildMetadata(r) if err != nil { - return headers, "", fmt.Errorf( + return headers, "", usererror.BadRequestf( "failed to build metadata for registry: %d with error: %w", info.RegistryID, err) } @@ -274,7 +275,7 @@ func (c *localRegistry) UploadPackage( info.Version = metadata.PackageMetadata.Version normalisedVersion, err2 := validateAndNormaliseVersion(info.Version) if err2 != nil { - return headers, "", fmt.Errorf("nuspec file contains an invalid version: %s with "+ + return headers, "", usererror.BadRequestf("nuspec file contains an invalid version: %s with "+ "package name: %s, registry name: %s", info.Version, info.Image, info.RegIdentifier) } info.Version = normalisedVersion @@ -286,9 +287,9 @@ func (c *localRegistry) UploadPackage( "failed to check package version existence for id: %s , version: %s "+ "with registry: %d with error: %w", info.Image, info.Version, info.RegistryID, err) } else if !versionExists { - return headers, "", fmt.Errorf( + return headers, "", usererror.BadRequestf( "can't push symbol package as package doesn't exists for id: %s , version: %s "+ - "with registry: %d with error: %w", info.Image, info.Version, info.RegistryID, err) + "with registry: %d", info.Image, info.Version, info.RegistryID) } fileExtension = SymbolsPackageExtension } else { From 2006b85c0462a0e002b598b4cb2bb70a1ab7e477 Mon Sep 17 00:00:00 2001 From: Pragyesh Mishra Date: Mon, 23 Feb 2026 21:51:10 +0530 Subject: [PATCH 2/5] [fix]: [AH-2686]: added logs --- registry/app/pkg/nuget/local.go | 67 +++++++++++++++++++++++++--- registry/app/pkg/nuget/proxy.go | 77 ++++++++++++++++++++++++++++----- 2 files changed, 127 insertions(+), 17 deletions(-) diff --git a/registry/app/pkg/nuget/local.go b/registry/app/pkg/nuget/local.go index 1196491df3..da04cfb877 100644 --- a/registry/app/pkg/nuget/local.go +++ b/registry/app/pkg/nuget/local.go @@ -75,8 +75,10 @@ func (c *localRegistry) GetServiceEndpoint( ctx context.Context, info nugettype.ArtifactInfo, ) *nugettype.ServiceEndpoint { + log.Ctx(ctx).Debug().Msgf("getting service endpoint for registry: %s", info.RegIdentifier) packageURL := c.urlProvider.PackageURL(ctx, info.RootIdentifier+"/"+info.RegIdentifier, "nuget") serviceEndpoints := buildServiceEndpoint(packageURL) + log.Ctx(ctx).Debug().Msgf("service endpoint built successfully for registry: %s", info.RegIdentifier) return serviceEndpoints } @@ -84,15 +86,18 @@ func (c *localRegistry) GetServiceEndpointV2( ctx context.Context, info nugettype.ArtifactInfo, ) *nugettype.ServiceEndpointV2 { + log.Ctx(ctx).Debug().Msgf("getting service endpoint v2 for registry: %s", info.RegIdentifier) packageURL := c.urlProvider.PackageURL(ctx, info.RootIdentifier+"/"+info.RegIdentifier, "nuget") serviceEndpoints := buildServiceV2Endpoint(packageURL) + log.Ctx(ctx).Debug().Msgf("service endpoint v2 built successfully for registry: %s", info.RegIdentifier) return serviceEndpoints } func (c *localRegistry) GetServiceMetadataV2( - _ context.Context, + ctx context.Context, _ nugettype.ArtifactInfo, ) *nugettype.ServiceMetadataV2 { + log.Ctx(ctx).Debug().Msg("getting service metadata v2") return getServiceMetadataV2() } @@ -100,11 +105,14 @@ func (c *localRegistry) ListPackageVersion( ctx context.Context, info nugettype.ArtifactInfo, ) (response *nugettype.PackageVersion, err error) { + log.Ctx(ctx).Debug().Msgf("listing package versions for registry: %d, image: %s", info.RegistryID, info.Image) artifacts, err2 := c.artifactDao.GetByRegistryIDAndImage(ctx, info.RegistryID, info.Image) if err2 != nil { + log.Ctx(ctx).Error().Err(err2).Msgf("failed to get artifacts for registry: %d and image: %s", info.RegistryID, info.Image) return nil, fmt.Errorf( "failed to get artifacts for registry: %d and image: %s: %w", info.RegistryID, info.Image, err2) } else if artifacts == nil || len(*artifacts) == 0 { + log.Ctx(ctx).Warn().Msgf("no artifacts found for registry: %d and image: %s", info.RegistryID, info.Image) return nil, fmt.Errorf( "no artifacts found for registry: %d and image: %s", info.RegistryID, info.Image) } @@ -112,6 +120,7 @@ func (c *localRegistry) ListPackageVersion( for _, artifact := range *artifacts { versions = append(versions, artifact.Version) } + log.Ctx(ctx).Info().Msgf("successfully listed %d package versions for registry: %d, image: %s", len(versions), info.RegistryID, info.Image) return &nugettype.PackageVersion{ Versions: versions, }, nil @@ -121,15 +130,19 @@ func (c *localRegistry) ListPackageVersionV2( ctx context.Context, info nugettype.ArtifactInfo, ) (response *nugettype.FeedResponse, err error) { + log.Ctx(ctx).Debug().Msgf("listing package versions v2 for registry: %d, image: %s", info.RegistryID, info.Image) packageURL := c.urlProvider.PackageURL(ctx, info.RootIdentifier+"/"+info.RegIdentifier, "nuget") artifacts, err2 := c.artifactDao.GetByRegistryIDAndImage(ctx, info.RegistryID, info.Image) if err2 != nil { + log.Ctx(ctx).Error().Err(err2).Msgf("failed to get artifacts for registry: %d and image: %s", info.RegistryID, info.Image) return nil, fmt.Errorf( "failed to get artifacts for registry: %d and image: %s: %w", info.RegistryID, info.Image, err2) } else if artifacts == nil || len(*artifacts) == 0 { + log.Ctx(ctx).Warn().Msgf("no artifacts found for registry: %d and image: %s", info.RegistryID, info.Image) return nil, fmt.Errorf( "no artifacts found for registry: %d and image: %s", info.RegistryID, info.Image) } + log.Ctx(ctx).Info().Msgf("successfully listed package versions v2 for registry: %d, image: %s", info.RegistryID, info.Image) return createFeedResponse(packageURL, info, artifacts) } @@ -137,11 +150,14 @@ func (c *localRegistry) CountPackageVersionV2( ctx context.Context, info nugettype.ArtifactInfo, ) (count int64, err error) { + log.Ctx(ctx).Debug().Msgf("counting package versions v2 for registry: %d, image: %s", info.RegistryID, info.Image) count, err = c.artifactDao.CountByImageName(ctx, info.RegistryID, info.Image) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to get artifacts count for registry: %d and image: %s", info.RegistryID, info.Image) return 0, fmt.Errorf( "failed to get artifacts count for registry: %d and image: %s: %w", info.RegistryID, info.Image, err) } + log.Ctx(ctx).Info().Msgf("package versions v2 count: %d for registry: %d, image: %s", count, info.RegistryID, info.Image) return count, nil } @@ -149,11 +165,14 @@ func (c *localRegistry) CountPackageV2( ctx context.Context, info nugettype.ArtifactInfo, searchTerm string, ) (count int64, err error) { + log.Ctx(ctx).Debug().Msgf("counting packages v2 for registry: %d, searchTerm: %s", info.RegistryID, searchTerm) count, err = c.artifactDao.CountByImageName(ctx, info.RegistryID, strings.ToLower(searchTerm)) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to get artifacts count for registry: %d and searchTerm: %s", info.RegistryID, searchTerm) return 0, fmt.Errorf( "failed to get artifacts count for registry: %d and image: %s: %w", info.RegistryID, searchTerm, err) } + log.Ctx(ctx).Info().Msgf("packages v2 count: %d for registry: %d, searchTerm: %s", count, info.RegistryID, searchTerm) return count, nil } @@ -161,12 +180,15 @@ func (c *localRegistry) SearchPackageV2( ctx context.Context, info nugettype.ArtifactInfo, searchTerm string, limit int, offset int, ) (*nugettype.FeedResponse, error) { + log.Ctx(ctx).Debug().Msgf("searching packages v2 for registry: %d, searchTerm: %s, limit: %d, offset: %d", info.RegistryID, searchTerm, limit, offset) packageURL := c.urlProvider.PackageURL(ctx, info.RootIdentifier+"/"+info.RegIdentifier, "nuget") artifacts, err := c.artifactDao.SearchByImageName(ctx, info.RegistryID, strings.ToLower(searchTerm), limit, offset) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to search artifacts for registry: %d and searchTerm: %s", info.RegistryID, searchTerm) return nil, fmt.Errorf( "failed to get artifacts for registry: %d and image: %s: %w", info.RegistryID, searchTerm, err) } + log.Ctx(ctx).Info().Msgf("successfully searched packages v2 for registry: %d, searchTerm: %s", info.RegistryID, searchTerm) return createSearchV2Response(packageURL, artifacts, searchTerm, limit, offset) } @@ -175,18 +197,22 @@ func (c *localRegistry) SearchPackage( info nugettype.ArtifactInfo, searchTerm string, limit int, offset int, ) (*nugettype.SearchResultResponse, error) { + log.Ctx(ctx).Debug().Msgf("searching packages for registry: %d, searchTerm: %s, limit: %d, offset: %d", info.RegistryID, searchTerm, limit, offset) packageURL := c.urlProvider.PackageURL(ctx, info.RootIdentifier+"/"+info.RegIdentifier, "nuget") artifacts, err := c.artifactDao.SearchByImageName(ctx, info.RegistryID, strings.ToLower(searchTerm), limit, offset) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to search artifacts for registry: %d and searchTerm: %s", info.RegistryID, searchTerm) return nil, fmt.Errorf( "failed to get artifacts for registry: %d and image: %s: %w", info.RegistryID, searchTerm, err) } count, err2 := c.artifactDao.CountByImageName(ctx, info.RegistryID, strings.ToLower(searchTerm)) if err2 != nil { + log.Ctx(ctx).Error().Err(err2).Msgf("failed to get artifacts count for registry: %d and searchTerm: %s", info.RegistryID, searchTerm) return nil, fmt.Errorf( "failed to get artifacts count for registry: %d and image: %s: %w", info.RegistryID, info.Image, err2) } + log.Ctx(ctx).Info().Msgf("successfully searched packages for registry: %d, searchTerm: %s, count: %d", info.RegistryID, searchTerm, count) return createSearchResponse(packageURL, artifacts, count) } @@ -194,15 +220,19 @@ func (c *localRegistry) GetPackageMetadata( ctx context.Context, info nugettype.ArtifactInfo, ) (nugettype.RegistrationResponse, error) { + log.Ctx(ctx).Debug().Msgf("getting package metadata for registry: %d, image: %s", info.RegistryID, info.Image) packageURL := c.urlProvider.PackageURL(ctx, info.RootIdentifier+"/"+info.RegIdentifier, "nuget") artifacts, err2 := c.artifactDao.GetByRegistryIDAndImage(ctx, info.RegistryID, info.Image) if err2 != nil { + log.Ctx(ctx).Error().Err(err2).Msgf("failed to get artifacts for registry: %d and image: %s", info.RegistryID, info.Image) return nil, fmt.Errorf( "failed to get artifacts for registry: %d and image: %s: %w", info.RegistryID, info.Image, err2) } else if artifacts == nil || len(*artifacts) == 0 { + log.Ctx(ctx).Warn().Msgf("no artifacts found for registry: %d and image: %s", info.RegistryID, info.Image) return nil, fmt.Errorf( "no artifacts found for registry: %d and image: %s", info.RegistryID, info.Image) } + log.Ctx(ctx).Info().Msgf("successfully retrieved package metadata for registry: %d, image: %s", info.RegistryID, info.Image) return createRegistrationIndexResponse(packageURL, info, artifacts) } @@ -210,17 +240,21 @@ func (c *localRegistry) GetPackageVersionMetadataV2( ctx context.Context, info nugettype.ArtifactInfo, ) (*nugettype.FeedEntryResponse, error) { + log.Ctx(ctx).Debug().Msgf("getting package version metadata v2 for registry: %d, image: %s, version: %s", info.RegistryID, info.Image, info.Version) packageURL := c.urlProvider.PackageURL(ctx, info.RootIdentifier+"/"+info.RegIdentifier, "nuget") image, err2 := c.imageDao.GetByName(ctx, info.RegistryID, info.Image) if err2 != nil { + log.Ctx(ctx).Error().Err(err2).Msgf("failed to get image for registry: %d and image: %s", info.RegistryID, info.Image) return nil, fmt.Errorf( "failed to get image for registry: %d and image: %s: %w", info.RegistryID, info.Image, err2) } artifact, err2 := c.artifactDao.GetByName(ctx, image.ID, info.Version) if err2 != nil { + log.Ctx(ctx).Error().Err(err2).Msgf("failed to get artifact for registry: %d, image: %s, version: %s", info.RegistryID, info.Image, info.Version) return nil, fmt.Errorf( "failed to get artifacts for registry: %d and image: %s: %w", info.RegistryID, info.Image, err2) } + log.Ctx(ctx).Info().Msgf("successfully retrieved package version metadata v2 for registry: %d, image: %s, version: %s", info.RegistryID, info.Image, info.Version) return createFeedEntryResponse(packageURL, info, artifact) } @@ -228,18 +262,22 @@ func (c *localRegistry) GetPackageVersionMetadata( ctx context.Context, info nugettype.ArtifactInfo, ) (*nugettype.RegistrationLeafResponse, error) { + log.Ctx(ctx).Debug().Msgf("getting package version metadata for registry: %d, image: %s, version: %s", info.RegistryID, info.Image, info.Version) packageURL := c.urlProvider.PackageURL(ctx, info.RootIdentifier+"/"+info.RegIdentifier, "nuget") image, err2 := c.imageDao.GetByName(ctx, info.RegistryID, info.Image) if err2 != nil { + log.Ctx(ctx).Error().Err(err2).Msgf("failed to get image for registry: %d and image: %s", info.RegistryID, info.Image) return nil, fmt.Errorf( "failed to get image for registry: %d and image: %s: %w", info.RegistryID, info.Image, err2) } artifact, err2 := c.artifactDao.GetByName(ctx, image.ID, info.Version) if err2 != nil { + log.Ctx(ctx).Error().Err(err2).Msgf("failed to get artifact for registry: %d, image: %s, version: %s", info.RegistryID, info.Image, info.Version) return nil, fmt.Errorf( "failed to get artifacts for registry: %d and image: %s: %w", info.RegistryID, info.Image, err2) } + log.Ctx(ctx).Info().Msgf("successfully retrieved package version metadata for registry: %d, image: %s, version: %s", info.RegistryID, info.Image, info.Version) return createRegistrationLeafResponse(packageURL, info, artifact), nil } @@ -247,6 +285,7 @@ func (c *localRegistry) UploadPackage( ctx context.Context, info nugettype.ArtifactInfo, fileReader io.ReadCloser, fileBundleType FileBundleType, ) (headers *commons.ResponseHeaders, sha256 string, err error) { + log.Ctx(ctx).Debug().Msgf("uploading package for registry: %d", info.RegistryID) tmpFileName := info.RootIdentifier + "-" + uuid.NewString() var fileExtension string metadata := nugetmetadata.Metadata{} @@ -254,11 +293,13 @@ func (c *localRegistry) UploadPackage( fileInfo, err := c.fileManager.UploadFileNoDBUpdate(ctx, info.RootIdentifier, nil, fileReader, info.RootParentID, info.RegistryID) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to upload file: %s with registry: %d", tmpFileName, info.RegistryID) return headers, "", fmt.Errorf( "failed to upload file: %s with registry: %d with error: %w", tmpFileName, info.RegistryID, err) } r, err := c.fileManager.DownloadFileByDigest(ctx, info.RootIdentifier, fileInfo, info.RootParentID, info.RegistryID) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to download file with registry: %d", info.RegistryID) return headers, "", fmt.Errorf( "failed to download file with registry: %d with error: %w", info.RegistryID, err) @@ -267,14 +308,16 @@ func (c *localRegistry) UploadPackage( metadata, err = c.buildMetadata(r) if err != nil { - return headers, "", usererror.BadRequestf( - "failed to build metadata for registry: %d with error: %w", - info.RegistryID, err) + log.Ctx(ctx).Error().Err(err).Msgf("failed to build metadata for registry %d", + info.RegistryID) + return headers, "", usererror.BadRequestf("failed to build metadata for registry: %d", + info.RegistryID) } info.Image = strings.ToLower(metadata.PackageMetadata.ID) info.Version = metadata.PackageMetadata.Version normalisedVersion, err2 := validateAndNormaliseVersion(info.Version) if err2 != nil { + log.Ctx(ctx).Error().Err(err2).Msgf("nuspec file contains an invalid version: %s with package name: %s, registry name: %s", info.Version, info.Image, info.RegIdentifier) return headers, "", usererror.BadRequestf("nuspec file contains an invalid version: %s with "+ "package name: %s, registry name: %s", info.Version, info.Image, info.RegIdentifier) } @@ -283,10 +326,12 @@ func (c *localRegistry) UploadPackage( if fileBundleType == SymbolsFile { versionExists, err3 := c.localBase.CheckIfVersionExists(ctx, info) if err3 != nil { + log.Ctx(ctx).Error().Err(err3).Msgf("failed to check package version existence for id: %s, version: %s with registry: %d", info.Image, info.Version, info.RegistryID) return headers, "", fmt.Errorf( "failed to check package version existence for id: %s , version: %s "+ "with registry: %d with error: %w", info.Image, info.Version, info.RegistryID, err) } else if !versionExists { + log.Ctx(ctx).Warn().Msgf("can't push symbol package as package doesn't exist for id: %s, version: %s with registry: %d", info.Image, info.Version, info.RegistryID) return headers, "", usererror.BadRequestf( "can't push symbol package as package doesn't exists for id: %s , version: %s "+ "with registry: %d", info.Image, info.Version, info.RegistryID) @@ -311,6 +356,11 @@ func (c *localRegistry) UploadPackage( &nugetmetadata.NugetMetadata{ Metadata: info.Metadata, }, fileInfo, false) + if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to update file manager and create artifact for package: %s, version: %s with registry: %d", info.Image, info.Version, info.RegistryID) + return h, checkSum, err + } + log.Ctx(ctx).Info().Msgf("successfully uploaded package: %s, version: %s for registry: %d with checksum: %s", info.Image, info.Version, info.RegistryID, checkSum) return h, checkSum, err } @@ -371,6 +421,7 @@ func (c *localRegistry) DownloadPackage( ctx context.Context, info nugettype.ArtifactInfo, ) (*commons.ResponseHeaders, *storage.FileReader, string, io.ReadCloser, error) { + log.Ctx(ctx).Debug().Msgf("downloading package for registry: %d, image: %s, version: %s, filename: %s", info.RegistryID, info.Image, info.Version, info.Filename) responseHeaders := &commons.ResponseHeaders{ Headers: make(map[string]string), Code: 0, @@ -379,8 +430,7 @@ func (c *localRegistry) DownloadPackage( path, err := c.fileManager.FindLatestFilePath(ctx, info.RegistryID, "/"+info.Image+"/"+info.Version, info.Filename) if err != nil { - log.Ctx(ctx).Error().Msgf("failed to find file node for id: %s , version: %s "+ - "with registry: %d with error: %v", info.Image, info.Version, info.RegistryID, err) + log.Ctx(ctx).Error().Err(err).Msgf("failed to find file node for id: %s, version: %s with registry: %d", info.Image, info.Version, info.RegistryID) return responseHeaders, nil, "", nil, fmt.Errorf("failed to find file node for id: %s , version: %s "+ "with registry: %d with error: %w", info.Image, info.Version, info.RegistryID, err) } @@ -389,11 +439,13 @@ func (c *localRegistry) DownloadPackage( info.RegistryID, info.RegIdentifier, info.RootIdentifier, true) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to download file for registry: %d, image: %s, version: %s", info.RegistryID, info.Image, info.Version) return responseHeaders, nil, "", nil, err } responseHeaders.Code = http.StatusOK responseHeaders.Headers["Content-Type"] = "application/octet-stream" responseHeaders.Headers["Content-Length"] = strconv.FormatInt(size, 10) + log.Ctx(ctx).Info().Msgf("successfully downloaded package for registry: %d, image: %s, version: %s, size: %d", info.RegistryID, info.Image, info.Version, size) return responseHeaders, fileReader, redirectURL, nil, nil } @@ -401,6 +453,7 @@ func (c *localRegistry) DeletePackage( ctx context.Context, info nugettype.ArtifactInfo, ) (*commons.ResponseHeaders, error) { + log.Ctx(ctx).Debug().Msgf("deleting package for registry: %d, image: %s, version: %s", info.RegistryID, info.Image, info.Version) responseHeaders := &commons.ResponseHeaders{ Headers: make(map[string]string), Code: 0, @@ -408,10 +461,12 @@ func (c *localRegistry) DeletePackage( err := c.localBase.DeleteVersion(ctx, info) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to delete package version with package: %s, version: %s and registry: %d", info.Image, info.Version, info.RegistryID) return responseHeaders, fmt.Errorf("failed to delete package version with package: %s, version: %s and "+ "registry: %d with error: %w", info.Image, info.Version, info.RegistryID, err) } responseHeaders.Code = http.StatusOK + log.Ctx(ctx).Info().Msgf("successfully deleted package for registry: %d, image: %s, version: %s", info.RegistryID, info.Image, info.Version) return responseHeaders, nil } diff --git a/registry/app/pkg/nuget/proxy.go b/registry/app/pkg/nuget/proxy.go index 219b8009e7..f5cfbe91d1 100644 --- a/registry/app/pkg/nuget/proxy.go +++ b/registry/app/pkg/nuget/proxy.go @@ -74,29 +74,37 @@ func (r *proxy) UploadPackage( func (r *proxy) DownloadPackage(ctx context.Context, info nugettype.ArtifactInfo) (*commons.ResponseHeaders, *storage.FileReader, string, io.ReadCloser, error) { + log.Ctx(ctx).Debug().Msgf("downloading package from proxy for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) upstreamProxy, err := r.proxyStore.GetByRegistryIdentifier(ctx, info.ParentID, info.RegIdentifier) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to get upstream proxy for registry: %s", info.RegIdentifier) return nil, nil, "", nil, err } exists := r.localRegistryHelper.FileExists(ctx, info) if exists { + log.Ctx(ctx).Debug().Msgf("file exists in local cache for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) headers, fileReader, redirectURL, err := r.localRegistryHelper.DownloadFile(ctx, info) if err == nil { + log.Ctx(ctx).Info().Msgf("successfully downloaded package from local cache for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) return headers, fileReader, redirectURL, nil, nil } - log.Warn().Ctx(ctx).Msgf("failed to pull from local, attempting streaming from remote, %v", err) + log.Ctx(ctx).Warn().Err(err).Msgf("failed to pull from local, attempting streaming from remote for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) } + log.Ctx(ctx).Debug().Msgf("attempting to download from remote for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) remote, err := NewRemoteRegistryHelper(ctx, r.spaceFinder, *upstreamProxy, r.service) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to create remote registry helper for registry: %s", info.RegIdentifier) return nil, nil, "", nil, err } file, err := remote.GetFile(ctx, info.Image, info.Version, info.ProxyEndpoint, info.Filename) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to get file from remote for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) return nil, nil, "", nil, err } + log.Ctx(ctx).Info().Msgf("successfully downloaded package from remote for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) go func(info nugettype.ArtifactInfo) { ctx2 := context.WithoutCancel(ctx) ctx2 = context.WithValue(ctx2, cfg.GoRoutineKey, "goRoutine") @@ -123,22 +131,26 @@ func (r *proxy) CountPackageVersionV2( ctx context.Context, info nugettype.ArtifactInfo, ) (count int64, err error) { + log.Ctx(ctx).Debug().Msgf("counting package versions v2 from proxy for registry: %s, image: %s", info.RegIdentifier, info.Image) upstreamProxy, err := r.proxyStore.GetByRegistryIdentifier(ctx, info.ParentID, info.RegIdentifier) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to get upstream proxy for registry: %s", info.RegIdentifier) return 0, err } helper, err := NewRemoteRegistryHelper(ctx, r.spaceFinder, *upstreamProxy, r.service) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to create remote registry helper for registry: %s", info.RegIdentifier) return 0, err } - // Use the adapter's CountPackageVersionV2 method directly count, err = helper.CountPackageVersionV2(ctx, info.Image) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to count package versions v2 from remote for registry: %s, image: %s", info.RegIdentifier, info.Image) return 0, err } + log.Ctx(ctx).Info().Msgf("package versions v2 count: %d from proxy for registry: %s, image: %s", count, info.RegIdentifier, info.Image) return count, nil } @@ -146,22 +158,26 @@ func (r *proxy) CountPackageV2( ctx context.Context, info nugettype.ArtifactInfo, searchTerm string, ) (count int64, err error) { + log.Ctx(ctx).Debug().Msgf("counting packages v2 from proxy for registry: %s, searchTerm: %s", info.RegIdentifier, searchTerm) upstreamProxy, err := r.proxyStore.GetByRegistryIdentifier(ctx, info.ParentID, info.RegIdentifier) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to get upstream proxy for registry: %s", info.RegIdentifier) return 0, err } helper, err := NewRemoteRegistryHelper(ctx, r.spaceFinder, *upstreamProxy, r.service) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to create remote registry helper for registry: %s", info.RegIdentifier) return 0, err } - // Use the adapter's CountPackageV2 method directly count, err = helper.CountPackageV2(ctx, searchTerm) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to count packages v2 from remote for registry: %s, searchTerm: %s", info.RegIdentifier, searchTerm) return 0, err } + log.Ctx(ctx).Info().Msgf("packages v2 count: %d from proxy for registry: %s, searchTerm: %s", count, info.RegIdentifier, searchTerm) return count, nil } @@ -169,24 +185,29 @@ func (r *proxy) SearchPackageV2( ctx context.Context, info nugettype.ArtifactInfo, searchTerm string, limit int, offset int, ) (*nugettype.FeedResponse, error) { + log.Ctx(ctx).Debug().Msgf("searching packages v2 from proxy for registry: %s, searchTerm: %s, limit: %d, offset: %d", info.RegIdentifier, searchTerm, limit, offset) upstreamProxy, err := r.proxyStore.GetByRegistryIdentifier(ctx, info.ParentID, info.RegIdentifier) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to get upstream proxy for registry: %s", info.RegIdentifier) return &nugettype.FeedResponse{}, err } helper, err := NewRemoteRegistryHelper(ctx, r.spaceFinder, *upstreamProxy, r.service) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to create remote registry helper for registry: %s", info.RegIdentifier) return &nugettype.FeedResponse{}, err } fileReader, err := helper.SearchPackageV2(ctx, searchTerm, limit, offset) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to search packages v2 from remote for registry: %s, searchTerm: %s", info.RegIdentifier, searchTerm) return &nugettype.FeedResponse{}, err } defer fileReader.Close() var result nugettype.FeedResponse if err = xml.NewDecoder(fileReader).Decode(&result); err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to decode search v2 response for registry: %s, searchTerm: %s", info.RegIdentifier, searchTerm) return &nugettype.FeedResponse{}, err } @@ -204,7 +225,6 @@ func (r *proxy) SearchPackageV2( } result.Links = links - // Update each entry's content URLs to point to our proxy for _, entry := range result.Entries { re := regexp.MustCompile(`Version='([^']+)'`) matches := re.FindStringSubmatch(entry.ID) @@ -212,11 +232,13 @@ func (r *proxy) SearchPackageV2( version := matches[1] err = modifyContent(entry, packageURL, info.Image, version) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to modify content for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, version) return &nugettype.FeedResponse{}, fmt.Errorf("failed to modify content: %w", err) } } } + log.Ctx(ctx).Info().Msgf("successfully searched packages v2 from proxy for registry: %s, searchTerm: %s", info.RegIdentifier, searchTerm) return &result, nil } @@ -224,41 +246,41 @@ func (r *proxy) SearchPackage( ctx context.Context, info nugettype.ArtifactInfo, searchTerm string, limit int, offset int, ) (*nugettype.SearchResultResponse, error) { + log.Ctx(ctx).Debug().Msgf("searching packages from proxy for registry: %s, searchTerm: %s, limit: %d, offset: %d", info.RegIdentifier, searchTerm, limit, offset) upstreamProxy, err := r.proxyStore.GetByRegistryIdentifier(ctx, info.ParentID, info.RegIdentifier) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to get upstream proxy for registry: %s", info.RegIdentifier) return nil, err } helper, err := NewRemoteRegistryHelper(ctx, r.spaceFinder, *upstreamProxy, r.service) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to create remote registry helper for registry: %s", info.RegIdentifier) return nil, err } - // Use the v3 search API directly fileReader, err := helper.SearchPackage(ctx, searchTerm, limit, offset) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to search packages from remote for registry: %s, searchTerm: %s", info.RegIdentifier, searchTerm) return nil, err } defer fileReader.Close() - // Parse the v3 search response directly var result nugettype.SearchResultResponse if err = json.NewDecoder(fileReader).Decode(&result); err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to decode search response for registry: %s, searchTerm: %s", info.RegIdentifier, searchTerm) return nil, err } - // Update URLs in search results to point to our proxy packageURL := r.urlProvider.PackageURL(ctx, info.RootIdentifier+"/"+info.RegIdentifier, "nuget") for _, searchResult := range result.Data { if searchResult != nil { - // Update RegistrationIndexURL to point to our proxy if searchResult.RegistrationIndexURL != "" { registrationURL := getRegistrationIndexURL(packageURL, searchResult.ID) searchResult.RegistrationIndexURL = registrationURL } - // Update RegistrationLeafURL in versions to point to our proxy for _, version := range searchResult.Versions { if version != nil && version.RegistrationLeafURL != "" { registrationURL := getRegistrationIndexURL(packageURL, searchResult.ID) @@ -268,6 +290,7 @@ func (r *proxy) SearchPackage( } } + log.Ctx(ctx).Info().Msgf("successfully searched packages from proxy for registry: %s, searchTerm: %s", info.RegIdentifier, searchTerm) return &result, nil } @@ -275,23 +298,29 @@ func (r *proxy) ListPackageVersion( ctx context.Context, info nugettype.ArtifactInfo, ) (*nugettype.PackageVersion, error) { + log.Ctx(ctx).Debug().Msgf("listing package versions from proxy for registry: %s, image: %s", info.RegIdentifier, info.Image) upstreamProxy, err := r.proxyStore.GetByRegistryIdentifier(ctx, info.ParentID, info.RegIdentifier) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to get upstream proxy for registry: %s", info.RegIdentifier) return &nugettype.PackageVersion{}, err } helper, err := NewRemoteRegistryHelper(ctx, r.spaceFinder, *upstreamProxy, r.service) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to create remote registry helper for registry: %s", info.RegIdentifier) return &nugettype.PackageVersion{}, err } fileReader, err := helper.ListPackageVersion(ctx, info.Image) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to list package versions from remote for registry: %s, image: %s", info.RegIdentifier, info.Image) return &nugettype.PackageVersion{}, err } var result nugettype.PackageVersion if err = json.NewDecoder(fileReader).Decode(&result); err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to decode package versions for registry: %s, image: %s", info.RegIdentifier, info.Image) return &nugettype.PackageVersion{}, err } + log.Ctx(ctx).Info().Msgf("successfully listed %d package versions from proxy for registry: %s, image: %s", len(result.Versions), info.RegIdentifier, info.Image) return &result, nil } @@ -299,17 +328,21 @@ func (r *proxy) GetPackageMetadata( ctx context.Context, info nugettype.ArtifactInfo, ) (nugettype.RegistrationResponse, error) { + log.Ctx(ctx).Debug().Msgf("getting package metadata from proxy for registry: %s, image: %s", info.RegIdentifier, info.Image) upstreamProxy, err := r.proxyStore.GetByRegistryIdentifier(ctx, info.ParentID, info.RegIdentifier) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to get upstream proxy for registry: %s", info.RegIdentifier) return &nugettype.RegistrationIndexResponse{}, err } helper, err := NewRemoteRegistryHelper(ctx, r.spaceFinder, *upstreamProxy, r.service) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to create remote registry helper for registry: %s", info.RegIdentifier) return &nugettype.RegistrationIndexResponse{}, err } fileReader, err := helper.GetPackageMetadata(ctx, info.Image, info.ProxyEndpoint) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to get package metadata from remote for registry: %s, image: %s", info.RegIdentifier, info.Image) return &nugettype.RegistrationIndexResponse{}, err } @@ -318,17 +351,20 @@ func (r *proxy) GetPackageMetadata( if info.ProxyEndpoint != "" { metadata, err2 := parseRegistrationIndexPageResponse(fileReader) if err2 != nil { - //todo: add handling for registration leaf + log.Ctx(ctx).Error().Err(err2).Msgf("failed to parse registration index page response for registry: %s, image: %s", info.RegIdentifier, info.Image) return &nugettype.RegistrationIndexPageResponse{}, err } updateRegistrationIndexPageResponse(metadata, packageURL, info.Image) + log.Ctx(ctx).Info().Msgf("successfully retrieved package metadata page from proxy for registry: %s, image: %s", info.RegIdentifier, info.Image) return metadata, nil } metadata, err2 := parseRegistrationIndexResponse(fileReader) if err2 != nil { + log.Ctx(ctx).Error().Err(err2).Msgf("failed to parse registration index response for registry: %s, image: %s", info.RegIdentifier, info.Image) return &nugettype.RegistrationIndexResponse{}, err } updateRegistrationIndexResponse(metadata, packageURL, info.Image) + log.Ctx(ctx).Info().Msgf("successfully retrieved package metadata from proxy for registry: %s, image: %s", info.RegIdentifier, info.Image) return metadata, nil } @@ -336,20 +372,25 @@ func (r *proxy) ListPackageVersionV2( ctx context.Context, info nugettype.ArtifactInfo, ) (*nugettype.FeedResponse, error) { + log.Ctx(ctx).Debug().Msgf("listing package versions v2 from proxy for registry: %s, image: %s", info.RegIdentifier, info.Image) upstreamProxy, err := r.proxyStore.GetByRegistryIdentifier(ctx, info.ParentID, info.RegIdentifier) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to get upstream proxy for registry: %s", info.RegIdentifier) return &nugettype.FeedResponse{}, err } helper, err := NewRemoteRegistryHelper(ctx, r.spaceFinder, *upstreamProxy, r.service) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to create remote registry helper for registry: %s", info.RegIdentifier) return &nugettype.FeedResponse{}, err } fileReader, err := helper.ListPackageVersionV2(ctx, info.Image) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to list package versions v2 from remote for registry: %s, image: %s", info.RegIdentifier, info.Image) return &nugettype.FeedResponse{}, err } var result nugettype.FeedResponse if err = xml.NewDecoder(fileReader).Decode(&result); err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to decode package versions v2 for registry: %s, image: %s", info.RegIdentifier, info.Image) return &nugettype.FeedResponse{}, err } packageURL := r.urlProvider.PackageURL(ctx, info.RootIdentifier+"/"+info.RegIdentifier, "nuget") @@ -371,11 +412,13 @@ func (r *proxy) ListPackageVersionV2( version := matches[1] err = modifyContent(entry, packageURL, info.Image, version) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to modify content for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, version) return &nugettype.FeedResponse{}, fmt.Errorf("failed to modify content: %w", err) } } } + log.Ctx(ctx).Info().Msgf("successfully listed package versions v2 from proxy for registry: %s, image: %s", info.RegIdentifier, info.Image) return &result, nil } @@ -383,29 +426,36 @@ func (r *proxy) GetPackageVersionMetadataV2( ctx context.Context, info nugettype.ArtifactInfo, ) (*nugettype.FeedEntryResponse, error) { + log.Ctx(ctx).Debug().Msgf("getting package version metadata v2 from proxy for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) packageURL := r.urlProvider.PackageURL(ctx, info.RootIdentifier+"/"+info.RegIdentifier, "nuget") upstreamProxy, err := r.proxyStore.GetByRegistryIdentifier(ctx, info.ParentID, info.RegIdentifier) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to get upstream proxy for registry: %s", info.RegIdentifier) return &nugettype.FeedEntryResponse{}, err } helper, err := NewRemoteRegistryHelper(ctx, r.spaceFinder, *upstreamProxy, r.service) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to create remote registry helper for registry: %s", info.RegIdentifier) return &nugettype.FeedEntryResponse{}, err } fileReader, err := helper.GetPackageVersionMetadataV2(ctx, info.Image, info.Version) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to get package version metadata v2 from remote for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) return &nugettype.FeedEntryResponse{}, err } var result nugettype.FeedEntryResponse if err = xml.NewDecoder(fileReader).Decode(&result); err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to decode package version metadata v2 for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) return &nugettype.FeedEntryResponse{}, err } result.XmlnsD = xmlnsDataServices result.XmlnsM = xmlnsDataServicesMetadata err = modifyContent(&result, packageURL, info.Image, info.Version) if err != nil { + log.Ctx(ctx).Error().Err(err).Msgf("failed to modify content for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) return &nugettype.FeedEntryResponse{}, fmt.Errorf("failed to modify content: %w", err) } + log.Ctx(ctx).Info().Msgf("successfully retrieved package version metadata v2 from proxy for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) return &result, nil } @@ -461,8 +511,10 @@ func (r *proxy) GetPackageVersionMetadata( } func (r *proxy) GetServiceEndpoint(ctx context.Context, info nugettype.ArtifactInfo) *nugettype.ServiceEndpoint { + log.Ctx(ctx).Debug().Msgf("getting service endpoint for proxy registry: %s", info.RegIdentifier) packageURL := r.urlProvider.PackageURL(ctx, info.RootIdentifier+"/"+info.RegIdentifier, "nuget") serviceEndpoints := buildServiceEndpoint(packageURL) + log.Ctx(ctx).Debug().Msgf("service endpoint built successfully for proxy registry: %s", info.RegIdentifier) return serviceEndpoints } @@ -470,12 +522,15 @@ func (r *proxy) GetServiceEndpointV2( ctx context.Context, info nugettype.ArtifactInfo, ) *nugettype.ServiceEndpointV2 { + log.Ctx(ctx).Debug().Msgf("getting service endpoint v2 for proxy registry: %s", info.RegIdentifier) packageURL := r.urlProvider.PackageURL(ctx, info.RootIdentifier+"/"+info.RegIdentifier, "nuget") serviceEndpoints := buildServiceV2Endpoint(packageURL) + log.Ctx(ctx).Debug().Msgf("service endpoint v2 built successfully for proxy registry: %s", info.RegIdentifier) return serviceEndpoints } -func (r *proxy) GetServiceMetadataV2(_ context.Context, _ nugettype.ArtifactInfo) *nugettype.ServiceMetadataV2 { +func (r *proxy) GetServiceMetadataV2(ctx context.Context, _ nugettype.ArtifactInfo) *nugettype.ServiceMetadataV2 { + log.Ctx(ctx).Debug().Msg("getting service metadata v2 for proxy") return getServiceMetadataV2() } From 1a93fc53b8ce6eb8061703d0b3b09e45db9375c5 Mon Sep 17 00:00:00 2001 From: Pragyesh Mishra Date: Mon, 23 Feb 2026 22:28:15 +0530 Subject: [PATCH 3/5] [fix]: [AH-2686]: added logs --- registry/app/pkg/nuget/local.go | 1 - 1 file changed, 1 deletion(-) diff --git a/registry/app/pkg/nuget/local.go b/registry/app/pkg/nuget/local.go index da04cfb877..72a391ebf7 100644 --- a/registry/app/pkg/nuget/local.go +++ b/registry/app/pkg/nuget/local.go @@ -276,7 +276,6 @@ func (c *localRegistry) GetPackageVersionMetadata( return nil, fmt.Errorf( "failed to get artifacts for registry: %d and image: %s: %w", info.RegistryID, info.Image, err2) } - log.Ctx(ctx).Info().Msgf("successfully retrieved package version metadata for registry: %d, image: %s, version: %s", info.RegistryID, info.Image, info.Version) return createRegistrationLeafResponse(packageURL, info, artifact), nil } From 8f43e71e16a7c43dfa53ebe59f63f56376f9fa35 Mon Sep 17 00:00:00 2001 From: Pragyesh Mishra Date: Mon, 23 Feb 2026 22:47:57 +0530 Subject: [PATCH 4/5] [fix]: [AH-2686]: added logs --- registry/app/pkg/nuget/local.go | 56 ++++++++--- registry/app/pkg/nuget/proxy.go | 168 ++++++++++++++++++++++++-------- 2 files changed, 168 insertions(+), 56 deletions(-) diff --git a/registry/app/pkg/nuget/local.go b/registry/app/pkg/nuget/local.go index 72a391ebf7..3ad8dffb85 100644 --- a/registry/app/pkg/nuget/local.go +++ b/registry/app/pkg/nuget/local.go @@ -108,7 +108,9 @@ func (c *localRegistry) ListPackageVersion( log.Ctx(ctx).Debug().Msgf("listing package versions for registry: %d, image: %s", info.RegistryID, info.Image) artifacts, err2 := c.artifactDao.GetByRegistryIDAndImage(ctx, info.RegistryID, info.Image) if err2 != nil { - log.Ctx(ctx).Error().Err(err2).Msgf("failed to get artifacts for registry: %d and image: %s", info.RegistryID, info.Image) + log.Ctx(ctx).Error().Err(err2). + Msgf("failed to get artifacts for registry: %d and image: %s", + info.RegistryID, info.Image) return nil, fmt.Errorf( "failed to get artifacts for registry: %d and image: %s: %w", info.RegistryID, info.Image, err2) } else if artifacts == nil || len(*artifacts) == 0 { @@ -120,7 +122,9 @@ func (c *localRegistry) ListPackageVersion( for _, artifact := range *artifacts { versions = append(versions, artifact.Version) } - log.Ctx(ctx).Info().Msgf("successfully listed %d package versions for registry: %d, image: %s", len(versions), info.RegistryID, info.Image) + log.Ctx(ctx).Info(). + Msgf("successfully listed %d package versions for registry: %d, image: %s", + len(versions), info.RegistryID, info.Image) return &nugettype.PackageVersion{ Versions: versions, }, nil @@ -134,7 +138,9 @@ func (c *localRegistry) ListPackageVersionV2( packageURL := c.urlProvider.PackageURL(ctx, info.RootIdentifier+"/"+info.RegIdentifier, "nuget") artifacts, err2 := c.artifactDao.GetByRegistryIDAndImage(ctx, info.RegistryID, info.Image) if err2 != nil { - log.Ctx(ctx).Error().Err(err2).Msgf("failed to get artifacts for registry: %d and image: %s", info.RegistryID, info.Image) + log.Ctx(ctx).Error().Err(err2). + Msgf("failed to get artifacts for registry: %d and image: %s", + info.RegistryID, info.Image) return nil, fmt.Errorf( "failed to get artifacts for registry: %d and image: %s: %w", info.RegistryID, info.Image, err2) } else if artifacts == nil || len(*artifacts) == 0 { @@ -142,7 +148,9 @@ func (c *localRegistry) ListPackageVersionV2( return nil, fmt.Errorf( "no artifacts found for registry: %d and image: %s", info.RegistryID, info.Image) } - log.Ctx(ctx).Info().Msgf("successfully listed package versions v2 for registry: %d, image: %s", info.RegistryID, info.Image) + log.Ctx(ctx).Info(). + Msgf("successfully listed package versions v2 for registry: %d, image: %s", + info.RegistryID, info.Image) return createFeedResponse(packageURL, info, artifacts) } @@ -153,11 +161,15 @@ func (c *localRegistry) CountPackageVersionV2( log.Ctx(ctx).Debug().Msgf("counting package versions v2 for registry: %d, image: %s", info.RegistryID, info.Image) count, err = c.artifactDao.CountByImageName(ctx, info.RegistryID, info.Image) if err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to get artifacts count for registry: %d and image: %s", info.RegistryID, info.Image) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to get artifacts count for registry: %d and image: %s", + info.RegistryID, info.Image) return 0, fmt.Errorf( "failed to get artifacts count for registry: %d and image: %s: %w", info.RegistryID, info.Image, err) } - log.Ctx(ctx).Info().Msgf("package versions v2 count: %d for registry: %d, image: %s", count, info.RegistryID, info.Image) + log.Ctx(ctx).Info(). + Msgf("package versions v2 count: %d for registry: %d, image: %s", + count, info.RegistryID, info.Image) return count, nil } @@ -168,7 +180,9 @@ func (c *localRegistry) CountPackageV2( log.Ctx(ctx).Debug().Msgf("counting packages v2 for registry: %d, searchTerm: %s", info.RegistryID, searchTerm) count, err = c.artifactDao.CountByImageName(ctx, info.RegistryID, strings.ToLower(searchTerm)) if err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to get artifacts count for registry: %d and searchTerm: %s", info.RegistryID, searchTerm) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to get artifacts count for registry: %d and searchTerm: %s", + info.RegistryID, searchTerm) return 0, fmt.Errorf( "failed to get artifacts count for registry: %d and image: %s: %w", info.RegistryID, searchTerm, err) } @@ -180,15 +194,21 @@ func (c *localRegistry) SearchPackageV2( ctx context.Context, info nugettype.ArtifactInfo, searchTerm string, limit int, offset int, ) (*nugettype.FeedResponse, error) { - log.Ctx(ctx).Debug().Msgf("searching packages v2 for registry: %d, searchTerm: %s, limit: %d, offset: %d", info.RegistryID, searchTerm, limit, offset) + log.Ctx(ctx).Debug(). + Msgf("searching packages v2 for registry: %d, searchTerm: %s, limit: %d, offset: %d", + info.RegistryID, searchTerm, limit, offset) packageURL := c.urlProvider.PackageURL(ctx, info.RootIdentifier+"/"+info.RegIdentifier, "nuget") artifacts, err := c.artifactDao.SearchByImageName(ctx, info.RegistryID, strings.ToLower(searchTerm), limit, offset) if err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to search artifacts for registry: %d and searchTerm: %s", info.RegistryID, searchTerm) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to search artifacts for registry: %d and searchTerm: %s", + info.RegistryID, searchTerm) return nil, fmt.Errorf( "failed to get artifacts for registry: %d and image: %s: %w", info.RegistryID, searchTerm, err) } - log.Ctx(ctx).Info().Msgf("successfully searched packages v2 for registry: %d, searchTerm: %s", info.RegistryID, searchTerm) + log.Ctx(ctx).Info(). + Msgf("successfully searched packages v2 for registry: %d, searchTerm: %s", + info.RegistryID, searchTerm) return createSearchV2Response(packageURL, artifacts, searchTerm, limit, offset) } @@ -197,22 +217,30 @@ func (c *localRegistry) SearchPackage( info nugettype.ArtifactInfo, searchTerm string, limit int, offset int, ) (*nugettype.SearchResultResponse, error) { - log.Ctx(ctx).Debug().Msgf("searching packages for registry: %d, searchTerm: %s, limit: %d, offset: %d", info.RegistryID, searchTerm, limit, offset) + log.Ctx(ctx).Debug(). + Msgf("searching packages for registry: %d, searchTerm: %s, limit: %d, offset: %d", + info.RegistryID, searchTerm, limit, offset) packageURL := c.urlProvider.PackageURL(ctx, info.RootIdentifier+"/"+info.RegIdentifier, "nuget") artifacts, err := c.artifactDao.SearchByImageName(ctx, info.RegistryID, strings.ToLower(searchTerm), limit, offset) if err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to search artifacts for registry: %d and searchTerm: %s", info.RegistryID, searchTerm) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to search artifacts for registry: %d and searchTerm: %s", + info.RegistryID, searchTerm) return nil, fmt.Errorf( "failed to get artifacts for registry: %d and image: %s: %w", info.RegistryID, searchTerm, err) } count, err2 := c.artifactDao.CountByImageName(ctx, info.RegistryID, strings.ToLower(searchTerm)) if err2 != nil { - log.Ctx(ctx).Error().Err(err2).Msgf("failed to get artifacts count for registry: %d and searchTerm: %s", info.RegistryID, searchTerm) + log.Ctx(ctx).Error().Err(err2). + Msgf("failed to get artifacts count for registry: %d and searchTerm: %s", + info.RegistryID, searchTerm) return nil, fmt.Errorf( "failed to get artifacts count for registry: %d and image: %s: %w", info.RegistryID, info.Image, err2) } - log.Ctx(ctx).Info().Msgf("successfully searched packages for registry: %d, searchTerm: %s, count: %d", info.RegistryID, searchTerm, count) + log.Ctx(ctx).Info(). + Msgf("successfully searched packages for registry: %d, searchTerm: %s, count: %d", + info.RegistryID, searchTerm, count) return createSearchResponse(packageURL, artifacts, count) } diff --git a/registry/app/pkg/nuget/proxy.go b/registry/app/pkg/nuget/proxy.go index f5cfbe91d1..3213d474b4 100644 --- a/registry/app/pkg/nuget/proxy.go +++ b/registry/app/pkg/nuget/proxy.go @@ -74,7 +74,9 @@ func (r *proxy) UploadPackage( func (r *proxy) DownloadPackage(ctx context.Context, info nugettype.ArtifactInfo) (*commons.ResponseHeaders, *storage.FileReader, string, io.ReadCloser, error) { - log.Ctx(ctx).Debug().Msgf("downloading package from proxy for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) + log.Ctx(ctx).Debug(). + Msgf("downloading package from proxy for registry: %s, image: %s, version: %s", + info.RegIdentifier, info.Image, info.Version) upstreamProxy, err := r.proxyStore.GetByRegistryIdentifier(ctx, info.ParentID, info.RegIdentifier) if err != nil { log.Ctx(ctx).Error().Err(err).Msgf("failed to get upstream proxy for registry: %s", info.RegIdentifier) @@ -83,16 +85,24 @@ func (r *proxy) DownloadPackage(ctx context.Context, info nugettype.ArtifactInfo exists := r.localRegistryHelper.FileExists(ctx, info) if exists { - log.Ctx(ctx).Debug().Msgf("file exists in local cache for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) + log.Ctx(ctx).Debug(). + Msgf("file exists in local cache for registry: %s, image: %s, version: %s", + info.RegIdentifier, info.Image, info.Version) headers, fileReader, redirectURL, err := r.localRegistryHelper.DownloadFile(ctx, info) if err == nil { - log.Ctx(ctx).Info().Msgf("successfully downloaded package from local cache for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) + log.Ctx(ctx).Info(). + Msgf("successfully downloaded package from local cache for registry: %s, image: %s, version: %s", + info.RegIdentifier, info.Image, info.Version) return headers, fileReader, redirectURL, nil, nil } - log.Ctx(ctx).Warn().Err(err).Msgf("failed to pull from local, attempting streaming from remote for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) + log.Ctx(ctx).Warn().Err(err). + Msgf("failed to pull from local, attempting streaming from remote for registry: %s, image: %s, version: %s", + info.RegIdentifier, info.Image, info.Version) } - log.Ctx(ctx).Debug().Msgf("attempting to download from remote for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) + log.Ctx(ctx).Debug(). + Msgf("attempting to download from remote for registry: %s, image: %s, version: %s", + info.RegIdentifier, info.Image, info.Version) remote, err := NewRemoteRegistryHelper(ctx, r.spaceFinder, *upstreamProxy, r.service) if err != nil { log.Ctx(ctx).Error().Err(err).Msgf("failed to create remote registry helper for registry: %s", info.RegIdentifier) @@ -101,10 +111,14 @@ func (r *proxy) DownloadPackage(ctx context.Context, info nugettype.ArtifactInfo file, err := remote.GetFile(ctx, info.Image, info.Version, info.ProxyEndpoint, info.Filename) if err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to get file from remote for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to get file from remote for registry: %s, image: %s, version: %s", + info.RegIdentifier, info.Image, info.Version) return nil, nil, "", nil, err } - log.Ctx(ctx).Info().Msgf("successfully downloaded package from remote for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) + log.Ctx(ctx).Info(). + Msgf("successfully downloaded package from remote for registry: %s, image: %s, version: %s", + info.RegIdentifier, info.Image, info.Version) go func(info nugettype.ArtifactInfo) { ctx2 := context.WithoutCancel(ctx) ctx2 = context.WithValue(ctx2, cfg.GoRoutineKey, "goRoutine") @@ -131,7 +145,9 @@ func (r *proxy) CountPackageVersionV2( ctx context.Context, info nugettype.ArtifactInfo, ) (count int64, err error) { - log.Ctx(ctx).Debug().Msgf("counting package versions v2 from proxy for registry: %s, image: %s", info.RegIdentifier, info.Image) + log.Ctx(ctx).Debug(). + Msgf("counting package versions v2 from proxy for registry: %s, image: %s", + info.RegIdentifier, info.Image) upstreamProxy, err := r.proxyStore.GetByRegistryIdentifier(ctx, info.ParentID, info.RegIdentifier) if err != nil { log.Ctx(ctx).Error().Err(err).Msgf("failed to get upstream proxy for registry: %s", info.RegIdentifier) @@ -146,11 +162,15 @@ func (r *proxy) CountPackageVersionV2( count, err = helper.CountPackageVersionV2(ctx, info.Image) if err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to count package versions v2 from remote for registry: %s, image: %s", info.RegIdentifier, info.Image) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to count package versions v2 from remote for registry: %s, image: %s", + info.RegIdentifier, info.Image) return 0, err } - log.Ctx(ctx).Info().Msgf("package versions v2 count: %d from proxy for registry: %s, image: %s", count, info.RegIdentifier, info.Image) + log.Ctx(ctx).Info(). + Msgf("package versions v2 count: %d from proxy for registry: %s, image: %s", + count, info.RegIdentifier, info.Image) return count, nil } @@ -158,7 +178,9 @@ func (r *proxy) CountPackageV2( ctx context.Context, info nugettype.ArtifactInfo, searchTerm string, ) (count int64, err error) { - log.Ctx(ctx).Debug().Msgf("counting packages v2 from proxy for registry: %s, searchTerm: %s", info.RegIdentifier, searchTerm) + log.Ctx(ctx).Debug(). + Msgf("counting packages v2 from proxy for registry: %s, searchTerm: %s", + info.RegIdentifier, searchTerm) upstreamProxy, err := r.proxyStore.GetByRegistryIdentifier(ctx, info.ParentID, info.RegIdentifier) if err != nil { log.Ctx(ctx).Error().Err(err).Msgf("failed to get upstream proxy for registry: %s", info.RegIdentifier) @@ -173,11 +195,15 @@ func (r *proxy) CountPackageV2( count, err = helper.CountPackageV2(ctx, searchTerm) if err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to count packages v2 from remote for registry: %s, searchTerm: %s", info.RegIdentifier, searchTerm) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to count packages v2 from remote for registry: %s, searchTerm: %s", + info.RegIdentifier, searchTerm) return 0, err } - log.Ctx(ctx).Info().Msgf("packages v2 count: %d from proxy for registry: %s, searchTerm: %s", count, info.RegIdentifier, searchTerm) + log.Ctx(ctx).Info(). + Msgf("packages v2 count: %d from proxy for registry: %s, searchTerm: %s", + count, info.RegIdentifier, searchTerm) return count, nil } @@ -185,7 +211,9 @@ func (r *proxy) SearchPackageV2( ctx context.Context, info nugettype.ArtifactInfo, searchTerm string, limit int, offset int, ) (*nugettype.FeedResponse, error) { - log.Ctx(ctx).Debug().Msgf("searching packages v2 from proxy for registry: %s, searchTerm: %s, limit: %d, offset: %d", info.RegIdentifier, searchTerm, limit, offset) + log.Ctx(ctx).Debug(). + Msgf("searching packages v2 from proxy for registry: %s, searchTerm: %s, limit: %d, offset: %d", + info.RegIdentifier, searchTerm, limit, offset) upstreamProxy, err := r.proxyStore.GetByRegistryIdentifier(ctx, info.ParentID, info.RegIdentifier) if err != nil { log.Ctx(ctx).Error().Err(err).Msgf("failed to get upstream proxy for registry: %s", info.RegIdentifier) @@ -200,14 +228,18 @@ func (r *proxy) SearchPackageV2( fileReader, err := helper.SearchPackageV2(ctx, searchTerm, limit, offset) if err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to search packages v2 from remote for registry: %s, searchTerm: %s", info.RegIdentifier, searchTerm) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to search packages v2 from remote for registry: %s, searchTerm: %s", + info.RegIdentifier, searchTerm) return &nugettype.FeedResponse{}, err } defer fileReader.Close() var result nugettype.FeedResponse if err = xml.NewDecoder(fileReader).Decode(&result); err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to decode search v2 response for registry: %s, searchTerm: %s", info.RegIdentifier, searchTerm) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to decode search v2 response for registry: %s, searchTerm: %s", + info.RegIdentifier, searchTerm) return &nugettype.FeedResponse{}, err } @@ -232,13 +264,17 @@ func (r *proxy) SearchPackageV2( version := matches[1] err = modifyContent(entry, packageURL, info.Image, version) if err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to modify content for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, version) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to modify content for registry: %s, image: %s, version: %s", + info.RegIdentifier, info.Image, version) return &nugettype.FeedResponse{}, fmt.Errorf("failed to modify content: %w", err) } } } - log.Ctx(ctx).Info().Msgf("successfully searched packages v2 from proxy for registry: %s, searchTerm: %s", info.RegIdentifier, searchTerm) + log.Ctx(ctx).Info(). + Msgf("successfully searched packages v2 from proxy for registry: %s, searchTerm: %s", + info.RegIdentifier, searchTerm) return &result, nil } @@ -246,7 +282,9 @@ func (r *proxy) SearchPackage( ctx context.Context, info nugettype.ArtifactInfo, searchTerm string, limit int, offset int, ) (*nugettype.SearchResultResponse, error) { - log.Ctx(ctx).Debug().Msgf("searching packages from proxy for registry: %s, searchTerm: %s, limit: %d, offset: %d", info.RegIdentifier, searchTerm, limit, offset) + log.Ctx(ctx).Debug(). + Msgf("searching packages from proxy for registry: %s, searchTerm: %s, limit: %d, offset: %d", + info.RegIdentifier, searchTerm, limit, offset) upstreamProxy, err := r.proxyStore.GetByRegistryIdentifier(ctx, info.ParentID, info.RegIdentifier) if err != nil { log.Ctx(ctx).Error().Err(err).Msgf("failed to get upstream proxy for registry: %s", info.RegIdentifier) @@ -261,14 +299,18 @@ func (r *proxy) SearchPackage( fileReader, err := helper.SearchPackage(ctx, searchTerm, limit, offset) if err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to search packages from remote for registry: %s, searchTerm: %s", info.RegIdentifier, searchTerm) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to search packages from remote for registry: %s, searchTerm: %s", + info.RegIdentifier, searchTerm) return nil, err } defer fileReader.Close() var result nugettype.SearchResultResponse if err = json.NewDecoder(fileReader).Decode(&result); err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to decode search response for registry: %s, searchTerm: %s", info.RegIdentifier, searchTerm) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to decode search response for registry: %s, searchTerm: %s", + info.RegIdentifier, searchTerm) return nil, err } @@ -290,7 +332,9 @@ func (r *proxy) SearchPackage( } } - log.Ctx(ctx).Info().Msgf("successfully searched packages from proxy for registry: %s, searchTerm: %s", info.RegIdentifier, searchTerm) + log.Ctx(ctx).Info(). + Msgf("successfully searched packages from proxy for registry: %s, searchTerm: %s", + info.RegIdentifier, searchTerm) return &result, nil } @@ -298,7 +342,9 @@ func (r *proxy) ListPackageVersion( ctx context.Context, info nugettype.ArtifactInfo, ) (*nugettype.PackageVersion, error) { - log.Ctx(ctx).Debug().Msgf("listing package versions from proxy for registry: %s, image: %s", info.RegIdentifier, info.Image) + log.Ctx(ctx).Debug(). + Msgf("listing package versions from proxy for registry: %s, image: %s", + info.RegIdentifier, info.Image) upstreamProxy, err := r.proxyStore.GetByRegistryIdentifier(ctx, info.ParentID, info.RegIdentifier) if err != nil { log.Ctx(ctx).Error().Err(err).Msgf("failed to get upstream proxy for registry: %s", info.RegIdentifier) @@ -312,15 +358,21 @@ func (r *proxy) ListPackageVersion( } fileReader, err := helper.ListPackageVersion(ctx, info.Image) if err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to list package versions from remote for registry: %s, image: %s", info.RegIdentifier, info.Image) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to list package versions from remote for registry: %s, image: %s", + info.RegIdentifier, info.Image) return &nugettype.PackageVersion{}, err } var result nugettype.PackageVersion if err = json.NewDecoder(fileReader).Decode(&result); err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to decode package versions for registry: %s, image: %s", info.RegIdentifier, info.Image) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to decode package versions for registry: %s, image: %s", + info.RegIdentifier, info.Image) return &nugettype.PackageVersion{}, err } - log.Ctx(ctx).Info().Msgf("successfully listed %d package versions from proxy for registry: %s, image: %s", len(result.Versions), info.RegIdentifier, info.Image) + log.Ctx(ctx).Info(). + Msgf("successfully listed %d package versions from proxy for registry: %s, image: %s", + len(result.Versions), info.RegIdentifier, info.Image) return &result, nil } @@ -328,7 +380,9 @@ func (r *proxy) GetPackageMetadata( ctx context.Context, info nugettype.ArtifactInfo, ) (nugettype.RegistrationResponse, error) { - log.Ctx(ctx).Debug().Msgf("getting package metadata from proxy for registry: %s, image: %s", info.RegIdentifier, info.Image) + log.Ctx(ctx).Debug(). + Msgf("getting package metadata from proxy for registry: %s, image: %s", + info.RegIdentifier, info.Image) upstreamProxy, err := r.proxyStore.GetByRegistryIdentifier(ctx, info.ParentID, info.RegIdentifier) if err != nil { log.Ctx(ctx).Error().Err(err).Msgf("failed to get upstream proxy for registry: %s", info.RegIdentifier) @@ -342,7 +396,9 @@ func (r *proxy) GetPackageMetadata( } fileReader, err := helper.GetPackageMetadata(ctx, info.Image, info.ProxyEndpoint) if err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to get package metadata from remote for registry: %s, image: %s", info.RegIdentifier, info.Image) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to get package metadata from remote for registry: %s, image: %s", + info.RegIdentifier, info.Image) return &nugettype.RegistrationIndexResponse{}, err } @@ -351,20 +407,28 @@ func (r *proxy) GetPackageMetadata( if info.ProxyEndpoint != "" { metadata, err2 := parseRegistrationIndexPageResponse(fileReader) if err2 != nil { - log.Ctx(ctx).Error().Err(err2).Msgf("failed to parse registration index page response for registry: %s, image: %s", info.RegIdentifier, info.Image) + log.Ctx(ctx).Error().Err(err2). + Msgf("failed to parse registration index page response for registry: %s, image: %s", + info.RegIdentifier, info.Image) return &nugettype.RegistrationIndexPageResponse{}, err } updateRegistrationIndexPageResponse(metadata, packageURL, info.Image) - log.Ctx(ctx).Info().Msgf("successfully retrieved package metadata page from proxy for registry: %s, image: %s", info.RegIdentifier, info.Image) + log.Ctx(ctx).Info(). + Msgf("successfully retrieved package metadata page from proxy for registry: %s, image: %s", + info.RegIdentifier, info.Image) return metadata, nil } metadata, err2 := parseRegistrationIndexResponse(fileReader) if err2 != nil { - log.Ctx(ctx).Error().Err(err2).Msgf("failed to parse registration index response for registry: %s, image: %s", info.RegIdentifier, info.Image) + log.Ctx(ctx).Error().Err(err2). + Msgf("failed to parse registration index response for registry: %s, image: %s", + info.RegIdentifier, info.Image) return &nugettype.RegistrationIndexResponse{}, err } updateRegistrationIndexResponse(metadata, packageURL, info.Image) - log.Ctx(ctx).Info().Msgf("successfully retrieved package metadata from proxy for registry: %s, image: %s", info.RegIdentifier, info.Image) + log.Ctx(ctx).Info(). + Msgf("successfully retrieved package metadata from proxy for registry: %s, image: %s", + info.RegIdentifier, info.Image) return metadata, nil } @@ -372,7 +436,9 @@ func (r *proxy) ListPackageVersionV2( ctx context.Context, info nugettype.ArtifactInfo, ) (*nugettype.FeedResponse, error) { - log.Ctx(ctx).Debug().Msgf("listing package versions v2 from proxy for registry: %s, image: %s", info.RegIdentifier, info.Image) + log.Ctx(ctx).Debug(). + Msgf("listing package versions v2 from proxy for registry: %s, image: %s", + info.RegIdentifier, info.Image) upstreamProxy, err := r.proxyStore.GetByRegistryIdentifier(ctx, info.ParentID, info.RegIdentifier) if err != nil { log.Ctx(ctx).Error().Err(err).Msgf("failed to get upstream proxy for registry: %s", info.RegIdentifier) @@ -385,12 +451,16 @@ func (r *proxy) ListPackageVersionV2( } fileReader, err := helper.ListPackageVersionV2(ctx, info.Image) if err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to list package versions v2 from remote for registry: %s, image: %s", info.RegIdentifier, info.Image) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to list package versions v2 from remote for registry: %s, image: %s", + info.RegIdentifier, info.Image) return &nugettype.FeedResponse{}, err } var result nugettype.FeedResponse if err = xml.NewDecoder(fileReader).Decode(&result); err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to decode package versions v2 for registry: %s, image: %s", info.RegIdentifier, info.Image) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to decode package versions v2 for registry: %s, image: %s", + info.RegIdentifier, info.Image) return &nugettype.FeedResponse{}, err } packageURL := r.urlProvider.PackageURL(ctx, info.RootIdentifier+"/"+info.RegIdentifier, "nuget") @@ -412,13 +482,17 @@ func (r *proxy) ListPackageVersionV2( version := matches[1] err = modifyContent(entry, packageURL, info.Image, version) if err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to modify content for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, version) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to modify content for registry: %s, image: %s, version: %s", + info.RegIdentifier, info.Image, version) return &nugettype.FeedResponse{}, fmt.Errorf("failed to modify content: %w", err) } } } - log.Ctx(ctx).Info().Msgf("successfully listed package versions v2 from proxy for registry: %s, image: %s", info.RegIdentifier, info.Image) + log.Ctx(ctx).Info(). + Msgf("successfully listed package versions v2 from proxy for registry: %s, image: %s", + info.RegIdentifier, info.Image) return &result, nil } @@ -426,7 +500,9 @@ func (r *proxy) GetPackageVersionMetadataV2( ctx context.Context, info nugettype.ArtifactInfo, ) (*nugettype.FeedEntryResponse, error) { - log.Ctx(ctx).Debug().Msgf("getting package version metadata v2 from proxy for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) + log.Ctx(ctx).Debug(). + Msgf("getting package version metadata v2 from proxy for registry: %s, image: %s, version: %s", + info.RegIdentifier, info.Image, info.Version) packageURL := r.urlProvider.PackageURL(ctx, info.RootIdentifier+"/"+info.RegIdentifier, "nuget") upstreamProxy, err := r.proxyStore.GetByRegistryIdentifier(ctx, info.ParentID, info.RegIdentifier) if err != nil { @@ -440,22 +516,30 @@ func (r *proxy) GetPackageVersionMetadataV2( } fileReader, err := helper.GetPackageVersionMetadataV2(ctx, info.Image, info.Version) if err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to get package version metadata v2 from remote for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to get package version metadata v2 from remote for registry: %s, image: %s, version: %s", + info.RegIdentifier, info.Image, info.Version) return &nugettype.FeedEntryResponse{}, err } var result nugettype.FeedEntryResponse if err = xml.NewDecoder(fileReader).Decode(&result); err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to decode package version metadata v2 for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to decode package version metadata v2 for registry: %s, image: %s, version: %s", + info.RegIdentifier, info.Image, info.Version) return &nugettype.FeedEntryResponse{}, err } result.XmlnsD = xmlnsDataServices result.XmlnsM = xmlnsDataServicesMetadata err = modifyContent(&result, packageURL, info.Image, info.Version) if err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to modify content for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to modify content for registry: %s, image: %s, version: %s", + info.RegIdentifier, info.Image, info.Version) return &nugettype.FeedEntryResponse{}, fmt.Errorf("failed to modify content: %w", err) } - log.Ctx(ctx).Info().Msgf("successfully retrieved package version metadata v2 from proxy for registry: %s, image: %s, version: %s", info.RegIdentifier, info.Image, info.Version) + log.Ctx(ctx).Info(). + Msgf("successfully retrieved package version metadata v2 from proxy for registry: %s, image: %s, version: %s", + info.RegIdentifier, info.Image, info.Version) return &result, nil } From 33a5c648115022a21dd4b7661fefaf83f277f91f Mon Sep 17 00:00:00 2001 From: Pragyesh Mishra Date: Mon, 23 Feb 2026 23:32:48 +0530 Subject: [PATCH 5/5] [fix]: [AH-2686]: added logs --- registry/app/pkg/nuget/local.go | 88 ++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 22 deletions(-) diff --git a/registry/app/pkg/nuget/local.go b/registry/app/pkg/nuget/local.go index 3ad8dffb85..59c34de0dc 100644 --- a/registry/app/pkg/nuget/local.go +++ b/registry/app/pkg/nuget/local.go @@ -252,7 +252,9 @@ func (c *localRegistry) GetPackageMetadata( packageURL := c.urlProvider.PackageURL(ctx, info.RootIdentifier+"/"+info.RegIdentifier, "nuget") artifacts, err2 := c.artifactDao.GetByRegistryIDAndImage(ctx, info.RegistryID, info.Image) if err2 != nil { - log.Ctx(ctx).Error().Err(err2).Msgf("failed to get artifacts for registry: %d and image: %s", info.RegistryID, info.Image) + log.Ctx(ctx).Error().Err(err2). + Msgf("failed to get artifacts for registry: %d and image: %s", + info.RegistryID, info.Image) return nil, fmt.Errorf( "failed to get artifacts for registry: %d and image: %s: %w", info.RegistryID, info.Image, err2) } else if artifacts == nil || len(*artifacts) == 0 { @@ -260,7 +262,9 @@ func (c *localRegistry) GetPackageMetadata( return nil, fmt.Errorf( "no artifacts found for registry: %d and image: %s", info.RegistryID, info.Image) } - log.Ctx(ctx).Info().Msgf("successfully retrieved package metadata for registry: %d, image: %s", info.RegistryID, info.Image) + log.Ctx(ctx).Info(). + Msgf("successfully retrieved package metadata for registry: %d, image: %s", + info.RegistryID, info.Image) return createRegistrationIndexResponse(packageURL, info, artifacts) } @@ -268,21 +272,29 @@ func (c *localRegistry) GetPackageVersionMetadataV2( ctx context.Context, info nugettype.ArtifactInfo, ) (*nugettype.FeedEntryResponse, error) { - log.Ctx(ctx).Debug().Msgf("getting package version metadata v2 for registry: %d, image: %s, version: %s", info.RegistryID, info.Image, info.Version) + log.Ctx(ctx).Debug(). + Msgf("getting package version metadata v2 for registry: %d, image: %s, version: %s", + info.RegistryID, info.Image, info.Version) packageURL := c.urlProvider.PackageURL(ctx, info.RootIdentifier+"/"+info.RegIdentifier, "nuget") image, err2 := c.imageDao.GetByName(ctx, info.RegistryID, info.Image) if err2 != nil { - log.Ctx(ctx).Error().Err(err2).Msgf("failed to get image for registry: %d and image: %s", info.RegistryID, info.Image) + log.Ctx(ctx).Error().Err(err2). + Msgf("failed to get image for registry: %d and image: %s", + info.RegistryID, info.Image) return nil, fmt.Errorf( "failed to get image for registry: %d and image: %s: %w", info.RegistryID, info.Image, err2) } artifact, err2 := c.artifactDao.GetByName(ctx, image.ID, info.Version) if err2 != nil { - log.Ctx(ctx).Error().Err(err2).Msgf("failed to get artifact for registry: %d, image: %s, version: %s", info.RegistryID, info.Image, info.Version) + log.Ctx(ctx).Error().Err(err2). + Msgf("failed to get artifact for registry: %d, image: %s, version: %s", + info.RegistryID, info.Image, info.Version) return nil, fmt.Errorf( "failed to get artifacts for registry: %d and image: %s: %w", info.RegistryID, info.Image, err2) } - log.Ctx(ctx).Info().Msgf("successfully retrieved package version metadata v2 for registry: %d, image: %s, version: %s", info.RegistryID, info.Image, info.Version) + log.Ctx(ctx).Info(). + Msgf("successfully retrieved package version metadata v2 for registry: %d, image: %s, version: %s", + info.RegistryID, info.Image, info.Version) return createFeedEntryResponse(packageURL, info, artifact) } @@ -290,21 +302,29 @@ func (c *localRegistry) GetPackageVersionMetadata( ctx context.Context, info nugettype.ArtifactInfo, ) (*nugettype.RegistrationLeafResponse, error) { - log.Ctx(ctx).Debug().Msgf("getting package version metadata for registry: %d, image: %s, version: %s", info.RegistryID, info.Image, info.Version) + log.Ctx(ctx).Debug(). + Msgf("getting package version metadata for registry: %d, image: %s, version: %s", + info.RegistryID, info.Image, info.Version) packageURL := c.urlProvider.PackageURL(ctx, info.RootIdentifier+"/"+info.RegIdentifier, "nuget") image, err2 := c.imageDao.GetByName(ctx, info.RegistryID, info.Image) if err2 != nil { - log.Ctx(ctx).Error().Err(err2).Msgf("failed to get image for registry: %d and image: %s", info.RegistryID, info.Image) + log.Ctx(ctx).Error().Err(err2). + Msgf("failed to get image for registry: %d and image: %s", + info.RegistryID, info.Image) return nil, fmt.Errorf( "failed to get image for registry: %d and image: %s: %w", info.RegistryID, info.Image, err2) } artifact, err2 := c.artifactDao.GetByName(ctx, image.ID, info.Version) if err2 != nil { - log.Ctx(ctx).Error().Err(err2).Msgf("failed to get artifact for registry: %d, image: %s, version: %s", info.RegistryID, info.Image, info.Version) + log.Ctx(ctx).Error().Err(err2). + Msgf("failed to get artifact for registry: %d, image: %s, version: %s", + info.RegistryID, info.Image, info.Version) return nil, fmt.Errorf( "failed to get artifacts for registry: %d and image: %s: %w", info.RegistryID, info.Image, err2) } - log.Ctx(ctx).Info().Msgf("successfully retrieved package version metadata for registry: %d, image: %s, version: %s", info.RegistryID, info.Image, info.Version) + log.Ctx(ctx).Info(). + Msgf("successfully retrieved package version metadata for registry: %d, image: %s, version: %s", + info.RegistryID, info.Image, info.Version) return createRegistrationLeafResponse(packageURL, info, artifact), nil } @@ -344,7 +364,9 @@ func (c *localRegistry) UploadPackage( info.Version = metadata.PackageMetadata.Version normalisedVersion, err2 := validateAndNormaliseVersion(info.Version) if err2 != nil { - log.Ctx(ctx).Error().Err(err2).Msgf("nuspec file contains an invalid version: %s with package name: %s, registry name: %s", info.Version, info.Image, info.RegIdentifier) + log.Ctx(ctx).Error().Err(err2). + Msgf("nuspec file contains an invalid version: %s with package name: %s, registry name: %s", + info.Version, info.Image, info.RegIdentifier) return headers, "", usererror.BadRequestf("nuspec file contains an invalid version: %s with "+ "package name: %s, registry name: %s", info.Version, info.Image, info.RegIdentifier) } @@ -353,12 +375,16 @@ func (c *localRegistry) UploadPackage( if fileBundleType == SymbolsFile { versionExists, err3 := c.localBase.CheckIfVersionExists(ctx, info) if err3 != nil { - log.Ctx(ctx).Error().Err(err3).Msgf("failed to check package version existence for id: %s, version: %s with registry: %d", info.Image, info.Version, info.RegistryID) + log.Ctx(ctx).Error().Err(err3). + Msgf("failed to check package version existence for id: %s, version: %s with registry: %d", + info.Image, info.Version, info.RegistryID) return headers, "", fmt.Errorf( "failed to check package version existence for id: %s , version: %s "+ "with registry: %d with error: %w", info.Image, info.Version, info.RegistryID, err) } else if !versionExists { - log.Ctx(ctx).Warn().Msgf("can't push symbol package as package doesn't exist for id: %s, version: %s with registry: %d", info.Image, info.Version, info.RegistryID) + log.Ctx(ctx).Warn(). + Msgf("can't push symbol package as package doesn't exist for id: %s, version: %s with registry: %d", + info.Image, info.Version, info.RegistryID) return headers, "", usererror.BadRequestf( "can't push symbol package as package doesn't exists for id: %s , version: %s "+ "with registry: %d", info.Image, info.Version, info.RegistryID) @@ -384,10 +410,14 @@ func (c *localRegistry) UploadPackage( Metadata: info.Metadata, }, fileInfo, false) if err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to update file manager and create artifact for package: %s, version: %s with registry: %d", info.Image, info.Version, info.RegistryID) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to update file manager and create artifact for package: %s, version: %s with registry: %d", + info.Image, info.Version, info.RegistryID) return h, checkSum, err } - log.Ctx(ctx).Info().Msgf("successfully uploaded package: %s, version: %s for registry: %d with checksum: %s", info.Image, info.Version, info.RegistryID, checkSum) + log.Ctx(ctx).Info(). + Msgf("successfully uploaded package: %s, version: %s for registry: %d with checksum: %s", + info.Image, info.Version, info.RegistryID, checkSum) return h, checkSum, err } @@ -448,7 +478,9 @@ func (c *localRegistry) DownloadPackage( ctx context.Context, info nugettype.ArtifactInfo, ) (*commons.ResponseHeaders, *storage.FileReader, string, io.ReadCloser, error) { - log.Ctx(ctx).Debug().Msgf("downloading package for registry: %d, image: %s, version: %s, filename: %s", info.RegistryID, info.Image, info.Version, info.Filename) + log.Ctx(ctx).Debug(). + Msgf("downloading package for registry: %d, image: %s, version: %s, filename: %s", + info.RegistryID, info.Image, info.Version, info.Filename) responseHeaders := &commons.ResponseHeaders{ Headers: make(map[string]string), Code: 0, @@ -457,7 +489,9 @@ func (c *localRegistry) DownloadPackage( path, err := c.fileManager.FindLatestFilePath(ctx, info.RegistryID, "/"+info.Image+"/"+info.Version, info.Filename) if err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to find file node for id: %s, version: %s with registry: %d", info.Image, info.Version, info.RegistryID) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to find file node for id: %s, version: %s with registry: %d", + info.Image, info.Version, info.RegistryID) return responseHeaders, nil, "", nil, fmt.Errorf("failed to find file node for id: %s , version: %s "+ "with registry: %d with error: %w", info.Image, info.Version, info.RegistryID, err) } @@ -466,13 +500,17 @@ func (c *localRegistry) DownloadPackage( info.RegistryID, info.RegIdentifier, info.RootIdentifier, true) if err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to download file for registry: %d, image: %s, version: %s", info.RegistryID, info.Image, info.Version) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to download file for registry: %d, image: %s, version: %s", + info.RegistryID, info.Image, info.Version) return responseHeaders, nil, "", nil, err } responseHeaders.Code = http.StatusOK responseHeaders.Headers["Content-Type"] = "application/octet-stream" responseHeaders.Headers["Content-Length"] = strconv.FormatInt(size, 10) - log.Ctx(ctx).Info().Msgf("successfully downloaded package for registry: %d, image: %s, version: %s, size: %d", info.RegistryID, info.Image, info.Version, size) + log.Ctx(ctx).Info(). + Msgf("successfully downloaded package for registry: %d, image: %s, version: %s, size: %d", + info.RegistryID, info.Image, info.Version, size) return responseHeaders, fileReader, redirectURL, nil, nil } @@ -480,7 +518,9 @@ func (c *localRegistry) DeletePackage( ctx context.Context, info nugettype.ArtifactInfo, ) (*commons.ResponseHeaders, error) { - log.Ctx(ctx).Debug().Msgf("deleting package for registry: %d, image: %s, version: %s", info.RegistryID, info.Image, info.Version) + log.Ctx(ctx).Debug(). + Msgf("deleting package for registry: %d, image: %s, version: %s", + info.RegistryID, info.Image, info.Version) responseHeaders := &commons.ResponseHeaders{ Headers: make(map[string]string), Code: 0, @@ -488,12 +528,16 @@ func (c *localRegistry) DeletePackage( err := c.localBase.DeleteVersion(ctx, info) if err != nil { - log.Ctx(ctx).Error().Err(err).Msgf("failed to delete package version with package: %s, version: %s and registry: %d", info.Image, info.Version, info.RegistryID) + log.Ctx(ctx).Error().Err(err). + Msgf("failed to delete package version with package: %s, version: %s and registry: %d", + info.Image, info.Version, info.RegistryID) return responseHeaders, fmt.Errorf("failed to delete package version with package: %s, version: %s and "+ "registry: %d with error: %w", info.Image, info.Version, info.RegistryID, err) } responseHeaders.Code = http.StatusOK - log.Ctx(ctx).Info().Msgf("successfully deleted package for registry: %d, image: %s, version: %s", info.RegistryID, info.Image, info.Version) + log.Ctx(ctx).Info(). + Msgf("successfully deleted package for registry: %d, image: %s, version: %s", + info.RegistryID, info.Image, info.Version) return responseHeaders, nil }