Skip to content

Commit

Permalink
Refactoring (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
ohkinozomu authored Nov 15, 2023
1 parent 54be56d commit 030d9ea
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 188 deletions.
12 changes: 6 additions & 6 deletions cmd/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ var agentCmd = &cobra.Command{
logger.Info("profiling enabled")
go func() {
var registry ncp.Registry
if config.Profiling.Registry == "cloudprofiler" {
switch config.Profiling.Registry {
case "cloudprofiler":
registry = ncp.CLOUD_PROFILER
} else if config.Profiling.Registry == "pyroscope" {
case "pyroscope":
registry = ncp.PYROSCOPE
} else {
default:
logger.Fatal("Unknown profiling registry")
}
c := ncp.Config{
Expand All @@ -109,11 +110,10 @@ var agentCmd = &cobra.Command{
labelMap := make(map[string]string)
for _, label := range labels {
parts := strings.SplitN(label, "=", 2)
if len(parts) == 2 {
labelMap[parts[0]] = parts[1]
} else {
if len(parts) != 2 {
logger.Fatal("Invalid label format")
}
labelMap[parts[0]] = parts[1]
}

c := agent.AgentConfig{
Expand Down
7 changes: 4 additions & 3 deletions cmd/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ var hubCmd = &cobra.Command{
logger.Info("profiling enabled")
go func() {
var registry ncp.Registry
if config.Profiling.Registry == "cloudprofiler" {
switch config.Profiling.Registry {
case "cloudprofiler":
registry = ncp.CLOUD_PROFILER
} else if config.Profiling.Registry == "pyroscope" {
case "pyroscope":
registry = ncp.PYROSCOPE
} else {
default:
logger.Fatal("Unknown profiling registry")
}
c := ncp.Config{
Expand Down
9 changes: 4 additions & 5 deletions e2e/basic/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {
go func(i int) {
defer wg.Done()

jsonData := map[string]interface{}{
jsonData := map[string]any{
"message": fmt.Sprintf("This is request %d", i),
}
jsonBytes, err := json.Marshal(jsonData)
Expand All @@ -47,7 +47,7 @@ func main() {
response, err := exec.Command("kubectl", "exec", "-n", namespace, podName, "--",
"curl", "-X", "POST", "-H", "FuyuuRouter-IDs: agent01", "-H", contentType, "-d", string(jsonBytes), routerURL, "-s").Output()

var responseJSON map[string]interface{}
var responseJSON map[string]any
if err := json.Unmarshal(response, &responseJSON); err != nil {
errors <- fmt.Sprintf("Failed to unmarshal JSON response: %s\nResponse: %s", err, response)
return
Expand All @@ -70,10 +70,9 @@ func main() {
errorCount++
}

if errorCount == 0 {
fmt.Println("All requests returned the correct response.")
} else {
if errorCount != 0 {
fmt.Printf("Some requests did not return the correct response. Errors: %d\n", errorCount)
os.Exit(1)
}
fmt.Println("All requests returned the correct response.")
}
9 changes: 4 additions & 5 deletions e2e/protobuf/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {
go func(i int) {
defer wg.Done()

jsonData := map[string]interface{}{
jsonData := map[string]any{
"message": fmt.Sprintf("This is request %d", i),
}
jsonBytes, err := json.Marshal(jsonData)
Expand All @@ -47,7 +47,7 @@ func main() {
response, err := exec.Command("kubectl", "exec", "-n", namespace, podName, "--",
"curl", "-X", "POST", "-H", "FuyuuRouter-IDs: agent01", "-H", contentType, "-d", string(jsonBytes), routerURL, "-s").Output()

var responseJSON map[string]interface{}
var responseJSON map[string]any
if err := json.Unmarshal(response, &responseJSON); err != nil {
errors <- fmt.Sprintf("Failed to unmarshal JSON response: %s\nResponse: %s", err, response)
return
Expand All @@ -70,10 +70,9 @@ func main() {
errorCount++
}

if errorCount == 0 {
fmt.Println("All requests returned the correct response.")
} else {
if errorCount != 0 {
fmt.Printf("Some requests did not return the correct response. Errors: %d\n", errorCount)
os.Exit(1)
}
fmt.Println("All requests returned the correct response.")
}
9 changes: 4 additions & 5 deletions e2e/zstd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {
go func(i int) {
defer wg.Done()

jsonData := map[string]interface{}{
jsonData := map[string]any{
"message": fmt.Sprintf("This is request %d", i),
}
jsonBytes, err := json.Marshal(jsonData)
Expand All @@ -47,7 +47,7 @@ func main() {
response, err := exec.Command("kubectl", "exec", "-n", namespace, podName, "--",
"curl", "-X", "POST", "-H", "FuyuuRouter-IDs: agent01", "-H", contentType, "-d", string(jsonBytes), routerURL, "-s").Output()

var responseJSON map[string]interface{}
var responseJSON map[string]any
if err := json.Unmarshal(response, &responseJSON); err != nil {
errors <- fmt.Sprintf("Failed to unmarshal JSON response: %s\nResponse: %s", err, response)
return
Expand All @@ -70,10 +70,9 @@ func main() {
errorCount++
}

if errorCount == 0 {
fmt.Println("All requests returned the correct response.")
} else {
if errorCount != 0 {
fmt.Printf("Some requests did not return the correct response. Errors: %d\n", errorCount)
os.Exit(1)
}
fmt.Println("All requests returned the correct response.")
}
6 changes: 4 additions & 2 deletions example/agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spec:
spec:
containers:
- name: fuyuu-router-agent
image: ohkinozomu/fuyuu-router:6932d5a4388f2080d7d1e20b6ffb9fe24e1c4303
image: ohkinozomu/fuyuu-router:0.0.2
volumeMounts:
- name: fuyuu-router-agent-config
mountPath: /app/config
Expand Down Expand Up @@ -43,4 +43,6 @@ metadata:
namespace: fuyuu-router
data:
config.toml: |
# TODO
[profiling]
registry = "pyroscope"
server_address = "http://pyroscope.pyroscope:4040"
4 changes: 2 additions & 2 deletions example/hub.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spec:
spec:
containers:
- name: fuyuu-router-hub
image: ohkinozomu/fuyuu-router:6932d5a4388f2080d7d1e20b6ffb9fe24e1c4303
image: ohkinozomu/fuyuu-router:0.0.2
volumeMounts:
- name: fuyuu-router-hub-config
mountPath: /app/config
Expand All @@ -37,4 +37,4 @@ data:
config.toml: |
[profiling]
registry = "pyroscope"
server_address = "pyroscope.pyroscope:4040"
server_address = "http://pyroscope.pyroscope:4040"
Loading

0 comments on commit 030d9ea

Please sign in to comment.