mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 04:17:55 +08:00
fix(convert): fix the update rule of download count for images (#1802)
Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com>
This commit is contained in:
@@ -980,3 +980,95 @@ func TestGetOneManifestAnnotations(t *testing.T) {
|
||||
So(*imageSummary.Source, ShouldBeBlank)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDownloadCount(t *testing.T) {
|
||||
Convey("manifest", t, func() {
|
||||
repoMeta, manifestMetaMap, indexDataMap := test.GetMetadataForRepos(
|
||||
test.Repo{
|
||||
Name: "repo",
|
||||
Images: []test.RepoImage{
|
||||
{
|
||||
Image: test.CreateRandomImage(),
|
||||
Tag: "10-downloads",
|
||||
Statistics: mTypes.DescriptorStatistics{
|
||||
DownloadCount: 10,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
repoSummary := convert.RepoMeta2RepoSummary(context.Background(), repoMeta[0], manifestMetaMap, indexDataMap,
|
||||
convert.SkipQGLField{}, nil)
|
||||
So(*repoSummary.DownloadCount, ShouldEqual, 10)
|
||||
So(*repoSummary.NewestImage.DownloadCount, ShouldEqual, 10)
|
||||
})
|
||||
|
||||
Convey("index", t, func() {
|
||||
img1, img2, img3 := test.CreateRandomImage(), test.CreateRandomImage(), test.CreateRandomImage()
|
||||
multiArch := test.CreateMultiarchWith().Images([]test.Image{img1, img2, img3}).Build()
|
||||
|
||||
repoMeta, manifestMetaMap, indexDataMap := test.GetMetadataForRepos(
|
||||
test.Repo{
|
||||
Name: "repo",
|
||||
MultiArchImages: []test.RepoMultiArchImage{
|
||||
{
|
||||
MultiarchImage: multiArch,
|
||||
Tag: "160-multiarch",
|
||||
ImageStatistics: map[string]mTypes.DescriptorStatistics{
|
||||
img1.DigestStr(): {DownloadCount: 10},
|
||||
img2.DigestStr(): {DownloadCount: 20},
|
||||
img3.DigestStr(): {DownloadCount: 30},
|
||||
multiArch.DigestStr(): {DownloadCount: 100},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
repoSummary := convert.RepoMeta2RepoSummary(context.Background(), repoMeta[0], manifestMetaMap, indexDataMap,
|
||||
convert.SkipQGLField{}, nil)
|
||||
So(*repoSummary.DownloadCount, ShouldEqual, 100)
|
||||
So(*repoSummary.NewestImage.DownloadCount, ShouldEqual, 100)
|
||||
})
|
||||
|
||||
Convey("index + manifest mixed", t, func() {
|
||||
img1 := test.CreateRandomImage()
|
||||
img2 := test.CreateRandomImage()
|
||||
img3 := test.CreateImageWith().DefaultLayers().ImageConfig(
|
||||
ispec.Image{Created: test.DateRef(2020, 1, 1, 1, 1, 1, 0, time.UTC)},
|
||||
).Build()
|
||||
|
||||
multiArch := test.CreateMultiarchWith().Images([]test.Image{img1, img2, img3}).Build()
|
||||
|
||||
repoMeta, manifestMetaMap, indexDataMap := test.GetMetadataForRepos(
|
||||
test.Repo{
|
||||
Name: "repo",
|
||||
Images: []test.RepoImage{
|
||||
{
|
||||
Image: test.CreateRandomImage(),
|
||||
Tag: "5-downloads",
|
||||
Statistics: mTypes.DescriptorStatistics{DownloadCount: 5},
|
||||
},
|
||||
},
|
||||
MultiArchImages: []test.RepoMultiArchImage{
|
||||
{
|
||||
MultiarchImage: multiArch,
|
||||
Tag: "160-multiarch",
|
||||
ImageStatistics: map[string]mTypes.DescriptorStatistics{
|
||||
img1.DigestStr(): {DownloadCount: 10},
|
||||
img2.DigestStr(): {DownloadCount: 20},
|
||||
img3.DigestStr(): {DownloadCount: 30},
|
||||
multiArch.DigestStr(): {DownloadCount: 100},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
repoSummary := convert.RepoMeta2RepoSummary(context.Background(), repoMeta[0], manifestMetaMap, indexDataMap,
|
||||
convert.SkipQGLField{}, nil)
|
||||
So(*repoSummary.DownloadCount, ShouldEqual, 105)
|
||||
So(*repoSummary.NewestImage.DownloadCount, ShouldEqual, 100)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -70,17 +70,15 @@ func RepoMeta2RepoSummary(ctx context.Context, repoMeta mTypes.RepoMetadata,
|
||||
platformString := strings.TrimSpace(fmt.Sprintf("%s %s", opSys, arch))
|
||||
repoPlatformsSet[platformString] = &gql_generated.Platform{Os: &opSys, Arch: &arch}
|
||||
}
|
||||
|
||||
repoDownloadCount += manifestMetaMap[*manifestSummary.Digest].DownloadCount
|
||||
}
|
||||
|
||||
repoDownloadCount += *imageSummary.DownloadCount
|
||||
|
||||
if *imageSummary.Vendor != "" {
|
||||
repoVendorsSet[*imageSummary.Vendor] = true
|
||||
}
|
||||
|
||||
lastUpdatedImageSummary = UpdateLastUpdatedTimestamp(&repoLastUpdatedTimestamp, lastUpdatedImageSummary, imageSummary)
|
||||
|
||||
repoDownloadCount += repoMeta.Statistics[descriptor.Digest].DownloadCount
|
||||
}
|
||||
|
||||
// calculate repo size = sum all manifest, config and layer blobs sizes
|
||||
@@ -248,6 +246,8 @@ func ImageIndex2ImageSummary(ctx context.Context, repo, tag string, indexDigest
|
||||
manifestSummaries = append(manifestSummaries, manifestSummary)
|
||||
}
|
||||
|
||||
totalDownloadCount += repoMeta.Statistics[indexDigestStr].DownloadCount
|
||||
|
||||
for _, signatures := range repoMeta.Signatures[indexDigest.String()] {
|
||||
if len(signatures) > 0 {
|
||||
isSigned = true
|
||||
@@ -511,7 +511,7 @@ func ImageManifest2ManifestSummary(ctx context.Context, repo, tag string, descri
|
||||
configSize = manifestContent.Config.Size
|
||||
artifactType = zcommon.GetManifestArtifactType(manifestContent)
|
||||
imageLastUpdated = zcommon.GetImageLastUpdated(configContent)
|
||||
downloadCount = manifestMeta.DownloadCount
|
||||
downloadCount = repoMeta.Statistics[digest.String()].DownloadCount
|
||||
isSigned = false
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user