Skip to content

Commit

Permalink
[Addon] update datadog trait (#749)
Browse files Browse the repository at this point in the history
Signed-off-by: kolossi <[email protected]>
Co-authored-by: kolossi <[email protected]>
  • Loading branch information
Kolossi and kolossi authored Feb 15, 2024
1 parent f4ddd9d commit 8d6dcdc
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 30 deletions.
84 changes: 56 additions & 28 deletions experimental/addons/datadog/definitions/datadog.cue
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,86 @@ import "strings"
labels: {}
description: "Add required env vars, annotations and host volume mount for datadog instrumentation"
attributes: {
appliesToWorkloads: ["deployments.apps","cronjobs.batch]
appliesToWorkloads: ["deployments.apps","cronjobs.batch"]
podDisruptive: true
}
}

template: {
let envVars=[
{
name: "DD_SERVICE"
name: "DD_SERVICE",
value: parameter.serviceName
},
{
name: "DD_ENV"
name: "DD_ENV",
value: parameter.env
},
{
name: "DD_VERSION"
name: "DD_VERSION",
value: parameter.version
},

if parameter.autoDependencyMap {
let autoDepenencyList = [ for x in strings.Split(parameter.autoDependencies,",") { strings.TrimSpace(x) } ]
let mappings = [ for x in autoDepenencyList { x + ":" + parameter.serviceName + "-dependency" }]

{
name: "DD_TRACE_SERVICE_MAPPING"
value: strings.Join(mappings, ",")
}
}
]

let volumeMount={
name: datadog
mountPath: path: parameter.mountPath
let volumeMount = {
name: parameter.volumeName,
mountPath: parameter.mountPath
}

let volume = {
name: datadog
name: parameter.volumeName,
hostPath: path: parameter.hostMountPath
}

let sourceAnnotation = {
if parameter.source != _|_ {
metadata: annotations: {
("ad.datadoghq.com/"+parameter.serviceName+".logs"): "[{\"source\": \""+parameter.source+"\"}]"
}
}
}

let patchContent= {
spec: {
containers: [
containers: [{
// +patchKey=name
env: envVars
env: envVars,
// +patchKey=name
volumeMounts: [volumeMount]
]
}]
// +patchKey=name
volumes: [volume]
}
if parameter.source != _|_ {
metadata: annotations: [{
"ad.datadoghq.com/"+parameter.serviceName+".logs": "[{\"source\": \""+parameter.source+"\"}]"
}]
}
}

patch: spec: {
if context.output.spec.template != _|_ {
template: patchContent
}
if context.output.spec.jobTemplate != _|_ {
if parameter.source != _|_ {
metadata: annotations: [{
"ad.datadoghq.com/"+parameter.serviceName+".logs": "[{\"source\": \""+parameter.source+"\"}]"
}]
patch: {
sourceAnnotation

spec: {
if context.output.spec.template != _|_ {
template: {
sourceAnnotation
patchContent
}
}
jobTemplate: {
spec: template: patchContent
if context.output.spec.jobTemplate != _|_ {
jobTemplate: {
sourceAnnotation
spec: template: {
sourceAnnotation
patchContent
}
}
}
}
}
Expand All @@ -87,8 +106,17 @@ template: {
// +usage=mount path on host (default /var/run/datadog)
hostMountPath: *"/var/run/datadog" | string

// +usage=source for logging (add as an annotation ad.datadoghq.com/<serviceName>.logs: [{"source":"<this value>"}]
// +usage=name of host mount volume (default datadog)
volumeName: *"datadog" | string

// +usage=source for logging (added as an annotation 'ad.datadoghq.com/<serviceName>.logs: [{"source":"<this value>"}]' )
source?: string

// +usage=auto-map standard dependencies to <serviceName>-dependency by setting DD_TRACE_SERVICE_MAPPING env var (default false)
autoDependencyMap: *false | bool

// +usage=comma-separated list of dependencies to be used by autoDependencyMap (default "http-client,redis,sql-server,kafka,faulthandlingdb")
autoDependencies: *"http-client,redis,sql-server,kafka,faulthandlingdb" | string
}

}
4 changes: 2 additions & 2 deletions experimental/addons/datadog/metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: datadog
version: 0.0.1
version: 0.0.2
system:
vela: ">=v1.9.0"
description: Sets up the annotations and environment variables to assist a webservice or cron-tasks component to have correct collection of logs and apm stats by a datadog agent installed on the host nodes.
description: Sets up the annotations and environment variables to assist a webservice or cron-task component to have correct collection of logs and apm stats by a datadog agent installed on the host nodes.
url:

tags:
Expand Down

0 comments on commit 8d6dcdc

Please sign in to comment.