diff --git a/main.tf b/main.tf index d1b1426..fa28830 100644 --- a/main.tf +++ b/main.tf @@ -1,5 +1,9 @@ locals { telemetry_ns = var.namespace + + otel_internal_hostname = format("otel-daemonset-collector.%v.svc.cluster.local", local.telemetry_ns) + otel_internal_port_number = 4318 + otel_internal_url = format("http://%v:%v/", local.otel_internal_hostname, local.otel_internal_port_number) } # Install opentelemetry-collector daemonset collector, handles collection of node and workload telemetry data @@ -66,30 +70,60 @@ resource "helm_release" "opentelemetry-operator" { timeout = 180 } -# SHOULD PROBABLY PUT THESE OBJECTS INTO A HELM CHART -# Create karpenter default -# resource "kubectl_manifest" "otelcol_daemonset" { -# depends_on = [ -# helm_release.opentelemetry-operator, -# ] -# yaml_body = templatefile("${path.module}/otelcol_daemonset.yaml.tpl", { - -# # cluster_name = var.cluster_name -# # tags = jsonencode(data.aws_default_tags.default_tags.tags) -# # amd_ami_family = "Bottlerocket" -# # amd_ami_alias = "bottlerocket" -# }) -# } +# Install the opentelemetry collectors and instrumentation +resource "helm_release" "otel-resources" { + depends_on = [ + helm_release.opentelemetry-operator, + ] -# resource "kubectl_manifest" "otelcol_simple" { -# depends_on = [ -# helm_release.opentelemetry-operator, -# ] -# yaml_body = templatefile("${path.module}/collector_simple.yaml", { + chart = "./otel" + name = "otel-resources" + namespace = local.telemetry_ns + version = local.module_version -# # cluster_name = var.cluster_name -# # tags = jsonencode(data.aws_default_tags.default_tags.tags) -# # amd_ami_family = "Bottlerocket" -# # amd_ami_alias = "bottlerocket" -# }) -# } \ No newline at end of file + set { + name = "collector.image" + value = format("%v/%v", + module.images.images[local.collector_key].dest_registry, + module.images.images[local.collector_key].dest_repository + ) + } + set { + name = "collector.tag" + value = module.images.images[local.collector_key].tag + } + set { + name = "collectorContrib.image" + value = format("%v/%v", + module.images.images[local.collector_contrib_key].dest_registry, + module.images.images[local.collector_contrib_key].dest_repository + ) + } + set { + name = "collectorContrib.tag" + value = module.images.images[local.collector_contrib_key].tag + } + set { + name = "loki.endpoint" + value = var.loki_endpoint + } + set { + name = "tempo.endpoint" + value = var.tempo_endpoint + } + set { + name = "otel.endpoint" + value = local.otel_internal_url + } + set { + name = "autoinstrumentation.java.image" + value = format("%v/%v", + module.images.images[local.auto_instrumentation_java_key].dest_registry, + module.images.images[local.auto_instrumentation_java_key].dest_repository + ) + } + set { + name = "autoinstrumentation.java.tag" + value = module.images.images[local.auto_instrumentation_java_key].tag + } +} \ No newline at end of file diff --git a/otel/.helmignore b/otel/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/otel/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/otel/Chart.yaml b/otel/Chart.yaml new file mode 100644 index 0000000..43363a9 --- /dev/null +++ b/otel/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: otel +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/otel/templates/NOTES.txt b/otel/templates/NOTES.txt new file mode 100644 index 0000000..f92400e --- /dev/null +++ b/otel/templates/NOTES.txt @@ -0,0 +1 @@ +Open Telemetry Collectors and Instrumentation has been installed. diff --git a/otel/templates/_helpers.tpl b/otel/templates/_helpers.tpl new file mode 100644 index 0000000..4f72626 --- /dev/null +++ b/otel/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "otel.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "otel.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "otel.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "otel.labels" -}} +helm.sh/chart: {{ include "otel.chart" . }} +{{ include "otel.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "otel.selectorLabels" -}} +app.kubernetes.io/name: {{ include "otel.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "otel.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "otel.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/java_instrumentation.yaml b/otel/templates/java_instrumentation.yaml similarity index 53% rename from java_instrumentation.yaml rename to otel/templates/java_instrumentation.yaml index 1ac1403..ec67844 100644 --- a/java_instrumentation.yaml +++ b/otel/templates/java_instrumentation.yaml @@ -2,10 +2,9 @@ apiVersion: opentelemetry.io/v1alpha1 kind: Instrumentation metadata: name: java-instrumentation - namespace: telemetry spec: exporter: - endpoint: http://otel-daemonset-collector.telemetry.svc.cluster.local:4318 + endpoint: {{ .Values.otel.endpoint }} propagators: - tracecontext - baggage @@ -13,4 +12,4 @@ spec: type: parentbased_traceidratio argument: "1" java: - image: 224384469011.dkr.ecr.us-gov-east-1.amazonaws.com/platform-test-z/autoinstrumentation-java:2.9.0 + image: "{{ .Values.autoinstrumentation.java.image }}:{{ .Values.autoinstrumentation.java.tag | default .Chart.AppVersion }}" \ No newline at end of file diff --git a/otelcol_daemonset.yaml b/otel/templates/otelcol_daemonset.yaml similarity index 95% rename from otelcol_daemonset.yaml rename to otel/templates/otelcol_daemonset.yaml index a7d434d..3eeae79 100644 --- a/otelcol_daemonset.yaml +++ b/otel/templates/otelcol_daemonset.yaml @@ -3,7 +3,6 @@ apiVersion: opentelemetry.io/v1beta1 kind: OpenTelemetryCollector metadata: name: otel-daemonset - namespace: telemetry spec: mode: daemonset config: @@ -155,9 +154,9 @@ spec: exporters: debug: {} otlphttp: - endpoint: http://loki-gateway.loki.svc.cluster.local:80/otlp + endpoint: "{{ .Values.loki.endpoint }}/otlp" otlp: - endpoint: http://tempo.tempo.svc.cluster.local:4317 + endpoint: {{ .Values.tempo.endpoint }} tls: insecure: true # prometheusremotewrite: @@ -189,8 +188,7 @@ spec: # receivers: [otlp, kubeletstats, spanmetrics] # processors: [memory_limiter, k8sattributes, batch] # exporters: [debug, prometheusremotewrite] - # image: 224384469011.dkr.ecr.us-gov-east-1.amazonaws.com/platform-test-z/opentelemetry-collector-k8s:0.111.0-amd64 - image: 224384469011.dkr.ecr.us-gov-east-1.amazonaws.com/platform-test-z/opentelemetry-collector-contrib:0.113.0-amd64 + image: "{{ .Values.collectorContrib.image }}:{{ .Values.collectorContrib.tag | default .Chart.AppVersion }}" serviceAccount: otel-daemon env: - name: K8S_NODE_NAME @@ -218,7 +216,6 @@ apiVersion: v1 kind: ServiceAccount metadata: name: otel-daemon - namespace: telemetry --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole @@ -267,4 +264,4 @@ roleRef: subjects: - kind: ServiceAccount name: otel-daemon - namespace: telemetry \ No newline at end of file + namespace: {{ .Release.Namespace }} \ No newline at end of file diff --git a/otelcol_deployment.yaml b/otel/templates/otelcol_deployment.yaml similarity index 79% rename from otelcol_deployment.yaml rename to otel/templates/otelcol_deployment.yaml index ddc8230..1511efd 100644 --- a/otelcol_deployment.yaml +++ b/otel/templates/otelcol_deployment.yaml @@ -2,8 +2,7 @@ apiVersion: opentelemetry.io/v1beta1 kind: OpenTelemetryCollector metadata: - name: otel-deploy - namespace: telemetry + name: otel-deployment spec: mode: deployment config: @@ -22,7 +21,7 @@ spec: exporters: debug: {} otlphttp: - endpoint: http://loki-gateway.loki.svc.cluster.local:80/otlp + endpoint: "{{ .Values.loki.endpoint }}/otlp" service: pipelines: metrics: @@ -31,23 +30,22 @@ spec: logs/entity_events: receivers: [k8s_cluster, k8sobjects] exporters: [debug, otlphttp] - image: 224384469011.dkr.ecr.us-gov-east-1.amazonaws.com/platform-test-z/opentelemetry-collector-k8s:0.111.0-amd64 - serviceAccount: otel-deploy + image: "{{ .Values.collector.image }}:{{ .Values.collector.tag | default .Chart.AppVersion }}" + serviceAccount: otel-deployment --- apiVersion: v1 kind: ServiceAccount metadata: labels: - app: otel-deploy - name: otel-deploy - namespace: telemetry + app: otel-deployment + name: otel-deployment --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: - name: otel-deploy + name: otel-deployment labels: - app: otel-deploy + app: otel-deployment rules: - apiGroups: - "" @@ -116,14 +114,14 @@ rules: apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: - name: otel-deploy + name: otel-deployment labels: - app: otel-deploy + app: otel-deployment roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole - name: otel-deploy + name: otel-deployment subjects: - kind: ServiceAccount - name: otel-deploy - namespace: telemetry \ No newline at end of file + name: otel-deployment + namespace: {{ .Release.Namespace }} \ No newline at end of file diff --git a/otel/values.yaml b/otel/values.yaml new file mode 100644 index 0000000..5254581 --- /dev/null +++ b/otel/values.yaml @@ -0,0 +1,25 @@ +# Default values for otel. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +collector: + image: "" + tag: "" + +collectorContrib: + image: "" + tag: "" + +loki: + endpoint: "" + +tempo: + endpoint: "" + +otel: + endpoint: "" + +autoinstrumentation: + java: + image: "" + tag: "" \ No newline at end of file diff --git a/variables.tf b/variables.tf index 634821d..9225b59 100644 --- a/variables.tf +++ b/variables.tf @@ -33,6 +33,16 @@ variable "otel_helm_version" { default = "0.71.2" } +variable "loki_endpoint" { + description = "The internal endpoint for the loki service" + type = string +} + +variable "tempo_endpoint" { + description = "Internal otlp endpoint of tempo" + type = string +} + # tflint-ignore: terraform_unused_declarations variable "tags" { description = "AWS Tags to apply to appropriate resources"