From aa05a952436ec17d1ff7fc831c22ad2b3135b979 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 25 Jan 2024 04:26:57 -0500 Subject: [PATCH] feat: allow setting the vector image as a global property --- docs/deployment/logs.md | 21 +++++++++++++++++++++ plugins/logs/logs.go | 5 +++-- plugins/logs/report.go | 15 ++++++++++----- plugins/logs/src/subcommands/subcommands.go | 2 +- plugins/logs/subcommands.go | 4 ++++ 5 files changed, 39 insertions(+), 8 deletions(-) diff --git a/docs/deployment/logs.md b/docs/deployment/logs.md index 6ac431f28..cc8c0a707 100644 --- a/docs/deployment/logs.md +++ b/docs/deployment/logs.md @@ -155,6 +155,27 @@ dokku logs:vector-logs --tail --num 10 The above command will show logs continually from the vector container, with an initial history of 10 log lines +#### Changing the vector image + +Dokku integrates with a Vector docker image version that is known to be compatible with the documentation. In some cases, it may be useful to specify an alternative image version. To do so, set the global `vector-image` property. + +```shell +dokku logs:set --global vector-image timberio/vector:0.35.X-debian +``` + +Once set, the vector container will need to be stopped and then started. Note that specifying the `--vector-image` flag on the `logs:vector-start` will override the setting. + +```shell +dokku logs:vector-stop +dokku logs:vector-start +``` + +Setting this to an empty string will reset the version to the version currently compatible with the Dokku installation. + +```shell +dokku logs:set --global vector-image +``` + #### Configuring a log sink Vector uses the concept of log "sinks" to send logs to a given endpoint. Log sinks may be configured globally or on a per-app basis by specifying a `vector-sink` in DSN form with the `logs:set` command. Specifying a sink value will reload any running vector container. diff --git a/plugins/logs/logs.go b/plugins/logs/logs.go index 52947051a..f3fb64806 100644 --- a/plugins/logs/logs.go +++ b/plugins/logs/logs.go @@ -18,8 +18,9 @@ var ( // GlobalProperties is a map of all valid global logs properties GlobalProperties = map[string]bool{ - "max-size": true, - "vector-sink": true, + "max-size": true, + "vector-image": true, + "vector-sink": true, } ) diff --git a/plugins/logs/report.go b/plugins/logs/report.go index b1ce8d95a..9a84eb856 100644 --- a/plugins/logs/report.go +++ b/plugins/logs/report.go @@ -11,11 +11,12 @@ func ReportSingleApp(appName string, format string, infoFlag string) error { } flags := map[string]common.ReportFunc{ - "--logs-computed-max-size": reportComputedMaxSize, - "--logs-global-max-size": reportGlobalMaxSize, - "--logs-global-vector-sink": reportGlobalVectorSink, - "--logs-max-size": reportMaxSize, - "--logs-vector-sink": reportVectorSink, + "--logs-computed-max-size": reportComputedMaxSize, + "--logs-global-max-size": reportGlobalMaxSize, + "--logs-global-vector-sink": reportGlobalVectorSink, + "--logs-max-size": reportMaxSize, + "--logs-vector-global-image": reportVectorGlobalImage, + "--logs-vector-sink": reportVectorSink, } flagKeys := []string{} @@ -42,6 +43,10 @@ func reportGlobalMaxSize(appName string) string { return common.PropertyGetDefault("logs", "--global", "max-size", MaxSize) } +func reportVectorGlobalImage(appName string) string { + return common.PropertyGetDefault("logs", "--global", "vector-image", VectorImage) +} + func reportGlobalVectorSink(appName string) string { return common.PropertyGet("logs", "--global", "vector-sink") } diff --git a/plugins/logs/src/subcommands/subcommands.go b/plugins/logs/src/subcommands/subcommands.go index 0ed04c277..a9f56604f 100644 --- a/plugins/logs/src/subcommands/subcommands.go +++ b/plugins/logs/src/subcommands/subcommands.go @@ -54,7 +54,7 @@ func main() { err = logs.CommandVectorLogs(*num, *tail) case "vector-start": args := flag.NewFlagSet("logs:vector-start", flag.ExitOnError) - vectorImage := args.String("vector-image", logs.VectorImage, "--vector-image: the name of the docker image to run for vector") + vectorImage := args.String("vector-image", "", "--vector-image: the name of the docker image to run for vector") args.Parse(os.Args[2:]) err = logs.CommandVectorStart(*vectorImage) case "vector-stop": diff --git a/plugins/logs/subcommands.go b/plugins/logs/subcommands.go index bbf9318da..cdc4c2a05 100644 --- a/plugins/logs/subcommands.go +++ b/plugins/logs/subcommands.go @@ -103,6 +103,10 @@ func CommandVectorStart(vectorImage string) error { return err } + if vectorImage == "" { + vectorImage = common.PropertyGet("logs", "--global", "vector-image") + } + if common.ContainerExists(vectorContainerName) { if common.ContainerIsRunning(vectorContainerName) { common.LogVerbose("Vector container is running")