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 grpc warnings in API server #76

Open
wants to merge 1 commit into
base: release-1.29-dd-v1.29.7-dd.1
Choose a base branch
from
Open
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
26 changes: 18 additions & 8 deletions staging/src/k8s.io/apiserver/pkg/storage/etcd3/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,29 @@ type monitorCollector struct {

mutex sync.Mutex
monitorGetter func() ([]Monitor, error)
monitors *[]Monitor

// get storage metric monitor is protected by mutex
monitorMutex sync.Mutex
}

func (m *monitorCollector) setGetter(monitorGetter func() ([]Monitor, error)) {
m.mutex.Lock()
defer m.mutex.Unlock()
m.monitorGetter = monitorGetter
func (m *monitorCollector) getMonitors() ([]Monitor, error) {
m.monitorMutex.Lock()
defer m.monitorMutex.Unlock()
if m.monitors == nil {
getters, err := m.monitorGetter()
if err != nil {
return nil, err
}
m.monitors = &getters
}
return *m.monitors, nil
}

func (m *monitorCollector) getGetter() func() ([]Monitor, error) {
func (m *monitorCollector) setGetter(monitorGetter func() ([]Monitor, error)) {
m.mutex.Lock()
defer m.mutex.Unlock()
return m.monitorGetter
m.monitorGetter = monitorGetter
}

// DescribeWithStability implements compbasemetrics.StableColletor
Expand All @@ -281,7 +292,7 @@ func (c *monitorCollector) DescribeWithStability(ch chan<- *compbasemetrics.Desc

// CollectWithStability implements compbasemetrics.StableColletor
func (c *monitorCollector) CollectWithStability(ch chan<- compbasemetrics.Metric) {
monitors, err := c.getGetter()()
monitors, err := c.getMonitors()
if err != nil {
return
}
Expand All @@ -293,7 +304,6 @@ func (c *monitorCollector) CollectWithStability(ch chan<- compbasemetrics.Metric
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
metrics, err := m.Monitor(ctx)
cancel()
m.Close()
if err != nil {
klog.InfoS("Failed to get storage metrics", "storage_cluster_id", storageClusterID, "err", err)
continue
Expand Down
Loading