Skip to content

Commit b6aad78

Browse files
committed
Porting Dirigent config to JSON
Signed-off-by: Lazar Cvetković <l.cvetkovic.997@gmail.com>
1 parent 3e27862 commit b6aad78

File tree

8 files changed

+146
-31
lines changed

8 files changed

+146
-31
lines changed

data/traces/example/dirigent.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[
2+
{
3+
"HashFunction": "c13acdc7567b225971cef2416a3a2b03c8a4d8d154df48afe75834e2f5c59ddf",
4+
"Image": "docker.io/cvetkovic/dirigent_grpc_function:latest",
5+
"Port": 80,
6+
"Protocol": "tcp",
7+
"ScalingUpperBound": 1,
8+
"ScalingLowerBound": 0,
9+
"IterationMultiplier": 80,
10+
"IOPercentage": 0,
11+
"EnvVars": [],
12+
"ProgramArgs": []
13+
},
14+
{
15+
"HashFunction": "a2faad786b3c813b12ce57d349d5e62f6d0f22ceecfa86cd72a962853383b600",
16+
"Image": "docker.io/cvetkovic/dirigent_grpc_function:latest",
17+
"Port": 80,
18+
"Protocol": "tcp",
19+
"ScalingUpperBound": 1,
20+
"ScalingLowerBound": 0,
21+
"IterationMultiplier": 80,
22+
"IOPercentage": 0,
23+
"EnvVars": [],
24+
"ProgramArgs": []
25+
},
26+
{
27+
"HashFunction": "7dc5aeabc131669912e8c793c8925cc9928321f45f13a4af031592b4611630d7",
28+
"Image": "docker.io/cvetkovic/dirigent_grpc_function:latest",
29+
"Port": 80,
30+
"Protocol": "tcp",
31+
"ScalingUpperBound": 1,
32+
"ScalingLowerBound": 0,
33+
"IterationMultiplier": 80,
34+
"IOPercentage": 0,
35+
"EnvVars": [],
36+
"ProgramArgs": []
37+
},
38+
{
39+
"HashFunction": "ae8a1640fa932024f59b38a0b001808b5c64612bd60c6f3eb80ba9461ba2d091",
40+
"Image": "docker.io/cvetkovic/dirigent_grpc_function:latest",
41+
"Port": 80,
42+
"Protocol": "tcp",
43+
"ScalingUpperBound": 1,
44+
"ScalingLowerBound": 0,
45+
"IterationMultiplier": 80,
46+
"IOPercentage": 0,
47+
"EnvVars": [],
48+
"ProgramArgs": []
49+
}
50+
]

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module github.com/vhive-serverless/loader
22

3-
go 1.22
3+
go 1.22.0
4+
45
toolchain go1.22.5
56

67
require (
@@ -16,6 +17,7 @@ require (
1617

1718
require (
1819
github.com/aws/aws-lambda-go v1.47.0
20+
github.com/containerd/log v0.1.0
1921
github.com/stretchr/testify v1.9.0
2022
github.com/vhive-serverless/vSwarm/utils/tracing/go v0.0.0-20240827121957-11be651eb39a
2123
go.mongodb.org/mongo-driver v1.17.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ github.com/aws/aws-lambda-go v1.47.0 h1:0H8s0vumYx/YKs4sE7YM0ktwL2eWse+kfopsRI1s
1111
github.com/aws/aws-lambda-go v1.47.0/go.mod h1:dpMpZgvWx5vuQJfBt0zqBha60q7Dd7RfgJv23DymV8A=
1212
github.com/campoy/embedmd v1.0.0 h1:V4kI2qTJJLf4J29RzI/MAt2c3Bl4dQSYPuflzwFH2hY=
1313
github.com/campoy/embedmd v1.0.0/go.mod h1:oxyr9RCiSXg0M3VJ3ks0UGfp98BpSSGr0kpiX3MzVl8=
14+
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
15+
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
1416
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1517
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1618
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

pkg/common/trace_types.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@ type FunctionMemoryStats struct {
7171
}
7272

7373
type DirigentMetadata struct {
74-
HashFunction string `csv:"HashFunction"`
75-
Image string `csv:"Image"`
76-
Port int `csv:"Port"`
77-
Protocol string `csv:"Protocol"`
78-
ScalingUpperBound int `csv:"ScalingUpperBound"`
79-
ScalingLowerBound int `csv:"ScalingLowerBound"`
80-
IterationMultiplier int `csv:"IterationMultiplier"`
81-
IOPercentage int `csv:"IOPercentage"`
82-
EnvVars string `csv:"EnvVars"`
83-
ProgramArgs string `csv:"ProgramArgs"`
74+
HashFunction string `json:"HashFunction"`
75+
Image string `json:"Image"`
76+
Port int `json:"Port"`
77+
Protocol string `json:"Protocol"`
78+
ScalingUpperBound int `json:"ScalingUpperBound"`
79+
ScalingLowerBound int `json:"ScalingLowerBound"`
80+
IterationMultiplier int `json:"IterationMultiplier"`
81+
IOPercentage int `json:"IOPercentage"`
82+
EnvVars []string `json:"EnvVars"`
83+
ProgramArgs []string `json:"ProgramArgs"`
8484
}
8585

8686
type Function struct {

pkg/driver/deployment/dirigent.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,6 @@ var registrationClient = &http.Client{
5353
},
5454
}
5555

56-
const CSVColumnDelimiter = " "
57-
58-
func prepareEnvVars(data string) []string {
59-
// FORMAT: arg1=value1 arg2=value2
60-
return strings.Split(data, CSVColumnDelimiter)
61-
}
62-
63-
func prepareProgramArgs(data string) []string {
64-
// FORMAT: arg1 val1 arg2 val2
65-
return strings.Split(data, CSVColumnDelimiter)
66-
}
67-
6856
func deployDirigent(function *common.Function, controlPlaneAddress string, busyLoopOnColdStart bool) {
6957
metadata := function.DirigentMetadata
7058

@@ -80,8 +68,8 @@ func deployDirigent(function *common.Function, controlPlaneAddress string, busyL
8068
"scaling_lower_bound": {strconv.Itoa(metadata.ScalingLowerBound)},
8169
"requested_cpu": {strconv.Itoa(function.CPURequestsMilli)},
8270
"requested_memory": {strconv.Itoa(function.MemoryRequestsMiB)},
83-
"env_vars": prepareEnvVars(metadata.EnvVars),
84-
"program_args": prepareProgramArgs(metadata.ProgramArgs),
71+
"env_vars": metadata.EnvVars, // FORMAT: arg1=value1 arg2=value2 ...
72+
"program_args": metadata.ProgramArgs, // FORMAT: arg1 arg2 ...
8573
}
8674

8775
if busyLoopOnColdStart {

pkg/trace/parser.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ package trace
2626

2727
import (
2828
"encoding/csv"
29+
"encoding/json"
2930
"fmt"
3031
"github.com/gocarina/gocsv"
3132
"github.com/vhive-serverless/loader/pkg/common"
@@ -126,7 +127,7 @@ func (p *AzureTraceParser) Parse(platform string) []*common.Function {
126127
invocationPath := p.DirectoryPath + "/invocations.csv"
127128
runtimePath := p.DirectoryPath + "/durations.csv"
128129
memoryPath := p.DirectoryPath + "/memory.csv"
129-
dirigentPath := p.DirectoryPath + "/dirigent.csv"
130+
dirigentPath := p.DirectoryPath + "/dirigent.json"
130131

131132
invocationTrace := parseInvocationTrace(invocationPath, p.duration)
132133
runtimeTrace := parseRuntimeTrace(runtimePath)
@@ -258,21 +259,20 @@ func parseMemoryTrace(traceFile string) *[]common.FunctionMemoryStats {
258259
}
259260

260261
func parseDirigentMetadata(traceFile string, platform string) *[]common.DirigentMetadata {
261-
if platform != "Dirigent" {
262+
if strings.ToLower(platform) != "dirigent" {
262263
return nil
263264
}
264265

265266
log.Infof("Parsing Dirigent metadata: %s", traceFile)
266267

267-
f, err := os.Open(traceFile)
268+
data, err := os.ReadFile(traceFile)
268269
if err != nil {
269-
log.Error("Failed to open trace memory specification file.")
270+
log.Error("Failed to read Dirigent trace file.")
270271
return nil
271272
}
272-
defer f.Close()
273273

274274
var metadata []common.DirigentMetadata
275-
err = gocsv.UnmarshalFile(f, &metadata)
275+
err = json.Unmarshal(data, &metadata)
276276
if err != nil {
277277
log.Fatal("Failed to parse trace runtime specification.")
278278
}

pkg/trace/parser_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,39 @@ func TestParserWrapper(t *testing.T) {
133133
t.Error("Unexpected results.")
134134
}
135135
}
136+
137+
func TestDirigentParser(t *testing.T) {
138+
data := *parseDirigentMetadata("test_data/dirigent.json", "Dirigent")
139+
140+
if len(data) != 2 {
141+
t.Error("Unexpected results.")
142+
}
143+
144+
if !(data[0].HashFunction == "c13acdc7567b225971cef2416a3a2b03c8a4d8d154df48afe75834e2f5c59ddf" &&
145+
data[0].Image == "docker.io/vhiveease/relay:latest" &&
146+
data[0].Port == 50000 &&
147+
data[0].Protocol == "tcp" &&
148+
data[0].ScalingUpperBound == 1 &&
149+
data[0].ScalingLowerBound == 1 &&
150+
data[0].IterationMultiplier == 80 &&
151+
data[0].IOPercentage == 0 &&
152+
len(data[0].EnvVars) == 1 &&
153+
len(data[0].ProgramArgs) == 8) {
154+
155+
t.Error("Unexpected results.")
156+
}
157+
158+
if !(data[1].HashFunction == "ae8a1640fa932024f59b38a0b001808b5c64612bd60c6f3eb80ba9461ba2d091" &&
159+
data[1].Image == "docker.io/cvetkovic/dirigent_grpc_function:latest" &&
160+
data[1].Port == 80 &&
161+
data[1].Protocol == "tcp" &&
162+
data[1].ScalingUpperBound == 1 &&
163+
data[1].ScalingLowerBound == 0 &&
164+
data[1].IterationMultiplier == 80 &&
165+
data[1].IOPercentage == 0 &&
166+
len(data[1].EnvVars) == 0 &&
167+
len(data[1].ProgramArgs) == 0) {
168+
169+
t.Error("Unexpected results.")
170+
}
171+
}

pkg/trace/test_data/dirigent.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[
2+
{
3+
"HashFunction": "c13acdc7567b225971cef2416a3a2b03c8a4d8d154df48afe75834e2f5c59ddf",
4+
"Image": "docker.io/vhiveease/relay:latest",
5+
"Port": 50000,
6+
"Protocol": "tcp",
7+
"ScalingUpperBound": 1,
8+
"ScalingLowerBound": 1,
9+
"IterationMultiplier": 80,
10+
"IOPercentage": 0,
11+
"EnvVars": [
12+
"ENABLE_TRACING=true"
13+
],
14+
"ProgramArgs": [
15+
"--addr=0.0.0.0:50000",
16+
"--function-endpoint-url=0.0.0.0",
17+
"--function-endpoint-port=50051",
18+
"--function-name=aes-go",
19+
"--value=10",
20+
"--generator=random",
21+
"--lowerBound=1000",
22+
"--upperBound=1001"
23+
]
24+
},
25+
{
26+
"HashFunction": "ae8a1640fa932024f59b38a0b001808b5c64612bd60c6f3eb80ba9461ba2d091",
27+
"Image": "docker.io/cvetkovic/dirigent_grpc_function:latest",
28+
"Port": 80,
29+
"Protocol": "tcp",
30+
"ScalingUpperBound": 1,
31+
"ScalingLowerBound": 0,
32+
"IterationMultiplier": 80,
33+
"IOPercentage": 0,
34+
"EnvVars": [],
35+
"ProgramArgs": []
36+
}
37+
]

0 commit comments

Comments
 (0)