Skip to content

Commit 0b5931e

Browse files
authored
[Fleet] Return tech preview package without prerelease flag (#1538)
1 parent 6932147 commit 0b5931e

37 files changed

Lines changed: 43192 additions & 19723 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
### Added
1616

1717
* Add deprecated field support. [#1516](https://github.com/elastic/package-registry/pull/1516)
18+
* Return tech preview package without prerelease flag [#1538](https://github.com/elastic/package-registry/pull/1538)
1819

1920
### Deprecated
2021

internal/storage/sqlindexer_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ func TestSQLGet_ListPackages(t *testing.T) {
306306
Prerelease: false,
307307
},
308308
},
309-
expected: 99,
309+
expected: 121,
310310
},
311311
{
312312
name: "all packages with all versions and no prerelease",
@@ -315,7 +315,7 @@ func TestSQLGet_ListPackages(t *testing.T) {
315315
AllVersions: true,
316316
},
317317
},
318-
expected: 495,
318+
expected: 664,
319319
},
320320
{
321321
name: "all packages with latest versions and no prerelease",
@@ -324,7 +324,7 @@ func TestSQLGet_ListPackages(t *testing.T) {
324324
Prerelease: false,
325325
},
326326
},
327-
expected: 99,
327+
expected: 121,
328328
},
329329
{
330330
name: "all packages prerelease",
@@ -410,7 +410,7 @@ func TestSQLGet_ListPackages(t *testing.T) {
410410
Capabilities: []string{"uptime"},
411411
},
412412
},
413-
expected: 98,
413+
expected: 121,
414414
},
415415
{
416416
name: "filtering packages with security capabilities",
@@ -421,7 +421,7 @@ func TestSQLGet_ListPackages(t *testing.T) {
421421
Capabilities: []string{"security"},
422422
},
423423
},
424-
expected: 99,
424+
expected: 121,
425425
},
426426
{
427427
name: "latest package",

packages/package.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,13 +612,18 @@ func (p *Package) IsPrerelease() bool {
612612
return isPrerelease(p.versionSemVer)
613613
}
614614

615+
func (p *Package) isTechPreview() bool {
616+
return isTechPreview(p.versionSemVer)
617+
}
618+
615619
func isPrerelease(version *semver.Version) bool {
616-
if version.Major() < 1 {
617-
return true
618-
}
619620
return version.Prerelease() != ""
620621
}
621622

623+
func isTechPreview(version *semver.Version) bool {
624+
return version.Major() < 1
625+
}
626+
622627
// LoadAssets (re)loads all the assets of the package
623628
// Based on the time when this is called, it might be that not all assets for a package exist yet, so it is reset every time.
624629
func (p *Package) LoadAssets() (err error) {

packages/package_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ func TestIsPrerelease(t *testing.T) {
302302
prerelease bool
303303
}{
304304
{"0.1.0-rc1", true},
305-
{"0.1.0", true}, // Major version 0 shouldn't be considered stable.
305+
{"0.1.0", false}, // Tech preview package should not be filtered by prerelease flag
306306
{"1.0.0-beta1", true},
307307
{"1.0.0-rc.1", true},
308308
{"1.0.0-SNAPSHOT", true},

packages/packages.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -775,16 +775,16 @@ func (f *Filter) legacyApply(ctx context.Context, packages Packages) Packages {
775775
}
776776

777777
if f.AllVersions {
778-
packageHasNonPrerelease := make(map[string]bool)
778+
packageHasNonPrereleaseAndTechPreview := make(map[string]bool)
779779
for _, p := range packagesList {
780-
if !p.IsPrerelease() {
781-
packageHasNonPrerelease[p.Name] = true
780+
if !p.IsPrerelease() && !p.isTechPreview() {
781+
packageHasNonPrereleaseAndTechPreview[p.Name] = true
782782
}
783783
}
784784

785785
i := 0
786786
for _, p := range packagesList {
787-
if packageHasNonPrerelease[p.Name] && p.IsPrerelease() {
787+
if packageHasNonPrereleaseAndTechPreview[p.Name] && (p.IsPrerelease() || p.isTechPreview()) {
788788
continue
789789
}
790790
packagesList[i] = p

packages/packages_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,9 @@ func TestPackagesFilter(t *testing.T) {
300300
// See: https://github.com/elastic/package-registry/pull/893
301301
filterTestPackage{Name: "apache", Version: "1.0.0-rc1"},
302302
filterTestPackage{Name: "apache", Version: "2.0.0-rc2"},
303-
filterTestPackage{Name: "redisenterprise", Version: "0.1.1"},
304303
filterTestPackage{Name: "obs_sec_package", Version: "2.0.0-rc1"},
304+
// Tech preview versions (major < 1) must be skipped if there are GA versions.
305+
filterTestPackage{Name: "redisenterprise", Version: "0.1.1"},
305306
),
306307
},
307308
{
@@ -352,7 +353,7 @@ func TestPackagesFilter(t *testing.T) {
352353
},
353354
Expected: []filterTestPackage{
354355
// There are two versions available for 8.5, but we return only
355-
// the GA one to avoid exposing prereleases to legacy kibanas.
356+
// the GA one to avoid exposing prereleases and tech previews to legacy kibanas.
356357
// See: https://github.com/elastic/package-registry/pull/893
357358
{Name: "redisenterprise", Version: "1.0.0"},
358359
},

packages/releases.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ const (
1414
ReleaseGa = "ga"
1515

1616
// Default release if no release is configured
17-
DefaultRelease = ReleaseGa
18-
DefaultPrerelease = ReleaseBeta
19-
DefaultLicense = "basic"
17+
DefaultRelease = ReleaseGa
18+
DefaultPrerelease = ReleaseBeta
19+
DefaultReleaseTechPreview = ReleaseBeta
20+
DefaultLicense = "basic"
2021
)
2122

2223
var ReleaseTypes = map[string]interface{}{
@@ -36,5 +37,9 @@ func releaseForSemVerCompat(version *semver.Version) string {
3637
if isPrerelease(version) {
3738
return DefaultPrerelease
3839
}
40+
if isTechPreview(version) {
41+
return DefaultReleaseTechPreview
42+
}
43+
3944
return DefaultRelease
4045
}

storage/indexer_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func TestGet_ListPackages(t *testing.T) {
153153
Prerelease: false,
154154
},
155155
},
156-
expected: 99,
156+
expected: 121,
157157
},
158158
{
159159
name: "all packages with all versions and no prerelease",
@@ -162,7 +162,7 @@ func TestGet_ListPackages(t *testing.T) {
162162
AllVersions: true,
163163
},
164164
},
165-
expected: 495,
165+
expected: 664,
166166
},
167167
{
168168
name: "all packages with latest versions and no prerelease",
@@ -171,7 +171,7 @@ func TestGet_ListPackages(t *testing.T) {
171171
Prerelease: false,
172172
},
173173
},
174-
expected: 99,
174+
expected: 121,
175175
},
176176
{
177177
name: "all packages prerelease",
@@ -257,7 +257,7 @@ func TestGet_ListPackages(t *testing.T) {
257257
Capabilities: []string{"uptime"},
258258
},
259259
},
260-
expected: 98,
260+
expected: 121,
261261
},
262262
{
263263
name: "filtering packages with security capabilities",
@@ -268,7 +268,7 @@ func TestGet_ListPackages(t *testing.T) {
268268
Capabilities: []string{"security"},
269269
},
270270
},
271-
expected: 99,
271+
expected: 121,
272272
},
273273
{
274274
name: "latest package",

testdata/generated/categories-agent-910.json

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
[
2+
{
3+
"id": "aws",
4+
"title": "AWS",
5+
"count": 2
6+
},
27
{
38
"id": "azure",
49
"title": "Azure",
510
"count": 2
611
},
12+
{
13+
"id": "cloud",
14+
"title": "Cloud",
15+
"count": 1
16+
},
17+
{
18+
"id": "containers",
19+
"title": "Containers",
20+
"count": 1
21+
},
722
{
823
"id": "crm",
924
"title": "CRM",
@@ -12,17 +27,36 @@
1227
{
1328
"id": "custom",
1429
"title": "Custom",
15-
"count": 18
30+
"count": 22
1631
},
1732
{
1833
"id": "datastore",
1934
"title": "Database",
35+
"count": 3
36+
},
37+
{
38+
"id": "message_queue",
39+
"title": "Message Broker",
40+
"count": 1,
41+
"parent_id": "observability",
42+
"parent_title": "Observability"
43+
},
44+
{
45+
"id": "monitoring",
46+
"title": "Monitoring",
47+
"count": 2,
48+
"parent_id": "observability",
49+
"parent_title": "Observability"
50+
},
51+
{
52+
"id": "support",
53+
"title": "Support",
2054
"count": 1
2155
},
2256
{
2357
"id": "web",
2458
"title": "Web Server",
25-
"count": 3,
59+
"count": 4,
2660
"parent_id": "observability",
2761
"parent_title": "Observability"
2862
}

testdata/generated/categories-agent-950.json

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
[
2+
{
3+
"id": "aws",
4+
"title": "AWS",
5+
"count": 2
6+
},
27
{
38
"id": "azure",
49
"title": "Azure",
510
"count": 2
611
},
12+
{
13+
"id": "cloud",
14+
"title": "Cloud",
15+
"count": 1
16+
},
17+
{
18+
"id": "containers",
19+
"title": "Containers",
20+
"count": 1
21+
},
722
{
823
"id": "crm",
924
"title": "CRM",
@@ -12,17 +27,36 @@
1227
{
1328
"id": "custom",
1429
"title": "Custom",
15-
"count": 19
30+
"count": 23
1631
},
1732
{
1833
"id": "datastore",
1934
"title": "Database",
35+
"count": 3
36+
},
37+
{
38+
"id": "message_queue",
39+
"title": "Message Broker",
40+
"count": 1,
41+
"parent_id": "observability",
42+
"parent_title": "Observability"
43+
},
44+
{
45+
"id": "monitoring",
46+
"title": "Monitoring",
47+
"count": 2,
48+
"parent_id": "observability",
49+
"parent_title": "Observability"
50+
},
51+
{
52+
"id": "support",
53+
"title": "Support",
2054
"count": 1
2155
},
2256
{
2357
"id": "web",
2458
"title": "Web Server",
25-
"count": 4,
59+
"count": 5,
2660
"parent_id": "observability",
2761
"parent_title": "Observability"
2862
}

0 commit comments

Comments
 (0)