fix: ensure the vector container does not exit when no configured sinks are in place
This commit is contained in:
@@ -73,8 +73,6 @@ dokku logs:vector-start
|
|||||||
|
|
||||||
This will start a new container named `vector` with Dokku's vector config mounted and ready for use. If a running container already exists, this command will do nothing. Additionally, if a container exists but is not running, this command will attempt to start the container.
|
This will start a new container named `vector` with Dokku's vector config mounted and ready for use. If a running container already exists, this command will do nothing. Additionally, if a container exists but is not running, this command will attempt to start the container.
|
||||||
|
|
||||||
By default, the vector container will do nothing and may exit immediately. It is necessary to configure a sink in order to ensure the vector container runs as necessary.
|
|
||||||
|
|
||||||
While the default vector image is hardcoded, users may specify an alternative via the `--vector-image` flag:
|
While the default vector image is hardcoded, users may specify an alternative via the `--vector-image` flag:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
@@ -101,8 +99,6 @@ The `vector` container will be stopped and removed from the system. If the conta
|
|||||||
|
|
||||||
#### Configuring a log sink
|
#### Configuring a log sink
|
||||||
|
|
||||||
> If no sinks are specified, the vector container will exit.
|
|
||||||
|
|
||||||
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 `sink` in DSN form with the `logs:set` command. Specifying a sink value will reload any running vector container.
|
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 `sink` in DSN form with the `logs:set` command. Specifying a sink value will reload any running vector container.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
@@ -131,8 +127,6 @@ As with app-specific sink settings, the global value may also be cleared by sett
|
|||||||
dokku logs:set --global sink
|
dokku logs:set --global sink
|
||||||
```
|
```
|
||||||
|
|
||||||
If no sink is specified, the vector container may exit prematurely.
|
|
||||||
|
|
||||||
##### Log Sink DSN Format
|
##### Log Sink DSN Format
|
||||||
|
|
||||||
The DSN form of a sink is as follows:
|
The DSN form of a sink is as follows:
|
||||||
|
|||||||
@@ -123,6 +123,10 @@ func valueToConfig(appName string, value string) (vectorSink, error) {
|
|||||||
if appName == "--global" {
|
if appName == "--global" {
|
||||||
i = "inputs[]=docker-global-source"
|
i = "inputs[]=docker-global-source"
|
||||||
}
|
}
|
||||||
|
if appName == "--null" {
|
||||||
|
i = "inputs[]=docker-null-source"
|
||||||
|
}
|
||||||
|
|
||||||
initialQuery := fmt.Sprintf("%s&%s", t, i)
|
initialQuery := fmt.Sprintf("%s&%s", t, i)
|
||||||
query := u.RawQuery
|
query := u.RawQuery
|
||||||
if query == "" {
|
if query == "" {
|
||||||
@@ -189,6 +193,24 @@ func writeVectorConfig() error {
|
|||||||
data.Sinks["docker-global-sink"] = sink
|
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, "", " ")
|
b, err := json.MarshalIndent(data, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -104,6 +104,11 @@ func CommandVectorLogs() error {
|
|||||||
func CommandVectorStart(vectorImage string) error {
|
func CommandVectorStart(vectorImage string) error {
|
||||||
common.LogInfo2("Starting vector container")
|
common.LogInfo2("Starting vector container")
|
||||||
if !common.ContainerExists(vectorContainerName) {
|
if !common.ContainerExists(vectorContainerName) {
|
||||||
|
common.LogVerbose("Ensuring vector configuration exists")
|
||||||
|
if err := writeVectorConfig(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return startVectorContainer(vectorImage)
|
return startVectorContainer(vectorImage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user