Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cherry pick PR 587 to release-0.5 and new release #588

Merged
merged 2 commits into from
Apr 4, 2023
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
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 @@ -31,6 +31,7 @@ type Metrics struct {
EC2DescribeInstanceCallCount prometheus.Counter
StsConnectionFailure prometheus.Counter
StsResponses *prometheus.CounterVec
DynamicFileFailures prometheus.Counter
}

func createMetrics(reg prometheus.Registerer) Metrics {
Expand All @@ -44,6 +45,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.5.16
0.5.17