Skip to content

Commit f140c24

Browse files
author
Harshil Goel
authored
fix(core): put new metrics behind a feature flag (#9337)
1 parent 129003b commit f140c24

File tree

4 files changed

+34
-21
lines changed

4 files changed

+34
-21
lines changed

dgraph/cmd/alpha/run.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ they form a Raft group and provide synchronous replication.
279279
Flag("normalize-compatibility-mode", "configure @normalize response formatting."+
280280
" 'v20': returns values with repeated key for fields with same alias (same as v20.11)."+
281281
" For more details, see https://github.com/hypermodeinc/dgraph/pull/7639").
282+
Flag("enable-detailed-metrics", "Enable metrics about disk reads and cache per predicate").
282283
String())
283284
}
284285

@@ -770,6 +771,7 @@ func run() {
770771
featureFlagsConf := z.NewSuperFlag(Alpha.Conf.GetString("feature-flags")).MergeAndCheckDefault(
771772
worker.FeatureFlagsDefaults)
772773
x.Config.NormalizeCompatibilityMode = featureFlagsConf.GetString("normalize-compatibility-mode")
774+
enableDetailedMetrics := featureFlagsConf.GetBool("enable-detailed-metrics")
773775

774776
x.PrintVersion()
775777
glog.Infof("x.Config: %+v", x.Config)
@@ -794,6 +796,7 @@ func run() {
794796
// schema before calling posting.Init().
795797
schema.Init(worker.State.Pstore)
796798
posting.Init(worker.State.Pstore, postingListCacheSize, removeOnUpdate)
799+
posting.SetEnabledDetailedMetrics(enableDetailedMetrics)
797800
defer posting.Cleanup()
798801
worker.Init(worker.State.Pstore)
799802

posting/lists.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ const (
4040
)
4141

4242
var (
43-
pstore *badger.DB
44-
closer *z.Closer
43+
pstore *badger.DB
44+
closer *z.Closer
45+
EnableDetailedMetrics bool
4546
)
4647

4748
// Init initializes the posting lists package, the in memory and dirty list hash.
@@ -53,6 +54,10 @@ func Init(ps *badger.DB, cacheSize int64, removeOnUpdate bool) {
5354
memoryLayer = initMemoryLayer(cacheSize, removeOnUpdate)
5455
}
5556

57+
func SetEnabledDetailedMetrics(enableMetrics bool) {
58+
EnableDetailedMetrics = enableMetrics
59+
}
60+
5661
func UpdateMaxCost(maxCost int64) {
5762
}
5863

@@ -305,15 +310,17 @@ func (lc *LocalCache) getInternal(key []byte, readFromDisk bool) (*List, error)
305310
}
306311

307312
func (lc *LocalCache) readPostingListAt(key []byte) (*pb.PostingList, error) {
308-
start := time.Now()
309-
defer func() {
310-
pk, _ := x.Parse(key)
311-
ms := x.SinceMs(start)
312-
var tags []tag.Mutator
313-
tags = append(tags, tag.Upsert(x.KeyMethod, "get"))
314-
tags = append(tags, tag.Upsert(x.KeyStatus, pk.Attr))
315-
_ = ostats.RecordWithTags(context.Background(), tags, x.BadgerReadLatencyMs.M(ms))
316-
}()
313+
if EnableDetailedMetrics {
314+
start := time.Now()
315+
defer func() {
316+
ms := x.SinceMs(start)
317+
pk, _ := x.Parse(key)
318+
var tags []tag.Mutator
319+
tags = append(tags, tag.Upsert(x.KeyMethod, "get"))
320+
tags = append(tags, tag.Upsert(x.KeyStatus, pk.Attr))
321+
_ = ostats.RecordWithTags(context.Background(), tags, x.BadgerReadLatencyMs.M(ms))
322+
}()
323+
}
317324

318325
pl := &pb.PostingList{}
319326
txn := pstore.NewTransactionAt(lc.startTs, false)

posting/mvcc.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -448,13 +448,14 @@ func initMemoryLayer(cacheSize int64, removeOnUpdate bool) *MemoryLayer {
448448
// Record the posting list cache hit ratio
449449
ostats.Record(context.Background(), x.PLCacheHitRatio.M(m.Ratio()))
450450

451-
x.NumPostingListCacheSave.M(ml.cache.numCacheRead.Load())
452-
ml.cache.numCacheSave.Store(0)
451+
if EnableDetailedMetrics {
452+
x.NumPostingListCacheSave.M(ml.cache.numCacheRead.Load())
453+
x.NumPostingListCacheRead.M(ml.cache.numCacheRead.Load())
454+
x.NumPostingListCacheReadFail.M(ml.cache.numCacheReadFails.Load())
455+
}
453456

454-
x.NumPostingListCacheRead.M(ml.cache.numCacheRead.Load())
457+
ml.cache.numCacheSave.Store(0)
455458
ml.cache.numCacheRead.Store(0)
456-
457-
x.NumPostingListCacheReadFail.M(ml.cache.numCacheReadFails.Load())
458459
ml.cache.numCacheReadFails.Store(0)
459460
}
460461
}()
@@ -558,10 +559,12 @@ func ReadPostingList(key []byte, it *badger.Iterator) (*List, error) {
558559
start := time.Now()
559560
defer func() {
560561
ms := x.SinceMs(start)
561-
var tags []tag.Mutator
562-
tags = append(tags, tag.Upsert(x.KeyMethod, "iterate"))
563-
tags = append(tags, tag.Upsert(x.KeyStatus, pk.Attr))
564-
_ = ostats.RecordWithTags(context.Background(), tags, x.BadgerReadLatencyMs.M(ms))
562+
if EnableDetailedMetrics {
563+
var tags []tag.Mutator
564+
tags = append(tags, tag.Upsert(x.KeyMethod, "iterate"))
565+
tags = append(tags, tag.Upsert(x.KeyStatus, pk.Attr))
566+
_ = ostats.RecordWithTags(context.Background(), tags, x.BadgerReadLatencyMs.M(ms))
567+
}
565568
}()
566569

567570
if pk.HasStartUid {

worker/server_state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const (
5353
GraphQLDefaults = `introspection=true; debug=false; extensions=true; poll-interval=1s; ` +
5454
`lambda-url=;`
5555
CacheDefaults = `size-mb=1024; percentage=40,40,20; remove-on-update=false`
56-
FeatureFlagsDefaults = `normalize-compatibility-mode=`
56+
FeatureFlagsDefaults = `normalize-compatibility-mode=; enable-detailed-metrics=false`
5757
)
5858

5959
// ServerState holds the state of the Dgraph server.

0 commit comments

Comments
 (0)