Skip to content

Commit

Permalink
Merge pull request #589 from nnmin-aws/nnmin-rel6
Browse files Browse the repository at this point in the history
cherry-pick PR 587 to release-0.6 and make new release
  • Loading branch information
k8s-ci-robot authored Apr 4, 2023
2 parents 77ef65a + 306c653 commit 0a6a87e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
14 changes: 13 additions & 1 deletion pkg/mapper/dynamicfile/dynamicfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.8
0.6.9

0 comments on commit 0a6a87e

Please sign in to comment.