fix: add support for url-encoded vector-sink config values
We additionally force-replace \u0026 with an ampersand to ensure we properly support & in config values (such as for URIs).
This commit is contained in:
@@ -197,4 +197,13 @@ Valid values for `SINK_TYPE` include all log vector log sinks, while `SINK_OPTIO
|
||||
- `[int]`: form: `key[]=int`
|
||||
- `table`: form: `option[key]=value`
|
||||
|
||||
For some sinks - such as the `http` sink - it may be useful to use special characters such as `&`. These characters must be url escaped as per [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986.html).
|
||||
|
||||
```shell
|
||||
# the following command will set the `http` sink with a uri config value
|
||||
# for a uri config value: https://loggerservice.com:1234/?token=abc1234&type=vector
|
||||
# the url quoted version: https%3A//loggerservice.com%3A1234/%3Ftoken%3Dabc1234%26type%3Dvector
|
||||
dokku logs:set test vector-sink "http://?uri=https%3A//loggerservice.com%3A1234/%3Ftoken%3Dabc1234%26type%3Dvector"
|
||||
```
|
||||
|
||||
Please read the [sink documentation](https://vector.dev/docs/reference/sinks/) for your sink of choice to configure the sink as desired.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package logs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -217,6 +218,8 @@ func writeVectorConfig() error {
|
||||
return err
|
||||
}
|
||||
|
||||
b = bytes.Replace(b, []byte("\\u0026"), []byte("&"), -1)
|
||||
|
||||
vectorConfig := filepath.Join(common.MustGetEnv("DOKKU_LIB_ROOT"), "data", "logs", "vector.json")
|
||||
if err := common.WriteSliceToFile(vectorConfig, []string{string(b)}); err != nil {
|
||||
return err
|
||||
|
||||
@@ -238,6 +238,32 @@ teardown() {
|
||||
assert_output ""
|
||||
}
|
||||
|
||||
@test "(logs) logs:set escaped uri" {
|
||||
run create_app
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku logs:set $TEST_APP vector-sink http://?uri=https%3A//loggerservice.com%3A1234/%3Ftoken%3Dabc1234%26type%3Dvector" 2>&1
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains "Setting vector-sink"
|
||||
assert_output_contains "Writing updated vector config to /var/lib/dokku/data/logs/vector.json"
|
||||
|
||||
run /bin/bash -c "dokku logs:report $TEST_APP --logs-vector-sink 2>&1"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "http://?uri=https%3A//loggerservice.com%3A1234/%3Ftoken%3Dabc1234%26type%3Dvector"
|
||||
|
||||
run /bin/bash -c "jq -r '.sinks[\"docker-sink:$TEST_APP\"].uri' /var/lib/dokku/data/logs/vector.json"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "https://loggerservice.com:1234/?token=abc1234&type=vector"
|
||||
}
|
||||
|
||||
@test "(logs) logs:set global" {
|
||||
run create_app
|
||||
echo "output: $output"
|
||||
|
||||
Reference in New Issue
Block a user