Skip to content

Commit 5b761fb

Browse files
committed
config/listener: Mirco Fixes For Review
- UnixMilli does not require UTC, UnixMilli() always returns UTC. - Don't reject event submissions when no rules exist. - Use strconv instead of fmt for a single number.
1 parent 9d50a7b commit 5b761fb

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

internal/config/rule.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type SourceRuleVersion struct {
1616
// NewSourceRuleVersion creates a new source version based on the current timestamp and a zero counter.
1717
func NewSourceRuleVersion() SourceRuleVersion {
1818
return SourceRuleVersion{
19-
Major: time.Now().UTC().UnixMilli(),
19+
Major: time.Now().UnixMilli(),
2020
Minor: 0,
2121
}
2222
}

internal/listener/listener.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"errors"
88
"fmt"
99
"net/http"
10+
"strconv"
1011
"time"
1112

1213
"github.com/icinga/icinga-go-library/database"
@@ -138,7 +139,7 @@ func (l *Listener) ProcessEvent(w http.ResponseWriter, r *http.Request) {
138139

139140
// If the client uses an outdated rules version, reject the request but also send the current rules version
140141
// and rules for this source back to the client, so it can retry the request with the updated rules.
141-
if latestRuleVersion := l.runtimeConfig.GetRulesVersionFor(src.ID); ev.RulesVersion != latestRuleVersion || latestRuleVersion == config.MissingRuleVersion {
142+
if latestRuleVersion := l.runtimeConfig.GetRulesVersionFor(src.ID); ev.RulesVersion != latestRuleVersion {
142143
w.WriteHeader(http.StatusPreconditionFailed)
143144
l.writeSourceRulesInfo(w, src)
144145

@@ -317,7 +318,7 @@ func (l *Listener) writeSourceRulesInfo(w http.ResponseWriter, source *config.So
317318
rulesInfo.Rules = make(map[string]string)
318319

319320
for _, rID := range sourceInfo.RuleIDs {
320-
id := fmt.Sprintf("%d", rID)
321+
id := strconv.FormatInt(rID, 10)
321322
filterExpr := ""
322323
if l.runtimeConfig.Rules[rID].ObjectFilterExpr.Valid {
323324
filterExpr = l.runtimeConfig.Rules[rID].ObjectFilterExpr.String

0 commit comments

Comments
 (0)