-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example: kubernetes: add example daemonset
Signed-off-by: Dominik Rosiek <drosiek@sumologic.com>
- Loading branch information
Dominik Rosiek
committed
Mar 10, 2021
1 parent
90c9a13
commit 21c5fb8
Showing
2 changed files
with
160 additions
and
1 deletion.
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,153 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: otel-collector-config | ||
data: | ||
config.yaml: |- | ||
receivers: | ||
filelog: | ||
include: | ||
# - /var/log/pods/namespace_pod-name_pod-uid/container-name/*.log | ||
- /var/log/pods/*/*/*.log | ||
exclude: | ||
# - /var/log/pods/namespace_pod-name_pod-uid/container-name/*.log | ||
- /var/log/pods/*/otel-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: '$$record matches "^\\{"' | ||
- output: parser-crio | ||
expr: '$$record matches "^[^ Z]+ "' | ||
- output: parser-containerd | ||
expr: '$$record 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: extract_metadata_from_filepath | ||
timestamp: | ||
parse_from: 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: extract_metadata_from_filepath | ||
timestamp: | ||
parse_from: time | ||
layout: '%Y-%m-%dT%H:%M:%S.%LZ' | ||
# Parse Docker format | ||
- type: json_parser | ||
id: parser-docker | ||
output: extract_metadata_from_filepath | ||
timestamp: | ||
parse_from: time | ||
layout: '%Y-%m-%dT%H:%M:%S.%LZ' | ||
# Extract metadata from file path | ||
- type: regex_parser | ||
id: extract_metadata_from_filepath | ||
regex: '^.*\/(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[a-f0-9\-]{36})\/(?P<container_name>[^\._]+)\/(?P<run_id>\d+)\.log$' | ||
parse_from: $$attributes.file_path | ||
# Move out attributes to Attributes | ||
- type: metadata | ||
attributes: | ||
stream: 'EXPR($.stream)' | ||
k8s.container.name: 'EXPR($.container_name)' | ||
k8s.namespace.name: 'EXPR($.namespace)' | ||
k8s.pod.name: 'EXPR($.pod_name)' | ||
run_id: 'EXPR($.run_id)' | ||
k8s.pod.uid: 'EXPR($.uid)' | ||
# Clean up log record | ||
- type: restructure | ||
id: clean-up-log-record | ||
ops: | ||
- remove: logtag | ||
- remove: stream | ||
- remove: container_name | ||
- remove: namespace | ||
- remove: pod_name | ||
- remove: run_id | ||
- remove: uid | ||
exporters: | ||
logging: | ||
loglevel: debug | ||
service: | ||
pipelines: | ||
logs: | ||
receivers: [filelog] | ||
exporters: [logging] | ||
--- | ||
apiVersion: apps/v1 | ||
kind: DaemonSet | ||
metadata: | ||
name: otel-collector | ||
labels: | ||
app: opentelemetry | ||
component: otel-collector | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: opentelemetry | ||
component: otel-collector | ||
template: | ||
metadata: | ||
labels: | ||
app: opentelemetry | ||
component: otel-collector | ||
spec: | ||
containers: | ||
- name: otel-collector | ||
image: otel/opentelemetry-collector-contrib:0.22.0 | ||
resources: | ||
limits: | ||
cpu: 100m | ||
memory: 200Mi | ||
requests: | ||
cpu: 100m | ||
memory: 200Mi | ||
volumeMounts: | ||
- mountPath: /var/log | ||
name: varlog | ||
readOnly: true | ||
- mountPath: /var/lib/docker/containers | ||
name: varlibdockercontainers | ||
readOnly: true | ||
- mountPath: /etc/otel/config.yaml | ||
name: data | ||
subPath: config.yaml | ||
readOnly: true | ||
terminationGracePeriodSeconds: 30 | ||
volumes: | ||
- name: varlog | ||
hostPath: | ||
path: /var/log | ||
- name: varlibdockercontainers | ||
hostPath: | ||
path: /var/lib/docker/containers | ||
- name: data | ||
configMap: | ||
name: otel-collector-config | ||
|
||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: otel-collector | ||
labels: | ||
app: opentelemetry | ||
component: otel-collector | ||
spec: | ||
ports: | ||
- name: metrics # Default endpoint for querying metrics. | ||
port: 8888 | ||
selector: | ||
component: otel-collector |