Skip to content

Commit 8d78f0b

Browse files
authored
Enable Datadog tracer, bump dependencies and align environment names (#31)
1 parent bd22c6f commit 8d78f0b

File tree

13 files changed

+308
-40
lines changed

13 files changed

+308
-40
lines changed

.github/workflows/sandbox.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,4 @@ jobs:
104104
api_key: ${{ secrets.DATADOG_API_KEY }}
105105
app_key: ${{ secrets.DATADOG_APP_KEY }}
106106
fail_on_critical_errors: true
107-
test_search_query: "env:sb service:gke-info-go team:platform-google-cloud-kubernetes state:live"
107+
test_search_query: "env:sandbox service:gke-info-go team:platform-google-cloud-kubernetes state:live"

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ plan.out
3636
# Ignore Infracost directories and files
3737
.infracost
3838

39+
# Ignore Visual Studio Code directories
40+
.vscode
41+
3942
# Other Files
4043
*.log
4144
*.bak

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repos:
99

1010

1111
- repo: https://github.com/antonbabenko/pre-commit-terraform
12-
rev: v1.92.0
12+
rev: v1.92.1
1313
hooks:
1414
- id: terraform_fmt
1515

@@ -30,7 +30,7 @@ repos:
3030
- --hook-config=--create-file-if-not-exist=false
3131

3232
- repo: https://github.com/bridgecrewio/checkov.git
33-
rev: 3.2.174
33+
rev: 3.2.219
3434
hooks:
3535
- id: checkov
3636
files: Dockerfile

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ COPY internal/ /app/internal/
3030

3131
# Build the application
3232

33-
RUN GOOS=linux CGO_ENABLED=0 go build -o main cmd/http/main.go
33+
# For Datadog ASM the Go build tag appsec is not necessary if CGO is enabled with CGO_ENABLED=1
34+
RUN GOOS=linux CGO_ENABLED=0 go build -v -tags appsec -o main cmd/http/main.go
3435

3536
# Expose the port your application listens on
3637

cmd/http/main.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,30 @@ import (
1010
"time"
1111

1212
"gke-info/internal/metadata"
13+
14+
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
15+
"gopkg.in/DataDog/dd-trace-go.v1/profiler"
16+
17+
httptrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/net/http"
1318
)
1419

1520
// main initializes the HTTP server and sets up the routes.
1621
func main() {
17-
mux := http.NewServeMux()
22+
tracer.Start()
23+
defer tracer.Stop()
24+
25+
err := profiler.Start(
26+
profiler.WithProfileTypes(
27+
profiler.CPUProfile,
28+
profiler.HeapProfile,
29+
),
30+
)
31+
if err != nil {
32+
log.Printf("Warning: Failed to start profiler: %v", err)
33+
}
34+
defer profiler.Stop()
35+
36+
mux := httptrace.NewServeMux()
1837
mux.HandleFunc("/gke-info-go/metadata/", metadata.MetadataHandler)
1938
mux.HandleFunc("/gke-info-go/health", metadata.HealthCheckHandler)
2039

deployments/regional/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ No requirements.
99

1010
| Name | Version |
1111
|------|---------|
12-
| <a name="provider_datadog"></a> [datadog](#provider\_datadog) | 3.40.0 |
13-
| <a name="provider_google"></a> [google](#provider\_google) | 5.36.0 |
12+
| <a name="provider_datadog"></a> [datadog](#provider\_datadog) | 3.42.0 |
13+
| <a name="provider_google"></a> [google](#provider\_google) | 5.40.0 |
1414
| <a name="provider_kubernetes"></a> [kubernetes](#provider\_kubernetes) | 2.31.0 |
1515

1616
## Modules
@@ -34,7 +34,7 @@ No modules.
3434
|------|-------------|------|---------|:--------:|
3535
| <a name="input_datadog_api_key"></a> [datadog\_api\_key](#input\_datadog\_api\_key) | Datadog API key | `string` | n/a | yes |
3636
| <a name="input_datadog_app_key"></a> [datadog\_app\_key](#input\_datadog\_app\_key) | Datadog APP key | `string` | n/a | yes |
37-
| <a name="input_env"></a> [env](#input\_env) | This is the environment suffix for example: sb (Sandbox), pre-prod (Pre-Production), prod (Production) | `string` | `"sb"` | no |
37+
| <a name="input_environment"></a> [environment](#input\_environment) | The full environment name for example: `sandbox`, `non-production`, `production` | `string` | `"sandbox"` | no |
3838
| <a name="input_gke_info_go_replicas"></a> [gke\_info\_go\_replicas](#input\_gke\_info\_go\_replicas) | The number of replicas for the gke-info deployment | `number` | `1` | no |
3939
| <a name="input_gke_info_go_version"></a> [gke\_info\_go\_version](#input\_gke\_info\_go\_version) | The version of the gke-info deployment | `string` | n/a | yes |
4040
| <a name="input_region"></a> [region](#input\_region) | The region to deploy the resources into | `string` | n/a | yes |

deployments/regional/locals.tf

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# https://www.terraform.io/docs/language/values/locals.html
33

44
locals {
5-
datadog_mci_synthetic_url = var.env == "prod" ? "https://gcp.osinfra.io/${local.datadog_synthetic_service}" : "https://${var.env}.gcp.osinfra.io/${local.datadog_synthetic_service}"
6-
datadog_synthetic_message_critical = var.env == "prod" ? "@hangouts-Platform-CriticalHighPriority" : ""
7-
datadog_synthetic_message_medium = var.env == "prod" ? "@hangouts-Platform-MediumLowInfoPriority" : ""
5+
datadog_mci_synthetic_url = var.environment == "production" ? "https://gcp.osinfra.io/${local.datadog_synthetic_service}" : "https://${local.env}.gcp.osinfra.io/${local.datadog_synthetic_service}"
6+
datadog_synthetic_message_critical = var.environment == "production" ? "@hangouts-Platform-CriticalHighPriority" : ""
7+
datadog_synthetic_message_medium = var.environment == "production" ? "@hangouts-Platform-MediumLowInfoPriority" : ""
88
datadog_synthetic_name = "GKE Info"
99
datadog_synthetic_service = "gke-info-go"
1010

@@ -64,10 +64,12 @@ locals {
6464
region = "us-east1"
6565
service = local.datadog_synthetic_service
6666
status = "paused"
67-
url = var.env == "prod" ? "https://us-east1.gcp.osinfra.io/${local.datadog_synthetic_service}" : "https://us-east1.${var.env}.gcp.osinfra.io/${local.datadog_synthetic_service}"
67+
url = var.environment == "production" ? "https://us-east1.gcp.osinfra.io/${local.datadog_synthetic_service}" : "https://us-east1.${local.env}.gcp.osinfra.io/${local.datadog_synthetic_service}"
6868
}
6969
} : {}
7070

71-
registry = var.env == "sb" ? "us-docker.pkg.dev/plt-lz-services-tf7f-sb/platform-docker-virtual" : "us-docker.pkg.dev/plt-lz-services-tf79-prod/platform-docker-virtual"
72-
kubernetes_project = var.env == "sb" ? "plt-k8s-tf39-sb" : var.env == "prod" ? "plt-k8s-tf10-prod" : "plt-k8s-tf33-nonprod"
71+
env = var.environment == "sandbox" ? "sb" : var.environment == "non-production" ? "non-prod" : var.environment == "production" ? "prod" : "none"
72+
73+
registry = var.environment == "sandbox" ? "us-docker.pkg.dev/plt-lz-services-tf7f-sb/platform-docker-virtual" : "us-docker.pkg.dev/plt-lz-services-tf79-prod/platform-docker-virtual"
74+
kubernetes_project = var.environment == "sandbox" ? "plt-k8s-tf39-sb" : var.environment == "production" ? "plt-k8s-tf10-prod" : "plt-k8s-tf33-nonprod"
7375
}

deployments/regional/main.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ resource "datadog_synthetics_test" "this" {
8282

8383
locations = each.value.locations
8484
message = each.value.message
85-
name = "${each.value.name} on - region:${each.value.region} env:${var.env}"
85+
name = "${each.value.name} on - region:${each.value.region} env:${var.environment}"
8686

8787
options_list {
8888
tick_every = 300
@@ -108,7 +108,7 @@ resource "datadog_synthetics_test" "this" {
108108
subtype = "http"
109109

110110
tags = [
111-
"env:${var.env}",
111+
"env:${var.environment}",
112112
"service:${each.value.service}",
113113
"region:${each.value.region}",
114114
"team:platform-google-cloud-kubernetes"
@@ -140,7 +140,7 @@ resource "kubernetes_deployment_v1" "gke_info_go" {
140140

141141
metadata {
142142
labels = {
143-
"tags.datadoghq.com/env" = var.env
143+
"tags.datadoghq.com/env" = var.environment
144144
"tags.datadoghq.com/service" = "gke-info-go"
145145
"tags.datadoghq.com/version" = var.gke_info_go_version
146146
}
@@ -162,7 +162,7 @@ resource "kubernetes_deployment_v1" "gke_info_go" {
162162
metadata {
163163
annotations = {
164164
"apm.datadoghq.com/env" = jsonencode({
165-
"DD_ENV" = var.env
165+
"DD_ENV" = var.environment
166166
"DD_SERVICE" = "gke-info-go"
167167
"DD_VERSION" = var.gke_info_go_version
168168
})
@@ -173,7 +173,7 @@ resource "kubernetes_deployment_v1" "gke_info_go" {
173173
# Enable Admission Controller to mutate new pods part of this deployment
174174
"admission.datadoghq.com/enabled" = "true"
175175
"app" = "gke-info-go"
176-
"tags.datadoghq.com/env" = var.env
176+
"tags.datadoghq.com/env" = var.environment
177177
"tags.datadoghq.com/service" = "gke-info-go"
178178
"tags.datadoghq.com/version" = var.gke_info_go_version
179179
}

deployments/regional/variables.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
variable "env" {
2-
description = "This is the environment suffix for example: sb (Sandbox), pre-prod (Pre-Production), prod (Production)"
1+
variable "environment" {
2+
description = "The full environment name for example: `sandbox`, `non-production`, `production`"
33
type = string
4-
default = "sb"
4+
default = "sandbox"
55
}
66

77
variable "datadog_api_key" {

entity.datadog.yaml

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,41 @@ metadata:
66
displayName: GKE Info Go
77

88
links:
9-
- name: Sandbox Global
9+
- name: Sandbox
1010
type: other
11-
url: "https://sb.gcp.osinfra.io/gke-info"
11+
url: "https://sb.gcp.osinfra.io/gke-info/health"
1212

13-
- name: Pre-Production Global
13+
- name: "Sandbox: us-east1-b"
1414
type: other
15-
url: "https://pre-prod.gcp.osinfra.io/gke-info"
15+
url: "https://us-east1-b.sb.gcp.osinfra.io/gke-info-go/gke-info/health"
1616

17-
- name: Production Global
17+
- name: "Sandbox: us-east4-a"
1818
type: other
19-
url: "https://gcp.osinfra.io/gke-info"
19+
url: "https://us-east4-a.sb.gcp.osinfra.io/gke-info-go/gke-info/health"
2020

21-
- name: osinfra-io/gke-info-go
22-
type: repo
23-
provider: github
24-
url: https://github.com/osinfra-io/gke-info-go
21+
- name: Pre-Production
22+
type: other
23+
url: "https://pre-prod.gcp.osinfra.io/gke-info/health"
24+
25+
- name: "Pre-Production: us-east1-b"
26+
type: other
27+
url: "https://us-east1-b.pre-prod.gcp.osinfra.io/gke-info/health"
28+
29+
- name: "Pre-Production: us-east4-a"
30+
type: other
31+
url: "https://us-east4-a.pre-prod.gcp.osinfra.io/gke-info/health"
32+
33+
- name: Production
34+
type: other
35+
url: "https://gcp.osinfra.io/gke-info/health"
36+
37+
- name: "Production: us-east1-b"
38+
type: other
39+
url: "https://us-east1-b.gcp.osinfra.io/gke-info/health"
40+
41+
- name: "Production: us-east4-a"
42+
type: other
43+
url: "https://us-east4-a.gcp.osinfra.io/gke-info/health"
2544

2645
owner: platform-google-cloud-kubernetes
2746

@@ -31,6 +50,7 @@ spec:
3150
type: web
3251
languages:
3352
- go
53+
3454
dependsOn:
3555
- service:istio-gateway
3656

0 commit comments

Comments
 (0)