Skip to content

Commit

Permalink
[simple-app] Add management of common Datadog Agent labels, annotatio…
Browse files Browse the repository at this point in the history
…ns and environment variables (#30)

**What did I want?**

To provide a standard and easy mechanism for configuring our Pods to work with the Datadog Agent and pass the appropriate metrics back to Datadog.

**What did I do?**

I've added in customizations for setting common environment variables, annotations and labels. Depending on whether or not we're running the Istio mesh or not, the behavior is slightly different.

**Proof**

## Scenario 1: `istio.enabled=false`, `datadog.enabled=true`, `datadog.scrapeMetrics=true`
```diff
install.go:173: [debug] Original chart version: ""
install.go:190: [debug] CHART PATH: /Users/diranged/git/nextdoor/k8s-charts/charts/simple-app

--- orig	2021-06-22 08:19:44.000000000 -0700
+++ new	2021-06-22 09:43:38.000000000 -0700
@@ -8,11 +8,22 @@
 metadata:
   name: simple-app-ingress-access
   labels:
-    helm.sh/chart: simple-app-0.10.0
+    helm.sh/chart: simple-app-0.11.0
     app.kubernetes.io/version: "latest"
     app.kubernetes.io/managed-by: Helm
     app.kubernetes.io/name: simple-app
     app.kubernetes.io/instance: simple-app
+    # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes
+    tags.datadoghq.com/env: "dev"
+    tags.datadoghq.com/service: "simple-app"
+    tags.datadoghq.com/version: "latest"
+    #
+    # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/
+    # (Disabled for now, here for future reference. Disabled because we can get
+    # the same value through the Kubernetes downward API, which doesn't introduce
+    # a potential Pod launching failure point.)
+    # admission.datadoghq.com/enabled: "true"
+    #
 spec:
   policyTypes: [Ingress]
   podSelector:
@@ -32,11 +43,22 @@
 metadata:
   name: simple-app
   labels:
-    helm.sh/chart: simple-app-0.10.0
+    helm.sh/chart: simple-app-0.11.0
     app.kubernetes.io/version: "latest"
     app.kubernetes.io/managed-by: Helm
     app.kubernetes.io/name: simple-app
     app.kubernetes.io/instance: simple-app
+    # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes
+    tags.datadoghq.com/env: "dev"
+    tags.datadoghq.com/service: "simple-app"
+    tags.datadoghq.com/version: "latest"
+    #
+    # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/
+    # (Disabled for now, here for future reference. Disabled because we can get
+    # the same value through the Kubernetes downward API, which doesn't introduce
+    # a potential Pod launching failure point.)
+    # admission.datadoghq.com/enabled: "true"
+    #
 ---
 # Source: simple-app/templates/service.yaml
 apiVersion: v1
@@ -44,11 +66,22 @@
 metadata:
   name: simple-app
   labels:
-    helm.sh/chart: simple-app-0.10.0
+    helm.sh/chart: simple-app-0.11.0
     app.kubernetes.io/version: "latest"
     app.kubernetes.io/managed-by: Helm
     app.kubernetes.io/name: simple-app
     app.kubernetes.io/instance: simple-app
+    # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes
+    tags.datadoghq.com/env: "dev"
+    tags.datadoghq.com/service: "simple-app"
+    tags.datadoghq.com/version: "latest"
+    #
+    # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/
+    # (Disabled for now, here for future reference. Disabled because we can get
+    # the same value through the Kubernetes downward API, which doesn't introduce
+    # a potential Pod launching failure point.)
+    # admission.datadoghq.com/enabled: "true"
+    #
 spec:
   type: ClusterIP
   ports:
@@ -70,11 +103,22 @@
 metadata:
   name: simple-app
   labels:
-    helm.sh/chart: simple-app-0.10.0
+    helm.sh/chart: simple-app-0.11.0
     app.kubernetes.io/version: "latest"
     app.kubernetes.io/managed-by: Helm
     app.kubernetes.io/name: simple-app
     app.kubernetes.io/instance: simple-app
+    # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes
+    tags.datadoghq.com/env: "dev"
+    tags.datadoghq.com/service: "simple-app"
+    tags.datadoghq.com/version: "latest"
+    #
+    # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/
+    # (Disabled for now, here for future reference. Disabled because we can get
+    # the same value through the Kubernetes downward API, which doesn't introduce
+    # a potential Pod launching failure point.)
+    # admission.datadoghq.com/enabled: "true"
+    #
 spec:
   replicas: 1
   selector:
@@ -84,12 +128,32 @@
   template:
     metadata:
       annotations:
-      labels:
-        helm.sh/chart: simple-app-0.10.0
+        ad.datadoghq.com/simple-app.check_names: ['prometheus']
+        ad.datadoghq.com/simple-app.init_configs: '[{}]'
+        ad.datadoghq.com/simple-app.instances: |-
+          [
+            {
+              "prometheus_url": "http://%%host%%:9090/metrics",
+              "namespace": "eks"
+            }
+          ]
+      labels:
+        helm.sh/chart: simple-app-0.11.0
         app.kubernetes.io/version: "latest"
         app.kubernetes.io/managed-by: Helm
         app.kubernetes.io/name: simple-app
         app.kubernetes.io/instance: simple-app
+        # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes
+        tags.datadoghq.com/env: "dev"
+        tags.datadoghq.com/service: "simple-app"
+        tags.datadoghq.com/version: "latest"
+        #
+        # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/
+        # (Disabled for now, here for future reference. Disabled because we can get
+        # the same value through the Kubernetes downward API, which doesn't introduce
+        # a potential Pod launching failure point.)
+        # admission.datadoghq.com/enabled: "true"
+        #
     spec:
       serviceAccountName: simple-app
       securityContext:
@@ -100,6 +164,30 @@
             {}
           image: nginx:latest
           imagePullPolicy: IfNotPresent
+          env:
+            # https://www.datadoghq.com/blog/monitor-kubernetes-docker/#instrument-your-code-to-send-metrics-to-dogstatsd
+            - name: DOGSTATSD_HOST_IP
+              valueFrom:
+                fieldRef:
+                  fieldPath: status.hostIP
+            # https://docs.datadoghq.com/agent/docker/apm/?tab=standard#docker-apm-agent-environment-variables
+            - name: DD_AGENT_HOST
+              valueFrom:
+                fieldRef:
+                  fieldPath: status.hostIP
+            # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes#full-configuration
+            - name: DD_ENV
+              valueFrom:
+                fieldRef:
+                  fieldPath: metadata.labels['tags.datadoghq.com/env']
+            - name: DD_SERVICE
+              valueFrom:
+                fieldRef:
+                  fieldPath: metadata.labels['tags.datadoghq.com/service']
+            - name: DD_VERSION
+              valueFrom:
+                fieldRef:
+                  fieldPath: metadata.labels['tags.datadoghq.com/version']
           resources:
             {}
           ports:
@@ -127,11 +215,22 @@
 metadata:
   name: simple-app
   labels:
-    helm.sh/chart: simple-app-0.10.0
+    helm.sh/chart: simple-app-0.11.0
     app.kubernetes.io/version: "latest"
     app.kubernetes.io/managed-by: Helm
     app.kubernetes.io/name: simple-app
     app.kubernetes.io/instance: simple-app
+    # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes
+    tags.datadoghq.com/env: "dev"
+    tags.datadoghq.com/service: "simple-app"
+    tags.datadoghq.com/version: "latest"
+    #
+    # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/
+    # (Disabled for now, here for future reference. Disabled because we can get
+    # the same value through the Kubernetes downward API, which doesn't introduce
+    # a potential Pod launching failure point.)
+    # admission.datadoghq.com/enabled: "true"
+    #
   annotations:
 spec:
   rules:
@@ -337,11 +436,22 @@
 metadata:
   name: simple-app
   labels:
-    helm.sh/chart: simple-app-0.10.0
+    helm.sh/chart: simple-app-0.11.0
     app.kubernetes.io/version: "latest"
     app.kubernetes.io/managed-by: Helm
     app.kubernetes.io/name: simple-app
     app.kubernetes.io/instance: simple-app
+    # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes
+    tags.datadoghq.com/env: "dev"
+    tags.datadoghq.com/service: "simple-app"
+    tags.datadoghq.com/version: "latest"
+    #
+    # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/
+    # (Disabled for now, here for future reference. Disabled because we can get
+    # the same value through the Kubernetes downward API, which doesn't introduce
+    # a potential Pod launching failure point.)
+    # admission.datadoghq.com/enabled: "true"
+    #
 spec:
   selector:
     matchLabels:
@@ -386,11 +496,22 @@
 metadata:
   name: "simple-app-test-connection"
   labels:
-    helm.sh/chart: simple-app-0.10.0
+    helm.sh/chart: simple-app-0.11.0
     app.kubernetes.io/version: "latest"
     app.kubernetes.io/managed-by: Helm
     app.kubernetes.io/name: simple-app
     app.kubernetes.io/instance: simple-app
+    # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes
+    tags.datadoghq.com/env: "dev"
+    tags.datadoghq.com/service: "simple-app"
+    tags.datadoghq.com/version: "latest"
+    #
+    # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/
+    # (Disabled for now, here for future reference. Disabled because we can get
+    # the same value through the Kubernetes downward API, which doesn't introduce
+    # a potential Pod launching failure point.)
+    # admission.datadoghq.com/enabled: "true"
+    #
   annotations:
     "helm.sh/hook": test
 spec:
```

## Scenario 2: `istio.enabled=true`, `datadog.enabled=true,` `datadog.scrapeMetrics=true`
```diff
install.go:173: [debug] Original chart version: ""
install.go:190: [debug] CHART PATH: /Users/diranged/git/nextdoor/k8s-charts/charts/simple-app

--- orig	2021-06-22 08:19:44.000000000 -0700
+++ new	2021-06-22 09:44:42.000000000 -0700
@@ -8,11 +8,22 @@
 metadata:
   name: simple-app-ingress-access
   labels:
-    helm.sh/chart: simple-app-0.10.0
+    helm.sh/chart: simple-app-0.11.0
     app.kubernetes.io/version: "latest"
     app.kubernetes.io/managed-by: Helm
     app.kubernetes.io/name: simple-app
     app.kubernetes.io/instance: simple-app
+    # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes
+    tags.datadoghq.com/env: "dev"
+    tags.datadoghq.com/service: "simple-app"
+    tags.datadoghq.com/version: "latest"
+    #
+    # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/
+    # (Disabled for now, here for future reference. Disabled because we can get
+    # the same value through the Kubernetes downward API, which doesn't introduce
+    # a potential Pod launching failure point.)
+    # admission.datadoghq.com/enabled: "true"
+    #
 spec:
   policyTypes: [Ingress]
   podSelector:
@@ -32,11 +43,22 @@
 metadata:
   name: simple-app
   labels:
-    helm.sh/chart: simple-app-0.10.0
+    helm.sh/chart: simple-app-0.11.0
     app.kubernetes.io/version: "latest"
     app.kubernetes.io/managed-by: Helm
     app.kubernetes.io/name: simple-app
     app.kubernetes.io/instance: simple-app
+    # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes
+    tags.datadoghq.com/env: "dev"
+    tags.datadoghq.com/service: "simple-app"
+    tags.datadoghq.com/version: "latest"
+    #
+    # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/
+    # (Disabled for now, here for future reference. Disabled because we can get
+    # the same value through the Kubernetes downward API, which doesn't introduce
+    # a potential Pod launching failure point.)
+    # admission.datadoghq.com/enabled: "true"
+    #
 ---
 # Source: simple-app/templates/service.yaml
 apiVersion: v1
@@ -44,11 +66,22 @@
 metadata:
   name: simple-app
   labels:
-    helm.sh/chart: simple-app-0.10.0
+    helm.sh/chart: simple-app-0.11.0
     app.kubernetes.io/version: "latest"
     app.kubernetes.io/managed-by: Helm
     app.kubernetes.io/name: simple-app
     app.kubernetes.io/instance: simple-app
+    # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes
+    tags.datadoghq.com/env: "dev"
+    tags.datadoghq.com/service: "simple-app"
+    tags.datadoghq.com/version: "latest"
+    #
+    # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/
+    # (Disabled for now, here for future reference. Disabled because we can get
+    # the same value through the Kubernetes downward API, which doesn't introduce
+    # a potential Pod launching failure point.)
+    # admission.datadoghq.com/enabled: "true"
+    #
 spec:
   type: ClusterIP
   ports:
@@ -70,11 +103,22 @@
 metadata:
   name: simple-app
   labels:
-    helm.sh/chart: simple-app-0.10.0
+    helm.sh/chart: simple-app-0.11.0
     app.kubernetes.io/version: "latest"
     app.kubernetes.io/managed-by: Helm
     app.kubernetes.io/name: simple-app
     app.kubernetes.io/instance: simple-app
+    # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes
+    tags.datadoghq.com/env: "dev"
+    tags.datadoghq.com/service: "simple-app"
+    tags.datadoghq.com/version: "latest"
+    #
+    # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/
+    # (Disabled for now, here for future reference. Disabled because we can get
+    # the same value through the Kubernetes downward API, which doesn't introduce
+    # a potential Pod launching failure point.)
+    # admission.datadoghq.com/enabled: "true"
+    #
 spec:
   replicas: 1
   selector:
@@ -84,12 +128,36 @@
   template:
     metadata:
       annotations:
-      labels:
-        helm.sh/chart: simple-app-0.10.0
+        proxy.istio.io/config: '{ "holdApplicationUntilProxyStarts": true }'
+        prometheus.io/scrape: "true"
+        prometheus.io/port: "9090"
+        prometheus.io/path: /metrics
+        ad.datadoghq.com/istio-proxy.check_names: ['prometheus']
+        ad.datadoghq.com/istio-proxy.init_configs: '[{}]'
+        ad.datadoghq.com/istio-proxy.instances: |-
+          [
+            {
+              "prometheus_url": "http://%%host%%:15020/stats/prometheus",
+              "namespace": "eks"
+            }
+          ]
+      labels:
+        helm.sh/chart: simple-app-0.11.0
         app.kubernetes.io/version: "latest"
         app.kubernetes.io/managed-by: Helm
         app.kubernetes.io/name: simple-app
         app.kubernetes.io/instance: simple-app
+        # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes
+        tags.datadoghq.com/env: "dev"
+        tags.datadoghq.com/service: "simple-app"
+        tags.datadoghq.com/version: "latest"
+        #
+        # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/
+        # (Disabled for now, here for future reference. Disabled because we can get
+        # the same value through the Kubernetes downward API, which doesn't introduce
+        # a potential Pod launching failure point.)
+        # admission.datadoghq.com/enabled: "true"
+        #
     spec:
       serviceAccountName: simple-app
       securityContext:
@@ -100,6 +168,30 @@
             {}
           image: nginx:latest
           imagePullPolicy: IfNotPresent
+          env:
+            # https://www.datadoghq.com/blog/monitor-kubernetes-docker/#instrument-your-code-to-send-metrics-to-dogstatsd
+            - name: DOGSTATSD_HOST_IP
+              valueFrom:
+                fieldRef:
+                  fieldPath: status.hostIP
+            # https://docs.datadoghq.com/agent/docker/apm/?tab=standard#docker-apm-agent-environment-variables
+            - name: DD_AGENT_HOST
+              valueFrom:
+                fieldRef:
+                  fieldPath: status.hostIP
+            # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes#full-configuration
+            - name: DD_ENV
+              valueFrom:
+                fieldRef:
+                  fieldPath: metadata.labels['tags.datadoghq.com/env']
+            - name: DD_SERVICE
+              valueFrom:
+                fieldRef:
+                  fieldPath: metadata.labels['tags.datadoghq.com/service']
+            - name: DD_VERSION
+              valueFrom:
+                fieldRef:
+                  fieldPath: metadata.labels['tags.datadoghq.com/version']
           resources:
             {}
           ports:
@@ -127,11 +219,22 @@
 metadata:
   name: simple-app
   labels:
-    helm.sh/chart: simple-app-0.10.0
+    helm.sh/chart: simple-app-0.11.0
     app.kubernetes.io/version: "latest"
     app.kubernetes.io/managed-by: Helm
     app.kubernetes.io/name: simple-app
     app.kubernetes.io/instance: simple-app
+    # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes
+    tags.datadoghq.com/env: "dev"
+    tags.datadoghq.com/service: "simple-app"
+    tags.datadoghq.com/version: "latest"
+    #
+    # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/
+    # (Disabled for now, here for future reference. Disabled because we can get
+    # the same value through the Kubernetes downward API, which doesn't introduce
+    # a potential Pod launching failure point.)
+    # admission.datadoghq.com/enabled: "true"
+    #
   annotations:
 spec:
   rules:
@@ -331,27 +434,6 @@
       name: redis
       protocol: REDIS
 ---
-# Source: simple-app/templates/servicemonitor.yaml
-apiVersion: monitoring.coreos.com/v1
-kind: ServiceMonitor
-metadata:
-  name: simple-app
-  labels:
-    helm.sh/chart: simple-app-0.10.0
-    app.kubernetes.io/version: "latest"
-    app.kubernetes.io/managed-by: Helm
-    app.kubernetes.io/name: simple-app
-    app.kubernetes.io/instance: simple-app
-spec:
-  selector:
-    matchLabels:
-      app.kubernetes.io/name: simple-app
-      app.kubernetes.io/instance: simple-app
-  endpoints:
-    - port: metrics
-      path: /metrics
-      scheme: http
----
 # Source: simple-app/charts/istio-endpoints/templates/sidecar.yaml
 apiVersion: networking.istio.io/v1beta1
 kind: Sidecar
@@ -386,11 +468,22 @@
 metadata:
   name: "simple-app-test-connection"
   labels:
-    helm.sh/chart: simple-app-0.10.0
+    helm.sh/chart: simple-app-0.11.0
     app.kubernetes.io/version: "latest"
     app.kubernetes.io/managed-by: Helm
     app.kubernetes.io/name: simple-app
     app.kubernetes.io/instance: simple-app
+    # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes
+    tags.datadoghq.com/env: "dev"
+    tags.datadoghq.com/service: "simple-app"
+    tags.datadoghq.com/version: "latest"
+    #
+    # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/
+    # (Disabled for now, here for future reference. Disabled because we can get
+    # the same value through the Kubernetes downward API, which doesn't introduce
+    # a potential Pod launching failure point.)
+    # admission.datadoghq.com/enabled: "true"
+    #
   annotations:
     "helm.sh/hook": test
 spec:
```
  • Loading branch information
diranged authored Jun 22, 2021
1 parent 585e016 commit ecb2834
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 6 deletions.
2 changes: 1 addition & 1 deletion charts/simple-app/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: simple-app
description: Default Microservice Helm Chart
type: application
version: 0.10.1
version: 0.11.0
appVersion: latest
maintainers:
- name: diranged
Expand Down
15 changes: 14 additions & 1 deletion charts/simple-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Default Microservice Helm Chart

![Version: 0.10.1](https://img.shields.io/badge/Version-0.10.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: latest](https://img.shields.io/badge/AppVersion-latest-informational?style=flat-square)
![Version: 0.11.0](https://img.shields.io/badge/Version-0.11.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: latest](https://img.shields.io/badge/AppVersion-latest-informational?style=flat-square)

[deployments]: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
[hpa]: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/
Expand All @@ -23,6 +23,14 @@ If you are operating in an Istio Service Mesh, see the
works. Otherwise, see the `Values.serviceMonitor` settings to configure a
Prometheus ServiceMonitor resource to monitor your application.

## Datadog Agent Support

This chart supports operating in environments where the Datadog Agent is
running. If you set the `Values.datadog.enabled` flag, then a series of
additional Pod Annotations, Labels and Environment Variables will be
automatically added in to your deployment. See the `Values.datadog` parameters
for further information.

## Istio Networking Support

### Monitoring through the Sidecar Proxy
Expand Down Expand Up @@ -62,6 +70,11 @@ This feature is turned on by default if you set `Values.istio.enabled=true` and
| autoscaling.maxReplicas | int | `100` | Sets the maximum number of Pods to run |
| autoscaling.minReplicas | int | `1` | Sets the minimum number of Pods to run |
| autoscaling.targetCPUUtilizationPercentage | int | `80` | Configures the HPA to target a particular CPU utilization percentage |
| datadog.enabled | bool | `true` | (`bool`) Whether or not the various datadog labels and options should be included or not. |
| datadog.env | string | `"dev"` | (`string`) The "env" tag to configure for the application - this maps to the Datadog environment concept for isolating traces/apm data. |
| datadog.metricsNamespace | string | `"eks"` | (`string`) The prefix to append to all metrics that are scraped by Datadog. We set this to one common value so that common metrics (like `istio_.*` or `go_.*`) are shared across all apps in Datadog for easier dashboard creation as well as comparision between applications. |
| datadog.scrapeMetrics | bool | `false` | (`bool`) If true, then we will configure the Datadog agent to scrape metrics from the Pod (or the `istio-proxy` sidecar). |
| datadog.service | `string` | `nil` | If set, this configures the "service" tag. If this is not set, the tag defaults to the `.Release.Name` for the application. |
| env | list | `[]` | Environment Variables for the primary container. These are all run through the tpl function (the key name and value), so you can dynamically name resources as you need. |
| envFrom | list | `[]` | Pull all of the environment variables listed in a ConfigMap into the Pod. See https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#configure-all-key-value-pairs-in-a-configmap-as-container-environment-variables for more details. |
| fullnameOverride | string | `""` | |
Expand Down
8 changes: 8 additions & 0 deletions charts/simple-app/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ If you are operating in an Istio Service Mesh, see the
works. Otherwise, see the `Values.serviceMonitor` settings to configure a
Prometheus ServiceMonitor resource to monitor your application.

## Datadog Agent Support

This chart supports operating in environments where the Datadog Agent is
running. If you set the `Values.datadog.enabled` flag, then a series of
additional Pod Annotations, Labels and Environment Variables will be
automatically added in to your deployment. See the `Values.datadog` parameters
for further information.

## Istio Networking Support

### Monitoring through the Sidecar Proxy
Expand Down
18 changes: 16 additions & 2 deletions charts/simple-app/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,25 @@ Create chart name and version as used by the chart label.
Common labels
*/}}
{{- define "simple-app.labels" -}}
{{- $tag := default .Chart.AppVersion .Values.image.tag -}}
{{- $_tag := default .Chart.AppVersion .Values.image.tag -}}
{{- $tag := $_tag | replace ":" "_" | trunc 63 | quote -}}
helm.sh/chart: {{ include "simple-app.chart" . }}
app.kubernetes.io/version: {{ $tag | replace ":" "_" | trunc 63 | quote }}
app.kubernetes.io/version: {{ $tag }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{ include "simple-app.selectorLabels" . }}
{{- if .Values.datadog.enabled }}
# https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes
tags.datadoghq.com/env: {{ .Values.datadog.env | quote }}
tags.datadoghq.com/service: {{ default .Release.Name .Values.datadog.service | quote }}
tags.datadoghq.com/version: {{ $tag }}
#
# https://docs.datadoghq.com/agent/cluster_agent/admission_controller/
# (Disabled for now, here for future reference. Disabled because we can get
# the same value through the Kubernetes downward API, which doesn't introduce
# a potential Pod launching failure point.)
# admission.datadoghq.com/enabled: "true"
#
{{- end }}
{{- end }}

{{/*
Expand Down
59 changes: 57 additions & 2 deletions charts/simple-app/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ spec:
conditions.
*/}}
proxy.istio.io/config: '{ "holdApplicationUntilProxyStarts": true }'

{{- /*
If monitoring is enabled, and we're in an Istio environment, then we
default to using the Isto metrics-merging feature where the sidecar
Expand All @@ -38,8 +37,35 @@ spec:
prometheus.io/port: {{ .Values.monitor.portNumber | quote }}
prometheus.io/path: {{ .Values.monitor.path }}
{{- end }}
{{- end }}

{{- /*
If the datadog agent is enabled,
*/}}
{{- if and .Values.datadog.enabled .Values.monitor.enabled .Values.datadog.scrapeMetrics }}
{{- if .Values.istio.enabled }}
ad.datadoghq.com/istio-proxy.check_names: ['prometheus']
ad.datadoghq.com/istio-proxy.init_configs: '[{}]'
ad.datadoghq.com/istio-proxy.instances: |-
[
{
"prometheus_url": "http://%%host%%:15020/stats/prometheus",
"namespace": "{{ .Values.datadog.metricsNamespace }}"
}
]
{{- else }}
ad.datadoghq.com/{{ .Chart.Name }}.check_names: ['prometheus']
ad.datadoghq.com/{{ .Chart.Name }}.init_configs: '[{}]'
ad.datadoghq.com/{{ .Chart.Name }}.instances: |-
[
{
"prometheus_url": "http://%%host%%:{{ .Values.monitor.portNumber }}{{ .Values.monitor.path }}",
"namespace": "{{ .Values.datadog.metricsNamespace }}"
}
]
{{- end }}
{{- end }}
labels:
{{- include "simple-app.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
Expand Down Expand Up @@ -119,8 +145,9 @@ spec:
{{- end }}
{{- end }}
{{- end }}
{{- with .Values.env }}
{{- if or .Values.env .Values.datadog.enabled }}
env:
{{- with .Values.env }}
{{- range $env := index . }}
- name: {{ tpl $env.name $ }}
{{- if $env.value }}
Expand All @@ -129,7 +156,35 @@ spec:
valueFrom: {{ tpl (toYaml $env.valueFrom) $ | nindent 16 }}
{{- end }}
{{- end }}
{{- end }}

{{- if .Values.datadog.enabled }}
# https://www.datadoghq.com/blog/monitor-kubernetes-docker/#instrument-your-code-to-send-metrics-to-dogstatsd
- name: DOGSTATSD_HOST_IP
valueFrom:
fieldRef:
fieldPath: status.hostIP
# https://docs.datadoghq.com/agent/docker/apm/?tab=standard#docker-apm-agent-environment-variables
- name: DD_AGENT_HOST
valueFrom:
fieldRef:
fieldPath: status.hostIP
# https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes#full-configuration
- name: DD_ENV
valueFrom:
fieldRef:
fieldPath: metadata.labels['tags.datadoghq.com/env']
- name: DD_SERVICE
valueFrom:
fieldRef:
fieldPath: metadata.labels['tags.datadoghq.com/service']
- name: DD_VERSION
valueFrom:
fieldRef:
fieldPath: metadata.labels['tags.datadoghq.com/version']
{{- end }}
{{- end }}

{{- with .Values.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
Expand Down
25 changes: 25 additions & 0 deletions charts/simple-app/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,31 @@ istio:
# from the application, rather than creating a new `ServiceMonitor` object.
enabled: false

# Configures labels and other parameters assuming that the Datadog Agent is
# installed on the underlying hosts and is part of the Kubernetes cluster.
datadog:
# -- (`bool`) Whether or not the various datadog labels and options should be
# included or not.
enabled: true

# -- (`string`) The "env" tag to configure for the application - this maps to
# the Datadog environment concept for isolating traces/apm data.
env: dev

# -- (`string`) If set, this configures the "service" tag. If this is not
# set, the tag defaults to the `.Release.Name` for the application.
service: null

# -- (`bool`) If true, then we will configure the Datadog agent to scrape
# metrics from the Pod (or the `istio-proxy` sidecar).
scrapeMetrics: false

# -- (`string`) The prefix to append to all metrics that are scraped by
# Datadog. We set this to one common value so that common metrics (like
# `istio_.*` or `go_.*`) are shared across all apps in Datadog for easier
# dashboard creation as well as comparision between applications.
metricsNamespace: eks

tests:
connection:
# -- The command used to trigger the test.
Expand Down

0 comments on commit ecb2834

Please sign in to comment.