Skip to content

Commit 98b8c0f

Browse files
committed
Mark GetBundleForChannel as deprecated and trim its response.
The RPC api.Registry/GetBundleForChannel is consumed only by package-server and by declarative index conversion. Neither reads any field other than CsvName and CsvJson. The package-server generates one call to this RPC per channel per package per catalog and is responsible for needlessly large CPU utilization and resident set sizes on registry pods. Removing the additional per-request processing and database queries that populate unused fields makes the registry server better able to absorb the bursty load from package-server. Upstream-repository: operator-registry Upstream-commit: 86907e18e912ee4c4cce76a6f6d6c1f518d423e3
1 parent 01e1cf8 commit 98b8c0f

File tree

10 files changed

+68
-104
lines changed

10 files changed

+68
-104
lines changed

staging/operator-registry/pkg/api/registry.proto

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ service Registry {
88
rpc ListPackages(ListPackageRequest) returns (stream PackageName) {}
99
rpc GetPackage(GetPackageRequest) returns (Package) {}
1010
rpc GetBundle(GetBundleRequest) returns (Bundle) {}
11-
rpc GetBundleForChannel(GetBundleInChannelRequest) returns (Bundle) {}
11+
rpc GetBundleForChannel(GetBundleInChannelRequest) returns (Bundle) {
12+
option deprecated = true;
13+
}
1214
rpc GetChannelEntriesThatReplace(GetAllReplacementsRequest) returns (stream ChannelEntry) {}
1315
rpc GetBundleThatReplaces(GetReplacementRequest) returns (Bundle) {}
1416
rpc GetChannelEntriesThatProvide(GetAllProvidersRequest) returns (stream ChannelEntry) {}

staging/operator-registry/pkg/registry/interface.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ type GRPCQuery interface {
3737
// Get a bundle by its package name, channel name and csv name from the index
3838
GetBundle(ctx context.Context, pkgName, channelName, csvName string) (*api.Bundle, error)
3939

40-
// Get the bundle in the specified package at the head of the specified channel
40+
// Get the bundle in the specified package at the head of the
41+
// specified channel. DEPRECATED. Returned bundles may have
42+
// only the "name" and "csvJson" fields populated in order to
43+
// support legacy usage.
4144
GetBundleForChannel(ctx context.Context, pkgName string, channelName string) (*api.Bundle, error)
4245

4346
// Get all channel entries that say they replace this one

staging/operator-registry/pkg/registry/populator_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ func TestQuerierForImage(t *testing.T) {
171171
{Group: "testapi.coreos.com", Version: "v1", Kind: "testapi"},
172172
},
173173
}
174-
EqualBundles(t, *expectedBundle, *etcdBundleByChannel)
174+
bareGetBundleForChannelResult := &api.Bundle{
175+
CsvName: expectedBundle.CsvName,
176+
CsvJson: expectedBundle.CsvJson + "\n",
177+
}
178+
EqualBundles(t, *bareGetBundleForChannelResult, *etcdBundleByChannel)
175179

176180
etcdBundle, err := store.GetBundle(context.TODO(), "etcd", "alpha", "etcdoperator.v0.9.2")
177181
require.NoError(t, err)

staging/operator-registry/pkg/server/server_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,13 @@ func testGetBundle(addr string, expected *api.Bundle) func(*testing.T) {
216216
}
217217

218218
func TestGetBundleForChannel(t *testing.T) {
219-
t.Run("Sqlite", testGetBundleForChannel(dbAddress, etcdoperator_v0_9_2("alpha", false, false)))
219+
{
220+
b := etcdoperator_v0_9_2("alpha", false, false)
221+
t.Run("Sqlite", testGetBundleForChannel(dbAddress, &api.Bundle{
222+
CsvName: b.CsvName,
223+
CsvJson: b.CsvJson + "\n",
224+
}))
225+
}
220226
t.Run("DeclarativeConfig", testGetBundleForChannel(cfgAddress, etcdoperator_v0_9_2("alpha", false, true)))
221227
}
222228

staging/operator-registry/pkg/sqlite/configmap_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ func TestQuerierForConfigmap(t *testing.T) {
175175
"{\"apiVersion\":\"apiextensions.k8s.io/v1beta1\",\"kind\":\"CustomResourceDefinition\",\"metadata\":{\"creationTimestamp\":null,\"name\":\"etcdbackups.etcd.database.coreos.com\"},\"spec\":{\"group\":\"etcd.database.coreos.com\",\"names\":{\"kind\":\"EtcdBackup\",\"listKind\":\"EtcdBackupList\",\"plural\":\"etcdbackups\",\"singular\":\"etcdbackup\"},\"scope\":\"Namespaced\",\"version\":\"v1beta2\",\"versions\":[{\"name\":\"v1beta2\",\"served\":true,\"storage\":true}]},\"status\":{\"acceptedNames\":{\"kind\":\"\",\"plural\":\"\"},\"conditions\":null,\"storedVersions\":null}}",
176176
"{\"apiVersion\":\"apiextensions.k8s.io/v1beta1\",\"kind\":\"CustomResourceDefinition\",\"metadata\":{\"creationTimestamp\":null,\"name\":\"etcdrestores.etcd.database.coreos.com\"},\"spec\":{\"group\":\"etcd.database.coreos.com\",\"names\":{\"kind\":\"EtcdRestore\",\"listKind\":\"EtcdRestoreList\",\"plural\":\"etcdrestores\",\"singular\":\"etcdrestore\"},\"scope\":\"Namespaced\",\"version\":\"v1beta2\",\"versions\":[{\"name\":\"v1beta2\",\"served\":true,\"storage\":true}]},\"status\":{\"acceptedNames\":{\"kind\":\"\",\"plural\":\"\"},\"conditions\":null,\"storedVersions\":null}}"},
177177
}
178-
EqualBundles(t, *expectedBundle, *etcdBundleByChannel)
178+
bareGetBundleForChannelResult := &api.Bundle{
179+
CsvName: expectedBundle.CsvName,
180+
CsvJson: expectedBundle.CsvJson + "\n",
181+
}
182+
EqualBundles(t, *bareGetBundleForChannelResult, *etcdBundleByChannel)
179183

180184
etcdBundle, err := store.GetBundle(context.TODO(), "etcd", "alpha", "etcdoperator.v0.9.2")
181185
require.NoError(t, err)

staging/operator-registry/pkg/sqlite/directory_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,11 @@ func TestQuerierForDirectory(t *testing.T) {
180180
{Group: "etcd.database.coreos.com", Version: "v1beta2", Kind: "EtcdCluster", Plural: "etcdclusters"},
181181
},
182182
}
183-
EqualBundles(t, *expectedBundle, *etcdBundleByChannel)
183+
bareGetBundleForChannelResult := &api.Bundle{
184+
CsvName: expectedBundle.CsvName,
185+
CsvJson: expectedBundle.CsvJson + "\n",
186+
}
187+
EqualBundles(t, *bareGetBundleForChannelResult, *etcdBundleByChannel)
184188

185189
etcdBundle, err := store.GetBundle(context.TODO(), "etcd", "alpha", "etcdoperator.v0.9.2")
186190
require.NoError(t, err)

staging/operator-registry/pkg/sqlite/query.go

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -287,64 +287,32 @@ func (s *SQLQuerier) GetBundle(ctx context.Context, pkgName, channelName, csvNam
287287
return out, nil
288288
}
289289

290-
func (s *SQLQuerier) GetBundleForChannel(ctx context.Context, pkgName string, channelName string) (*api.Bundle, error) {
291-
query := `SELECT DISTINCT channel_entry.entry_id, operatorbundle.name, operatorbundle.bundle, operatorbundle.bundlepath, operatorbundle.version, operatorbundle.skiprange FROM channel
292-
INNER JOIN operatorbundle ON channel.head_operatorbundle_name=operatorbundle.name
293-
INNER JOIN channel_entry ON (channel_entry.channel_name = channel.name and channel_entry.package_name=channel.package_name and channel_entry.operatorbundle_name=operatorbundle.name)
294-
WHERE channel.package_name=? AND channel.name=? LIMIT 1`
295-
rows, err := s.db.QueryContext(ctx, query, pkgName, channelName)
290+
func (s *SQLQuerier) GetBundleForChannel(ctx context.Context, pkg string, channel string) (*api.Bundle, error) {
291+
query := `
292+
SELECT operatorbundle.name, operatorbundle.csv FROM operatorbundle INNER JOIN channel
293+
ON channel.head_operatorbundle_name = operatorbundle.name
294+
WHERE channel.name = :channel AND channel.package_name = :package`
295+
rows, err := s.db.QueryContext(ctx, query, sql.Named("channel", channel), sql.Named("package", pkg))
296296
if err != nil {
297297
return nil, err
298298
}
299299
defer rows.Close()
300300

301301
if !rows.Next() {
302-
return nil, fmt.Errorf("no entry found for %s %s", pkgName, channelName)
303-
}
304-
var entryId sql.NullInt64
305-
var name sql.NullString
306-
var bundle sql.NullString
307-
var bundlePath sql.NullString
308-
var version sql.NullString
309-
var skipRange sql.NullString
310-
if err := rows.Scan(&entryId, &name, &bundle, &bundlePath, &version, &skipRange); err != nil {
311-
return nil, err
312-
}
313-
314-
out := &api.Bundle{}
315-
if bundle.Valid && bundle.String != "" {
316-
out, err = registry.BundleStringToAPIBundle(bundle.String)
317-
if err != nil {
318-
return nil, err
319-
}
320-
}
321-
out.CsvName = name.String
322-
out.PackageName = pkgName
323-
out.ChannelName = channelName
324-
out.BundlePath = bundlePath.String
325-
out.Version = version.String
326-
out.SkipRange = skipRange.String
327-
328-
provided, required, err := s.GetApisForEntry(ctx, entryId.Int64)
329-
if err != nil {
330-
return nil, err
331-
}
332-
out.ProvidedApis = provided
333-
out.RequiredApis = required
334-
335-
dependencies, err := s.GetDependenciesForBundle(ctx, name.String, version.String, bundlePath.String)
336-
if err != nil {
337-
return nil, err
302+
return nil, fmt.Errorf("no entry found for %s %s", pkg, channel)
338303
}
339-
out.Dependencies = dependencies
340-
341-
properties, err := s.GetPropertiesForBundle(ctx, name.String, version.String, bundlePath.String)
342-
if err != nil {
304+
var (
305+
name sql.NullString
306+
csv sql.NullString
307+
)
308+
if err := rows.Scan(&name, &csv); err != nil {
343309
return nil, err
344310
}
345-
out.Properties = properties
346311

347-
return out, nil
312+
return &api.Bundle{
313+
CsvName: name.String,
314+
CsvJson: csv.String,
315+
}, nil
348316
}
349317

350318
func (s *SQLQuerier) GetChannelEntriesThatReplace(ctx context.Context, name string) (entries []*registry.ChannelEntry, err error) {

vendor/github.com/operator-framework/operator-registry/pkg/api/registry.proto

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/operator-framework/operator-registry/pkg/registry/interface.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/operator-framework/operator-registry/pkg/sqlite/query.go

Lines changed: 16 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)