Skip to content

Commit

Permalink
let's see if this works
Browse files Browse the repository at this point in the history
  • Loading branch information
drewgonzales360 committed Sep 20, 2024
1 parent 8268497 commit f217ccd
Showing 1 changed file with 18 additions and 8 deletions.
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

0 comments on commit f217ccd

Please sign in to comment.