-
Notifications
You must be signed in to change notification settings - Fork 96
feat: grafloki start/stop #2696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
d1fc453
port sink configuration over to kubernetes
brianle1301 67e744f
remove vector config template
brianle1301 6f5e7e4
change bufferSize type
brianle1301 d42f820
properly tag data volumes in docker backend
brianle1301 fee1fef
update job poll logic
brianle1301 e696e81
fix linter and don't retry failed validation
brianle1301 f7a3359
fix linter
brianle1301 2d1aaf7
update ci to take into account new logs aggregator volumes
brianle1301 bcc2320
fix kurtosis service logs
brianle1301 b9c3787
fix validation command
brianle1301 c89a65e
revert to printf for consistency
brianle1301 42dc1e3
resolve review comments
brianle1301 d65e588
variable placeholders for nil maps
brianle1301 2ce3ee4
clean logs aggregator data dir volume
brianle1301 1348c0a
Don't connect container to network if networkId is an empty string
brianle1301 eb94f59
fix cleaning
brianle1301 44ed5b6
add doc for Kubernetes backend
brianle1301 0289df8
Merge branch 'main' into main
tedim52 18d53e1
clearer docs
brianle1301 6b84372
lint
brianle1301 8b5a3d6
Merge branch 'main' into main
brianle1301 35c815e
add grafloki command
tedim52 bc38cad
start grafloki command
tedim52 ed78d91
add stop, defers, idempotent start
tedim52 1fc23ac
refactor
tedim52 fc1bfdb
refactor
tedim52 d5e0ac2
add start grafloki in k8s
tedim52 55c1577
fmt
tedim52 2d257c0
create loki service
tedim52 dbbfdc2
Merge branch 'tedi/export-k8s-logging' into tedi/grafloki
tedim52 82cff1d
Merge branch 'main' into tedi/grafloki
tedim52 3bdab8c
lint
tedim52 377a48b
some clean up
tedim52 976e86b
add note on design decision
tedim52 25f481a
add docs
tedim52 a096b44
fixes
tedim52 40044c7
wait for loki deployment
tedim52 1c2432d
picassos bull
tedim52 18d744f
change label names
tedim52 0c83a49
env vars
tedim52 8df4b0c
fix naming
tedim52 80f72d0
typo
tedim52 e3768b2
lint
tedim52 58efdf2
fix defer undoing
tedim52 0fd294f
fix defer undoing
tedim52 9b17e6f
address cmts
tedim52 5b00f85
fixes
tedim52 dc5aa3a
fixes
tedim52 007f0ce
Merge branch 'main' into tedi/grafloki
tedim52 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,21 @@ | ||
| package grafloki | ||
|
|
||
| import ( | ||
| "github.com/kurtosis-tech/kurtosis/cli/cli/command_str_consts" | ||
| "github.com/kurtosis-tech/kurtosis/cli/cli/commands/grafloki/start" | ||
| "github.com/kurtosis-tech/kurtosis/cli/cli/commands/grafloki/stop" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // GraflokiCmd suppressing exhaustruct requirement because this struct has ~40 properties | ||
| // nolint: exhaustruct | ||
| var GraflokiCmd = &cobra.Command{ | ||
| Use: command_str_consts.GraflokiCmdStr, | ||
| Short: "Start Grafana/Loki for log collection", | ||
| RunE: nil, | ||
| } | ||
|
|
||
| func init() { | ||
| GraflokiCmd.AddCommand(start.GraflokiStartCmd.MustGetCobraCommand()) | ||
| GraflokiCmd.AddCommand(stop.GraflokiStopCmd.MustGetCobraCommand()) | ||
| } |
This file contains hidden or 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,124 @@ | ||
| package start | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel" | ||
| "github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel/args" | ||
| "github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel/flags" | ||
| "github.com/kurtosis-tech/kurtosis/cli/cli/command_str_consts" | ||
| "github.com/kurtosis-tech/kurtosis/cli/cli/defaults" | ||
| "github.com/kurtosis-tech/kurtosis/cli/cli/helpers/engine_manager" | ||
| "github.com/kurtosis-tech/kurtosis/cli/cli/helpers/grafloki" | ||
| "github.com/kurtosis-tech/kurtosis/cli/cli/helpers/kurtosis_config_getter" | ||
| "github.com/kurtosis-tech/kurtosis/cli/cli/kurtosis_config/resolved_config" | ||
| "github.com/kurtosis-tech/kurtosis/cli/cli/out" | ||
| "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/logs_aggregator" | ||
| "github.com/kurtosis-tech/stacktrace" | ||
| "github.com/sirupsen/logrus" | ||
| ) | ||
|
|
||
| const ( | ||
| defaultEngineVersion = "" | ||
| restartEngineOnSameVersionIfAnyRunning = true | ||
| ) | ||
|
|
||
| var GraflokiStartCmd = &lowlevel.LowlevelKurtosisCommand{ | ||
| CommandStr: command_str_consts.GraflokiStartCmdStr, | ||
| ShortDescription: "Starts a Grafana/Loki instance.", | ||
| LongDescription: "Starts a Grafana/Loki instance and configures Kurtosis engine to send logs to it.", | ||
| RunFunc: run, | ||
| Flags: nil, | ||
| Args: nil, | ||
| PostValidationAndRunFunc: nil, | ||
| PreValidationAndRunFunc: nil, | ||
| } | ||
|
|
||
| func run( | ||
| ctx context.Context, | ||
| _ *flags.ParsedFlags, | ||
| _ *args.ParsedArgs, | ||
|
|
||
| ) error { | ||
| clusterConfig, err := kurtosis_config_getter.GetKurtosisClusterConfig() | ||
| if err != nil { | ||
| return stacktrace.Propagate(err, "An error occurred getting Kurtosis cluster config.") | ||
| } | ||
|
|
||
| // NOTE(tedi 04/03/25): If you're wondering why the grafana / loki instance is being started by the CLI (and not in container-engine-lib via KurtosisBackend as with LogsCollector and LogsAggregator), here's why: | ||
|
tedim52 marked this conversation as resolved.
|
||
| // 1. now that Kurtosis is purely OSS, it's important to reduce maintenance surface / complexity inside Kurtosis core (Engine, APIContainer, KurtosisBackend, Starlark Engine) | ||
| // wherever possible infra not essential to Kurtosis core should be built outside of it or at the edges (e.g. client) | ||
| // 2. the export logs feature was built in service of leveraging existing logging solutions/not rebuilding logging in Kurtosis | ||
| // 3. having grafloki started/managed by the CLI lets us build on the export logs feature | ||
| // In other words | ||
| // putting it in the CLI is saying - “You could set up Grafana and Loki yourself, and then restart the engine to point to it, Kurtosis CLI will do that for you to save you a step” | ||
| // putting it in Kurtosis core is saying - “Grafana and Loki are core a necessary part of the Kurtosis platform and supports the Kurtosis abstraction/value prop" - which is not the case | ||
| // https://drawpaintacademy.com/the-bull/ | ||
| var lokiHost string | ||
| var grafanaUrl string | ||
| switch clusterConfig.GetClusterType() { | ||
| case resolved_config.KurtosisClusterType_Docker: | ||
| lokiHost, grafanaUrl, err = grafloki.StartGrafLokiInDocker(ctx) | ||
| if err != nil { | ||
| return stacktrace.Propagate(err, "An error occurred starting Grafana and Loki in Docker.") | ||
| } | ||
| case resolved_config.KurtosisClusterType_Kubernetes: | ||
| lokiHost, grafanaUrl, err = grafloki.StartGrafLokiInKubernetes(ctx) | ||
| if err != nil { | ||
| return stacktrace.Propagate(err, "An error occurred starting Grafana and Loki in Kubernetes.") | ||
| } | ||
| default: | ||
| return stacktrace.NewError("Unsupported cluster type: %v", clusterConfig.GetClusterType().String()) | ||
| } | ||
|
|
||
| // This matches the exact configurations here: https://vector.dev/docs/reference/configuration/sinks/loki/ | ||
| lokiSink := map[string]map[string]interface{}{ | ||
|
tedim52 marked this conversation as resolved.
|
||
| "loki": { | ||
| "type": "loki", | ||
| "endpoint": lokiHost, | ||
| "encoding": map[string]string{ | ||
| "codec": "json", | ||
| }, | ||
| "labels": map[string]string{ | ||
| "job": "kurtosis", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| logrus.Infof("Configuring engine to send logs to Loki...") | ||
| err = restartEngineWithLogsSink(ctx, lokiSink) | ||
| if err != nil { | ||
| return stacktrace.Propagate(err, "An error occurred restarting engine to be configured to send logs to Loki.") | ||
| } | ||
|
|
||
| out.PrintOutLn(fmt.Sprintf("Grafana running at %v", grafanaUrl)) | ||
| return nil | ||
| } | ||
|
|
||
| func restartEngineWithLogsSink(ctx context.Context, sink logs_aggregator.Sinks) error { | ||
| engineManager, err := engine_manager.NewEngineManager(ctx) | ||
| if err != nil { | ||
| return stacktrace.Propagate(err, "An error occurred creating an engine manager.") | ||
| } | ||
| dontRestartAPIContainers := false | ||
| _, engineClientCloseFunc, restartEngineErr := engineManager.RestartEngineIdempotently(ctx, | ||
| defaults.DefaultEngineLogLevel, | ||
| defaultEngineVersion, | ||
| restartEngineOnSameVersionIfAnyRunning, | ||
| defaults.DefaultEngineEnclavePoolSize, | ||
| defaults.DefaultEnableDebugMode, | ||
| defaults.DefaultGitHubAuthTokenOverride, | ||
| dontRestartAPIContainers, | ||
| defaults.DefaultDomain, | ||
| defaults.DefaultLogRetentionPeriod, | ||
| sink) | ||
| if restartEngineErr != nil { | ||
| return stacktrace.Propagate(restartEngineErr, "An error occurred restarting the Kurtosis engine") | ||
| } | ||
| defer func() { | ||
| if err = engineClientCloseFunc(); err != nil { | ||
| logrus.Warnf("Error closing the engine client:\n'%v'", err) | ||
| } | ||
| }() | ||
| return nil | ||
| } | ||
This file contains hidden or 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,54 @@ | ||
| package stop | ||
|
|
||
| import ( | ||
| "context" | ||
| "github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel" | ||
| "github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel/args" | ||
| "github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel/flags" | ||
| "github.com/kurtosis-tech/kurtosis/cli/cli/command_str_consts" | ||
| "github.com/kurtosis-tech/kurtosis/cli/cli/helpers/grafloki" | ||
| "github.com/kurtosis-tech/kurtosis/cli/cli/helpers/kurtosis_config_getter" | ||
| "github.com/kurtosis-tech/kurtosis/cli/cli/kurtosis_config/resolved_config" | ||
| "github.com/kurtosis-tech/kurtosis/cli/cli/out" | ||
| "github.com/kurtosis-tech/stacktrace" | ||
| ) | ||
|
|
||
| var GraflokiStopCmd = &lowlevel.LowlevelKurtosisCommand{ | ||
| CommandStr: command_str_consts.GraflokiStopCmdStr, | ||
| ShortDescription: "Stops a grafana/loki instance.", | ||
| LongDescription: "Stop a grafana/loki instance if one already exists.", | ||
| RunFunc: run, | ||
| Flags: nil, | ||
| Args: nil, | ||
| PreValidationAndRunFunc: nil, | ||
| PostValidationAndRunFunc: nil, | ||
| } | ||
|
|
||
| func run( | ||
| ctx context.Context, | ||
| _ *flags.ParsedFlags, | ||
| _ *args.ParsedArgs, | ||
| ) error { | ||
| clusterConfig, err := kurtosis_config_getter.GetKurtosisClusterConfig() | ||
| if err != nil { | ||
| return stacktrace.Propagate(err, "An error occurred getting Kurtosis cluster config.") | ||
| } | ||
|
|
||
| switch clusterConfig.GetClusterType() { | ||
| case resolved_config.KurtosisClusterType_Docker: | ||
| err := grafloki.StopGrafLokiInDocker(ctx) | ||
| if err != nil { | ||
| return stacktrace.Propagate(err, "An error occurred stopping Grafana and Loki containers in Docker.") | ||
| } | ||
| case resolved_config.KurtosisClusterType_Kubernetes: | ||
| err := grafloki.StopGrafLokiInKubernetes(ctx) | ||
| if err != nil { | ||
| return stacktrace.Propagate(err, "An error occurred stopping Grafana and Loki containers in Kubernetes.") | ||
| } | ||
| default: | ||
| return stacktrace.NewError("Unsupported cluster type: %v", clusterConfig.GetClusterType().String()) | ||
| } | ||
|
|
||
| out.PrintOutLn("Successfully stopped Grafana and Loki containers.") | ||
| return nil | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.