这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/deployment/logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,19 @@ For some sinks - such as the `http` sink - it may be useful to use special chara
dokku logs:set test vector-sink "http://?uri=https%3A//loggerservice.com%3A1234/%3Ftoken%3Dabc1234%26type%3Dvector"
```

For kubernetes, it may be necessary to use template syntax - `{{ .parent.child }}` - in the sink configuration. Naively using brackets will fail due to the Helm chart install process assuming that the template should be interpreted at Helm install time vs by Vector itself. To avoid this, use `base64enc:` values (available only for top-level properties at this time). The following example shows how to use `{{ pod }}` as a value.

```shell
# encode the value with a Helm `print` statement wrapper
encoded="$(echo '{{ print "{{ pod }}" }}' | base64)"
# the value of encoded should be: e3sgcHJpbnQgInt7IHBvZCB9fSIgfX0K

# set the value
dokku logs:set test vector-sink "http://?process=base64enc%3A${encoded}"
```

This will transform the value to it's encoded form when configuring Vector sinks for Kubernetes.

Please read the [sink documentation](https://vector.dev/docs/reference/configuration/sinks/) for your sink of choice to configure the sink as desired.

##### Configuring the app label
Expand Down
1 change: 1 addition & 0 deletions docs/deployment/schedulers/k3s.md
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ Next, run the `scheduler-k3s:ensure-charts` command with the `vector` chart to f
```shell
dokku scheduler-k3s:ensure-charts --charts vector
```
Please see the [vector logs documentation](/docs/deployment/logs.md#configuring-a-log-sink) for more information on specifying vector sinks.

### Supported Resource Management Properties

Expand Down
17 changes: 17 additions & 0 deletions plugins/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package logs

import (
"embed"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -102,5 +103,21 @@ func SinkValueToConfig(appName string, sinkValue string) (VectorSink, error) {
data["inputs"] = []string{"docker-null-source"}
}

// add special support for `base64enc:VAL` fields
for key, value := range data {
valueString, ok := value.(string)
if !ok {
continue
}

if encodedValue, found := strings.CutPrefix(valueString, "base64enc:"); found {
decodedValue, err := base64.StdEncoding.DecodeString(encodedValue)
if err != nil {
return data, fmt.Errorf("Error decoding base64: %w", err)
}
data[key] = strings.TrimSpace(string(decodedValue))
}
}

return data, nil
}
2 changes: 1 addition & 1 deletion plugins/scheduler-k3s/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,7 @@ func installHelmCharts(ctx context.Context, clientset KubernetesClient, shouldIn
}
}

if chart.ReleaseName == "vector" {
if chart.ReleaseName == "vector" && chart.Namespace == "vector" {
values = updateVectorValues(values)
}

Expand Down
26 changes: 26 additions & 0 deletions tests/unit/scheduler-k3s-3.bats
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,32 @@ teardown_() {
assert_output "2"
}

@test "(scheduler-k3s) deploy kustomize with vector sink" {
if [[ -z "$DOCKERHUB_USERNAME" ]] || [[ -z "$DOCKERHUB_TOKEN" ]]; then
skip "skipping due to missing docker.io credentials DOCKERHUB_USERNAME:DOCKERHUB_TOKEN"
fi

encoded="$(echo '{{ print "{{ pod }}" }}' | base64)"
run /bin/bash -c "echo $encoded"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "e3sgcHJpbnQgInt7IHBvZCB9fSIgfX0K"

run /bin/bash -c "dokku logs:set --global vector-sink 'http://?process=base64enc%3A${encoded}'"
echo "output: $output"
echo "status: $status"
assert_success

INGRESS_CLASS=nginx install_k3s

run /bin/bash -c "kubectl get cm -n vector vector -o yaml"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "process: '{{ pod }}'"
}

inject_kustomization_yaml() {
local APP="$1"
local APP_REPO_DIR="$2"
Expand Down
Loading