-
Notifications
You must be signed in to change notification settings - Fork 37
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
19 changed files
with
2,798 additions
and
63 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
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,101 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/smartcontractkit/chainlink-testing-framework/framework" | ||
"github.com/urfave/cli/v2" | ||
"log" | ||
"os" | ||
"os/exec" | ||
) | ||
|
||
func main() { | ||
app := &cli.App{ | ||
Name: "ctf", | ||
Usage: "Manage Docker containers, networks, and TOML files for CTF framework", | ||
Commands: []*cli.Command{ | ||
{ | ||
Name: "clean", | ||
Usage: "Remove Docker containers and networks with 'framework=ctf' label", | ||
Action: func(c *cli.Context) error { | ||
// Execute the bash command | ||
err := cleanDockerResources() | ||
if err != nil { | ||
return fmt.Errorf("failed to clean Docker resources: %w", err) | ||
} | ||
return nil | ||
}, | ||
}, | ||
{ | ||
Name: "observability", | ||
Usage: "Process a TOML file, remove fields with '.out' keys", | ||
Subcommands: []*cli.Command{ | ||
{ | ||
Name: "up", | ||
Usage: "", | ||
UsageText: "", | ||
Description: "", | ||
Action: func(c *cli.Context) error { return observabilityUp() }, | ||
}, | ||
{ | ||
Name: "down", | ||
Usage: "", | ||
UsageText: "", | ||
Description: "", | ||
Action: func(c *cli.Context) error { return observabilityDown() }, | ||
}, | ||
}, | ||
Action: func(c *cli.Context) error { | ||
_ = c.String("file") | ||
// TODO: might be useful? | ||
return nil | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
err := app.Run(os.Args) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func cleanDockerResources() error { | ||
// Bash command for removing Docker containers and networks with "framework=ctf" label | ||
cmd := exec.Command("bash", "-c", ` | ||
docker ps -aq --filter "label=framework=ctf" | xargs -r docker rm -f && \ | ||
docker network ls --filter "label=framework=ctf" -q | xargs -r docker network rm | ||
`) | ||
framework.L.Info().Str("Cmd", cmd.String()).Msg("Running command") | ||
output, err := cmd.CombinedOutput() | ||
if err != nil { | ||
return fmt.Errorf("error running clean command: %s", string(output)) | ||
} | ||
return nil | ||
} | ||
|
||
func observabilityUp() error { | ||
cmd := exec.Command("bash", "-c", fmt.Sprintf(` | ||
cd %s && \ | ||
docker compose up | ||
`, framework.ObservabilityPath)) | ||
framework.L.Info().Str("Cmd", cmd.String()).Msg("Running command") | ||
output, err := cmd.CombinedOutput() | ||
if err != nil { | ||
return fmt.Errorf("error running clean command: %s", string(output)) | ||
} | ||
return nil | ||
} | ||
|
||
func observabilityDown() error { | ||
cmd := exec.Command("bash", "-c", fmt.Sprintf(` | ||
cd %s && \ | ||
docker compose down -v | ||
`, framework.ObservabilityPath)) | ||
framework.L.Info().Str("Cmd", cmd.String()).Msg("Running command") | ||
output, err := cmd.CombinedOutput() | ||
if err != nil { | ||
return fmt.Errorf("error running clean command: %s", string(output)) | ||
} | ||
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
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,11 @@ | ||
## Observability tools | ||
We have some observability tools we use with our harness, you can use them by calling | ||
``` | ||
ctf observability up | ||
``` | ||
Change your `Loki` config in your `.envrc` you use to run tests | ||
``` | ||
export LOKI_TENANT_ID=promtail | ||
export LOKI_URL=http://host.docker.internal:3030/loki/api/v1/push | ||
``` | ||
Then check [Loki](http://localhost:3000/explore?panes=%7B%220EE%22:%7B%22datasource%22:%22P8E80F9AEF21F6940%22,%22queries%22:%5B%7B%22refId%22:%22A%22,%22expr%22:%22%7Bjob%3D%5C%22ctf%5C%22%7D%22,%22queryType%22:%22range%22,%22datasource%22:%7B%22type%22:%22loki%22,%22uid%22:%22P8E80F9AEF21F6940%22%7D,%22editorMode%22:%22code%22%7D%5D,%22range%22:%7B%22from%22:%22now-5m%22,%22to%22:%22now%22%7D%7D%7D&schemaVersion=1&orgId=1) logs |
Oops, something went wrong.