Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os_release.go: Removed caching of modtime/filename of os-release file #2987

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions collector/os_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,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 @@ -134,28 +132,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
Loading