diff --git a/registry/app/pkg/nuget/local.go b/registry/app/pkg/nuget/local.go index 9258c46fda..59c34de0dc 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" @@ -74,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 } @@ -83,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() } @@ -99,11 +105,16 @@ 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) } @@ -111,6 +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) return &nugettype.PackageVersion{ Versions: versions, }, nil @@ -120,15 +134,23 @@ 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) } @@ -136,11 +158,18 @@ 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 } @@ -148,11 +177,16 @@ 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 } @@ -160,12 +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) 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) } @@ -174,18 +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) 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) } @@ -193,15 +248,23 @@ 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) } @@ -209,17 +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) 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) } @@ -227,18 +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) 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 } @@ -246,6 +332,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{} @@ -253,11 +340,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) @@ -266,15 +355,19 @@ func (c *localRegistry) UploadPackage( metadata, err = c.buildMetadata(r) if err != nil { - return headers, "", fmt.Errorf( - "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 { - return headers, "", fmt.Errorf("nuspec file contains an invalid version: %s with "+ + 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) } info.Version = normalisedVersion @@ -282,13 +375,19 @@ 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 { - return headers, "", fmt.Errorf( + 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 with error: %w", info.Image, info.Version, info.RegistryID, err) + "with registry: %d", info.Image, info.Version, info.RegistryID) } fileExtension = SymbolsPackageExtension } else { @@ -310,6 +409,15 @@ 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 } @@ -370,6 +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) responseHeaders := &commons.ResponseHeaders{ Headers: make(map[string]string), Code: 0, @@ -378,8 +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().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) } @@ -388,11 +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) 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 } @@ -400,6 +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) responseHeaders := &commons.ResponseHeaders{ Headers: make(map[string]string), Code: 0, @@ -407,10 +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) 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..3213d474b4 100644 --- a/registry/app/pkg/nuget/proxy.go +++ b/registry/app/pkg/nuget/proxy.go @@ -74,29 +74,51 @@ 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 +145,32 @@ 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 +178,32 @@ 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 +211,35 @@ 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 +257,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 +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) 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 +282,47 @@ 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 +332,9 @@ 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 +342,37 @@ 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 +380,25 @@ 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 +407,28 @@ 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 +436,31 @@ 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 +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) 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 +500,46 @@ 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 +595,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 +606,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() }