The `<plugin>-global-<property>` keys in `:report` output returned the resolved value with the built-in default substituted in, so external tooling could not distinguish a property that had been set globally to the default from one that had never been set. The bare keys for caddy, haproxy, and traefik global-only properties had the same shape. The `global-<property>` keys now hold the raw stored value and are empty when nothing has been set, and a new `computed-<property>` key holds the effective value used at runtime, falling back through the per-app value (where one exists), the global value, and the built-in default. The bare global-only keys for the three proxy plugins are removed in favor of the raw/computed pair. Closes #8631.
150 lines
4.0 KiB
Go
150 lines
4.0 KiB
Go
package logs
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/dokku/dokku/plugins/common"
|
|
)
|
|
|
|
// ReportSingleApp is an internal function that displays the logs report for one or more apps
|
|
func ReportSingleApp(appName string, format string, infoFlag string) error {
|
|
if appName != "--global" {
|
|
if err := common.VerifyAppName(appName); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
os.Setenv("DOKKU_REPORT_FORMAT", format)
|
|
os.Setenv("DOKKU_REPORT_FLAG", infoFlag)
|
|
var flags map[string]common.ReportFunc
|
|
if appName == "--global" {
|
|
flags = map[string]common.ReportFunc{
|
|
"--logs-computed-app-label-alias": reportComputedAppLabelAlias,
|
|
"--logs-computed-max-size": reportComputedMaxSize,
|
|
"--logs-global-app-label-alias": reportGlobalAppLabelAlias,
|
|
"--logs-global-max-size": reportGlobalMaxSize,
|
|
"--logs-global-vector-sink": reportGlobalVectorSink,
|
|
"--logs-vector-global-image": reportVectorGlobalImage,
|
|
"--logs-vector-global-networks": reportVectorGlobalNetworks,
|
|
}
|
|
} else {
|
|
flags = map[string]common.ReportFunc{
|
|
"--logs-computed-app-label-alias": reportComputedAppLabelAlias,
|
|
"--logs-computed-max-size": reportComputedMaxSize,
|
|
"--logs-global-app-label-alias": reportGlobalAppLabelAlias,
|
|
"--logs-global-max-size": reportGlobalMaxSize,
|
|
"--logs-global-vector-sink": reportGlobalVectorSink,
|
|
"--logs-app-label-alias": reportAppLabelAlias,
|
|
"--logs-max-size": reportMaxSize,
|
|
"--logs-vector-global-image": reportVectorGlobalImage,
|
|
"--logs-vector-global-networks": reportVectorGlobalNetworks,
|
|
"--logs-vector-sink": reportVectorSink,
|
|
}
|
|
}
|
|
|
|
flagKeys := []string{}
|
|
for flagKey := range flags {
|
|
flagKeys = append(flagKeys, flagKey)
|
|
}
|
|
|
|
trimPrefix := false
|
|
uppercaseFirstCharacter := true
|
|
infoFlags := common.CollectReport(appName, infoFlag, flags)
|
|
return common.ReportSingleApp("logs", appName, infoFlag, infoFlags, flagKeys, format, trimPrefix, uppercaseFirstCharacter)
|
|
}
|
|
|
|
func reportComputedAppLabelAlias(appName string) string {
|
|
value := reportAppLabelAlias(appName)
|
|
if value == "" {
|
|
value = reportGlobalAppLabelAlias(appName)
|
|
}
|
|
if value == "" {
|
|
value = AppLabelAlias
|
|
}
|
|
|
|
return value
|
|
}
|
|
|
|
func reportGlobalAppLabelAlias(appName string) string {
|
|
return common.PropertyGet("logs", "--global", "app-label-alias")
|
|
}
|
|
|
|
func reportAppLabelAlias(appName string) string {
|
|
return common.PropertyGet("logs", appName, "app-label-alias")
|
|
}
|
|
|
|
func reportComputedMaxSize(appName string) string {
|
|
value := reportMaxSize(appName)
|
|
if value == "" {
|
|
value = reportGlobalMaxSize(appName)
|
|
}
|
|
if value == "" {
|
|
value = MaxSize
|
|
}
|
|
|
|
return value
|
|
}
|
|
|
|
func reportGlobalMaxSize(appName string) string {
|
|
return common.PropertyGet("logs", "--global", "max-size")
|
|
}
|
|
|
|
func reportVectorGlobalImage(appName string) string {
|
|
return getComputedVectorImage()
|
|
}
|
|
|
|
func reportVectorGlobalNetworks(appName string) string {
|
|
return common.PropertyGet("logs", "--global", "vector-networks")
|
|
}
|
|
|
|
func reportGlobalVectorSink(appName string) string {
|
|
value := common.PropertyGet("logs", "--global", "vector-sink")
|
|
if value == "" {
|
|
return value
|
|
}
|
|
|
|
if os.Getenv("DOKKU_REPORT_FORMAT") != "stdout" {
|
|
return value
|
|
}
|
|
|
|
if os.Getenv("DOKKU_REPORT_FLAG") == "--logs-global-vector-sink" {
|
|
return value
|
|
}
|
|
|
|
// only show the schema and sanitize the rest
|
|
sink, err := SinkValueToConfig("--global", value)
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
|
|
return fmt.Sprintf("%s://redacted", sink["type"])
|
|
}
|
|
|
|
func reportMaxSize(appName string) string {
|
|
return common.PropertyGet("logs", appName, "max-size")
|
|
}
|
|
|
|
func reportVectorSink(appName string) string {
|
|
value := common.PropertyGet("logs", appName, "vector-sink")
|
|
if value == "" {
|
|
return value
|
|
}
|
|
|
|
if os.Getenv("DOKKU_REPORT_FORMAT") != "stdout" {
|
|
return value
|
|
}
|
|
|
|
if os.Getenv("DOKKU_REPORT_FLAG") == "--logs-vector-sink" {
|
|
return value
|
|
}
|
|
|
|
// only show the schema and sanitize the rest
|
|
sink, err := SinkValueToConfig(appName, value)
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
|
|
return fmt.Sprintf("%s://redacted", sink["type"])
|
|
}
|