-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
250 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright © Weifeng Wang <[email protected]> | ||
// | ||
// Licensed under the Apache License 2.0. | ||
|
||
package all | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/MakeNowJust/heredoc" | ||
"github.com/qclaogui/codelab-monitoring/internal" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var supportedDeploymentModes = []string{"monolithic-mode"} | ||
var mode string | ||
|
||
func NewCmdAll() *cobra.Command { | ||
var allCmd = &cobra.Command{ | ||
Short: "Run Grafana LGTMP Stack All-in-one.", | ||
Use: "all", | ||
Example: heredoc.Doc(` | ||
# Start up all in monolithic-mode | ||
$ lgtmp up all | ||
# Start up all in microservices-mode | ||
$ lgtmp up all --mode microservices-mode | ||
`), | ||
|
||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
// up-monolithic-mode-all-in-one Run monolithic-mode all-in-one | ||
// deploy-monolithic-mode-all-in-one Deploy monolithic-mode all-in-one | ||
action := cmd.Parent().Use | ||
target := fmt.Sprintf("%s-%s-all-in-one", action, mode) | ||
if err := internal.ExecuteCommand("make", "-C", ".", target); err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
allCmd.Flags().StringVarP(&mode, "mode", "m", "monolithic-mode", | ||
fmt.Sprintf("deployment mode for all-in-one. Supported modes are: %s.", strings.Join(supportedDeploymentModes, ", "))) | ||
|
||
return allCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright © Weifeng Wang <[email protected]> | ||
// | ||
// Licensed under the Apache License 2.0. | ||
|
||
package profiles | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/MakeNowJust/heredoc" | ||
"github.com/qclaogui/codelab-monitoring/internal" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var supportedDeploymentModes = []string{"monolithic-mode", "microservices-mode"} | ||
var mode string | ||
|
||
func NewCmdProfiles() *cobra.Command { | ||
var profilesCmd = &cobra.Command{ | ||
Short: "Run Pyroscope for Profiles.", | ||
Use: "profiles", | ||
Example: heredoc.Doc(` | ||
# Start up profiles in monolithic-mode | ||
$ lgtmp up profiles | ||
# Start up profiles in microservices-mode | ||
$ lgtmp up profiles --mode microservices-mode | ||
`), | ||
|
||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
// up-monolithic-mode-profiles Run monolithic-mode profiles | ||
// deploy-monolithic-mode-profiles Deploy monolithic-mode profiles | ||
action := cmd.Parent().Use | ||
target := fmt.Sprintf("%s-%s-profiles", action, mode) | ||
if err := internal.ExecuteCommand("make", "-C", ".", target); err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
profilesCmd.Flags().StringVarP(&mode, "mode", "m", "monolithic-mode", | ||
fmt.Sprintf("deployment mode for profiles. Supported modes are: %s.", strings.Join(supportedDeploymentModes, ", "))) | ||
|
||
return profilesCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright © Weifeng Wang <[email protected]> | ||
// | ||
// Licensed under the Apache License 2.0. | ||
|
||
package traces | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/MakeNowJust/heredoc" | ||
"github.com/qclaogui/codelab-monitoring/internal" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var supportedDeploymentModes = []string{"monolithic-mode", "microservices-mode"} | ||
var mode string | ||
|
||
func NewCmdTraces() *cobra.Command { | ||
var tracesCmd = &cobra.Command{ | ||
Short: "Run Tempo for Traces.", | ||
Use: "traces", | ||
Example: heredoc.Doc(` | ||
# Start up traces in monolithic-mode | ||
$ lgtmp up traces | ||
# Start up traces in microservices-mode | ||
$ lgtmp up traces --mode microservices-mode | ||
`), | ||
|
||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
// up-monolithic-mode-traces Run monolithic-mode traces | ||
// deploy-monolithic-mode-traces Deploy monolithic-mode traces | ||
action := cmd.Parent().Use | ||
target := fmt.Sprintf("%s-%s-traces", action, mode) | ||
if err := internal.ExecuteCommand("make", "-C", ".", target); err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
tracesCmd.Flags().StringVarP(&mode, "mode", "m", "monolithic-mode", | ||
fmt.Sprintf("deployment mode for traces. Supported modes are: %s.", strings.Join(supportedDeploymentModes, ", "))) | ||
|
||
return tracesCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright © Weifeng Wang <[email protected]> | ||
// | ||
// Licensed under the Apache License 2.0. | ||
|
||
package internal | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"os/signal" | ||
"strings" | ||
"syscall" | ||
) | ||
|
||
func ExecuteCommand(command string, args ...string) error { | ||
cmd := exec.Command(command, args...) | ||
var stderr bytes.Buffer | ||
cmd.Stderr = os.Stderr | ||
cmd.Stdout = os.Stdout | ||
if err := cmd.Start(); err != nil { | ||
log.Fatalf("Error: %s\n", stderr.String()) | ||
} | ||
|
||
// make target is the last argment | ||
target := args[len(args)-1] | ||
if strings.HasPrefix(target, "down-") || strings.HasPrefix(target, "delete-") { | ||
err := cmd.Wait() | ||
if err != nil { | ||
return err | ||
} | ||
} else { | ||
signalChan := make(chan os.Signal, 1) | ||
signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM) | ||
|
||
done := make(chan error, 1) | ||
go func() { done <- cmd.Wait() }() | ||
|
||
select { | ||
case <-signalChan: | ||
fmt.Printf("Received interrupt signal, stopping %s...\n", target) | ||
_ = cmd.Process.Signal(os.Interrupt) | ||
select { | ||
case <-signalChan: | ||
fmt.Printf("Force stopping %s...\n", target) | ||
_ = cmd.Process.Kill() | ||
os.Exit(1) // Exit with a status code of 1 | ||
case <-done: | ||
os.Exit(0) // Exit with a status code of 0 | ||
} | ||
case err := <-done: | ||
if err != nil { | ||
os.Exit(1) // Exit with a status code of 1 upon failure | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.