-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement collection GETs for node pools #883
Changes from all commits
0af1323
17513a4
256c8dc
0a734bb
53de71c
f8b56ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,6 @@ import ( | |
"iter" | ||
"strings" | ||
|
||
azcorearm "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" | ||
|
||
"github.com/Azure/ARO-HCP/internal/api/arm" | ||
) | ||
|
||
|
@@ -24,14 +22,14 @@ type Cache struct { | |
subscription map[string]*SubscriptionDocument | ||
} | ||
|
||
type operationCacheIterator struct { | ||
operation map[string]*OperationDocument | ||
err error | ||
type cacheIterator struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For my understanding, why is there an in-memory cache for CosmosDB? Was there a particular REST p95 that couldn't be reached without caching? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's there for historical reasons, from early in development before we had access to Cosmos DB. Both the Cosmos DB client and the in-memory cache are hidden behind a generic database interface. Once we got Cosmos DB access it was decided to keep the interface and cache around as a unit test aid, and for a time it was helpful when our database use cases were simple. But it's technical debt now; it's become an obstacle to leveraging more advanced features of Cosmos DB. I'm honestly ready to ditch it and just use gomock or some such for unit tests, but I'll need to find time to pay that debt. |
||
docs []any | ||
err error | ||
} | ||
|
||
func (iter operationCacheIterator) Items(ctx context.Context) iter.Seq[[]byte] { | ||
func (iter cacheIterator) Items(ctx context.Context) iter.Seq[[]byte] { | ||
return func(yield func([]byte) bool) { | ||
for _, doc := range iter.operation { | ||
for _, doc := range iter.docs { | ||
// Marshalling the document struct only to immediately unmarshal | ||
// it back to a document struct is a little silly but this is to | ||
// conform to the DBClientIterator interface. | ||
|
@@ -48,7 +46,11 @@ func (iter operationCacheIterator) Items(ctx context.Context) iter.Seq[[]byte] { | |
} | ||
} | ||
|
||
func (iter operationCacheIterator) GetError() error { | ||
func (iter cacheIterator) GetContinuationToken() string { | ||
return "" | ||
} | ||
|
||
func (iter cacheIterator) GetError() error { | ||
return iter.err | ||
} | ||
|
||
|
@@ -108,21 +110,19 @@ func (c *Cache) DeleteResourceDoc(ctx context.Context, resourceID *arm.ResourceI | |
return nil | ||
} | ||
|
||
func (c *Cache) ListResourceDocs(ctx context.Context, prefix *arm.ResourceID, resourceType *azcorearm.ResourceType, pageSizeHint int32, continuationToken *string) ([]*ResourceDocument, *string, error) { | ||
var resourceList []*ResourceDocument | ||
func (c *Cache) ListResourceDocs(ctx context.Context, prefix *arm.ResourceID, maxItems int32, continuationToken *string) DBClientIterator { | ||
var iterator cacheIterator | ||
|
||
// Make sure key prefix is lowercase. | ||
prefixString := strings.ToLower(prefix.String() + "/") | ||
|
||
for key, doc := range c.resource { | ||
if strings.HasPrefix(key, prefixString) { | ||
if resourceType == nil || strings.EqualFold(resourceType.String(), doc.Key.ResourceType.String()) { | ||
resourceList = append(resourceList, doc) | ||
} | ||
iterator.docs = append(iterator.docs, doc) | ||
} | ||
} | ||
|
||
return resourceList, nil, nil | ||
return iterator | ||
} | ||
|
||
func (c *Cache) GetOperationDoc(ctx context.Context, operationID string) (*OperationDocument, error) { | ||
|
@@ -164,7 +164,11 @@ func (c *Cache) DeleteOperationDoc(ctx context.Context, operationID string) erro | |
} | ||
|
||
func (c *Cache) ListAllOperationDocs(ctx context.Context) DBClientIterator { | ||
return operationCacheIterator{operation: c.operation} | ||
var iterator cacheIterator | ||
for _, doc := range c.operation { | ||
iterator.docs = append(iterator.docs, doc) | ||
} | ||
return iterator | ||
} | ||
|
||
func (c *Cache) GetSubscriptionDoc(ctx context.Context, subscriptionID string) (*SubscriptionDocument, error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be done with a
WHERE
clause at the DB layer?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically yes, but see my in-memory cache answer below.
I'm going to leave this as is for this PR but I added a "FIXME" comment here to circle back to it once I've gotten rid of the generic database interface I described below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Not being able to delegate this kind of thing to the DB because of the vestigial in-memory implementation IMO makes getting rid of it a good use of time before long.