feat: allow specifying a custom app label alias when shipping logs via vector
Closes #7354
This commit is contained in:
@@ -257,7 +257,7 @@ func writeVectorConfig() error {
|
||||
|
||||
data.Sources[fmt.Sprintf("docker-source:%s", inflectedAppName)] = vectorSource{
|
||||
Type: "docker_logs",
|
||||
IncludeLabels: []string{fmt.Sprintf("com.dokku.app-name=%s", appName)},
|
||||
IncludeLabels: []string{fmt.Sprintf("%s=%s", reportComputedAppLabelAlias(appName), appName)},
|
||||
}
|
||||
|
||||
data.Sinks[fmt.Sprintf("docker-sink:%s", inflectedAppName)] = sink
|
||||
@@ -272,7 +272,7 @@ func writeVectorConfig() error {
|
||||
|
||||
data.Sources["docker-global-source"] = vectorSource{
|
||||
Type: "docker_logs",
|
||||
IncludeLabels: []string{"com.dokku.app-name"},
|
||||
IncludeLabels: []string{reportGlobalAppLabelAlias("global")},
|
||||
}
|
||||
|
||||
data.Sinks["docker-global-sink"] = sink
|
||||
|
||||
@@ -10,18 +10,23 @@ import (
|
||||
// MaxSize is the default max retention size for docker logs
|
||||
const MaxSize = "10m"
|
||||
|
||||
// AppLabelAlias is the property key for the app label alias
|
||||
const AppLabelAlias = "com.dokku.app-name"
|
||||
|
||||
var (
|
||||
// DefaultProperties is a map of all valid logs properties with corresponding default property values
|
||||
DefaultProperties = map[string]string{
|
||||
"max-size": "",
|
||||
"vector-sink": "",
|
||||
"app-label-alias": AppLabelAlias,
|
||||
"max-size": MaxSize,
|
||||
"vector-sink": "",
|
||||
}
|
||||
|
||||
// GlobalProperties is a map of all valid global logs properties
|
||||
GlobalProperties = map[string]bool{
|
||||
"max-size": true,
|
||||
"vector-image": true,
|
||||
"vector-sink": true,
|
||||
"app-label-alias": true,
|
||||
"max-size": true,
|
||||
"vector-image": true,
|
||||
"vector-sink": true,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -11,12 +11,15 @@ 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-global-image": reportVectorGlobalImage,
|
||||
"--logs-vector-sink": reportVectorSink,
|
||||
"--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-sink": reportVectorSink,
|
||||
}
|
||||
|
||||
flagKeys := []string{}
|
||||
@@ -30,6 +33,23 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
|
||||
return common.ReportSingleApp("logs", appName, infoFlag, infoFlags, flagKeys, format, trimPrefix, uppercaseFirstCharacter)
|
||||
}
|
||||
|
||||
func reportComputedAppLabelAlias(appName string) string {
|
||||
value := reportAppLabelAlias(appName)
|
||||
if value == "" {
|
||||
value = reportGlobalAppLabelAlias(appName)
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
func reportGlobalAppLabelAlias(appName string) string {
|
||||
return common.PropertyGetDefault("logs", "--global", "app-label-alias", AppLabelAlias)
|
||||
}
|
||||
|
||||
func reportAppLabelAlias(appName string) string {
|
||||
return common.PropertyGet("logs", appName, "app-label-alias")
|
||||
}
|
||||
|
||||
func reportComputedMaxSize(appName string) string {
|
||||
value := reportMaxSize(appName)
|
||||
if value == "" {
|
||||
|
||||
@@ -72,7 +72,13 @@ func CommandSet(appName string, property string, value string) error {
|
||||
}
|
||||
|
||||
common.CommandPropertySet("logs", appName, property, value, DefaultProperties, GlobalProperties)
|
||||
if property == "vector-sink" {
|
||||
|
||||
vectorProperties := map[string]bool{
|
||||
"app-label-alias": true,
|
||||
"vector-sink": true,
|
||||
}
|
||||
|
||||
if _, ok := vectorProperties[property]; ok {
|
||||
common.LogVerboseQuiet(fmt.Sprintf("Writing updated vector config to %s", filepath.Join(common.GetDataDirectory("logs"), "vector.json")))
|
||||
return writeVectorConfig()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user