Add vector service.

This commit is contained in:
2023-07-21 07:16:19 +01:00
parent 496e3c9e44
commit f13b350f73
2 changed files with 95 additions and 0 deletions

View File

@@ -43,6 +43,13 @@ in
# TODO: trim this down # TODO: trim this down
allow_caps = ["all"]; allow_caps = ["all"];
volumes.enabled = true; volumes.enabled = true;
extra_labels = [
"job_name"
"task_group_name"
"task_name"
"namespace"
"node_name"
];
}; };
}; };

88
services/vector.hcl Normal file
View File

@@ -0,0 +1,88 @@
job "vector" {
datacenters = ["alo"]
type = "system"
group "vector" {
network {
port "api" {
#host_network = "tailscale"
to = 8686
}
}
ephemeral_disk {
size = 500
sticky = true
}
task "vector" {
driver = "docker"
config {
image = "timberio/vector:0.28.X-alpine"
ports = ["api"]
volumes = ["/var/run/docker.sock:/var/run/docker.sock:ro"]
}
env {
VECTOR_CONFIG = "local/vector.toml"
VECTOR_REQUIRE_HEALTHY = "true"
}
service {
check {
port = "api"
type = "http"
path = "/health"
interval = "30s"
timeout = "5s"
}
}
resources {
cpu = 500 # 500 MHz
memory = 256 # 256MB
}
template {
destination = "local/vector.toml"
change_mode = "signal"
change_signal = "SIGHUP"
# overriding the delimiters to [[ ]] to avoid conflicts with Vector's native templating, which also uses {{ }}
left_delimiter = "[["
right_delimiter = "]]"
data=<<EOH
data_dir = "alloc/data/vector/"
[api]
enabled = true
address = "0.0.0.0:8686"
playground = false
[sources.logs]
type = "docker_logs"
[transforms.transformed]
type = "remap"
inputs = [ "logs" ]
source = '''
.debug = parse_key_value!(.message)
.job_name = split(get!(value: .label, path: ["com.hashicorp.nomad.job_name"]), "/")[0] ?? get!(value: .label, path: ["com.hashicorp.nomad.job_name"])
'''
[sinks.loki]
type = "loki"
inputs = ["transformed"]
endpoint = "http://[[ range service "loki" ]][[ .Address ]]:[[ .Port ]][[ end ]]"
encoding.codec = "json"
buffer.type = "memory"
out_of_order_action = "accept"
request.concurrency = "adaptive"
remove_label_fields = true
healthcheck.enabled = true
[sinks.loki.labels]
job = "{{label.\"com.hashicorp.nomad.job_name\" }}"
task = "{{label.\"com.hashicorp.nomad.task_name\" }}"
group = "{{label.\"com.hashicorp.nomad.task_group_name\" }}"
namespace = "{{label.\"com.hashicorp.nomad.namespace\" }}"
node = "{{label.\"com.hashicorp.nomad.node_name\" }}"
correlation_id = "{{ message.requestId }}"
stream = "{{ stream }}"
EOH
}
kill_timeout = "30s"
}
}
}