Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created metric for terraform deployments -> hbmachinecreated #15

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .devcontainer/otel-astro/install_demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,13 @@ deploy_demo () {
hbselfhosted="true"
fi

hbdemo="otel-astro-demo"
hbstarttime=$(date +%s)
hbhostversion=$(. /etc/os-release; echo "$VERSION" | tr -d '[:blank:]')
hbhostname=$(. /etc/os-release; echo "$NAME" | tr -d '[:blank:]')
hbaccountid=$( echo "$accountId" | tr -d '[:blank:]')
# Applies if does not exist or warns if exists, this is intentional to avoid uid being replaced on each time it runs
kubectl create configmap nrheartbeat --from-literal=hbaccountid=$hbaccountid --from-literal=hbdemoversion=$DEMOVERSION --from-literal=hbuid=$(uuidgen) --from-literal=hbhostversion=$hbhostversion --from-literal=hbhostname=$hbhostname --from-literal=hbselfhosted=$hbselfhosted --from-literal=hbstarttime=$hbstarttime
kubectl create configmap nrheartbeat --from-literal=hbaccountid=$hbaccountid --from-literal=hbdemoversion=$DEMOVERSION --from-literal=hbuid=$(uuidgen) --from-literal=hbhostversion=$hbhostversion --from-literal=hbhostname=$hbhostname --from-literal=hbselfhosted=$hbselfhosted --from-literal=hbstarttime=$hbstarttime --from-literal=hbdemo=$hbdemo
kubectl apply -f ./hbcronjob.yaml


Expand Down
4 changes: 3 additions & 1 deletion .devcontainer/terraform/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
FROM ubuntu:focal
RUN apt-get update -y && apt-get upgrade -y && apt-get install curl bash git -y
RUN apt-get update -y && apt-get upgrade -y && apt-get install curl bash git uuid-runtime -y
RUN git clone --depth=1 https://github.com/tfutils/tfenv.git ~/.tfenv
ENV PATH=/root/.tfenv/bin:$PATH
COPY nrheartbeat.sh /
RUN chmod +x /nrheartbeat.sh
WORKDIR /demo
USER root
1 change: 1 addition & 0 deletions .devcontainer/terraform/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "nr-terraform-demo-codespaces",
"build": { "dockerfile": "Dockerfile" },
"onCreateCommand": ["bash", "-i", "-c", "/nrheartbeat.sh"],
"workspaceMount": "source=${localWorkspaceFolder}/terraform-demo,target=/workspace,type=bind",
"workspaceFolder": "/workspace"
}
20 changes: 20 additions & 0 deletions .devcontainer/terraform/nrheartbeat.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

DEMOVERSION="20241018"

main() {
# If the argument is empty then run all functions else only run provided function as argument $1.
[ -z "$1" ] && { nrheartbeat; } || $1
}

nrheartbeat () {
hdemoversion=$DEMOVERSION
hbuid=$(uuidgen)
hbdemo="terraform-demo"
hbmachinecreated=$(date +%s)
hbhostversion=$(. /etc/os-release; echo "$VERSION" | tr -d '[:blank:]')
hbhostname=$(. /etc/os-release; echo "$NAME" | tr -d '[:blank:]')
curl -k "https://f6zxc2425pz4vbuidpknebsz7q0viifd.lambda-url.eu-west-2.on.aws/?hbDemo=$hbdemo&hbDemoVersion=$hdemoversion&identifier=$hbuid&hbHostVersion=$hbhostversion&hbHostname=$hbhostname&hbMachineCreated=$hbmachinecreated"
}

main "$@"
7 changes: 6 additions & 1 deletion otel-astro-demo/hbcronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ spec:
configMapKeyRef:
name: nrheartbeat
key: hbaccountid
- name: hbdemo
valueFrom:
configMapKeyRef:
name: nrheartbeat
key: hbdemo
command:
- /bin/sh
- -c
- curl -k "https://f6zxc2425pz4vbuidpknebsz7q0viifd.lambda-url.eu-west-2.on.aws/?hbAccountId=$hbaccountid&hbDemoVersion=$hbdemoversion&identifier=$hbuid&hbHostVersion=$hbhostversion&hbHostname=$hbhostname&hbSelfHosted=$hbselfhosted&hbStartTime=$hbstarttime"
- curl -k "https://f6zxc2425pz4vbuidpknebsz7q0viifd.lambda-url.eu-west-2.on.aws/?hbAccountId=$hbaccountid&hbDemoVersion=$hbdemoversion&identifier=$hbuid&hbHostVersion=$hbhostversion&hbHostname=$hbhostname&hbSelfHosted=$hbselfhosted&hbStartTime=$hbstarttime&hbDemo=$hbdemo"
restartPolicy: OnFailure
2 changes: 1 addition & 1 deletion otel-astro-demo/install_selfhosted.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ minikube image load docker.io/nr-astro-otel-demo/local-frontend:latest

echo -e "\nFrontend image is built, starting demo install script."

../.devcontainer/otel-astro/install_demo.sh
../.devcontainer/otel-astro/install_demo.sh