Skip to content

Commit 1206e2a

Browse files
author
Harshil Goel
authored
fix(core): put new metrics behind a feature flag (#9337) (#9348)
Cherry pick
1 parent 7d11922 commit 1206e2a

4 files changed

Lines changed: 34 additions & 21 deletions

File tree

dgraph/cmd/alpha/run.go

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

@@ -753,6 +754,7 @@ func run() {
753754
featureFlagsConf := z.NewSuperFlag(Alpha.Conf.GetString("feature-flags")).MergeAndCheckDefault(
754755
worker.FeatureFlagsDefaults)
755756
x.Config.NormalizeCompatibilityMode = featureFlagsConf.GetString("normalize-compatibility-mode")
757+
enableDetailedMetrics := featureFlagsConf.GetBool("enable-detailed-metrics")
756758

757759
x.PrintVersion()
758760
glog.Infof("x.Config: %+v", x.Config)
@@ -777,6 +779,7 @@ func run() {
777779
// schema before calling posting.Init().
778780
schema.Init(worker.State.Pstore)
779781
posting.Init(worker.State.Pstore, postingListCacheSize, removeOnUpdate)
782+
posting.SetEnabledDetailedMetrics(enableDetailedMetrics)
780783
defer posting.Cleanup()
781784
worker.Init(worker.State.Pstore)
782785

posting/lists.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ const (
2828
)
2929

3030
var (
31-
pstore *badger.DB
32-
closer *z.Closer
31+
pstore *badger.DB
32+
closer *z.Closer
33+
EnableDetailedMetrics bool
3334
)
3435

3536
// Init initializes the posting lists package, the in memory and dirty list hash.
@@ -41,6 +42,10 @@ func Init(ps *badger.DB, cacheSize int64, removeOnUpdate bool) {
4142
memoryLayer = initMemoryLayer(cacheSize, removeOnUpdate)
4243
}
4344

45+
func SetEnabledDetailedMetrics(enableMetrics bool) {
46+
EnableDetailedMetrics = enableMetrics
47+
}
48+
4449
func UpdateMaxCost(maxCost int64) {
4550
}
4651

@@ -297,15 +302,17 @@ func (lc *LocalCache) getInternal(key []byte, readFromDisk bool) (*List, error)
297302
}
298303

299304
func (lc *LocalCache) readPostingListAt(key []byte) (*pb.PostingList, error) {
300-
start := time.Now()
301-
defer func() {
302-
pk, _ := x.Parse(key)
303-
ms := x.SinceMs(start)
304-
var tags []tag.Mutator
305-
tags = append(tags, tag.Upsert(x.KeyMethod, "get"))
306-
tags = append(tags, tag.Upsert(x.KeyStatus, pk.Attr))
307-
_ = ostats.RecordWithTags(context.Background(), tags, x.BadgerReadLatencyMs.M(ms))
308-
}()
305+
if EnableDetailedMetrics {
306+
start := time.Now()
307+
defer func() {
308+
ms := x.SinceMs(start)
309+
pk, _ := x.Parse(key)
310+
var tags []tag.Mutator
311+
tags = append(tags, tag.Upsert(x.KeyMethod, "get"))
312+
tags = append(tags, tag.Upsert(x.KeyStatus, pk.Attr))
313+
_ = ostats.RecordWithTags(context.Background(), tags, x.BadgerReadLatencyMs.M(ms))
314+
}()
315+
}
309316

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

posting/mvcc.go

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

440-
x.NumPostingListCacheSave.M(ml.cache.numCacheRead.Load())
441-
ml.cache.numCacheSave.Store(0)
440+
if EnableDetailedMetrics {
441+
x.NumPostingListCacheSave.M(ml.cache.numCacheRead.Load())
442+
x.NumPostingListCacheRead.M(ml.cache.numCacheRead.Load())
443+
x.NumPostingListCacheReadFail.M(ml.cache.numCacheReadFails.Load())
444+
}
442445

443-
x.NumPostingListCacheRead.M(ml.cache.numCacheRead.Load())
446+
ml.cache.numCacheSave.Store(0)
444447
ml.cache.numCacheRead.Store(0)
445-
446-
x.NumPostingListCacheReadFail.M(ml.cache.numCacheReadFails.Load())
447448
ml.cache.numCacheReadFails.Store(0)
448449
}
449450
}()
@@ -547,10 +548,12 @@ func ReadPostingList(key []byte, it *badger.Iterator) (*List, error) {
547548
start := time.Now()
548549
defer func() {
549550
ms := x.SinceMs(start)
550-
var tags []tag.Mutator
551-
tags = append(tags, tag.Upsert(x.KeyMethod, "iterate"))
552-
tags = append(tags, tag.Upsert(x.KeyStatus, pk.Attr))
553-
_ = ostats.RecordWithTags(context.Background(), tags, x.BadgerReadLatencyMs.M(ms))
551+
if EnableDetailedMetrics {
552+
var tags []tag.Mutator
553+
tags = append(tags, tag.Upsert(x.KeyMethod, "iterate"))
554+
tags = append(tags, tag.Upsert(x.KeyStatus, pk.Attr))
555+
_ = ostats.RecordWithTags(context.Background(), tags, x.BadgerReadLatencyMs.M(ms))
556+
}
554557
}()
555558

556559
if pk.HasStartUid {

worker/server_state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const (
4242
GraphQLDefaults = `introspection=true; debug=false; extensions=true; poll-interval=1s; ` +
4343
`lambda-url=;`
4444
CacheDefaults = `size-mb=1024; percentage=40,40,20; remove-on-update=false`
45-
FeatureFlagsDefaults = `normalize-compatibility-mode=`
45+
FeatureFlagsDefaults = `normalize-compatibility-mode=; enable-detailed-metrics=false`
4646
)
4747

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

0 commit comments

Comments
 (0)