Skip to content
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
13 changes: 13 additions & 0 deletions pkg/controller/fileobserver/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ const (
FileDeleted
)

func (t ActionType) name() string {
switch t {
case FileCreated:
return "create"
case FileDeleted:
return "delete"
case FileModified:
return "modified"
default:
return "unknown"
}
}

// String returns human readable form of action taken on a file.
func (t ActionType) String(filename string) string {
switch t {
Expand Down
18 changes: 18 additions & 0 deletions pkg/controller/fileobserver/observer_polling.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"time"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/component-base/metrics"
"k8s.io/component-base/metrics/legacyregistry"
"k8s.io/klog"
)

Expand Down Expand Up @@ -114,6 +116,9 @@ func (o *pollingObserver) processReactors(stopCh <-chan struct{}) {
klog.Infof("Observed file %q has been modified (old=%q, new=%q)", filename, lastKnownFileState.hash, currentFileState.hash)
action = FileModified
}
// increment metrics counter for this file
observerActionsMetrics.WithLabelValues(filename, action.name()).Inc()
// execute the register reactor
if err := reactors[i](filename, action); err != nil {
klog.Errorf("Reactor for %q failed: %v", filename, err)
}
Expand All @@ -132,6 +137,19 @@ func (o *pollingObserver) processReactors(stopCh <-chan struct{}) {
}
}

var observerActionsMetrics = metrics.NewCounterVec(&metrics.CounterOpts{
Subsystem: "fileobserver",
Name: "action_count",
Help: "Counter for every observed action for all monitored files",
StabilityLevel: metrics.ALPHA,
}, []string{"name", "filename"})

func init() {
(&sync.Once{}).Do(func() {
legacyregistry.MustRegister(observerActionsMetrics)
})
}

// Run will start a new observer.
func (o *pollingObserver) Run(stopChan <-chan struct{}) {
klog.Info("Starting file observer")
Expand Down