@@ -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}
0 commit comments