Skip to content

Commit 4d3729b

Browse files
committed
fix lint
1 parent 3776d31 commit 4d3729b

File tree

5 files changed

+21
-23
lines changed

5 files changed

+21
-23
lines changed

plugins/outputs/cloudwatchlogs/internal/pusher/retention_policy_ttl.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type payload struct {
2727
timestamp time.Time
2828
}
2929

30-
type retentionPolicyTTL struct {
30+
type RetentionPolicyTTL struct {
3131
logger telegraf.Logger
3232
stateFilePath string
3333
// oldTimestamps come from the TTL file on agent start. Key is escaped group name
@@ -39,8 +39,8 @@ type retentionPolicyTTL struct {
3939
done chan struct{}
4040
}
4141

42-
func NewRetentionPolicyTTL(logger telegraf.Logger, fileStatePath string) *retentionPolicyTTL {
43-
r := &retentionPolicyTTL{
42+
func NewRetentionPolicyTTL(logger telegraf.Logger, fileStatePath string) *RetentionPolicyTTL {
43+
r := &RetentionPolicyTTL{
4444
logger: logger,
4545
stateFilePath: filepath.Join(fileStatePath, logscommon.RetentionPolicyTTLFileName),
4646
oldTimestamps: make(map[string]time.Time),
@@ -55,19 +55,19 @@ func NewRetentionPolicyTTL(logger telegraf.Logger, fileStatePath string) *retent
5555
}
5656

5757
// Update will update the newTimestamps to the current time that will later be persisted to disk.
58-
func (r *retentionPolicyTTL) Update(group string) {
58+
func (r *RetentionPolicyTTL) Update(group string) {
5959
r.ch <- payload{
6060
group: group,
6161
timestamp: time.Now(),
6262
}
6363
}
6464

65-
func (r *retentionPolicyTTL) Done() {
65+
func (r *RetentionPolicyTTL) Done() {
6666
close(r.done)
6767
}
6868

6969
// IsExpired checks from the timestamps in the read state file at the agent start.
70-
func (r *retentionPolicyTTL) IsExpired(group string) bool {
70+
func (r *RetentionPolicyTTL) IsExpired(group string) bool {
7171
if ts, ok := r.oldTimestamps[escapeLogGroup(group)]; ok {
7272
return ts.Add(ttlTime).Before(time.Now())
7373
}
@@ -76,7 +76,7 @@ func (r *retentionPolicyTTL) IsExpired(group string) bool {
7676
}
7777

7878
// UpdateFromFile updates the newTimestamps cache using the timestamp from the loaded state file.
79-
func (r *retentionPolicyTTL) UpdateFromFile(group string) {
79+
func (r *RetentionPolicyTTL) UpdateFromFile(group string) {
8080
if oldTs, ok := r.oldTimestamps[escapeLogGroup(group)]; ok {
8181
r.ch <- payload{
8282
group: group,
@@ -85,7 +85,7 @@ func (r *retentionPolicyTTL) UpdateFromFile(group string) {
8585
}
8686
}
8787

88-
func (r *retentionPolicyTTL) loadTTLState() {
88+
func (r *RetentionPolicyTTL) loadTTLState() {
8989
if _, err := os.Stat(r.stateFilePath); err != nil {
9090
r.logger.Debug("retention policy ttl state file does not exist")
9191
return
@@ -125,7 +125,7 @@ func (r *retentionPolicyTTL) loadTTLState() {
125125
}
126126
}
127127

128-
func (r *retentionPolicyTTL) process() {
128+
func (r *RetentionPolicyTTL) process() {
129129
t := time.NewTicker(time.Minute)
130130
defer t.Stop()
131131

@@ -142,13 +142,13 @@ func (r *retentionPolicyTTL) process() {
142142
}
143143
}
144144

145-
func (r *retentionPolicyTTL) updateTimestamp(group string, timestamp time.Time) {
145+
func (r *RetentionPolicyTTL) updateTimestamp(group string, timestamp time.Time) {
146146
r.mu.Lock()
147147
defer r.mu.Unlock()
148148
r.newTimestamps[escapeLogGroup(group)] = timestamp
149149
}
150150

151-
func (r *retentionPolicyTTL) saveTTLState() {
151+
func (r *RetentionPolicyTTL) saveTTLState() {
152152
r.mu.RLock()
153153
defer r.mu.RUnlock()
154154

@@ -157,16 +157,16 @@ func (r *retentionPolicyTTL) saveTTLState() {
157157
buf.Write([]byte(group + ":" + strconv.FormatInt(timestamp.UnixMilli(), 10) + "\n"))
158158
}
159159

160-
err := os.WriteFile(r.stateFilePath, buf.Bytes(), 0644)
160+
err := os.WriteFile(r.stateFilePath, buf.Bytes(), 0644) // nolint:gosec
161161
if err != nil {
162162
r.logger.Errorf("unable to write retention policy ttl state file: %v", err)
163163
}
164164
}
165165

166-
func escapeLogGroup(group string) (escapedLogGroup string) {
167-
escapedLogGroup = filepath.ToSlash(group)
166+
func escapeLogGroup(group string) string {
167+
escapedLogGroup := filepath.ToSlash(group)
168168
escapedLogGroup = strings.Replace(escapedLogGroup, "/", "_", -1)
169169
escapedLogGroup = strings.Replace(escapedLogGroup, " ", "_", -1)
170170
escapedLogGroup = strings.Replace(escapedLogGroup, ":", "_", -1)
171-
return
171+
return escapedLogGroup
172172
}

plugins/outputs/cloudwatchlogs/internal/pusher/retention_policy_ttl_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func TestRetentionPolicyTTL(t *testing.T) {
144144
content := "group1:" + strconv.FormatInt(nowMillis, 10) + "\n" +
145145
"group2:" + strconv.FormatInt(nowMillis+60000, 10) + "\n"
146146

147-
err := os.WriteFile(stateFilePath, []byte(content), 0644)
147+
err := os.WriteFile(stateFilePath, []byte(content), 0644) // nolint:gosec
148148
assert.NoError(t, err)
149149

150150
// Create a new TTL instance that will load the file
@@ -172,7 +172,7 @@ func TestRetentionPolicyTTL(t *testing.T) {
172172
"\n" + // Empty line should be skipped
173173
"invalid_line_no_separator\n"
174174

175-
err := os.WriteFile(stateFilePath, []byte(content), 0644)
175+
err := os.WriteFile(stateFilePath, []byte(content), 0644) // nolint:gosec
176176
assert.NoError(t, err)
177177

178178
ttl := NewRetentionPolicyTTL(logger, tempDir)

plugins/outputs/cloudwatchlogs/internal/pusher/target.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type targetManager struct {
4646
dlg chan Target
4747
prp chan Target
4848
// cache of most recent retention policy changes
49-
retentionPolicyTTL *retentionPolicyTTL
49+
retentionPolicyTTL *RetentionPolicyTTL
5050
}
5151

5252
func NewTargetManager(logger telegraf.Logger, service cloudWatchLogsService, fileStateFolder string) TargetManager {

plugins/outputs/cloudwatchlogs/internal/pusher/target_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ func TestTargetManagerWithTTL(t *testing.T) {
407407
ttlFilePath := filepath.Join(tempDir, logscommon.RetentionPolicyTTLFileName)
408408
now := time.Now()
409409
content := escapeLogGroup(target.Group) + ":" + strconv.FormatInt(now.UnixMilli(), 10) + "\n"
410-
err := os.WriteFile(ttlFilePath, []byte(content), 0644)
410+
err := os.WriteFile(ttlFilePath, []byte(content), 0644) // nolint:gosec
411411
assert.NoError(t, err)
412412

413413
mockService := new(mockLogsService)

translator/translate/logs/ruleFileStateFolder.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ type FileStateFolder struct {
1111
}
1212

1313
// FileStateFolder is internal value, not exposing to customer
14-
func (f *FileStateFolder) ApplyRule(input interface{}) (returnKey string, returnVal interface{}) {
14+
func (f *FileStateFolder) ApplyRule(_ interface{}) (string, interface{}) {
1515
res := map[string]interface{}{}
1616
res["file_state_folder"] = util.GetFileStateFolder()
17-
returnKey = Output_Cloudwatch_Logs
18-
returnVal = res
19-
return
17+
return Output_Cloudwatch_Logs, res
2018
}
2119
func init() {
2220
f := new(FileStateFolder)

0 commit comments

Comments
 (0)