diff --git a/pkg/mapper/dynamicfile/dynamicfile.go b/pkg/mapper/dynamicfile/dynamicfile.go index 62ca816f3..d3430c442 100644 --- a/pkg/mapper/dynamicfile/dynamicfile.go +++ b/pkg/mapper/dynamicfile/dynamicfile.go @@ -10,6 +10,7 @@ import ( "os" "sigs.k8s.io/aws-iam-authenticator/pkg/arn" "sigs.k8s.io/aws-iam-authenticator/pkg/config" + "sigs.k8s.io/aws-iam-authenticator/pkg/metrics" "strings" "sync" "time" @@ -86,15 +87,24 @@ func NewDynamicFileMapStore(cfg config.Config) (*DynamicFileMapStore, error) { func (m *DynamicFileMapStore) startLoadDynamicFile(stopCh <-chan struct{}) { go wait.Until(func() { - m.loadDynamicFile() + err := m.loadDynamicFile() + if err != nil { + logrus.Errorf("startLoadDynamicFile: failed when loadDynamicFile, %+v", err) + metrics.Get().DynamicFileFailures.Inc() + return + } // start to watch the file change watcher, err := fsnotify.NewWatcher() if err != nil { logrus.Errorf("startLoadDynamicFile: failed when call fsnotify.NewWatcher, %+v", err) + metrics.Get().DynamicFileFailures.Inc() + return } err = watcher.Add(m.filename) if err != nil { logrus.Errorf("startLoadDynamicFile: could not add file to watcher %v", err) + metrics.Get().DynamicFileFailures.Inc() + return } defer watcher.Close() @@ -124,6 +134,8 @@ func (m *DynamicFileMapStore) startLoadDynamicFile(stopCh <-chan struct{}) { } case err := <-watcher.Errors: logrus.Errorf("startLoadDynamicFile: watcher.Errors for dynamic file %v", err) + metrics.Get().DynamicFileFailures.Inc() + return } } }, time.Second, stopCh) diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index dd3771f77..4f730598c 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -39,6 +39,7 @@ type Metrics struct { EC2DescribeInstanceCallCount prometheus.Counter StsConnectionFailure prometheus.Counter StsResponses *prometheus.CounterVec + DynamicFileFailures prometheus.Counter } func createMetrics(reg prometheus.Registerer) Metrics { @@ -52,6 +53,13 @@ func createMetrics(reg prometheus.Registerer) Metrics { Help: "EKS Configmap watch failures", }, ), + DynamicFileFailures: factory.NewCounter( + prometheus.CounterOpts{ + Namespace: Namespace, + Name: "dynamicfile_failures_total", + Help: "Dynamic file failures", + }, + ), StsConnectionFailure: factory.NewCounter( prometheus.CounterOpts{ Namespace: Namespace, diff --git a/version.txt b/version.txt index bc8443e34..186400227 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.6.8 \ No newline at end of file +0.6.9 \ No newline at end of file