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

Refactor nflog configuration options to make it similar to Silences. #3220

Merged
merged 9 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 12 additions & 11 deletions nflog/nflog.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,6 @@ func New(o Options) (*Log, error) {
return nil, err
}

if o.SnapshotFile != "" {
if r, err := os.Open(o.SnapshotFile); err != nil {
if !os.IsNotExist(err) {
return nil, err
}
} else {
o.SnapshotReader = r
defer r.Close()
}
}

l := &Log{
clock: clock.New(),
retention: o.Retention,
Expand All @@ -266,6 +255,18 @@ func New(o Options) (*Log, error) {
l.logger = o.Logger
}

if o.SnapshotFile != "" {
if r, err := os.Open(o.SnapshotFile); err != nil {
if !os.IsNotExist(err) {
return nil, err
}
level.Debug(l.logger).Log("msg", "failed to load notification log snapshot file", "err", err)
gotjosh marked this conversation as resolved.
Show resolved Hide resolved
} else {
o.SnapshotReader = r
defer r.Close()
}
}

if o.SnapshotReader != nil {
if err := l.loadSnapshot(o.SnapshotReader); err != nil {
return l, err
Expand Down
23 changes: 13 additions & 10 deletions silence/silence.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,16 +319,6 @@ func New(o Options) (*Silences, error) {
if err := o.validate(); err != nil {
return nil, err
}
if o.SnapshotFile != "" {
if r, err := os.Open(o.SnapshotFile); err != nil {
if !os.IsNotExist(err) {
return nil, err
}
} else {
o.SnapshotReader = r
defer r.Close()
}
}
s := &Silences{
clock: clock.New(),
mc: matcherCache{},
Expand All @@ -342,6 +332,19 @@ func New(o Options) (*Silences, error) {
if o.Logger != nil {
s.logger = o.Logger
}

if o.SnapshotFile != "" {
if r, err := os.Open(o.SnapshotFile); err != nil {
if !os.IsNotExist(err) {
return nil, err
}
level.Debug(s.logger).Log("msg", "failed to load silence snapshot file", "err", err)
} else {
o.SnapshotReader = r
defer r.Close()
}
}

if o.SnapshotReader != nil {
if err := s.loadSnapshot(o.SnapshotReader); err != nil {
return s, err
Expand Down