-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
190 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: goreleaser | ||
|
||
on: | ||
push: | ||
tags: | ||
- "*" | ||
|
||
jobs: | ||
goreleaser: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.17 | ||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v2 | ||
with: | ||
version: latest | ||
args: release --rm-dist | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GH_GORELEASER_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
env: | ||
- GO111MODULE=on | ||
- CGO_ENABLED=0 | ||
|
||
builds: | ||
- binary: nomad-vector-logger.bin | ||
id: nomad-vector-logger | ||
goos: | ||
- linux | ||
goarch: | ||
- amd64 | ||
ldflags: | ||
- -s -w -X "main.buildString={{ .Tag }} ({{ .ShortCommit }} {{ .Date }})" | ||
dir: . | ||
|
||
archives: | ||
- format: tar.gz | ||
files: | ||
- README.md | ||
- LICENSE | ||
- config.sample.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,110 @@ | ||
<a href="https://zerodha.tech"><img src="https://zerodha.tech/static/images/github-badge.svg" align="right" /></a> | ||
|
||
# nomad-vector-logger | ||
A daemon which continuously watches jobs running in a Nomad cluster and templates out a Vector configuration file which can be used to collect application logs enriched with Nomad metadata. | ||
|
||
A daemon which continuously watches jobs running in a [Nomad](https://www.nomadproject.io/) cluster and templates out a [Vector](https://vector.dev/) configuration file which can be used to collect application logs enriched with Nomad metadata. | ||
|
||
## Why | ||
|
||
### The Problem | ||
|
||
Currently, Nomad stores all application logs inside `$NOMAD_DATA_DIR/$NOMAD_ALLOC_DIR/logs/` directory. The limitation here is that these logs don't come with any metadata about the task/job/allocation. If you're running multiple applications on the same host, a log collecting agent cannot distinguish these logs. For `docker` driver, this is a solved problem by configuring the `log_driver` for the container. | ||
|
||
However for `raw_exec` and `exec` this still seems to be an issue until [10219](https://github.com/hashicorp/nomad/issues/10219) is addressed. | ||
|
||
### The Solution | ||
|
||
- Nomad provides an [Events stream](https://github.com/mr-karan/nomad-events-sink) which continuosly streams events from the Nomad cluster.`nomad-vector-logger` is a Go daemon which subscribes to the Events stream on topic `Allocation` and listens for allocation updates. | ||
- It then **templates** out a `vector` configuration to collect app logs from the allocation's log directory and enriches the configuration with metadata such as `NodeID`, `Namesapce`, `Task Name`, `JobName`, `AllocID` etc. | ||
- `vector` is started with a [`--watch-config`](https://vector.dev/docs/administration/management/#reloading) flag which automatically live-reloads `vector` whenever config changes. A config change can happen whenever an allocation is _created/stopped/restarted_. | ||
|
||
You can see a sample [config file](./examples/vector/nomad.toml) that is generated by this program. This can be used in addition with other vector config files to provide the config for rest of pipeline (additional transformations, sinks etc). | ||
|
||
#### Before | ||
|
||
Logs without any metdata on `/opt/nomad/data/alloc/$ALLOC_ID/alloc/logs`: | ||
|
||
``` | ||
==> proxy.stdout.0 <== | ||
192.168.29.76 - - [17/Jun/2022:11:01:42 +0000] "GET / HTTP/1.1" 200 27 "-" "curl/7.81.0" "-" | ||
``` | ||
|
||
#### After | ||
|
||
This is an example JSON log collected from `nginx` task running with `raw_exec` task driver on Nomad, collected using `vector`: | ||
|
||
```json | ||
{ | ||
"file": "/opt/nomad/data/alloc/2cbf80ff-ef2a-e634-33ec-e097a6061001/alloc/logs/proxy.stdout.0", | ||
"host": "pop-os", | ||
"message": "192.168.29.76 - - [17/Jun/2022:11:00:03 +0000] \"GET / HTTP/1.1\" 200 27 \"-\" \"curl/7.81.0\" \"-\"", | ||
"nomad_alloc_id": "2cbf80ff-ef2a-e634-33ec-e097a6061001", | ||
"nomad_group_name": "nginx", | ||
"nomad_job_name": "nginx", | ||
"nomad_namespace": "default", | ||
"nomad_node_name": "pop-os", | ||
"nomad_task_name": "proxy", | ||
"source_type": "file", | ||
"timestamp": "2022-06-17T11:00:03.922205021Z" | ||
} | ||
``` | ||
|
||
## Deploy | ||
|
||
- This is meant to run inside a Nomad cluster and should have proper ACL to listen to `Allocation:*` events. | ||
- This is meant to be run as a `system` job. Each allocation of this program is responsible to configure `vector` for the allocations running on the host. | ||
- Vector should be deployed externally, as a system job as well and should have access to the same directory that this program uses to generate the files. | ||
|
||
You can choose one of the various deployment options: | ||
|
||
### Binary | ||
|
||
Grab the latest release from [Releases](https://github.com/mr-karan/nomad-vector-logger/releases). | ||
|
||
To run: | ||
|
||
``` | ||
$ ./nomad-vector-logger.bin --config config.toml | ||
``` | ||
|
||
### Nomad | ||
|
||
TODO | ||
|
||
### Docker | ||
|
||
TODO | ||
|
||
## Configuration | ||
|
||
Refer to [config.sample.toml](./config.sample.toml) for a list of configurable values. | ||
|
||
### Environment Variables | ||
|
||
All config variables can also be populated as env vairables by prefixing `NOMAD_VECTOR_LOGGER_` and replacing `.` with `__`. | ||
|
||
For eg: `app.data_dir` becomes `NOMAD_VECTOR_LOGGER_app__data_dir`. | ||
|
||
Nomad API client reads the following environment variables: | ||
|
||
- `NOMAD_TOKEN` | ||
- `NOMAD_ADDR` | ||
- `NOMAD_REGION` | ||
- `NOMAD_NAMESPACE` | ||
- `NOMAD_HTTP_AUTH` | ||
- `NOMAD_CACERT` | ||
- `NOMAD_CAPATH` | ||
- `NOMAD_CLIENT_CERT` | ||
- `NOMAD_CLIENT_KEY` | ||
- `NOMAD_TLS_SERVER_NAME` | ||
- `NOMAD_SKIP_VERIFY` | ||
|
||
You can read about them in detail [here](https://www.nomadproject.io/docs/runtime/environment). | ||
|
||
## Contribution | ||
|
||
Please feel free to open a new issue for bugs, feedback etc. | ||
|
||
## LICENSE | ||
|
||
[LICENSE](./LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
[sources.source_nomad_alloc_2cbf80ff-ef2a-e634-33ec-e097a6061001_proxy] | ||
type = "file" | ||
include = [ "/opt/nomad/data/alloc/2cbf80ff-ef2a-e634-33ec-e097a6061001/alloc/logs/proxy*" ] | ||
line_delimiter = "\n" | ||
read_from = "beginning" | ||
|
||
[transforms.transform_nomad_alloc_2cbf80ff-ef2a-e634-33ec-e097a6061001_proxy] | ||
type = "remap" | ||
inputs = ["source_nomad_alloc_2cbf80ff-ef2a-e634-33ec-e097a6061001_proxy"] | ||
source = ''' | ||
# Store Nomad metadata. | ||
.nomad_namespace = "default" | ||
.nomad_node_name = "pop-os" | ||
.nomad_job_name = "nginx" | ||
.nomad_group_name = "nginx" | ||
.nomad_task_name = "proxy" | ||
.nomad_alloc_id = "2cbf80ff-ef2a-e634-33ec-e097a6061001" | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[sinks.stdout_nomad] | ||
type = "console" | ||
inputs = ["transform_nomad_alloc*"] | ||
target = "stdout" | ||
|
||
[sinks.stdout_nomad.encoding] | ||
codec = "json" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters