fix: ensure the vector container does not exit when no configured sinks are in place

This commit is contained in:
Jose Diaz-Gonzalez
2021-01-04 01:12:25 -05:00
parent 43d6a2ad94
commit 94696e81fa
3 changed files with 27 additions and 6 deletions

View File

@@ -123,6 +123,10 @@ func valueToConfig(appName string, value string) (vectorSink, error) {
if appName == "--global" {
i = "inputs[]=docker-global-source"
}
if appName == "--null" {
i = "inputs[]=docker-null-source"
}
initialQuery := fmt.Sprintf("%s&%s", t, i)
query := u.RawQuery
if query == "" {
@@ -189,6 +193,24 @@ func writeVectorConfig() error {
data.Sinks["docker-global-sink"] = sink
}
if len(data.Sources) == 0 {
// pull from no containers
data.Sources["docker-null-source"] = vectorSource{
Type: "docker_logs",
IncludeLabels: []string{"com.dokku.vector-null"},
}
}
if len(data.Sinks) == 0 {
// write logs to a blackhole
sink, err := valueToConfig("--null", "blackhole://?print_amount=1")
if err != nil {
return err
}
data.Sinks["docker-null-sink"] = sink
}
b, err := json.MarshalIndent(data, "", " ")
if err != nil {
return err

View File

@@ -104,6 +104,11 @@ func CommandVectorLogs() error {
func CommandVectorStart(vectorImage string) error {
common.LogInfo2("Starting vector container")
if !common.ContainerExists(vectorContainerName) {
common.LogVerbose("Ensuring vector configuration exists")
if err := writeVectorConfig(); err != nil {
return err
}
return startVectorContainer(vectorImage)
}