forked from mr-karan/nomad-vector-logger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeployment.nomad
145 lines (125 loc) · 3.48 KB
/
deployment.nomad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
job "vector" {
datacenters = ["dc1"]
namespace = "default"
type = "system"
group "vector" {
count = 1
restart {
attempts = 3
interval = "10m"
delay = "30s"
mode = "fail"
}
# For vector's data directory.
ephemeral_disk {
size = 500
sticky = true
}
network {
port "metrics" {
to = 8686
static = 8686
}
mode = "host"
}
service {
provider = "nomad"
name = "vector-agent-monitoring"
port = "metrics"
}
task "vector" {
# Need access to the underlying `/opt/nomad/data/alloc` directory to get the logs.
driver = "raw_exec"
# Run the program.
config {
# Path to vector on your host machine.
command = "/usr/local/bin/vector"
args = [
"--watch-config",
"--config",
"$${NOMAD_TASK_DIR}/base.toml",
"--config-dir=$${NOMAD_ALLOC_DIR}/vector_gen_configs/"
]
}
resources {
cpu = 500
memory = 500
}
# Template with Vector's configuration
template {
data = file(abspath("./dev/base.toml.tpl"))
destination = "local/base.toml"
change_mode = "restart"
# overriding the delimiters to [[ ]] to avoid conflicts with Vector's native templating, which also uses {{ }}
left_delimiter = "[["
right_delimiter = "]]"
}
# Some delay in killing the task in case Vector is still sending data to upstream sinks,
kill_timeout = "60s"
}
task "nomad-vector-logger" {
# Need access to Nomad API running.
driver = "raw_exec"
# Should run first so that it can generate a config for vector.
lifecycle {
hook = "prestart"
sidecar = true
}
meta {
nomad_addr = "${nomad.advertise.address}"
}
# Run the program.
config {
command = "/usr/local/bin/nomad-vector-logger.bin"
args = [
"--config",
"$${NOMAD_TASK_DIR}/nomad-vector-logger.toml"
]
}
resources {
cpu = 500
memory = 500
}
# Template with Vector's configuration
template {
data = file(abspath("./dev/nomad-vector-logger.toml.tpl"))
destination = "local/nomad-vector-logger.toml"
change_mode = "restart"
}
template {
data = <<EOH
NOMAD_ADDR="http://{{env "NOMAD_IP_metrics"}}:4646"
EOH
destination = "secrets/file.env"
env = true
}
template {
data = file(abspath("./dev/static/sink.toml.tpl"))
destination = "local/static/sink.toml"
change_mode = "restart"
# overriding the delimiters to [[ ]] to avoid conflicts with Vector's native templating, which also uses {{ }}
left_delimiter = "[["
right_delimiter = "]]"
}
}
task "await-config-generation" {
driver = "raw_exec"
# This waits till the config files are generated by nomad-vector-logger before starting vector.
config {
command = "/usr/bin/bash"
args = [
"-c",
"echo -n 'Waiting for files to be generated'; until ls -laht ${NOMAD_ALLOC_DIR}/vector_gen_configs/nomad.toml 2>&1 >/dev/null; do echo '.'; sleep 2; done"
]
}
resources {
cpu = 200
memory = 128
}
lifecycle {
hook = "prestart"
sidecar = false
}
}
}
}