Skip to content

Commit

Permalink
refactor common files to multiloader folder
Browse files Browse the repository at this point in the history
Signed-off-by: Lenson <[email protected]>
  • Loading branch information
nosnelmil committed Dec 22, 2024
1 parent dd17625 commit ee6a717
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 129 deletions.
27 changes: 0 additions & 27 deletions pkg/common/config_types.go

This file was deleted.

15 changes: 0 additions & 15 deletions pkg/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,6 @@ const (
AwsTraceFuncRepositoryName = "invitro_trace_function_aws"
)

// Multi-loader Constants
const (
TraceFormatString = "{}"
)

// Multi-loader possible collectable metrics
const (
Activator string = "activator"
AutoScaler string = "autoscaler"
TOP string = "top"
Prometheus string = "prometheus"
)

var ValidCollectableMetrics = []string{Activator, AutoScaler, TOP, Prometheus}

// CPULimits
const (
CPULimit1vCPU string = "1vCPU"
Expand Down
9 changes: 0 additions & 9 deletions pkg/common/node_types.go

This file was deleted.

53 changes: 6 additions & 47 deletions pkg/common/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import (
"net"
"os"
"os/exec"
"path"
"slices"
"strings"

log "github.com/sirupsen/logrus"
)
Expand All @@ -26,61 +24,22 @@ func CheckNode(node string) {
}

func CheckPath(path string) {
if(path) == "" { return }
if (path) == "" {
return
}
_, err := os.Stat(path)
if err != nil {
log.Fatal(err)
}
}

func IsValidIP(ip string) bool {
parsedIP := net.ParseIP(ip)
return parsedIP != nil
}

// Check general multi-loader configuration that applies to all platforms
func CheckMultiLoaderConfig(multiLoaderConfig MultiLoaderConfiguration) {
log.Info("Checking multi-loader configuration")
// Check if all paths are valid
CheckPath(multiLoaderConfig.BaseConfigPath)
// Check each study
if len(multiLoaderConfig.Studies) == 0 {
log.Fatal("No study found in configuration file")
}
for _, study := range multiLoaderConfig.Studies {
// Check trace directory
// if configs does not have TracePath or OutputPathPreix, either TracesDir or (TracesFormat and TraceValues) should be defined along with OutputDir
if study.TracesDir == "" && (study.TracesFormat == "" || len(study.TraceValues) == 0) {
if _, ok := study.Config["TracePath"]; !ok {
log.Fatal("Missing one of TracesDir, TracesFormat & TraceValues, Config.TracePath in multi_loader_config ", study.Name)
}
}
if study.TracesFormat != ""{
// check if trace format contains TRACE_FORMAT_STRING
if !strings.Contains(study.TracesFormat, TraceFormatString) {
log.Fatal("Invalid TracesFormat in multi_loader_config ", study.Name, ". Missing ", TraceFormatString, " in format")
}
}
if study.OutputDir == "" {
if _, ok := study.Config["OutputPathPrefix"]; !ok {
log.Warn("Missing one of OutputDir or Config.OutputPathPrefix in multi_loader_config ", study.Name)
// set default output directory
study.OutputDir = path.Join("data", "out", study.Name)
log.Warn("Setting default output directory to ", study.OutputDir)
}
}
}
log.Info("All experiments configs are valid")
}

func CheckCollectableMetrics(metrics string) {
if !slices.Contains(ValidCollectableMetrics, metrics) {
log.Fatal("Invalid metrics ", metrics)
}
parsedIP := net.ParseIP(ip)
return parsedIP != nil
}

func CheckCPULimit(cpuLimit string) {
if !slices.Contains(ValidCPULimits, cpuLimit) {
log.Fatal("Invalid CPU Limit ", cpuLimit)
}
}
}
16 changes: 0 additions & 16 deletions pkg/config/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"os"

log "github.com/sirupsen/logrus"
"github.com/vhive-serverless/loader/pkg/common"
)

type FailureConfiguration struct {
Expand Down Expand Up @@ -115,18 +114,3 @@ func ReadFailureConfiguration(path string) *FailureConfiguration {

return &config
}

func ReadMultiLoaderConfigurationFile(path string) common.MultiLoaderConfiguration {
byteValue, err := os.ReadFile(path)
if err != nil {
log.Fatal(err)
}

var config common.MultiLoaderConfiguration
err = json.Unmarshal(byteValue, &config)
if err != nil {
log.Fatal(err)
}

return config
}
15 changes: 15 additions & 0 deletions tools/multi_loader/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

log "github.com/sirupsen/logrus"

"github.com/vhive-serverless/loader/pkg/config"
"github.com/vhive-serverless/loader/tools/multi_loader/types"
)

Expand All @@ -23,3 +24,17 @@ func ReadMultiLoaderConfigurationFile(path string) types.MultiLoaderConfiguratio

return config
}

func DeterminePlatformFromConfig(multiLoaderConfig types.MultiLoaderConfiguration) string {
// Determine platform
baseConfigByteValue, err := os.ReadFile(multiLoaderConfig.BaseConfigPath)
if err != nil {
log.Fatal(err)
}
var loaderConfig config.LoaderConfiguration
// Unmarshal base configuration
if err = json.Unmarshal(baseConfigByteValue, &loaderConfig); err != nil {
log.Fatal(err)
}
return loaderConfig.Platform
}
16 changes: 1 addition & 15 deletions tools/multi_loader/runner/multi_loader_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func NewMultiLoaderRunner(configPath string, verbosity string, iatGeneration boo
ml_common.CheckMultiLoaderConfig(multiLoaderConfig)

// determine platform
platform := determinePlatform(multiLoaderConfig)
platform := ml_common.DeterminePlatformFromConfig(multiLoaderConfig)

runner := MultiLoaderRunner{
MultiLoaderConfig: multiLoaderConfig,
Expand All @@ -61,20 +61,6 @@ func NewMultiLoaderRunner(configPath string, verbosity string, iatGeneration boo
return &runner, nil
}

func determinePlatform(multiLoaderConfig types.MultiLoaderConfiguration) string {
// Determine platform
baseConfigByteValue, err := os.ReadFile(multiLoaderConfig.BaseConfigPath)
if err != nil {
log.Fatal(err)
}
var loaderConfig config.LoaderConfiguration
// Unmarshal base configuration
if err = json.Unmarshal(baseConfigByteValue, &loaderConfig); err != nil {
log.Fatal(err)
}
return loaderConfig.Platform
}

func (d *MultiLoaderRunner) RunDryRun() {
log.Info("Running dry run")
d.DryRun = true
Expand Down

0 comments on commit ee6a717

Please sign in to comment.