Skip to content

Commit

Permalink
feat: record Scorch run info to text file for each executed run
Browse files Browse the repository at this point in the history
The following info about each run is recorded to a plain text file.

* Experiment Name
* Experiment Commit Hash
* Scorch Run Name
* Start Time
* End Time
* Phenix Version
* Minimega Version

The plain text file with the above information is written to the Scorch
run directory, which by default is at the following location.

/phenix/images/<exp_name>/files/scorch/run-<run_id>/info-scorch-run-<run_id>_<run_start_time>.txt
  • Loading branch information
nblair2 authored and activeshadow committed Jun 22, 2023
1 parent b95907a commit eb46d1c
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/go/api/scorch/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"
"time"

"phenix/api/scorch/scorchexe"
Expand All @@ -18,7 +19,9 @@ import (
"phenix/types"
ifaces "phenix/types/interfaces"
"phenix/util"
"phenix/util/mm/mmcli"
"phenix/util/shell"
"phenix/version"
"phenix/web/scorch"

log "github.com/activeshadow/libminimega/minilog"
Expand Down Expand Up @@ -156,6 +159,10 @@ func (this *Scorch) Running(ctx context.Context, exp *types.Experiment) error {
this.stopFilebeat(ctx, cmd, port)
}

if err := this.recordInfo(runID, runDir, exp.Metadata.Name, start); err != nil {
errors = multierror.Append(errors, err)
}

if _, err := os.Stat(runDir); err == nil {
archive := filepath.Join(exp.FilesDir(), fmt.Sprintf("scorch-run-%d_%s.tgz", runID, start.Format(time.RFC3339)))

Expand Down Expand Up @@ -326,6 +333,45 @@ func (this Scorch) stopFilebeat(ctx context.Context, cmd *exec.Cmd, port int) {
}
}

func (this Scorch) recordInfo(runID int, runDir, name string, startTime time.Time) error {
c := mmcli.NewCommand()
c.Command = "version"

mmVersion, err := mmcli.SingleResponse(mmcli.Run(c))
if err != nil {
return fmt.Errorf("getting minimega version: %w", err)
}

info := []string{
"Experiment Name: %s",
"Experiment Commit Hash: %s",
"Scorch Run Name: %s",
"Start Time: %s",
"End Time: %s",
"Phenix Version: %s %s %s",
"Minimega Version: %s",
}

body := fmt.Sprintf(
strings.Join(info, "\n"),
name, "TODO", this.md.RunName(runID),
startTime.Format(time.RFC3339), time.Now().UTC().Format(time.RFC3339),
version.Commit, version.Tag, version.Date, mmVersion,
)

fileName := fmt.Sprintf("info-scorch-run-%d_%s.txt", runID, startTime.Format(time.RFC3339))

if err := os.MkdirAll(runDir, 0755); err != nil {
return fmt.Errorf("creating %s directory for scorch run %d: %w", runDir, runID, err)
}

if err := os.WriteFile(filepath.Join(runDir, fileName), []byte(body), 0644); err != nil {
return fmt.Errorf("writing scorch information file (%s): %w", fileName, err)
}

return nil
}

func executor(ctx context.Context, components scorchmd.ComponentSpecMap, exe *scorchmd.Loop, opts ...Option) error {
options := NewOptions(opts...)

Expand Down

0 comments on commit eb46d1c

Please sign in to comment.