-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NH-9834: Adding collection of container logs
- Loading branch information
Showing
6 changed files
with
283 additions
and
2 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
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,169 @@ | ||
exporters: | ||
otlp: | ||
endpoint: ${OTEL_ENVOY_ADDRESS} | ||
tls: | ||
insecure: ${OTEL_ENVOY_ADDRESS_TLS_INSECURE} | ||
headers: | ||
"Authorization": "Bearer ${SOLARWINDS_API_TOKEN}" | ||
extensions: | ||
health_check: {} | ||
|
||
processors: | ||
groupbyattrs/all: | ||
keys: | ||
- k8s.container.name | ||
- k8s.namespace.name | ||
- k8s.pod.name | ||
- k8s.pod.uid | ||
|
||
resource: | ||
attributes: | ||
|
||
# Collector and Manifest version | ||
- key: sw.k8s.agent.manifest.version | ||
value: "1.0" | ||
action: insert | ||
|
||
# Cluster | ||
- key: sw.k8s.cluster.uid | ||
value: ${CLUSTER_UID} | ||
action: insert | ||
|
||
- key: k8s.cluster.name | ||
value: ${CLUSTER_NAME} | ||
action: insert | ||
|
||
# Node | ||
- key: k8s.node.name | ||
value: ${NODE_NAME} | ||
action: insert | ||
|
||
batch: | ||
send_batch_size: 8192 | ||
send_batch_max_size: 8192 | ||
timeout: 1s | ||
receivers: | ||
filelog: | ||
include: [ /var/log/pods/*/*/*.log ] | ||
# Exclude collector container's logs. The file format is /var/log/pods/<namespace_name>_<pod_name>_<pod_uid>/<container_name>/<run_id>.log | ||
exclude: [ "/var/log/pods/${POD_NAMESPACE}_${POD_NAME}*_*/swi-opentelemetry-collector/*.log" ] | ||
start_at: beginning | ||
include_file_path: true | ||
include_file_name: false | ||
operators: | ||
# Find out which format is used by kubernetes | ||
- type: router | ||
id: get-format | ||
routes: | ||
- output: parser-docker | ||
expr: 'body matches "^\\{"' | ||
- output: parser-crio | ||
expr: 'body matches "^[^ Z]+ "' | ||
- output: parser-containerd | ||
expr: 'body matches "^[^ Z]+Z"' | ||
# Parse CRI-O format | ||
- type: regex_parser | ||
id: parser-crio | ||
regex: '^(?P<time>[^ Z]+) (?P<stream>stdout|stderr) (?P<logtag>[^ ]*)( |)(?P<log>.*)$' | ||
output: merge-cri-lines | ||
parse_to: body | ||
timestamp: | ||
parse_from: body.time | ||
layout_type: gotime | ||
layout: '2006-01-02T15:04:05.000000000-07:00' | ||
# Parse CRI-Containerd format | ||
- type: regex_parser | ||
id: parser-containerd | ||
regex: '^(?P<time>[^ ^Z]+Z) (?P<stream>stdout|stderr) (?P<logtag>[^ ]*)( |)(?P<log>.*)$' | ||
output: merge-cri-lines | ||
parse_to: body | ||
timestamp: | ||
parse_from: body.time | ||
layout: '%Y-%m-%dT%H:%M:%S.%LZ' | ||
# Parse Docker format | ||
- type: json_parser | ||
id: parser-docker | ||
parse_to: body | ||
output: merge-docker-lines | ||
timestamp: | ||
parse_from: body.time | ||
layout: '%Y-%m-%dT%H:%M:%S.%LZ' | ||
|
||
# Merge log lines split by Docker logging driver. | ||
- type: recombine | ||
id: merge-docker-lines | ||
source_identifier: attributes["log.file.path"] | ||
output: merge-multiline-logs | ||
combine_field: body.log | ||
combine_with: "" | ||
is_last_entry: body.log matches "\n$" | ||
|
||
# Merge log lines split by CRI logging drivers. | ||
- type: recombine | ||
id: merge-cri-lines | ||
source_identifier: attributes["log.file.path"] | ||
output: merge-multiline-logs | ||
combine_field: body.log | ||
combine_with: "" | ||
is_last_entry: body.logtag == "F" | ||
overwrite_with: newest | ||
|
||
# Merges incoming log records into multiline logs. | ||
- type: recombine | ||
id: merge-multiline-logs | ||
output: extract-metadata-from-filepath | ||
source_identifier: attributes["log.file.path"] | ||
combine_field: body.log | ||
combine_with: "" | ||
is_first_entry: body.log matches "^\\[?\\d{4}-\\d{1,2}-\\d{1,2}.\\d{2}:\\d{2}:\\d{2}.*" | ||
|
||
# Extract metadata from file path | ||
- type: regex_parser | ||
id: extract-metadata-from-filepath | ||
regex: '^.*\/(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[a-f0-9\-]+)\/(?P<container_name>[^\._]+)\/(?P<run_id>\d+)\.log$' | ||
parse_from: attributes["log.file.path"] | ||
|
||
# Rename attributes | ||
- type: move | ||
id: move-attributes | ||
from: body.stream | ||
to: attributes["stream"] | ||
- type: move | ||
from: attributes.container_name | ||
to: attributes["k8s.container.name"] | ||
- type: move | ||
from: attributes.namespace | ||
to: attributes["k8s.namespace.name"] | ||
- type: move | ||
from: attributes.pod_name | ||
to: attributes["k8s.pod.name"] | ||
- type: move | ||
from: attributes.run_id | ||
to: attributes["run_id"] | ||
- type: move | ||
from: attributes.uid | ||
to: attributes["k8s.pod.uid"] | ||
- type: remove | ||
field: attributes["log.file.path"] | ||
- type: move | ||
from: body.log | ||
to: body | ||
|
||
service: | ||
extensions: | ||
- health_check | ||
pipelines: | ||
logs: | ||
exporters: | ||
- otlp | ||
processors: | ||
- groupbyattrs/all | ||
- resource | ||
- batch | ||
receivers: | ||
- filelog | ||
telemetry: | ||
logs: | ||
level: "info" | ||
metrics: | ||
address: 0.0.0.0:8888 |
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
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,22 @@ | ||
apiVersion: apps/v1 | ||
kind: DaemonSet | ||
metadata: | ||
name: swi-opentelemetry-collector-logs | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: swi-opentelemetry-collector | ||
image: nighthawk-swi-opentelemetry-collector | ||
imagePullPolicy: Never | ||
env: | ||
- name: SOLARWINDS_API_TOKEN | ||
$patch: delete | ||
- name: OTEL_ENVOY_ADDRESS | ||
value: "timeseries-mock-service:9082" | ||
- name: OTEL_ENVOY_ADDRESS_TLS_INSECURE | ||
value: "true" | ||
- name: CLUSTER_NAME | ||
value: "cluster name" | ||
- name: CLUSTER_UID | ||
value: "cluster-uid-123456789" |