Skip to content

Commit

Permalink
style: Minor styling improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Mahendra Paipuri <[email protected]>
  • Loading branch information
mahendrapaipuri committed Dec 24, 2023
1 parent d548420 commit 710c135
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
8 changes: 4 additions & 4 deletions pkg/collector/ipmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ var (
)

func init() {
registerCollector(ipmiCollectorSubsystem, defaultEnabled, NewIpmiCollector)
registerCollector(ipmiCollectorSubsystem, defaultEnabled, NewIPMICollector)
}

// NewIpmiCollector returns a new Collector exposing IMPI DCMI power metrics.
func NewIpmiCollector(logger log.Logger) (Collector, error) {
// NewIPMICollector returns a new Collector exposing IMPI DCMI power metrics.
func NewIPMICollector(logger log.Logger) (Collector, error) {

wattsMetricDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, ipmiCollectorSubsystem, "watts_total"),
"Current Power consumption in watts", []string{}, nil,
)

var execMode string = ""
var execMode string

// Split command
cmdSlice := strings.Split(*ipmiDcmiCmd, " ")
Expand Down
12 changes: 8 additions & 4 deletions pkg/jobstats/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ func writeTimeStampToFile(filePath string, timeStamp time.Time, logger log.Logge
timeStampByte := []byte(timeStampString)
err := os.WriteFile(filePath, timeStampByte, 0644)
if err != nil {
level.Error(logger).Log("msg", "Failed to write timestamp to file", "time", timeStampString, "file", filePath, "err", err)
level.Error(logger).
Log("msg", "Failed to write timestamp to file", "time", timeStampString, "file", filePath, "err", err)
}
}

Expand Down Expand Up @@ -280,16 +281,19 @@ func (j *jobStatsDB) Collect() error {
if currentTime.Sub(j.lastJobsUpdateTime) < time.Duration(24*time.Hour) {
return j.getJobStats(j.lastJobsUpdateTime, currentTime)
}
level.Info(j.logger).Log("msg", "DB update duration is more than 1 day. Doing incremental update. This may take a while...")
level.Info(j.logger).
Log("msg", "DB update duration is more than 1 day. Doing incremental update. This may take a while...")

// If duration is more than 1 day, do update for each day
var nextUpdateTime time.Time
for {
nextUpdateTime = j.lastJobsUpdateTime.Add(24 * time.Hour)
if nextUpdateTime.Compare(currentTime) == -1 {
level.Debug(j.logger).Log("msg", "Incremental DB update step", "from", j.lastJobsUpdateTime, "to", nextUpdateTime)
level.Debug(j.logger).
Log("msg", "Incremental DB update step", "from", j.lastJobsUpdateTime, "to", nextUpdateTime)
if err := j.getJobStats(j.lastJobsUpdateTime, nextUpdateTime); err != nil {
level.Error(j.logger).Log("msg", "Failed incremental update", "from", j.lastJobsUpdateTime, "to", nextUpdateTime, "err", err)
level.Error(j.logger).
Log("msg", "Failed incremental update", "from", j.lastJobsUpdateTime, "to", nextUpdateTime, "err", err)
return err
}
} else {
Expand Down
14 changes: 12 additions & 2 deletions pkg/jobstats/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,12 @@ func TestNewJobStatsDB(t *testing.T) {

// Check content of last update time file. It should change
if timeString, err := os.ReadFile(lastJobsUpdateTimeFile); string(timeString) != "2023-12-21T00:00:00" {
t.Errorf("Last update time string test failed. Expected %s got %s %s", "2023-12-21T00:00:00", string(timeString), err)
t.Errorf(
"Last update time string test failed. Expected %s got %s %s",
"2023-12-21T00:00:00",
string(timeString),
err,
)
}

// Remove last update time file
Expand All @@ -187,7 +192,12 @@ func TestNewJobStatsDB(t *testing.T) {

// Check content of last update time file. It should change
if timeString, err := os.ReadFile(lastJobsUpdateTimeFile); string(timeString) != "2023-12-22T00:00:00" {
t.Errorf("Last update time string test failed. Expected %s got %s %s", "2023-12-22T00:00:00", string(timeString), err)
t.Errorf(
"Last update time string test failed. Expected %s got %s %s",
"2023-12-22T00:00:00",
string(timeString),
err,
)
}
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/jobstats/slurm.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ func slurmChecks(logger log.Logger) error {

// If current user is slurm or root pass checks
if currentUser, err := user.Current(); err == nil && (currentUser.Username == "slurm" || currentUser.Uid == "0") {
level.Debug(logger).Log("msg", "Current user have enough privileges to get job data for all users", "user", currentUser.Username)
level.Debug(logger).
Log("msg", "Current user have enough privileges to get job data for all users", "user", currentUser.Username)
return nil
}

Expand Down

0 comments on commit 710c135

Please sign in to comment.