Skip to content

Commit

Permalink
Merge pull request #144 from armosec/fix-since-until
Browse files Browse the repository at this point in the history
chore: Add indexes for collections
  • Loading branch information
Bezbran authored Jul 29, 2024
2 parents 048680c + 39fbc80 commit 49994be
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
51 changes: 51 additions & 0 deletions db/mongo/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ var collectionIndexes = map[string][]mongo.IndexModel{
{Key: "guid", Value: 1},
},
},
{
Keys: bson.D{
{Key: "activeSubscription.licenseType", Value: 1},
{Key: "activeSubscription.subscriptionStatus", Value: 1},
{Key: "subscription_date", Value: 1},
},
},
},
consts.UsersNotificationsCacheCollection: {
{
Expand Down Expand Up @@ -322,6 +329,50 @@ var collectionIndexes = map[string][]mongo.IndexModel{
},
},
},
consts.ClustersCollection: {
{
Keys: bson.D{
{Key: "_id", Value: 1},
{Key: "customers", Value: 1},
},
},
},
// We are paying the proce of not handling this index from config service but as a module
consts.TokensCollection: {
{
Keys: bson.D{
{Key: "customerGuid", Value: 1},
{Key: "value", Value: 1},
{Key: "type", Value: 1},
},
},
},
consts.VulnerabilityExceptionPolicyCollection: {
{
Keys: bson.D{
{Key: "guid", Value: 1},
},
},
{
Keys: bson.D{
{Key: "name", Value: 1},
},
},
{
Keys: bson.D{
{Key: "customers", Value: 1},
},
},
{
Keys: bson.D{
{Key: "attributes.namespaceOnly", Value: 1},
{Key: "designators.attributes.cluster", Value: 1},
{Key: "designators.attributes.namespace", Value: 1},
// can't index on both customer and designators, as they are in different arrays
// {Key: "customers", Value: 1},
},
},
},
}

// defaultIndex is the default index for all collections unless overridden in collectionIndexes
Expand Down
16 changes: 10 additions & 6 deletions testers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"config-service/types"
"encoding/json"
"fmt"
"slices"
"time"

"github.com/armosec/armoapi-go/armotypes"
Expand Down Expand Up @@ -652,12 +653,15 @@ func testGetDocsWithOptions[T types.DocContent](suite *MainTestSuite, path strin
if err != nil {
suite.FailNow(err.Error())
}
sort.Slice(docs, func(i, j int) bool {
return docs[i].GetName() < docs[j].GetName()
})
sort.Slice(expectedDocs, func(i, j int) bool {
return expectedDocs[i].GetName() < expectedDocs[j].GetName()
})
sortFunc := func(a T, b T) int {
if nameInt := strings.Compare(a.GetName(), b.GetName()); nameInt != 0 {
return nameInt
} else {
return strings.Compare(a.GetGUID(), b.GetGUID())
}
}
slices.SortFunc(docs, sortFunc)
slices.SortFunc(expectedDocs, sortFunc)
diff := cmp.Diff(docs, expectedDocs, compareOpts...)
suite.Equal("", diff)
return docs
Expand Down
1 change: 1 addition & 0 deletions utils/consts/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const (
RuntimeIncidentCollection = "v1_runtime_incidents"
RuntimeIncidentPolicyCollection = "v1_runtime_incident_policies"
IntegrationReferenceCollection = "v1_integration_references"
TokensCollection = "tokens"

//Common document fields
IdField = "_id"
Expand Down

0 comments on commit 49994be

Please sign in to comment.