Skip to content

Commit f2a6cb1

Browse files
authored
Merge pull request #48 from redis-field-engineering/dynatrace-tf
2 parents b26ddd3 + 8cbdb74 commit f2a6cb1

File tree

10 files changed

+513
-11
lines changed

10 files changed

+513
-11
lines changed

dynatrace_v2/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bundle.zip
2+
extension.zip

dynatrace_v2/README.adoc

Lines changed: 77 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,95 @@ use the https://www.dynatrace.com/support/help/extend-dynatrace/extensions20/ext
1111

1212
* link:#Installation[Installation]
1313
* link:#Dashboards[Dashboards]
14-
* link:#Dashboards[Alternative Redis Plugins]
14+
* link:#Alternative-Redis-Plugins[Alternative Redis Plugins]
1515
* link:#Support[Support]
1616
* link:#License[License]
1717

1818
== Installation
1919

20-
The Dyntrace v2.0 Extensions support Prometheus metrics, and as such we have created the necessary extension file and
21-
dashboards so that this option is available. At this time Dynatrace are still testing their signing mechanism so that
22-
this extension is not available directly from them, but will have to be built and signed according to their instructions.
20+
The Dynatrace v2.0 Extensions Framework supports Prometheus metrics, and as such we have created the necessary extension file and
21+
dashboards so that this option is available. At this time Dynatrace are still testing their signing mechanism, so this
22+
extension is not available directly from them but will have to be built and signed according to their instructions.
2323
They have indicated that they will sign 3rd party extensions starting in Q1 2025, at which point this process will no
2424
longer be necessary.
2525

26-
Clone the repository and cd into its root folder ('redis-enterprise-dynatrace-observability'). The contents are already
27-
in the required format; a 'src' directory containing a .yml file and a folder containing .json dashboard files.
26+
=== Setting Up the Dynatrace Extension
2827

29-
Follow the instructions here:
28+
==== Prerequisites
3029

31-
https://www.dynatrace.com/support/help/extend-dynatrace/extensions20/sign-extension
30+
* Python 3.7+ installed on your system
31+
* A Dynatrace tenant
32+
* An API token with permissions: `extensions.read`, `extensions.write`, `extensions.manage`, and `metrics.ingest`
33+
* Redis Enterprise Software or Redis Cloud with metrics exporter enabled on port 8070
34+
35+
==== Step-by-Step Installation
36+
37+
1. Set up a Python virtual environment and install dt-cli:
38+
+
39+
[source,bash]
40+
----
41+
python -m venv dt-venv
42+
source dt-venv/bin/activate # On Windows: dt-venv\Scripts\activate
43+
pip install dt-cli
44+
----
45+
46+
2. Create certificates required for signing the extension:
47+
+
48+
[source,bash]
49+
----
50+
# Create a directory for certificates
51+
mkdir -p secrets
52+
53+
# Generate a CA certificate
54+
dt extension genca --no-ca-passphrase
55+
56+
# Generate a CA key
57+
dt extension generate-developer-pem -o developer.pem --ca-crt ca.pem --ca-key ca.key --name "Redis Developer"
58+
59+
# Move certificates to the secrets directory
60+
mv ca.pem ca.key developer.pem developer.key secrets/
61+
----
62+
63+
3. Assemble, sign, and upload the extension:
64+
+
65+
[source,bash]
66+
----
67+
# Assemble the extension
68+
dt extension assemble
69+
70+
# Sign the extension with your developer certificate
71+
dt extension sign --key secrets/developer.pem
72+
73+
# Upload the extension to your Dynatrace tenant
74+
dt extension upload --tenant-url https://YOUR_TENANT_ID.live.dynatrace.com --api-token YOUR_API_TOKEN bundle.zip
75+
----
76+
77+
4. *Important:* For remote monitoring, you need an ActiveGate or OneAgent. Install it by following the https://docs.dynatrace.com/docs/ingest-from/dynatrace-activegate/installation/linux[Dynatrace ActiveGate installation instructions].
78+
79+
5. Install your CA certificate on the ActiveGate:
80+
+
81+
[source,bash]
82+
----
83+
# Copy the CA certificate to ActiveGate
84+
sudo cp secrets/ca.pem /var/lib/dynatrace/remotepluginmodule/agent/conf/certificates/
85+
86+
# Restart ActiveGate to apply changes
87+
sudo systemctl restart dynatracegateway
88+
----
89+
90+
6. In your Dynatrace tenant:
91+
* Go to "Settings" → "Extensions"
92+
* Find "Redis Enterprise Extension" and click "Activate"
93+
* Configure remote monitoring with your Redis endpoint: `https://YOUR_REDIS_SOFTWARE_ENDPOINT:8070/v2`
94+
95+
=== Terraform Automation for GCP
96+
97+
If you have an Active-Active Redis Enterprise deployment in GCP, you can use our Terraform scripts to automate the entire process. See the `terraform/gcp` directory for configuration details.
3298

3399
== Dashboards
34100

35-
This respository includes sample Dynatrace dashboards for monitoring your Redis deplyoment. See the
36-
link:/dynatrace/dashboards[dashboards] folder for the available set of dashboards.
101+
This repository includes sample Dynatrace dashboards for monitoring your Redis deployment. See the
102+
link:/src/dashboards[dashboards] folder for the available set of dashboards.
37103

38104
== Support
39105

@@ -43,4 +109,4 @@ please https://github.com/{project-owner}/{project-name}/issues[file an issue].
43109

44110
== License
45111

46-
This code in this repository is licensed under the MIT License. Copyright (C) 2023 Redis, Inc.
112+
This code in this repository is licensed under the MIT License. Copyright (C) 2023 Redis, Inc.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
.tfvars
2+
3+
# Local .terraform directories
4+
**/.terraform/*
5+
6+
# .tfstate files
7+
*.tfstate
8+
*.tfstate.*
9+
10+
# Crash log files
11+
crash.log
12+
crash.*.log
13+
14+
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
15+
# password, private keys, and other secrets. These should not be part of version
16+
# control as they are data points which are potentially sensitive and subject
17+
# to change depending on the environment.
18+
*.tfvars
19+
*.tfvars.json
20+
21+
# Ignore override files as they are usually used to override resources locally and so
22+
# are not checked in
23+
override.tf
24+
override.tf.json
25+
*_override.tf
26+
*_override.tf.json
27+
28+
# Ignore transient lock info files created by terraform apply
29+
.terraform.tfstate.lock.info
30+
31+
# Include override files you do wish to add to version control using negated pattern
32+
# !example_override.tf
33+
34+
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
35+
# example: *tfplan*
36+
37+
# Ignore CLI configuration files
38+
.terraformrc
39+
terraform.rc
40+
secrets
41+
modified.json
42+
extension.zip
43+
bundle.zip
44+
dt_object_id.txt
45+
.dt_venv

dynatrace_v2/terraform/gcp/.terraform.lock.hcl

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# example.auto.tfvars
2+
3+
project = ""
4+
region = ""
5+
zone = ""
6+
network = ""
7+
subnet = ""
8+
ssh_private_key = ""
9+
dynatrace_api_token = ""
10+
custom_ca_pem = ""
11+
developer_pem = ""
12+
gcp_user_name = ""
13+
tenant_id = ""
14+
primary_endpoint = ""
15+
secondary_endpoint = ""
16+
extension_version = ""

dynatrace_v2/terraform/gcp/main.tf

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# main.tf
2+
3+
provider "google" {
4+
project = var.project
5+
region = var.region
6+
}
7+
8+
terraform {
9+
required_providers {
10+
dynatrace = {
11+
version = "~> 1.0"
12+
source = "dynatrace-oss/dynatrace"
13+
}
14+
}
15+
}
16+
17+
data "google_compute_network" "primary_network" {
18+
name = var.network
19+
}
20+
21+
resource "google_compute_instance" "activegate" {
22+
name = "dynatrace-activegate"
23+
machine_type = "e2-medium"
24+
zone = var.zone
25+
26+
boot_disk {
27+
initialize_params {
28+
image = "ubuntu-os-cloud/ubuntu-2004-lts"
29+
}
30+
}
31+
32+
network_interface {
33+
network = var.network
34+
subnetwork = var.subnet
35+
access_config {}
36+
}
37+
38+
tags = ["dynatrace"]
39+
}
40+
41+
locals {
42+
dynatrace_tenant_url = "https://${var.tenant_id}.live.dynatrace.com"
43+
activegate_installer_url = "https://${var.tenant_id}.live.dynatrace.com/api/v1/deployment/installer/gateway/unix/latest?arch=x86"
44+
}
45+
46+
resource "null_resource" "install_activegate" {
47+
provisioner "remote-exec" {
48+
inline = [
49+
"#!/bin/bash",
50+
"sudo apt-get update",
51+
"sudo apt-get install -y wget",
52+
"wget -O ActiveGate.sh \"${local.activegate_installer_url}\" --header=\"Authorization: Api-Token ${var.dynatrace_api_token}\"",
53+
"chmod +x ActiveGate.sh",
54+
"sudo ./ActiveGate.sh"
55+
]
56+
}
57+
connection {
58+
type = "ssh"
59+
host = google_compute_instance.activegate.network_interface[0].access_config[0].nat_ip
60+
user = var.gcp_user_name
61+
private_key = file(var.ssh_private_key)
62+
}
63+
depends_on = [google_compute_instance.activegate]
64+
}
65+
66+
67+
68+
resource "null_resource" "upload_extension" {
69+
provisioner "local-exec" {
70+
command = <<EOT
71+
python3 -m venv .dt_venv
72+
source .dt_venv/bin/activate
73+
pip install dt-cli
74+
base_dir=$(pwd)
75+
cd ../..
76+
dt extension assemble
77+
dt extension sign --key $base_dir/${var.developer_pem}
78+
dt extension upload --tenant-url ${local.dynatrace_tenant_url} --api-token ${var.dynatrace_api_token} bundle.zip
79+
EOT
80+
}
81+
provisioner "local-exec" {
82+
when = destroy
83+
command = <<EOT
84+
python3 -m venv .dt_venv
85+
source .dt_venv/bin/activate
86+
DTCLI_API_TOKEN=${self.triggers.dynatrace_api_token} dt extension delete --tenant-url ${self.triggers.dynatrace_tenant_url} custom:com.redis.enterprise.extension
87+
EOT
88+
89+
}
90+
triggers = {
91+
extension_hash = filesha256("../../src/extension.yaml")
92+
dynatrace_api_token = var.dynatrace_api_token
93+
dynatrace_tenant_url = local.dynatrace_tenant_url
94+
}
95+
depends_on = [null_resource.install_activegate]
96+
}
97+
98+
resource "null_resource" "install_ca_pem" {
99+
provisioner "file" {
100+
source = var.custom_ca_pem
101+
destination = "ca.pem"
102+
}
103+
provisioner "remote-exec" {
104+
inline = [
105+
"sudo mv ~/ca.pem /var/lib/dynatrace/remotepluginmodule/agent/conf/certificates/ca.pem",
106+
"sudo systemctl restart dynatracegateway"
107+
]
108+
}
109+
connection {
110+
type = "ssh"
111+
host = google_compute_instance.activegate.network_interface[0].access_config[0].nat_ip
112+
user = var.gcp_user_name
113+
private_key = file(var.ssh_private_key)
114+
}
115+
depends_on = [null_resource.install_activegate]
116+
}
117+
118+
119+
resource "null_resource" "create_monitoring_configuration" {
120+
depends_on = [ google_compute_instance.activegate, null_resource.upload_extension, null_resource.install_ca_pem, null_resource.install_activegate ]
121+
provisioner "local-exec" {
122+
command = "./start-monitoring.sh ${var.primary_endpoint} ${var.secondary_endpoint} ${var.extension_version} ${var.dynatrace_api_token} ${var.tenant_id}"
123+
}
124+
125+
provisioner "local-exec" {
126+
when = destroy
127+
command = "./stop-monitoring.sh ${self.triggers.token} ${self.triggers.tenant_id}"
128+
}
129+
130+
triggers = {
131+
token = var.dynatrace_api_token
132+
tenant_id = var.tenant_id
133+
}
134+
}

0 commit comments

Comments
 (0)