GeezerVison is showing github.com — perf(sac): remove cluster and namespace store caches · stackrox/stackrox@9c07886
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: central/cluster/datastore/datastore.go +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -49,7 +49,7 @@ type DataStore interface { | 49 | 49 | GetClusterID(ctx context.Context, name string) (string, bool, error) | 50 | 50 | GetClusterName(ctx context.Context, id string) (string, bool, error) | 51 | 51 | GetClusters(ctx context.Context) ([]*storage.Cluster, error) | 52 | | - GetClustersForSAC() ([]effectiveaccessscope.Cluster, error) | | 52 | + GetClustersForSAC(ctx context.Context) ([]effectiveaccessscope.Cluster, error) | 53 | 53 | GetClusterLabels(ctx context.Context, clusterID string) (map[string]string, error) | 54 | 54 | CountClusters(ctx context.Context) (int, error) | 55 | 55 | Exists(ctx context.Context, id string) (bool, error) | |
Collapse file Copy file name to clipboardExpand all lines: central/cluster/datastore/datastore_impl.go +14-3Lines changed: 14 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,7 +17,6 @@ import ( | 17 | 17 | clusterHealthStore "github.com/stackrox/rox/central/cluster/store/clusterhealth" | 18 | 18 | clusterInitStore "github.com/stackrox/rox/central/clusterinit/store" | 19 | 19 | compliancePruning "github.com/stackrox/rox/central/complianceoperator/v2/pruner" | 20 | | - "github.com/stackrox/rox/central/convert/storagetoeffectiveaccessscope" | 21 | 20 | clusterCVEDS "github.com/stackrox/rox/central/cve/cluster/datastore" | 22 | 21 | deploymentDataStore "github.com/stackrox/rox/central/deployment/datastore" | 23 | 22 | imageIntegrationDataStore "github.com/stackrox/rox/central/imageintegration/datastore" | @@ -364,8 +363,20 @@ func (ds *datastoreImpl) GetClusters(ctx context.Context) ([]*storage.Cluster, e | 364 | 363 | return ds.searchRawClusters(ctx, pkgSearch.EmptyQuery()) | 365 | 364 | } | 366 | 365 |
| 367 | | -func (ds *datastoreImpl) GetClustersForSAC() ([]effectiveaccessscope.Cluster, error) { | 368 | | - return storagetoeffectiveaccessscope.Clusters(ds.clusterStorage.GetAllFromCacheForSAC()), nil | | 366 | +func (ds *datastoreImpl) GetClustersForSAC(ctx context.Context) ([]effectiveaccessscope.Cluster, error) { | | 367 | + var clusters []effectiveaccessscope.Cluster | | 368 | + err := ds.clusterStorage.Walk(sac.WithAllAccess(ctx), func(cluster *storage.Cluster) error { | | 369 | + clusters = append(clusters, &storage.Cluster{ | | 370 | + Id: cluster.GetId(), | | 371 | + Name: cluster.GetName(), | | 372 | + Labels: cluster.GetLabels(), | | 373 | + }) | | 374 | + return nil | | 375 | + }) | | 376 | + if err != nil { | | 377 | + return nil, err | | 378 | + } | | 379 | + return clusters, nil | 369 | 380 | } | 370 | 381 |
| 371 | 382 | func (ds *datastoreImpl) GetClusterName(ctx context.Context, id string) (string, bool, error) { | |
Collapse file Copy file name to clipboardExpand all lines: central/cluster/datastore/datastore_impl_postgres_test.go +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -57,7 +57,7 @@ import ( | 57 | 57 | ) | 58 | 58 |
| 59 | 59 | const ( | 60 | | - fakeClusterID = "FAKECLUSTERID" | | 60 | + fakeClusterID = "00000000-0000-4000-8000-000000000001" | 61 | 61 | mainImage = "docker.io/stackrox/rox:latest" | 62 | 62 | centralEndpoint = "central.stackrox:443" | 63 | 63 | ) | |
Collapse file Copy file name to clipboardExpand all lines: central/cluster/datastore/datastore_sac_test.go +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -349,7 +349,7 @@ func (s *clusterDatastoreSACSuite) TestGetClustersForSAC() { | 349 | 349 | defer s.deleteCluster(clusterID2) | 350 | 350 | s.Require().NoError(err) | 351 | 351 |
| 352 | | - clusters, err := s.datastore.GetClustersForSAC() | | 352 | + clusters, err := s.datastore.GetClustersForSAC(context.Background()) | 353 | 353 | s.NoError(err) | 354 | 354 | clusterNames := make([]string, 0, len(clusters)) | 355 | 355 | for _, cluster := range clusters { | |
Collapse file Copy file name to clipboardExpand all lines: central/cluster/datastore/mocks/datastore.go +4-4Lines changed: 4 additions & 4 deletions Collapse file Copy file name to clipboardExpand all lines: central/cluster/store/cluster/mocks/store.go -14Lines changed: 0 additions & 14 deletions Collapse file Copy file name to clipboardExpand all lines: central/cluster/store/cluster/postgres/gen.go +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,4 +2,4 @@ package postgres | 2 | 2 |
| 3 | 3 | // Cluster store does not use Postgres CopyFrom operation to copy data into DB. This is because copyFrom requires an | 4 | 4 | // explicit delete prior to copy consequently prohibiting references to clusters table. | 5 | | -//go:generate pg-table-bindings-wrapper --type=storage.Cluster --cached-store --for-sac --search-category CLUSTERS --no-copy-from --default-sort search.Cluster.String() | | 5 | +//go:generate pg-table-bindings-wrapper --type=storage.Cluster --search-category CLUSTERS --no-copy-from --default-sort search.Cluster.String() |
Collapse file Copy file name to clipboardExpand all lines: central/cluster/store/cluster/postgres/store.go +1-12Lines changed: 1 addition & 12 deletions Collapse file Copy file name to clipboard +43Lines changed: 43 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +//go:build sql_integration | | 2 | + | | 3 | +package postgres | | 4 | + | | 5 | +import ( | | 6 | + "context" | | 7 | + | | 8 | + "github.com/stackrox/rox/generated/storage" | | 9 | + "github.com/stackrox/rox/pkg/sac" | | 10 | + "github.com/stackrox/rox/pkg/uuid" | | 11 | +) | | 12 | + | | 13 | +func (s *ClustersStoreSuite) TestReadsObserveOtherStoreWrites() { | | 14 | + ctx := sac.WithAllAccess(context.Background()) | | 15 | + writer := New(s.testDB.DB) | | 16 | + cluster := &storage.Cluster{Id: uuid.NewV4().String(), Name: "shared-cluster", Labels: map[string]string{"team": "initial"}} | | 17 | + _, found, err := s.store.Get(ctx, cluster.GetId()) | | 18 | + s.Require().NoError(err) | | 19 | + s.Require().False(found) | | 20 | + | | 21 | + s.Require().NoError(writer.Upsert(ctx, cluster)) | | 22 | + result, found, err := s.store.Get(ctx, cluster.GetId()) | | 23 | + s.Require().NoError(err) | | 24 | + s.Require().True(found) | | 25 | + s.Equal(cluster.GetLabels(), result.GetLabels()) | | 26 | + | | 27 | + cluster.Labels = map[string]string{"team": "updated"} | | 28 | + s.Require().NoError(writer.Upsert(ctx, cluster)) | | 29 | + results, missing, err := s.store.GetMany(ctx, []string{cluster.GetId()}) | | 30 | + s.Require().NoError(err) | | 31 | + s.Require().Empty(missing) | | 32 | + s.Require().Len(results, 1) | | 33 | + s.Equal(cluster.GetLabels(), results[0].GetLabels()) | | 34 | + | | 35 | + s.Require().NoError(writer.Delete(ctx, cluster.GetId())) | | 36 | + _, found, err = s.store.Get(ctx, cluster.GetId()) | | 37 | + s.Require().NoError(err) | | 38 | + s.False(found) | | 39 | + results, missing, err = s.store.GetMany(ctx, []string{cluster.GetId()}) | | 40 | + s.Require().NoError(err) | | 41 | + s.Empty(results) | | 42 | + s.Equal([]int{0}, missing) | | 43 | +} |
Collapse file Copy file name to clipboardExpand all lines: central/cluster/store/cluster/store.go -3Lines changed: 0 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -21,7 +21,4 @@ type Store interface { | 21 | 21 |
| 22 | 22 | Walk(ctx context.Context, fn func(obj *storage.Cluster) error) error | 23 | 23 | WalkByQuery(ctx context.Context, query *v1.Query, fn func(obj *storage.Cluster) error) error | 24 | | - | 25 | | - // Deprecated: It will not clone the object so it should be used only for SAC. | 26 | | - GetAllFromCacheForSAC() []*storage.Cluster | 27 | 24 | } |
|