Skip to content

Commit

Permalink
remove the monitor sampler
Browse files Browse the repository at this point in the history
  • Loading branch information
deads2k committed May 31, 2023
1 parent ae0cc3f commit a9be206
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 256 deletions.
2 changes: 0 additions & 2 deletions pkg/monitor/api.go
Expand Up @@ -63,8 +63,6 @@ func Start(ctx context.Context, restConfig *rest.Config, additionalEventInterval

// add interval creation at the same point where we add the monitors
startClusterOperatorMonitoring(ctx, m, configClient)

m.StartSampling(ctx)
return m, nil
}

Expand Down
57 changes: 0 additions & 57 deletions pkg/monitor/monitor.go
@@ -1,7 +1,6 @@
package monitor

import (
"context"
"fmt"
"sort"
"strconv"
Expand Down Expand Up @@ -44,37 +43,6 @@ func NewMonitorWithInterval(interval time.Duration) *Monitor {

var _ Interface = &Monitor{}

// StartSampling starts sampling every interval until the provided context is done.
// A sample is captured when the context is closed.
func (m *Monitor) StartSampling(ctx context.Context) {
if m.interval == 0 {
return
}
go func() {
ticker := time.NewTicker(m.interval)
defer ticker.Stop()
hasConditions := false
for {
select {
case <-ticker.C:
case <-ctx.Done():
hasConditions = m.sample(hasConditions)
return
}
hasConditions = m.sample(hasConditions)
}
}()
}

// AddSampler adds a sampler function to the list of samplers to run every interval.
// Conditions discovered this way are recorded with a start and end time if they persist
// across multiple sampling intervals.
func (m *Monitor) AddSampler(fn SamplerFunc) {
m.lock.Lock()
defer m.lock.Unlock()
m.samplers = append(m.samplers, fn)
}

func (m *Monitor) CurrentResourceState() monitorapi.ResourcesMap {
m.recordedResourceLock.Lock()
defer m.recordedResourceLock.Unlock()
Expand Down Expand Up @@ -235,31 +203,6 @@ func (m *Monitor) RecordAt(t time.Time, conditions ...monitorapi.Condition) {
}
}

func (m *Monitor) sample(hasPrevious bool) bool {
m.lock.Lock()
samplers := m.samplers
m.lock.Unlock()

now := time.Now().UTC()
var conditions []*monitorapi.Condition
for _, fn := range samplers {
conditions = append(conditions, fn(now)...)
}
if len(conditions) == 0 {
if !hasPrevious {
return false
}
}

m.lock.Lock()
defer m.lock.Unlock()
m.samples = append(m.samples, &sample{
at: now,
conditions: conditions,
})
return len(conditions) > 0
}

func (m *Monitor) snapshot() ([]*sample, monitorapi.Intervals, monitorapi.Intervals) {
m.lock.Lock()
defer m.lock.Unlock()
Expand Down
1 change: 0 additions & 1 deletion pkg/monitor/noop.go
Expand Up @@ -19,4 +19,3 @@ func (*noOpMonitor) Record(conditions ...monitorapi.Condition)
func (*noOpMonitor) RecordAt(t time.Time, conditions ...monitorapi.Condition) {}
func (*noOpMonitor) StartInterval(t time.Time, condition monitorapi.Condition) int { return 0 }
func (*noOpMonitor) EndInterval(startedInterval int, t time.Time) {}
func (*noOpMonitor) AddSampler(fn SamplerFunc) {}
20 changes: 0 additions & 20 deletions pkg/monitor/operator.go
Expand Up @@ -263,26 +263,6 @@ func startClusterOperatorMonitoring(ctx context.Context, m Recorder, client conf
},
)

m.AddSampler(func(now time.Time) []*monitorapi.Condition {
var conditions []*monitorapi.Condition
for _, obj := range cvInformer.GetStore().List() {
cv, ok := obj.(*configv1.ClusterVersion)
if !ok {
continue
}
if len(cv.Status.History) > 0 {
if cv.Status.History[0].State != configv1.CompletedUpdate {
conditions = append(conditions, &monitorapi.Condition{
Level: monitorapi.Warning,
Locator: locateClusterVersion(cv),
Message: fmt.Sprintf("cluster is updating to %s", versionOrImage(cv.Status.History[0])),
})
}
}
}
return conditions
})

go cvInformer.Run(ctx.Done())
}

Expand Down
94 changes: 0 additions & 94 deletions pkg/monitor/sampler.go

This file was deleted.

80 changes: 0 additions & 80 deletions pkg/monitor/sampler_test.go

This file was deleted.

2 changes: 0 additions & 2 deletions pkg/monitor/types.go
Expand Up @@ -29,8 +29,6 @@ type Recorder interface {

StartInterval(t time.Time, condition monitorapi.Condition) int
EndInterval(startedInterval int, t time.Time)

AddSampler(fn SamplerFunc)
}

type ConditionalSampler interface {
Expand Down

0 comments on commit a9be206

Please sign in to comment.