Skip to content

Commit

Permalink
add sampling helm chart
Browse files Browse the repository at this point in the history
Signed-off-by: Robbie Lankford <[email protected]>
  • Loading branch information
rlankfo committed Jan 31, 2024
1 parent e0df642 commit a944ceb
Show file tree
Hide file tree
Showing 21 changed files with 465 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/sampling/.helmignore
Original file line number Diff line number Diff line change
@@ -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/
9 changes: 9 additions & 0 deletions charts/sampling/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependencies:
- name: grafana-agent
repository: https://grafana.github.io/helm-charts
version: 0.30.0
- name: grafana-agent
repository: https://grafana.github.io/helm-charts
version: 0.30.0
digest: sha256:2c08fa0d15062cc1d32e70998835208314f0a15bef4f90cd82235c9f89163813
generated: "2024-01-05T15:38:15.160358-08:00"
16 changes: 16 additions & 0 deletions charts/sampling/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v2
name: sampling
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: "v0.38.1"

dependencies:
- name: grafana-agent
version: 0.30.0
repository: https://grafana.github.io/helm-charts
alias: grafana-agent-deployment
- name: grafana-agent
version: 0.30.0
repository: https://grafana.github.io/helm-charts
alias: grafana-agent-statefulset
5 changes: 5 additions & 0 deletions charts/sampling/templates/_agent_config_deployment.river.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{- define "agent.config.deployment" -}}
{{- include "deployment.receiver.otlp" . }}
{{- include "deployment.processor.batch" . }}
{{- include "deployment.exporter.loadbalancing" . }}
{{- end -}}
15 changes: 15 additions & 0 deletions charts/sampling/templates/_agent_config_statefulset.river.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{- define "agent.config.statefulset" -}}
{{- include "statefulset.receiver.otlp" . }}
{{- include "statefulset.connector.spanmetrics" . }}
{{- include "statefulset.processor.transform.use_grafana_metric_names" . }}
{{- include "statefulset.processor.filter" . }}
{{- include "statefulset.connector.servicegraph" . }}
{{- if .Values.sampling.enabled -}}
{{- include "statefulset.processor.tail_sampling" . }}
{{- end -}}
{{- include "statefulset.processor.batch" . }}
{{- include "statefulset.exporter.prometheus" . }}
{{- include "statefulset.prometheus.remote_write" . }}
{{- include "exporter.otlp" . }}
{{- include "auth.basic" . }}
{{- end -}}
9 changes: 9 additions & 0 deletions charts/sampling/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{/* use the release name as the serviceAccount name for deployment and statefulset agents */}}
{{- define "grafana-agent.serviceAccountName" -}}
{{- default .Release.Name }}
{{- end }}

{{/* Calculate name of image ID to use for "grafana-agent". */}}
{{- define "grafana-agent.imageId" -}}
{{- printf ":%s" .Chart.AppVersion }}
{{- end }}
8 changes: 8 additions & 0 deletions charts/sampling/templates/_otelcol_auth_basic.river.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{- define "auth.basic" -}}
otelcol.auth.basic "grafana_cloud_tempo" {
// https://grafana.com/docs/agent/latest/flow/reference/components/otelcol.auth.basic/
username = env("GRAFANA_CLOUD_TEMPO_USERNAME")
password = env("GRAFANA_CLOUD_API_KEY")
}

{{ end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{- define "statefulset.connector.servicegraph" -}}
otelcol.connector.servicegraph "default" {
// https://grafana.com/docs/agent/latest/flow/reference/components/otelcol.connector.servicegraph/
dimensions = [
{{- range $.Values.metricsGeneration.dimensions }}
{{ . | quote }},
{{- end }}
]
latency_histogram_buckets = ["0s", "0.005s", "0.01s", "0.025s", "0.05s", "0.075s", "0.1s", "0.25s", "0.5s", "0.75s", "1s", "2.5s", "5s", "7.5s", "10s"]

store {
ttl = "2s"
}

output {
metrics = [otelcol.processor.batch.default.input]
}
}

{{ end }}
26 changes: 26 additions & 0 deletions charts/sampling/templates/_otelcol_connector_spanmetrics.river.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{- define "statefulset.connector.spanmetrics" -}}
otelcol.connector.spanmetrics "default" {
// https://grafana.com/docs/agent/latest/flow/reference/components/otelcol.connector.spanmetrics/
{{- range $.Values.metricsGeneration.dimensions }}
dimension {
name = {{ . | quote }}
}
{{- end }}

namespace = "traces.spanmetrics"

histogram {
unit = "s"

explicit {
buckets = ["0s", "0.005s", "0.01s", "0.025s", "0.05s", "0.075s", "0.1s", "0.25s", "0.5s", "0.75s", "1s", "2.5s", "5s", "7.5s", "10s"]
}
}

output {
metrics = [otelcol.processor.transform.use_grafana_metric_names.input]
}
}


{{ end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- define "deployment.exporter.loadbalancing" -}}
otelcol.exporter.loadbalancing "default" {
// https://grafana.com/docs/agent/latest/flow/reference/components/otelcol.exporter.loadbalancing/
resolver {
dns {
hostname = "{{ .Release.Name }}-grafana-agent-statefulset.{{ .Release.Namespace }}.svc.cluster.local."
}
}

protocol {
otlp {
client {
tls {
insecure = true
}
}
}
}
}

{{ end }}
10 changes: 10 additions & 0 deletions charts/sampling/templates/_otelcol_exporter_otlp.river.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{- define "exporter.otlp" -}}
otelcol.exporter.otlp "grafana_cloud_tempo" {
// https://grafana.com/docs/agent/latest/flow/reference/components/otelcol.exporter.otlp/
client {
endpoint = env("GRAFANA_CLOUD_TEMPO_ENDPOINT")
auth = otelcol.auth.basic.grafana_cloud_tempo.handler
}
}

{{ end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{- define "statefulset.exporter.prometheus" -}}
otelcol.exporter.prometheus "grafana_cloud_prometheus" {
// https://grafana.com/docs/agent/latest/flow/reference/components/otelcol.exporter.prometheus/
add_metric_suffixes = false
forward_to = [prometheus.remote_write.grafana_cloud_prometheus.receiver]
}

{{ end }}
20 changes: 20 additions & 0 deletions charts/sampling/templates/_otelcol_processor_batch.river.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{- define "deployment.processor.batch" -}}
otelcol.processor.batch "default" {
// https://grafana.com/docs/agent/latest/flow/reference/components/otelcol.processor.batch/
output {
traces = [otelcol.exporter.loadbalancing.default.input]
}
}

{{ end }}

{{- define "statefulset.processor.batch" -}}
otelcol.processor.batch "default" {
// https://grafana.com/docs/agent/latest/flow/reference/components/otelcol.processor.batch/
output {
metrics = [otelcol.exporter.prometheus.grafana_cloud_prometheus.input]
traces = [otelcol.exporter.otlp.grafana_cloud_tempo.input]
}
}

{{ end }}
17 changes: 17 additions & 0 deletions charts/sampling/templates/_otelcol_processor_filter.river.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- define "statefulset.processor.filter" -}}
otelcol.processor.filter "drop_unneeded_span_metrics" {
// https://grafana.com/docs/agent/latest/flow/reference/components/otelcol.processor.filter/
error_mode = "ignore"

metrics {
datapoint = [
"IsMatch(metric.name, \"traces.spanmetrics.calls|traces.spanmetrics.duration\") and IsMatch(attributes[\"span.kind\"], \"SPAN_KIND_INTERNAL|SPAN_KIND_CLIENT|SPAN_KIND_PRODUCER\")",
]
}

output {
metrics = [otelcol.processor.batch.default.input]
}
}

{{ end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- define "statefulset.processor.tail_sampling" -}}
otelcol.processor.tail_sampling "default" {
// https://grafana.com/docs/agent/latest/flow/reference/components/otelcol.processor.tail_sampling/

{{ .Values.sampling.strategies | indent 2 }}

output {
traces = [otelcol.processor.batch.default.input]
}
}

{{ end }}
19 changes: 19 additions & 0 deletions charts/sampling/templates/_otelcol_processor_transform.river.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- define "statefulset.processor.transform.use_grafana_metric_names" -}}
otelcol.processor.transform "use_grafana_metric_names" {
// https://grafana.com/docs/agent/latest/flow/reference/components/otelcol.processor.transform/
error_mode = "ignore"

metric_statements {
context = "metric"
statements = [
"set(name, \"traces.spanmetrics.latency\") where name == \"traces.spanmetrics.duration\"",
"set(name, \"traces.spanmetrics.calls.total\") where name == \"traces.spanmetrics.calls\"",
]
}

output {
metrics = [otelcol.processor.filter.drop_unneeded_span_metrics.input]
}
}

{{ end }}
33 changes: 33 additions & 0 deletions charts/sampling/templates/_otelcol_receiver_otlp.river.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{{- define "deployment.receiver.otlp" -}}
otelcol.receiver.otlp "default" {
// https://grafana.com/docs/agent/latest/flow/reference/components/otelcol.receiver.otlp/

// configures the default grpc endpoint "0.0.0.0:4317"
grpc { }
// configures the default http/protobuf endpoint "0.0.0.0:4318"
http { }

output {
traces = [otelcol.processor.batch.default.input]
}
}

{{ end }}

{{- define "statefulset.receiver.otlp" -}}
otelcol.receiver.otlp "default" {
// https://grafana.com/docs/agent/latest/flow/reference/components/otelcol.receiver.otlp/

// configures the default grpc endpoint "0.0.0.0:4317"
grpc { }

output {
traces = [
{{ if .Values.sampling.enabled }}otelcol.processor.tail_sampling.default.input,{{ end }}
otelcol.connector.servicegraph.default.input,
otelcol.connector.spanmetrics.default.input,
]
}
}

{{ end }}
20 changes: 20 additions & 0 deletions charts/sampling/templates/_prometheus_remote_write.river.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{- define "statefulset.prometheus.remote_write" -}}
prometheus.remote_write "grafana_cloud_prometheus" {
// https://grafana.com/docs/agent/latest/flow/reference/components/prometheus.remote_write/
endpoint {
url = env("GRAFANA_CLOUD_PROMETHEUS_URL")

basic_auth {
username = env("GRAFANA_CLOUD_PROMETHEUS_USERNAME")
password = env("GRAFANA_CLOUD_API_KEY")
}
queue_config {
retry_on_http_429 = false
}
}
external_labels = {
"__metrics_gen_instance" = env("POD_UID"),
}
}

{{ end }}
8 changes: 8 additions & 0 deletions charts/sampling/templates/configmap_deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-grafana-agent-deployment
labels:
{{- include "grafana-agent.labels" . | nindent 4 }}
data:
config.river: |- {{- (include "agent.config.deployment" .) | nindent 4 }}
8 changes: 8 additions & 0 deletions charts/sampling/templates/configmap_statefulset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-grafana-agent-statefulset
labels:
{{- include "grafana-agent.labels" . | nindent 4 }}
data:
config.river: |- {{- (include "agent.config.statefulset" .) | nindent 4 }}
Loading

0 comments on commit a944ceb

Please sign in to comment.