Skip to content

Commit 1528a65

Browse files
committed
PMM-14431 Small refactor.
1 parent 858c62a commit 1528a65

File tree

2 files changed

+2
-7
lines changed

2 files changed

+2
-7
lines changed

exporter/collstats_collector_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,11 @@ func TestCollStatsForFakeCountType(t *testing.T) {
109109
collName := "test_collection_account"
110110
coll := database.Collection(collName)
111111

112-
// Insert some data
113112
_, err := coll.InsertOne(ctx, bson.M{"account_id": 1, "count": 10})
114113
require.NoError(t, err)
115114
_, err = coll.InsertOne(ctx, bson.M{"account_id": 2, "count": 20})
116115
require.NoError(t, err)
117116

118-
// Create indexes
119117
indexModel := mongo.IndexModel{
120118
Keys: bson.D{{Key: "account_id", Value: 1}},
121119
Options: options.Index().SetName("test_index_account"),
@@ -136,7 +134,6 @@ func TestCollStatsForFakeCountType(t *testing.T) {
136134
logger := promslog.New(&promslog.Config{})
137135
c := newCollectionStatsCollector(ctx, client, logger, false, ti, collection, false)
138136

139-
// Expected metrics (simplified, adjust values as needed)
140137
expected := strings.NewReader(`
141138
# HELP mongodb_collstats_storageStats_indexSizes collstats.storageStats.indexSizes
142139
# TYPE mongodb_collstats_storageStats_indexSizes untyped

exporter/metrics.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ func metricHelp(prefix, name string) string {
309309
// GetAllIndexesForCollections returns all index names for the given list of "db.collection" strings.
310310
func GetAllIndexesForCollections(ctx context.Context, client *mongo.Client, collections []string) ([]string, error) {
311311
var indexNames []string
312-
313312
for _, dbCollection := range collections {
314313
parts := strings.SplitN(dbCollection, ".", 2) //nolint:mnd
315314
if len(parts) != 2 {
@@ -321,8 +320,7 @@ func GetAllIndexesForCollections(ctx context.Context, client *mongo.Client, coll
321320
coll := client.Database(dbName).Collection(collName)
322321
cursor, err := coll.Indexes().List(ctx)
323322
if err != nil {
324-
// skip collections where indexes cannot be listed (e.g., views, system collections)
325-
continue
323+
continue // skip collections where indexes cannot be listed (e.g., views, system collections)
326324
}
327325
defer cursor.Close(ctx) //nolint:errcheck
328326

@@ -369,7 +367,6 @@ func makeMetrics(reservedNames []string, prefix string, m bson.M, labels map[str
369367
return res
370368
}
371369

372-
// Helper for switch block from makeMetrics
373370
func handleMetricSwitch(reservedNames []string, prefix, nextPrefix, k string, val interface{}, l map[string]string, compatibleMode bool) []prometheus.Metric {
374371
var res []prometheus.Metric
375372
switch v := val.(type) {
@@ -408,6 +405,7 @@ func handleMetricSwitch(reservedNames []string, prefix, nextPrefix, k string, va
408405
}
409406
}
410407
}
408+
411409
return res
412410
}
413411

0 commit comments

Comments
 (0)