From 4f5035627ebe1b18ec94026a0d87e96c64acf936 Mon Sep 17 00:00:00 2001 From: Thomas Stringer Date: Wed, 20 Mar 2024 21:31:35 -0400 Subject: [PATCH] Add elasticsearch --- Makefile | 21 ++- collector/manifest.yaml | 15 +- .../templates/opentelemetry-collector.yaml | 132 +++++++++++++++++- scripts/elasticsearch_install.sh | 32 +++++ version | 2 +- 5 files changed, 191 insertions(+), 11 deletions(-) create mode 100755 scripts/elasticsearch_install.sh diff --git a/Makefile b/Makefile index 065f59b..cf6c12d 100644 --- a/Makefile +++ b/Makefile @@ -47,10 +47,10 @@ install-tools-and-app: install-tools install-app install-tools-and-app-local: install-tools-local install-app-local .PHONY: install-tools-local -install-tools-local: create-namespace-observability install-cert-manager install-jaeger install-tempo install-kube-prometheus-stack install-opentelemetry-operator install-opentelemetry-collector-local +install-tools-local: create-namespace-observability install-cert-manager install-jaeger install-tempo install-kube-prometheus-stack install-elasticsearch install-opentelemetry-operator install-opentelemetry-collector-local .PHONY: install-tools -install-tools: create-namespace-observability install-cert-manager install-jaeger install-tempo install-kube-prometheus-stack install-opentelemetry-operator install-opentelemetry-collector +install-tools: create-namespace-observability install-cert-manager install-jaeger install-tempo install-kube-prometheus-stack install-elasticsearch install-opentelemetry-operator install-opentelemetry-collector .PHONY: create-namespace-observability create-namespace-observability: @@ -78,7 +78,10 @@ install-opentelemetry-operator: .PHONY: install-opentelemetry-collector-local install-opentelemetry-collector-local: - helm upgrade --install -n observability otel ./collector/opentelemetry + helm upgrade --install \ + -n observability \ + --set es.password=$(shell kubectl get secret -n observability elasticsearch-es-elastic-user -o jsonpath='{.data.elastic}' | base64 -d) \ + otel ./collector/opentelemetry .PHONY: install-opentelemetry-collector install-opentelemetry-collector: @@ -86,9 +89,14 @@ install-opentelemetry-collector: -n observability \ --install \ --set collector.image.repository=ghcr.io/trstringer/otel-shopping-cart-collector \ + --set es.password=$(shell kubectl get secret -n observability elasticsearch-es-elastic-user -o jsonpath='{.data.elastic}' | base64 -d) \ otel \ ./collector/opentelemetry +.PHONY: install-elasticsearch +install-elasticsearch: + ./scripts/elasticsearch_install.sh + .PHONY: create-namespace-app create-namespace-app: if ! kubectl get ns app; then kubectl create ns app; fi @@ -148,6 +156,13 @@ port-forward-grafana: port-forward-prometheus: kubectl port-forward -n observability svc/prometheus-kube-prometheus-prometheus 9090 +.PHONY: port-forward-kibana +port-forward-kibana: + @echo "Kibana elastic user password:" + @kubectl get secret -n observability elasticsearch-es-elastic-user -o jsonpath='{.data.elastic}' | base64 -d + @echo + kubectl port-forward -n observability svc/kibana-kb-http 5601 + .PHONY: e2e e2e: ./scripts/e2e.sh diff --git a/collector/manifest.yaml b/collector/manifest.yaml index a04f73a..a82d094 100644 --- a/collector/manifest.yaml +++ b/collector/manifest.yaml @@ -11,13 +11,16 @@ exporters: gomod: go.opentelemetry.io/collector v0.94.1 - import: go.opentelemetry.io/collector/exporter/otlpexporter gomod: go.opentelemetry.io/collector v0.94.1 - - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter v0.94.0 - -processors: - - import: go.opentelemetry.io/collector/processor/batchprocessor - gomod: go.opentelemetry.io/collector v0.94.1 + - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter v0.96.0 + - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/elasticsearchexporter v0.96.0 receivers: - import: go.opentelemetry.io/collector/receiver/otlpreceiver gomod: go.opentelemetry.io/collector v0.94.1 - - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver v0.94.0 + - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver v0.96.0 + - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filelogreceiver v0.96.0 + +processors: + - import: go.opentelemetry.io/collector/processor/batchprocessor + gomod: go.opentelemetry.io/collector v0.94.1 + - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor v0.96.0 diff --git a/collector/opentelemetry/templates/opentelemetry-collector.yaml b/collector/opentelemetry/templates/opentelemetry-collector.yaml index cac7377..f070465 100644 --- a/collector/opentelemetry/templates/opentelemetry-collector.yaml +++ b/collector/opentelemetry/templates/opentelemetry-collector.yaml @@ -4,12 +4,27 @@ metadata: name: otel-collector spec: image: "{{ .Values.collector.image.repository }}:{{ .Values.collector.image.tag }}" - mode: statefulset + mode: daemonset serviceAccount: otelcol ports: - name: prom port: 9090 + volumes: + - name: varlog + hostPath: + path: /var/log + - name: es + secret: + secretName: elasticsearch-es-default-es-transport-certs + volumeMounts: + - name: varlog + mountPath: /var/log + readOnly: true + - name: es + mountPath: /var/es + readOnly: true targetAllocator: + allocationStrategy: "per-node" enabled: true serviceAccount: otelcol prometheusCR: @@ -33,9 +48,111 @@ spec: endpoint: http://otel-collector-targetallocator interval: 30s collector_id: "${POD_NAME}" + # Pulled directly from https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/80ebb76abe215144c0c3314c19e1a767629433cd/examples/kubernetes/otel-collector.yaml + filelog: + include: + - /var/log/pods/*/*/*.log + start_at: end + 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