-
Notifications
You must be signed in to change notification settings - Fork 730
server: change PD region label isolate level Histogram to Gauge #976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
3570864
12dda50
a0b7141
fc72631
812d930
c4c0197
5888b3e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,14 +66,13 @@ var ( | |
Help: "Status of the regions.", | ||
}, []string{"type"}) | ||
|
||
regionLabelLevelHistogram = prometheus.NewHistogram( | ||
prometheus.HistogramOpts{ | ||
regionLabelLevelGauge = prometheus.NewGaugeVec( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it safe to change a metrics' type? Can prometheus handle it right? /cc @overvenus There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gauge use |
||
prometheus.GaugeOpts{ | ||
Namespace: "pd", | ||
Subsystem: "regions", | ||
Name: "label_level", | ||
Help: "Bucketed histogram of the label level of the region.", | ||
Buckets: prometheus.LinearBuckets(0, 1, 8), | ||
}) | ||
Help: "Number of regions in the different label level.", | ||
}, []string{"type"}) | ||
|
||
timeJumpBackCounter = prometheus.NewCounter( | ||
prometheus.CounterOpts{ | ||
|
@@ -155,6 +154,6 @@ func init() { | |
prometheus.MustRegister(tsoCounter) | ||
prometheus.MustRegister(storeStatusGauge) | ||
prometheus.MustRegister(regionStatusGauge) | ||
prometheus.MustRegister(regionLabelLevelHistogram) | ||
prometheus.MustRegister(regionLabelLevelGauge) | ||
prometheus.MustRegister(metadataGauge) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ | |
package server | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pingcap/pd/server/core" | ||
"github.com/pingcap/pd/server/namespace" | ||
) | ||
|
@@ -66,7 +68,7 @@ func (r *regionStatistics) deleteEntry(deleteIndex regionStatisticType, regionID | |
} | ||
} | ||
|
||
func (r *regionStatistics) Observe(region *core.RegionInfo, stores []*core.StoreInfo, labels []string) { | ||
func (r *regionStatistics) Observe(region *core.RegionInfo, stores []*core.StoreInfo) { | ||
// Region state. | ||
regionID := region.GetId() | ||
namespace := r.classifier.GetRegionNamespace(region) | ||
|
@@ -104,11 +106,59 @@ func (r *regionStatistics) Observe(region *core.RegionInfo, stores []*core.Store | |
} | ||
r.deleteEntry(deleteIndex, regionID) | ||
r.index[regionID] = peerTypeIndex | ||
if len(stores) == 0 { | ||
return | ||
} | ||
|
||
func (r *regionStatistics) clearDefunctRegion(regionID uint64) { | ||
if oldIndex, ok := r.index[regionID]; ok { | ||
r.deleteEntry(oldIndex, regionID) | ||
} | ||
} | ||
|
||
func (r *regionStatistics) Collect() { | ||
regionStatusGauge.WithLabelValues("miss_peer_region_count").Set(float64(len(r.stats[missPeer]))) | ||
regionStatusGauge.WithLabelValues("extra_peer_region_count").Set(float64(len(r.stats[extraPeer]))) | ||
regionStatusGauge.WithLabelValues("down_peer_region_count").Set(float64(len(r.stats[downPeer]))) | ||
regionStatusGauge.WithLabelValues("pending_peer_region_count").Set(float64(len(r.stats[pendingPeer]))) | ||
regionStatusGauge.WithLabelValues("incorrect_namespace_region_count").Set(float64(len(r.stats[incorrectNamespace]))) | ||
} | ||
|
||
type labelLevelStatistics struct { | ||
regionLabelLevelStats map[uint64]int | ||
labelLevelCounter map[int]int | ||
} | ||
|
||
func newLabelLevelStatistics() *labelLevelStatistics { | ||
return &labelLevelStatistics{ | ||
regionLabelLevelStats: make(map[uint64]int), | ||
labelLevelCounter: make(map[int]int), | ||
} | ||
} | ||
|
||
func (l *labelLevelStatistics) Observe(region *core.RegionInfo, stores []*core.StoreInfo, labels []string) { | ||
regionID := region.GetId() | ||
regionLabelLevel := getRegionLabelIsolationLevel(stores, labels) | ||
regionLabelLevelHistogram.Observe(float64(regionLabelLevel)) | ||
if level, ok := l.regionLabelLevelStats[regionID]; ok { | ||
if level == regionLabelLevel { | ||
return | ||
} | ||
l.labelLevelCounter[level]-- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if region was merged, so there is no heartbeat anymore, namely Observe will not be called. Maybe we should add a function which can delete all relative stats of merged region. |
||
} | ||
l.regionLabelLevelStats[regionID] = regionLabelLevel | ||
l.labelLevelCounter[regionLabelLevel]++ | ||
} | ||
|
||
func (l *labelLevelStatistics) Collect() { | ||
for level, count := range l.labelLevelCounter { | ||
typ := fmt.Sprintf("level_%d", level) | ||
regionStatusGauge.WithLabelValues(typ).Set(float64(count)) | ||
} | ||
} | ||
|
||
func (l *labelLevelStatistics) clearDefunctRegion(regionID uint64) { | ||
if level, ok := l.regionLabelLevelStats[regionID]; ok { | ||
l.labelLevelCounter[level]-- | ||
delete(l.regionLabelLevelStats, regionID) | ||
} | ||
} | ||
|
||
func getRegionLabelIsolationLevel(stores []*core.StoreInfo, labels []string) int { | ||
|
@@ -149,11 +199,3 @@ func notIsolatedStoresWithLabel(stores []*core.StoreInfo, label string) [][]*cor | |
} | ||
return res | ||
} | ||
|
||
func (r *regionStatistics) Collect() { | ||
regionStatusGauge.WithLabelValues("miss_peer_region_count").Set(float64(len(r.stats[missPeer]))) | ||
regionStatusGauge.WithLabelValues("extra_peer_region_count").Set(float64(len(r.stats[extraPeer]))) | ||
regionStatusGauge.WithLabelValues("down_peer_region_count").Set(float64(len(r.stats[downPeer]))) | ||
regionStatusGauge.WithLabelValues("pending_peer_region_count").Set(float64(len(r.stats[pendingPeer]))) | ||
regionStatusGauge.WithLabelValues("incorrect_namespace_region_count").Set(float64(len(r.stats[incorrectNamespace]))) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there some way to call this function in RemoveRegion(), maybe other places will call the RemoveRegion() in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use less this method, otherwise, the logic is more confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I misunderstood, but now the statistics not belong to
RegionsInfo
, it also needs to know some stores information.