mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
grpcproxy: add richer metrics for watch
This commit is contained in:
parent
0326d6fdd3
commit
a686c994cd
37
proxy/grpcproxy/metrics.go
Normal file
37
proxy/grpcproxy/metrics.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// Copyright 2016 The etcd Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package grpcproxy
|
||||||
|
|
||||||
|
import "github.com/prometheus/client_golang/prometheus"
|
||||||
|
|
||||||
|
var (
|
||||||
|
watchersCoalescing = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
|
Namespace: "etcd",
|
||||||
|
Subsystem: "grpc_proxy",
|
||||||
|
Name: "watchers_coalescing_total",
|
||||||
|
Help: "Total number of current watchers coalescing",
|
||||||
|
})
|
||||||
|
eventsCoalescing = prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
|
Namespace: "etcd",
|
||||||
|
Subsystem: "grpc_proxy",
|
||||||
|
Name: "events_coalescing_total",
|
||||||
|
Help: "Total number of events coalescing",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
prometheus.MustRegister(watchersCoalescing)
|
||||||
|
prometheus.MustRegister(eventsCoalescing)
|
||||||
|
}
|
@ -89,6 +89,9 @@ func (wb *watchBroadcast) bcast(wr clientv3.WatchResponse) {
|
|||||||
for r := range wb.receivers {
|
for r := range wb.receivers {
|
||||||
r.send(wr)
|
r.send(wr)
|
||||||
}
|
}
|
||||||
|
if wb.size() > 0 {
|
||||||
|
eventsCoalescing.Add(float64(wb.size() - 1))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add puts a watcher into receiving a broadcast if its revision at least
|
// add puts a watcher into receiving a broadcast if its revision at least
|
||||||
@ -121,6 +124,8 @@ func (wb *watchBroadcast) add(w *watcher) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
wb.receivers[w] = struct{}{}
|
wb.receivers[w] = struct{}{}
|
||||||
|
watchersCoalescing.Inc()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
func (wb *watchBroadcast) delete(w *watcher) {
|
func (wb *watchBroadcast) delete(w *watcher) {
|
||||||
@ -130,6 +135,10 @@ func (wb *watchBroadcast) delete(w *watcher) {
|
|||||||
panic("deleting missing watcher from broadcast")
|
panic("deleting missing watcher from broadcast")
|
||||||
}
|
}
|
||||||
delete(wb.receivers, w)
|
delete(wb.receivers, w)
|
||||||
|
if !wb.empty() {
|
||||||
|
// do not dec the only left watcher for coalescing.
|
||||||
|
watchersCoalescing.Dec()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wb *watchBroadcast) size() int {
|
func (wb *watchBroadcast) size() int {
|
||||||
@ -141,6 +150,11 @@ func (wb *watchBroadcast) size() int {
|
|||||||
func (wb *watchBroadcast) empty() bool { return wb.size() == 0 }
|
func (wb *watchBroadcast) empty() bool { return wb.size() == 0 }
|
||||||
|
|
||||||
func (wb *watchBroadcast) stop() {
|
func (wb *watchBroadcast) stop() {
|
||||||
|
if !wb.empty() {
|
||||||
|
// do not dec the only left watcher for coalescing.
|
||||||
|
watchersCoalescing.Sub(float64(wb.size() - 1))
|
||||||
|
}
|
||||||
|
|
||||||
wb.cancel()
|
wb.cancel()
|
||||||
<-wb.donec
|
<-wb.donec
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user