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

pillar/volumemgr: Kick watchdog inside for loops #3596

Merged
merged 1 commit into from
Nov 20, 2023
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
19 changes: 13 additions & 6 deletions pkg/pillar/cmd/volumemgr/handlediskmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@
// diskMetricsTimerTask calculates and publishes disk metrics periodically
func diskMetricsTimerTask(ctx *volumemgrContext, handleChannel chan interface{}) {
log.Functionln("starting report diskMetricsTimerTask timer task")
createOrUpdateDiskMetrics(ctx)

wdName := agentName + "metrics"
ctx.ps.StillRunning(wdName, warningTime, errorTime)
ctx.ps.RegisterFileWatchdog(wdName)

createOrUpdateDiskMetrics(ctx, wdName)

Check warning on line 105 in pkg/pillar/cmd/volumemgr/handlediskmetrics.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/volumemgr/handlediskmetrics.go#L100-L105

Added lines #L100 - L105 were not covered by tests

diskMetricInterval := time.Duration(ctx.globalConfig.GlobalValueInt(types.DiskScanMetricInterval)) * time.Second
max := float64(diskMetricInterval)
Expand All @@ -106,18 +111,15 @@
// Return handle to caller
handleChannel <- diskMetricTicker

wdName := agentName + "metrics"

// Run a periodic timer so we always update StillRunning
stillRunning := time.NewTicker(25 * time.Second)
ctx.ps.StillRunning(wdName, warningTime, errorTime)
ctx.ps.RegisterFileWatchdog(wdName)

for {
select {
case <-diskMetricTicker.C:
start := time.Now()
createOrUpdateDiskMetrics(ctx)
createOrUpdateDiskMetrics(ctx, wdName)

Check warning on line 122 in pkg/pillar/cmd/volumemgr/handlediskmetrics.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/volumemgr/handlediskmetrics.go#L122

Added line #L122 was not covered by tests
ctx.ps.CheckMaxTimeTopic(wdName, "createOrUpdateDiskMetrics", start,
warningTime, errorTime)

Expand All @@ -128,13 +130,14 @@
}

// createOrUpdateDiskMetrics creates or updates metrics for all disks, mountpaths and volumeStatuses
func createOrUpdateDiskMetrics(ctx *volumemgrContext) {
func createOrUpdateDiskMetrics(ctx *volumemgrContext, wdName string) {

Check warning on line 133 in pkg/pillar/cmd/volumemgr/handlediskmetrics.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/volumemgr/handlediskmetrics.go#L133

Added line #L133 was not covered by tests
log.Functionf("createOrUpdateDiskMetrics")
var diskMetricList []*types.DiskMetric
startPubTime := time.Now()

disks := diskmetrics.FindDisksPartitions(log)
for _, d := range disks {
ctx.ps.StillRunning(wdName, warningTime, errorTime)

Check warning on line 140 in pkg/pillar/cmd/volumemgr/handlediskmetrics.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/volumemgr/handlediskmetrics.go#L140

Added line #L140 was not covered by tests
size, _ := diskmetrics.PartitionSize(log, d)
log.Tracef("createOrUpdateDiskMetrics: Disk/partition %s size %d", d, size)
var metric *types.DiskMetric
Expand All @@ -161,6 +164,7 @@
for _, path := range types.ReportDiskPaths {
var u *types.UsageStat
var err error
ctx.ps.StillRunning(wdName, warningTime, errorTime)

Check warning on line 167 in pkg/pillar/cmd/volumemgr/handlediskmetrics.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/volumemgr/handlediskmetrics.go#L167

Added line #L167 was not covered by tests
if path == types.PersistDir {
// dedicated handler for PersistDir as we have to use PersistType dependent calculations
u, err = diskmetrics.PersistUsageStat(log)
Expand Down Expand Up @@ -203,6 +207,7 @@
log.Tracef("createOrUpdateDiskMetrics: persistUsage %d, elapse sec %v", persistUsage, time.Since(startPubTime).Seconds())

for _, path := range types.ReportDirPaths {
ctx.ps.StillRunning(wdName, warningTime, errorTime)

Check warning on line 210 in pkg/pillar/cmd/volumemgr/handlediskmetrics.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/volumemgr/handlediskmetrics.go#L210

Added line #L210 was not covered by tests
usage, err := diskmetrics.DirUsage(log, path)
log.Tracef("createOrUpdateDiskMetrics: ReportDirPath %s usage %d err %v", path, usage, err)
if err != nil {
Expand All @@ -225,6 +230,7 @@
log.Tracef("createOrUpdateDiskMetrics: DirPaths in persist, elapse sec %v", time.Since(startPubTime).Seconds())

for _, path := range types.AppPersistPaths {
ctx.ps.StillRunning(wdName, warningTime, errorTime)

Check warning on line 233 in pkg/pillar/cmd/volumemgr/handlediskmetrics.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/volumemgr/handlediskmetrics.go#L233

Added line #L233 was not covered by tests
usage, err := diskmetrics.DirUsage(log, path)
log.Tracef("createOrUpdateDiskMetrics: AppPersistPath %s usage %d err %v", path, usage, err)
if err != nil {
Expand All @@ -246,6 +252,7 @@
}
publishDiskMetrics(ctx, diskMetricList...)
for _, volumeStatus := range getAllVolumeStatus(ctx) {
ctx.ps.StillRunning(wdName, warningTime, errorTime)

Check warning on line 255 in pkg/pillar/cmd/volumemgr/handlediskmetrics.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/volumemgr/handlediskmetrics.go#L255

Added line #L255 was not covered by tests
if err := createOrUpdateAppDiskMetrics(ctx, volumeStatus); err != nil {
log.Errorf("CreateOrUpdateCommonDiskMetrics: exception while publishing diskmetric. %s", err.Error())
}
Expand Down
Loading