Skip to content

Commit

Permalink
APIGOV-28410 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
alrosca committed Sep 19, 2024
1 parent 4251dcc commit ea5db88
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
6 changes: 3 additions & 3 deletions pkg/transaction/metric/cachestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ func (c *cacheStorage) initialize() {

func (c *cacheStorage) loadUsage(storageCache cache.Cache) {
// update the collector usage start time
usageStartTime, err := c.parseTimeFromCache(storageCache, usageStartTimeKey)
usageStartTime, err := parseTimeFromCache(storageCache, usageStartTimeKey)
if err == nil && !agent.GetCentralConfig().GetUsageReportingConfig().IsOfflineMode() {
// do not load this start time when offline
c.collector.usageStartTime = usageStartTime
}
// update the collector metric start time
metricStartTime, err := c.parseTimeFromCache(storageCache, metricStartTimeKey)
metricStartTime, err := parseTimeFromCache(storageCache, metricStartTimeKey)
if err == nil && !agent.GetCentralConfig().GetUsageReportingConfig().IsOfflineMode() {
// do not load this start time when offline
c.collector.metricStartTime = metricStartTime
Expand Down Expand Up @@ -254,7 +254,7 @@ func (c *cacheStorage) storeCacheJob() {
}
}

func (c *cacheStorage) parseTimeFromCache(storage cache.Cache, key string) (time.Time, error) {
func parseTimeFromCache(storage cache.Cache, key string) (time.Time, error) {
resultTime := now()
item, err := storage.Get(key)
if err != nil {
Expand Down
9 changes: 2 additions & 7 deletions pkg/transaction/metric/reportcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,15 @@ func (c *usageReportCache) updateEvents(lighthouseEvent UsageEvent) {
}

func (c *usageReportCache) setLastPublishTimestamp(lastPublishTimestamp time.Time) {
c.reportCache.Set(lastPublishTimestampKey, lastPublishTimestamp.String())
c.reportCache.Set(lastPublishTimestampKey, lastPublishTimestamp)
c.reportCache.Save(c.cacheFilePath)
}

func (c *usageReportCache) getLastPublishTimestamp() time.Time {
c.reportCacheLock.Lock()
defer c.reportCacheLock.Unlock()

value, err := c.reportCache.Get(lastPublishTimestampKey)
if err != nil {
return time.Time{}
}

lastPublishTime, err := time.Parse(time.RFC3339, value.(string))
lastPublishTime, err := parseTimeFromCache(c.reportCache, lastPublishTimestampKey)
if err != nil {
return time.Time{}
}
Expand Down

0 comments on commit ea5db88

Please sign in to comment.