Skip to content
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

fix k8s-k8s-watch add handler cache keys metrics #982

Merged
merged 3 commits into from
Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bcs-common/pkg/bcsapi/clustermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func XRequestID() context.Context {
func NewClusterManager(config *Config) cm.ClusterManagerClient {
rand.Seed(time.Now().UnixNano())
if len(config.Hosts) == 0 {
//! pay more attension for nil return
//! pay more attention for nil return
return nil
}
//create grpc connection
Expand Down
2 changes: 1 addition & 1 deletion bcs-common/pkg/master/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (e *Empty) Init() error {
func (e *Empty) Finit() {
}

//Register registery information to storage
//Register registry information to storage
func (e *Empty) Register() error {
return nil

Expand Down
9 changes: 8 additions & 1 deletion bcs-k8s/bcs-k8s-watch/app/k8s/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,16 @@ func (w *Watcher) ListKeys() []string {
func (w *Watcher) Run(stopCh <-chan struct{}) {
// do with handler data
go w.handleQueueData(stopCh)

// metrics collect watcher fifo queue length
go wait.NonSlidingUntil(func() {
metrics.ReportK8sWatcherQueueLength(w.resourceType, float64(w.queue.Length()))
}, time.Second*1, stopCh)
}, time.Second * 1, stopCh)

// metrics collect watcher cache keys length
go wait.NonSlidingUntil(func() {
metrics.ReportK8sWatcherCacheKeys(w.resourceType, float64(len(w.ListKeys())))
}, time.Second * 1, stopCh)

// run controller.
w.controller.Run(stopCh)
Expand Down
14 changes: 14 additions & 0 deletions bcs-k8s/bcs-k8s-watch/pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ var (
Buckets: []float64{0.0005, 0.001, 0.0025, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.0, 3.0},
}, []string{"cluster_id", "handler", "namespace", "resource_type", "method", "status"})

// bcs-k8s-watch record watcher cache keys_num
requestsWatcherCacheKeysLength = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "bcs_k8s_watch",
Subsystem: "cache",
Name: "keys_num",
Help: "The total number of watcher object keys",
}, []string{"watcher"})

// bcs-k8s-watch record watcher queue length
requestsWatcherQueueLength = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "bcs_k8s_watch",
Expand Down Expand Up @@ -86,6 +94,7 @@ func init() {
prometheus.MustRegister(requestsTotalHandlerQueue)
prometheus.MustRegister(requestLatencyHandler)
prometheus.MustRegister(requestsWatcherQueueLength)
prometheus.MustRegister(requestsWatcherCacheKeysLength)

// handler discard events
prometheus.MustRegister(handlerDiscardEvents)
Expand Down Expand Up @@ -127,6 +136,11 @@ func ReportK8sWatcherQueueLengthDec(watcher string) {
requestsWatcherQueueLength.WithLabelValues(watcher).Dec()
}

// ReportK8sWatcherQueueLength report watcher queue length
func ReportK8sWatcherCacheKeys(watcher string, queueLen float64) {
requestsWatcherCacheKeysLength.WithLabelValues(watcher).Set(queueLen)
}

// ReportK8sWatchHandlerDiscardEvents report handler discard events num
func ReportK8sWatchHandlerDiscardEvents(clusterID, handler string) {
handlerDiscardEvents.WithLabelValues(clusterID, handler).Inc()
Expand Down
2 changes: 1 addition & 1 deletion bcs-services/bcs-cpuset-device/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func setConfig(conf *config.Config, op *options.Option) {
conf.ClusterID = op.ClusterID
conf.NodeIP = op.Address

// client cert directoty
// client cert directory
if op.CertConfig.ClientCertFile != "" && op.CertConfig.CAFile != "" &&
op.CertConfig.ClientKeyFile != "" {

Expand Down
2 changes: 1 addition & 1 deletion bcs-services/bcs-gateway-discovery/app/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type ServerOptions struct {
Etcd EtcdRegistry `json:"etcdRegistry"`
}

//Valid check if necessary paramter is setting correctly
//Valid check if necessary parameter is setting correctly
func (opt *ServerOptions) Valid() error {
if len(opt.AdminAPI) == 0 {
return fmt.Errorf("Lost admin api setting")
Expand Down
2 changes: 1 addition & 1 deletion install/cryptool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ func main() {
}
fmt.Printf("Original text: %s\n", string(out))
default:
fmt.Printf("Unkown action...\n")
fmt.Printf("Unknown action...\n")
}
}