Skip to content

Commit

Permalink
os_release.go: Removed caching of modtime/filename of os-release file.
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Davies <jpds@protonmail.com>
  • Loading branch information
jpds committed Apr 15, 2024
1 parent 336b1fa commit 6d403f4
Showing 1 changed file with 0 additions and 20 deletions.
20 changes: 0 additions & 20 deletions collector/os_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ type osReleaseCollector struct {
infoDesc *prometheus.Desc
logger log.Logger
os *osRelease
osFilename string // file name of cached release information
osMtime time.Time // mtime of cached release file
osMutex sync.RWMutex
osReleaseFilenames []string // all os-release file names to check
version float64
Expand Down Expand Up @@ -142,28 +140,10 @@ func (c *osReleaseCollector) UpdateStruct(path string) error {
}
defer releaseFile.Close()

stat, err := releaseFile.Stat()
if err != nil {
return err
}

t := stat.ModTime()
c.osMutex.RLock()
upToDate := path == c.osFilename && t == c.osMtime
c.osMutex.RUnlock()
if upToDate {
// osReleaseCollector struct is already up-to-date.
return nil
}

// Acquire a lock to update the osReleaseCollector struct.
c.osMutex.Lock()
defer c.osMutex.Unlock()

level.Debug(c.logger).Log("msg", "file modification time has changed",
"file", path, "old_value", c.osMtime, "new_value", t)
c.osFilename = path
c.osMtime = t
// SystemVersion.plist is xml file with MacOs version info
if strings.Contains(releaseFile.Name(), "SystemVersion.plist") {
c.os, err = getMacosProductVersion(releaseFile.Name())
Expand Down

0 comments on commit 6d403f4

Please sign in to comment.