Skip to content

Commit 1d9d34c

Browse files
authored
Merge pull request #99 from mongodb/audit-tooling-updates
Audit tooling updates
2 parents 5c1aa71 + 9521e1a commit 1d9d34c

File tree

12 files changed

+330
-21
lines changed

12 files changed

+330
-21
lines changed

audit/common/Constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ const (
107107
StreamProcessingDir = "atlas-stream-processing"
108108
TriggersDir = "triggers"
109109
VectorSearchDir = "atlas-vector-search"
110+
AiIntegrationsDir = "ai-integrations"
110111
)
111112

112113
var CanonicalLanguages = []string{Bash, C, CPP,

audit/common/GetProductInfo.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func GetProductInfo(projectOrSubdir string) ProductInfo {
2323
}
2424

2525
var SubProductDirs = []string{
26+
AiIntegrationsDir,
2627
DataFederationDir,
2728
OnlineArchiveDir,
2829
StreamProcessingDir,
@@ -32,6 +33,11 @@ var SubProductDirs = []string{
3233
}
3334

3435
var productInfoMap = map[string]ProductInfo{
36+
"ai-integrations": {
37+
ProductName: Atlas,
38+
ProductType: DirIsSubProduct,
39+
SubProduct: VectorSearch,
40+
},
3541
"atlas-cli": {
3642
ProductName: Atlas,
3743
ProductType: CollectionIsSubProduct,
@@ -137,6 +143,11 @@ var productInfoMap = map[string]ProductInfo{
137143
ProductType: CollectionIsProduct,
138144
SubProduct: "",
139145
},
146+
"drivers": {
147+
ProductName: Drivers,
148+
ProductType: CollectionIsProduct,
149+
SubProduct: "",
150+
},
140151
"entity-framework": {
141152
ProductName: EFCoreProvider,
142153
ProductType: CollectionIsProduct,

audit/dodec/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Get counts broken down in the following ways:
2525
- [By product](src/aggregations/GetProductCategoryCounts.go)
2626
- [By Atlas sub-product](src/aggregations/GetSubProductCategoryCounts.go)
2727
- [For one specific category by product](src/aggregations/GetSpecificCategoryByProduct.go)
28+
- [For usage examples added in the last month](src/aggregations/FindUsageExamplesForMonth.go)
29+
- [For applied usage examples (>300 characters) added in the last week](src/aggregations/FindNewAppliedUsageExamples.go)
2830
- Complexity counts:
2931
- [One line usage examples by docs property](src/aggregations/GetOneLineUsageExampleCounts.go)
3032
- [Minimum, median, maximum character counts for code examples in the collection, and one-liner counts](src/aggregations/GetMinMedianMaxCodeLength.go)

audit/dodec/src/PerformAggregation.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"dodec/aggregations"
66
"dodec/types"
77
"dodec/utils"
8+
"time"
9+
810
"go.mongodb.org/mongo-driver/v2/bson"
911
"go.mongodb.org/mongo-driver/v2/mongo"
1012
)
@@ -36,6 +38,7 @@ func PerformAggregation(db *mongo.Database, ctx context.Context) {
3638
}
3739
//substringToFindInCodeExamples := "defaultauthdb"
3840
//substringToFindInPageURL := "code-examples"
41+
monthForReporting := time.November
3942

4043
for _, collectionName := range collectionNames {
4144
//simpleMap = aggregations.GetCategoryCounts(db, collectionName, simpleMap, ctx)
@@ -56,7 +59,8 @@ func PerformAggregation(db *mongo.Database, ctx context.Context) {
5659
//pageIdChangesCountMap = aggregations.GetDocsIdsWithRecentActivity(db, collectionName, pageIdChangesCountMap, ctx)
5760
//pageIdsWithNodeLangCountMismatch = aggregations.GetPagesWithNodeLangCountMismatch(db, collectionName, pageIdsWithNodeLangCountMismatch, ctx)
5861
//pageIdsWithNodeLangCountMismatch = aggregations.FindDocsMissingProduct(db, collectionName, pageIdsWithNodeLangCountMismatch, ctx)
59-
productSubProductCounter = aggregations.FindNewAppliedUsageExamples(db, collectionName, productSubProductCounter, ctx)
62+
//productSubProductCounter = aggregations.FindNewAppliedUsageExamples(db, collectionName, productSubProductCounter, ctx)
63+
productSubProductCounter = aggregations.FindUsageExamplesForMonth(db, collectionName, productSubProductCounter, monthForReporting, ctx)
6064
//pageIdsWithNodeLangCountMismatch = aggregations.FindURLContainingString(db, collectionName, pageIdsWithNodeLangCountMismatch, ctx, substringToFindInPageURL)
6165
}
6266

@@ -79,5 +83,6 @@ func PerformAggregation(db *mongo.Database, ctx context.Context) {
7983
//utils.PrintCodeLengthMapToConsole(codeLengthMap)
8084
//utils.PrintPageIdChangesCountMap(pageIdChangesCountMap)
8185
//utils.PrintPageIdsWithNodeLangCountMismatch(pageIdsWithNodeLangCountMismatch)
82-
utils.PrintPageIdNewAppliedUsageExampleCounts(productSubProductCounter)
86+
//utils.PrintPageIdNewAppliedUsageExampleCounts(productSubProductCounter)
87+
utils.PrintMonthlyUsageExampleCounts(productSubProductCounter, monthForReporting)
8388
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package aggregations
2+
3+
import (
4+
"common"
5+
"context"
6+
"dodec/types"
7+
"dodec/utils"
8+
"fmt"
9+
"time"
10+
11+
"go.mongodb.org/mongo-driver/v2/bson"
12+
"go.mongodb.org/mongo-driver/v2/mongo"
13+
)
14+
15+
// FindUsageExamplesForMonth looks for docs pages in Atlas that have had a new usage example added during the target month.
16+
// We get a count of new usage examples matching this criteria, return the count and the page_id, and
17+
// track the product and sub-product in the types.NewAppliedUsageExampleCounterByProductSubProduct
18+
func FindUsageExamplesForMonth(db *mongo.Database, collectionName string, productSubProductCounter types.NewAppliedUsageExampleCounterByProductSubProduct, monthForReporting time.Month, ctx context.Context) types.NewAppliedUsageExampleCounterByProductSubProduct {
19+
// Target a specific month (example for November 2025):
20+
targetYear := 2025
21+
monthStart := time.Date(targetYear, monthForReporting, 1, 0, 0, 0, 0, time.UTC)
22+
monthEnd := monthStart.AddDate(0, 1, 0) // First day of next month
23+
// Define the aggregation pipeline
24+
pipeline := mongo.Pipeline{
25+
// Find only page documents where the `nodes` value is not null
26+
{{"$match", bson.D{
27+
{"_id", bson.D{{"$ne", "summaries"}}},
28+
{"nodes", bson.D{{"$ne", nil}}}, // Ensure nodes is not null
29+
}}},
30+
31+
// Unwind the `nodes` value to match on specific node elements
32+
{{"$unwind", bson.D{{"path", "$nodes"}}}},
33+
34+
{{"$match", bson.D{
35+
{"$and", bson.A{
36+
// Filter for nodes that have been added during the target month
37+
bson.D{{"$and", bson.A{
38+
bson.D{{"nodes.date_added", bson.D{{"$gte", monthStart}}}},
39+
bson.D{{"nodes.date_added", bson.D{{"$lt", monthEnd}}}},
40+
}}},
41+
// Consider only usage examples
42+
bson.D{{"nodes.category", common.UsageExample}},
43+
}},
44+
}}},
45+
46+
// First group by Product and SubProduct
47+
bson.D{{"$group", bson.D{
48+
{"_id", bson.D{
49+
{"product", "$product"},
50+
{"subProduct", bson.D{{"$ifNull", bson.A{"$sub_product", "None"}}}},
51+
}},
52+
{"nodesPerProduct", bson.D{{"$push", bson.D{
53+
{"_id", "$_id"}, // Preserve original document _id
54+
{"nodes", "$nodes"}, // Collect nodes
55+
}}}},
56+
}}},
57+
// Unwind after the first group to regroup by original _id
58+
bson.D{{"$unwind", bson.D{{"path", "$nodesPerProduct"}}}},
59+
// Regroup by original document _id within each Product and SubProduct
60+
bson.D{{"$group", bson.D{
61+
{"_id", bson.D{
62+
{"product", "$_id.product"},
63+
{"subProduct", "$_id.subProduct"},
64+
{"documentId", "$nodesPerProduct._id"},
65+
}},
66+
{"new_applied_usage_examples", bson.D{{"$push", "$nodesPerProduct.nodes"}}},
67+
{"count", bson.D{{"$sum", 1}}},
68+
}}},
69+
// Optionally sort by count in descending order
70+
bson.D{{"$sort", bson.D{{"count", -1}}}},
71+
}
72+
// Execute the aggregation
73+
collection := db.Collection(collectionName)
74+
cursor, err := collection.Aggregate(ctx, pipeline)
75+
if err != nil {
76+
println(fmt.Errorf("failed to execute aggregate query: %v", err))
77+
return productSubProductCounter
78+
}
79+
defer cursor.Close(ctx)
80+
collectionPagesWithNewAppliedUsageExamples := make([]types.PageIdNewAppliedUsageExamples, 0)
81+
for cursor.Next(ctx) {
82+
var result types.PageIdNewAppliedUsageExamples
83+
if err = cursor.Decode(&result); err != nil {
84+
println(fmt.Errorf("failed to decode result document: %v", err))
85+
return productSubProductCounter
86+
}
87+
88+
// If a sub-product map for the product does not exist yet, create one
89+
if _, ok := productSubProductCounter.ProductSubProductCounts[result.ID.Product]; !ok {
90+
productSubProductCounter.ProductSubProductCounts[result.ID.Product] = make(map[string]int)
91+
}
92+
93+
// The docs org would like to see a breakdown of focus areas. For the purpose of reporting this result, I'm arbitrarily
94+
// assigning some of the key focus areas as "sub-product" if a page ID contains a substring related to these focus
95+
// areas. That makes it easy to report on these things as sub-products even if they're not officially sub-products.
96+
resultAdjustedForFocusAreas := utils.GetFocusAreaAsSubProduct(result)
97+
if resultAdjustedForFocusAreas.ID.SubProduct != "None" {
98+
productSubProductCounter.ProductSubProductCounts[result.ID.Product][resultAdjustedForFocusAreas.ID.SubProduct] += resultAdjustedForFocusAreas.Count
99+
100+
// Add the adjusted for focus area count to the product accumulator
101+
productSubProductCounter.ProductAggregateCount[result.ID.Product] += resultAdjustedForFocusAreas.Count
102+
} else {
103+
// If the subproduct is "None", just append the original count
104+
productSubProductCounter.ProductSubProductCounts[result.ID.Product][result.ID.SubProduct] += result.Count
105+
// Add the non-adjusted subproduct count to the product accumulator
106+
productSubProductCounter.ProductAggregateCount[result.ID.Product] += result.Count
107+
}
108+
collectionPagesWithNewAppliedUsageExamples = append(collectionPagesWithNewAppliedUsageExamples, resultAdjustedForFocusAreas)
109+
}
110+
if err = cursor.Err(); err != nil {
111+
println(fmt.Errorf("cursor encountered an error: %v", err))
112+
return productSubProductCounter
113+
}
114+
if collectionPagesWithNewAppliedUsageExamples != nil && len(collectionPagesWithNewAppliedUsageExamples) > 0 {
115+
productSubProductCounter.PagesInCollections[collectionName] = collectionPagesWithNewAppliedUsageExamples
116+
}
117+
return productSubProductCounter
118+
}

audit/dodec/src/go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
module dodec
22

3-
go 1.23.1
3+
go 1.24.0
44

55
require (
66
common v0.0.0
77
github.com/joho/godotenv v1.5.1
8-
go.mongodb.org/mongo-driver/v2 v2.2.2
8+
go.mongodb.org/mongo-driver/v2 v2.4.0
99
)
1010

1111
require (
1212
github.com/golang/snappy v1.0.0 // indirect
13-
github.com/klauspost/compress v1.18.0 // indirect
13+
github.com/klauspost/compress v1.18.1 // indirect
1414
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
1515
github.com/xdg-go/scram v1.1.2 // indirect
1616
github.com/xdg-go/stringprep v1.0.4 // indirect
1717
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
18-
go.mongodb.org/mongo-driver v1.17.4 // indirect
19-
golang.org/x/crypto v0.37.0 // indirect
20-
golang.org/x/sync v0.13.0 // indirect
21-
golang.org/x/text v0.24.0 // indirect
18+
go.mongodb.org/mongo-driver v1.17.6 // indirect
19+
golang.org/x/crypto v0.45.0 // indirect
20+
golang.org/x/sync v0.18.0 // indirect
21+
golang.org/x/text v0.31.0 // indirect
2222
)
2323

2424
replace common => ../../common

audit/dodec/src/go.sum

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
88
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
99
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
1010
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
11+
github.com/klauspost/compress v1.18.1 h1:bcSGx7UbpBqMChDtsF28Lw6v/G94LPrrbMbdC3JH2co=
12+
github.com/klauspost/compress v1.18.1/go.mod h1:ZQFFVG+MdnR0P+l6wpXgIL4NTtwiKIdBnrBd8Nrxr+0=
1113
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
1214
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
1315
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
@@ -19,14 +21,20 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS
1921
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
2022
go.mongodb.org/mongo-driver v1.17.4 h1:jUorfmVzljjr0FLzYQsGP8cgN/qzzxlY9Vh0C9KFXVw=
2123
go.mongodb.org/mongo-driver v1.17.4/go.mod h1:Hy04i7O2kC4RS06ZrhPRqj/u4DTYkFDAAccj+rVKqgQ=
24+
go.mongodb.org/mongo-driver v1.17.6 h1:87JUG1wZfWsr6rIz3ZmpH90rL5tea7O3IHuSwHUpsss=
25+
go.mongodb.org/mongo-driver v1.17.6/go.mod h1:Hy04i7O2kC4RS06ZrhPRqj/u4DTYkFDAAccj+rVKqgQ=
2226
go.mongodb.org/mongo-driver/v2 v2.2.1 h1:w5xra3yyu/sGrziMzK1D0cRRaH/b7lWCSsoN6+WV6AM=
2327
go.mongodb.org/mongo-driver/v2 v2.2.1/go.mod h1:qQkDMhCGWl3FN509DfdPd4GRBLU/41zqF/k8eTRceps=
2428
go.mongodb.org/mongo-driver/v2 v2.2.2 h1:9cYuS3fl1Xhqwpfazso10V7BHQD58kCgtzhfAmJYz9c=
2529
go.mongodb.org/mongo-driver/v2 v2.2.2/go.mod h1:qQkDMhCGWl3FN509DfdPd4GRBLU/41zqF/k8eTRceps=
30+
go.mongodb.org/mongo-driver/v2 v2.4.0 h1:Oq6BmUAAFTzMeh6AonuDlgZMuAuEiUxoAD1koK5MuFo=
31+
go.mongodb.org/mongo-driver/v2 v2.4.0/go.mod h1:jHeEDJHJq7tm6ZF45Issun9dbogjfnPySb1vXA7EeAI=
2632
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
2733
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
2834
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE=
2935
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
36+
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
37+
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
3038
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
3139
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
3240
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
@@ -35,6 +43,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
3543
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
3644
golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
3745
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
46+
golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I=
47+
golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
3848
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
3949
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
4050
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -48,6 +58,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
4858
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
4959
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
5060
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
61+
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
62+
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
5163
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
5264
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
5365
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=

0 commit comments

Comments
 (0)