Skip to content

Commit

Permalink
Merge branch 'master' into fix-overload
Browse files Browse the repository at this point in the history
  • Loading branch information
rleungx committed Jun 18, 2019
2 parents dda4595 + 293d4b5 commit e9abc2a
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 120 deletions.
2 changes: 1 addition & 1 deletion docs/api.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions server/api/api.raml
Expand Up @@ -64,6 +64,7 @@ types:
max-merge-region-size?: integer
max-merge-region-keys?: integer
split-merge-interval?: string
enable-two-way-merge?: boolean
patrol-region-interval?: string
max-store-down-time?: string
leader-schedule-limit?: integer
Expand Down
2 changes: 1 addition & 1 deletion server/cluster.go
Expand Up @@ -143,7 +143,7 @@ func (c *RaftCluster) start() error {

c.cachedCluster = cluster
c.coordinator = newCoordinator(c.cachedCluster, c.s.hbStreams, c.s.classifier)
c.cachedCluster.regionStats = newRegionStatistics(c.s.scheduleOpt, c.s.classifier)
c.cachedCluster.regionStats = statistics.NewRegionStatistics(c.s.scheduleOpt, c.s.classifier)
c.quit = make(chan struct{})

c.wg.Add(3)
Expand Down
14 changes: 7 additions & 7 deletions server/cluster_info.go
Expand Up @@ -35,8 +35,8 @@ type clusterInfo struct {
kv *core.KV
meta *metapb.Cluster
opt *scheduleOption
regionStats *regionStatistics
labelLevelStats *labelLevelStatistics
regionStats *statistics.RegionStatistics
labelLevelStats *statistics.LabelLevelStatistics
storesStats *statistics.StoresStats
prepareChecker *prepareChecker
changedRegions chan *core.RegionInfo
Expand All @@ -51,7 +51,7 @@ func newClusterInfo(id core.IDAllocator, opt *scheduleOption, kv *core.KV) *clus
id: id,
opt: opt,
kv: kv,
labelLevelStats: newLabelLevelStatistics(),
labelLevelStats: statistics.NewLabelLevelStatistics(),
storesStats: statistics.NewStoresStats(),
prepareChecker: newPrepareChecker(),
changedRegions: make(chan *core.RegionInfo, defaultChangedRegionsLimit),
Expand Down Expand Up @@ -620,9 +620,9 @@ func (c *clusterInfo) handleRegionHeartbeat(region *core.RegionInfo) error {
}
for _, item := range overlaps {
if c.regionStats != nil {
c.regionStats.clearDefunctRegion(item.GetId())
c.regionStats.ClearDefunctRegion(item.GetId())
}
c.labelLevelStats.clearDefunctRegion(item.GetId())
c.labelLevelStats.ClearDefunctRegion(item.GetId())
}

// Update related stores.
Expand Down Expand Up @@ -670,13 +670,13 @@ func (c *clusterInfo) collectMetrics() {
c.hotSpotCache.CollectMetrics(c.storesStats)
}

func (c *clusterInfo) GetRegionStatsByType(typ regionStatisticType) []*core.RegionInfo {
func (c *clusterInfo) GetRegionStatsByType(typ statistics.RegionStatisticType) []*core.RegionInfo {
if c.regionStats == nil {
return nil
}
c.RLock()
defer c.RUnlock()
return c.regionStats.getRegionStatsByType(typ)
return c.regionStats.GetRegionStatsByType(typ)
}

func (c *clusterInfo) GetOpt() namespace.ScheduleOptions {
Expand Down
10 changes: 5 additions & 5 deletions server/handler.go
Expand Up @@ -677,7 +677,7 @@ func (h *Handler) GetDownPeerRegions() ([]*core.RegionInfo, error) {
}
c.RLock()
defer c.RUnlock()
return c.cachedCluster.GetRegionStatsByType(downPeer), nil
return c.cachedCluster.GetRegionStatsByType(statistics.DownPeer), nil
}

// GetExtraPeerRegions gets the region exceeds the specified number of peers.
Expand All @@ -688,7 +688,7 @@ func (h *Handler) GetExtraPeerRegions() ([]*core.RegionInfo, error) {
}
c.RLock()
defer c.RUnlock()
return c.cachedCluster.GetRegionStatsByType(extraPeer), nil
return c.cachedCluster.GetRegionStatsByType(statistics.ExtraPeer), nil
}

// GetMissPeerRegions gets the region less than the specified number of peers.
Expand All @@ -699,7 +699,7 @@ func (h *Handler) GetMissPeerRegions() ([]*core.RegionInfo, error) {
}
c.RLock()
defer c.RUnlock()
return c.cachedCluster.GetRegionStatsByType(missPeer), nil
return c.cachedCluster.GetRegionStatsByType(statistics.MissPeer), nil
}

// GetPendingPeerRegions gets the region with pending peer.
Expand All @@ -710,7 +710,7 @@ func (h *Handler) GetPendingPeerRegions() ([]*core.RegionInfo, error) {
}
c.RLock()
defer c.RUnlock()
return c.cachedCluster.GetRegionStatsByType(pendingPeer), nil
return c.cachedCluster.GetRegionStatsByType(statistics.PendingPeer), nil
}

// GetIncorrectNamespaceRegions gets the region with incorrect namespace peer.
Expand All @@ -721,5 +721,5 @@ func (h *Handler) GetIncorrectNamespaceRegions() ([]*core.RegionInfo, error) {
}
c.RLock()
defer c.RUnlock()
return c.cachedCluster.GetRegionStatsByType(incorrectNamespace), nil
return c.cachedCluster.GetRegionStatsByType(statistics.IncorrectNamespace), nil
}
18 changes: 0 additions & 18 deletions server/metrics.go
Expand Up @@ -41,22 +41,6 @@ var (
Help: "Status of the cluster.",
}, []string{"name"})

regionStatusGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "pd",
Subsystem: "regions",
Name: "status",
Help: "Status of the regions.",
}, []string{"type"})

regionLabelLevelGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "pd",
Subsystem: "regions",
Name: "label_level",
Help: "Number of regions in the different label level.",
}, []string{"type"})

timeJumpBackCounter = prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: "pd",
Expand Down Expand Up @@ -150,8 +134,6 @@ func init() {
prometheus.MustRegister(regionHeartbeatLatency)
prometheus.MustRegister(hotSpotStatusGauge)
prometheus.MustRegister(tsoCounter)
prometheus.MustRegister(regionStatusGauge)
prometheus.MustRegister(regionLabelLevelGauge)
prometheus.MustRegister(metadataGauge)
prometheus.MustRegister(etcdStateGauge)
prometheus.MustRegister(patrolCheckRegionsHistogram)
Expand Down
18 changes: 18 additions & 0 deletions server/statistics/metrics.go
Expand Up @@ -32,6 +32,14 @@ var (
Help: "Store status for schedule",
}, []string{"namespace", "address", "store", "type"})

regionStatusGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "pd",
Subsystem: "regions",
Name: "status",
Help: "Status of the regions.",
}, []string{"type"})

clusterStatusGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "pd",
Expand All @@ -55,12 +63,22 @@ var (
Name: "status",
Help: "Status of the scheduling configurations.",
}, []string{"type", "namespace"})

regionLabelLevelGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "pd",
Subsystem: "regions",
Name: "label_level",
Help: "Number of regions in the different label level.",
}, []string{"type"})
)

func init() {
prometheus.MustRegister(hotCacheStatusGauge)
prometheus.MustRegister(storeStatusGauge)
prometheus.MustRegister(regionStatusGauge)
prometheus.MustRegister(clusterStatusGauge)
prometheus.MustRegister(placementStatusGauge)
prometheus.MustRegister(configStatusGauge)
prometheus.MustRegister(regionLabelLevelGauge)
}

0 comments on commit e9abc2a

Please sign in to comment.