Skip to content

Commit

Permalink
feat: add option to enable tracing to GH infrastructure action
Browse files Browse the repository at this point in the history
  • Loading branch information
mrekucci committed Aug 19, 2024
1 parent a445db8 commit 89399b3
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 32 deletions.
19 changes: 16 additions & 3 deletions .github/workflows/infrastructure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ on:
description: 'Debug Deployment'
type: boolean
default: false
tracing:
description: 'Enable Tracing'
type: boolean
default: false
logs:
description: 'Collect Logs'
type: boolean
Expand Down Expand Up @@ -64,23 +68,25 @@ jobs:
sudo systemctl restart systemd-resolved
IS_MANUAL_DEPLOYMENT=$([ "${{ github.event_name }}" == "workflow_dispatch" ] && echo true || echo false)
TARGET_MACHINE_IP=$([ "${IS_MANUAL_DEPLOYMENT}" == "true" ] && echo "$(dig +short ${{ github.event.inputs.target_machine }})" || echo "127.0.0.1")
CLUSTER_ENVIRONMENT_FLAG="--environment devenv"
CLUSTER_PROFILE_FLAG=$([ "${IS_MANUAL_DEPLOYMENT}" == "true" ] && echo "--profile ${{ github.event.inputs.profile }}" || echo "--profile ci")
CLUSTER_LOGS_FLAG=$([ "${{ github.event.inputs.logs }}" == "false" ] && echo "--no-logs-collection" || echo "")
CLUSTER_DATADOG_KEY_FLAG=$([ "${IS_MANUAL_DEPLOYMENT}" == "true" ] && echo "--datadog-key ${{ secrets.DATADOG_API_KEY }}" || echo "")
CLUSTER_L1_RPC_URL_FLAG="--l1-rpc-url ${{ secrets.L1_RPC_URL }}"
CLUSTER_OTEL_COLLECTOR_ENDPOINT_URL_FLAG=$([ "${{ github.event.inputs.tracing }}" == "true" ] && echo "--otel-collector-endpoint-url grpc://${TARGET_MACHINE_IP}:4317" || echo "")
CLUSTER_DEBUG_FLAG=$([ "${{ github.event.inputs.debug }}" == "true" ] && echo "--debug" || echo "")
TARGET_MACHINE_IP=$([ "${IS_MANUAL_DEPLOYMENT}" == "true" ] && echo "$(dig +short ${{ github.event.inputs.target_machine }})" || echo "127.0.0.1")
echo "RUNNER_START_TIME=${RUNNER_START_TIME}" >> ${GITHUB_ENV}
echo "IS_MANUAL_DEPLOYMENT=${IS_MANUAL_DEPLOYMENT}" >> ${GITHUB_ENV}
echo "TARGET_MACHINE_IP=${TARGET_MACHINE_IP}" >> ${GITHUB_ENV}
echo "CLUSTER_ENVIRONMENT_FLAG=${CLUSTER_ENVIRONMENT_FLAG}" >> ${GITHUB_ENV}
echo "CLUSTER_PROFILE_FLAG=${CLUSTER_PROFILE_FLAG}" >> ${GITHUB_ENV}
echo "CLUSTER_LOGS_FLAG=${CLUSTER_LOGS_FLAG}" >> ${GITHUB_ENV}
echo "CLUSTER_DATADOG_KEY_FLAG=${CLUSTER_DATADOG_KEY_FLAG}" >> ${GITHUB_ENV}
echo "CLUSTER_L1_RPC_URL_FLAG=${CLUSTER_L1_RPC_URL_FLAG}" >> ${GITHUB_ENV}
echo "CLUSTER_OTEL_COLLECTOR_ENDPOINT_URL_FLAG=${CLUSTER_OTEL_COLLECTOR_ENDPOINT_URL_FLAG}" >> ${GITHUB_ENV}
echo "CLUSTER_DEBUG_FLAG=${CLUSTER_DEBUG_FLAG}" >> ${GITHUB_ENV}
echo "TARGET_MACHINE_IP=${TARGET_MACHINE_IP}" >> ${GITHUB_ENV}
- name: Notify - Deployment Initialized
if: ${{ env.IS_MANUAL_DEPLOYMENT == 'true' }}
Expand Down Expand Up @@ -203,7 +209,14 @@ jobs:
- name: Deploy Cluster
run: |
START_TIME="$(date +%s)"
./cluster.sh deploy ${CLUSTER_ENVIRONMENT_FLAG} ${CLUSTER_PROFILE_FLAG} ${CLUSTER_LOGS_FLAG} ${CLUSTER_DATADOG_KEY_FLAG} ${CLUSTER_L1_RPC_URL_FLAG} ${CLUSTER_DEBUG_FLAG}
./cluster.sh deploy \
${CLUSTER_ENVIRONMENT_FLAG} \
${CLUSTER_PROFILE_FLAG} \
${CLUSTER_LOGS_FLAG} \
${CLUSTER_DATADOG_KEY_FLAG} \
${CLUSTER_L1_RPC_URL_FLAG} \
${CLUSTER_OTEL_COLLECTOR_ENDPOINT_URL_FLAG} \
${CLUSTER_DEBUG_FLAG}
END_TIME="$(date +%s)"
echo "DEPLOY_DURATION=$(date -ud "@$((END_TIME - START_TIME))" +'%H:%M:%S')" >> ${GITHUB_ENV}
working-directory: infrastructure/nomad
Expand Down
52 changes: 32 additions & 20 deletions infrastructure/nomad/cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,36 @@ environment_name="devenv"
profile_name="devnet"
datadog_key=""
l1_rpc_url=""
otel_collector_endpoint_url=""

help() {
echo "Usage:"
echo "$0 [init [--environment <name=devenv>] [--skip-certificates-setup] [--debug]]"
echo "$0 [deploy [version=HEAD] [--environment <name=devenv>] [--profile <name=devnet>] [--force-build-templates] [--no-logs-collection] [--datadog-key <key>] [--l1-rpc-url <url>] [--release] [--debug]]"
echo "$0 [deploy [version=HEAD] [--environment <name=devenv>] [--profile <name=devnet>] [--force-build-templates] [--no-logs-collection] [--datadog-key <key>] [--l1-rpc-url <url>] [--otel-collector-endpoint-url <url>] [--release] [--debug]]"
echo "$0 [destroy [--debug]] [--help]"
echo "$0 --help"
echo
echo "Parameters:"
echo " init Initialize the environment."
echo " --environment <name=devenv> Specify the environment to use (default is devenv)."
echo " --skip-certificates-setup Skip the certificates installation and setup."
echo " --debug Enable debug mode for detailed output."
echo " init Initialize the environment."
echo " --environment <name=devenv> Specify the environment to use (default is devenv)."
echo " --skip-certificates-setup Skip the certificates installation and setup."
echo " --debug Enable debug mode for detailed output."
echo
echo " deploy [version=HEAD] Deploy the specified artifact version (a git commit hash or an existing AWS S3 tag). If not specified or set to HEAD, a local build is triggered."
echo " --environment <name=devenv> Specify the environment to use (default is devenv)."
echo " --profile <name=devnet> Specify the profile to use (default is devnet)."
echo " --force-build-templates Force the build of all job templates before deployment."
echo " --no-logs-collection Disable the collection of logs from deployed jobs."
echo " --datadog-key <key> Datadog API key, cannot be empty."
echo " --l1-rpc-url <url> L1 RPC URL, cannot be empty."
echo " --release It will ignore the specified deployment version and use the current HEAD tag as the build version."
echo " --debug Enable debug mode for detailed output."
echo " deploy [version=HEAD] Deploy the specified artifact version (a git commit hash or an existing AWS S3 tag). If not specified or set to HEAD, a local build is triggered."
echo " --environment <name=devenv> Specify the environment to use (default is devenv)."
echo " --profile <name=devnet> Specify the profile to use (default is devnet)."
echo " --force-build-templates Force the build of all job templates before deployment."
echo " --no-logs-collection Disable the collection of logs from deployed jobs."
echo " --datadog-key <key> Datadog API key, cannot be empty."
echo " --l1-rpc-url <url> L1 RPC URL, cannot be empty."
echo " --otel-collector-endpoint-url <url> OpenTelemetry Collector Endpoint URL, cannot be empty."
echo " --release It will ignore the specified deployment version and use the current HEAD tag as the build version."
echo " --debug Enable debug mode for detailed output."
echo
echo " destroy Destroy the whole cluster."
echo " --debug Enable debug mode for detailed output."
echo " destroy Destroy the whole cluster."
echo " --debug Enable debug mode for detailed output."
echo
echo " --help Display this help message."
echo " --help Display this help message."
echo
echo "Examples:"
echo " Initialize with default environment and profile:"
Expand All @@ -66,8 +68,8 @@ help() {
echo " Deploy with a specific version, environment, profile and force to build all job templates:"
echo " $0 deploy v0.1.0 --environment devenv --profile testnet --force-build-templates"
echo
echo " Deploy with a specific version, environment, profile in debug mode with disabled logs collection, Datadog API key and L1 RPC URL:"
echo " $0 deploy v0.1.0 --environment devenv --profile testnet --no-logs-collection --datadog-key your_datadog_key --l1-rpc-url your_rpc_url --debug"
echo " Deploy with a specific version, environment, profile in debug mode with disabled logs collection, Datadog API key, L1 RPC URL, and OpenTememetry Collector Endpoint URL:"
echo " $0 deploy v0.1.0 --environment devenv --profile testnet --no-logs-collection --datadog-key your_datadog_key --l1-rpc-url your_rpc_url --otel-collector-endpoint-url your_otel_url --debug"
echo
echo " Destroy with specific environment and debug mode:"
echo " $0 destroy --environment devenv --debug"
Expand All @@ -77,7 +79,7 @@ help() {
usage() {
echo "Usage:"
echo "$0 [init [--environment <name=devenv>] [--skip-certificates-setup] [--debug]]"
echo "$0 [deploy [version=HEAD] [--environment <name=devenv>] [--profile <name=devnet>] [--force-build-templates] [--no-logs-collection] [--datadog-key <key>] [--l1-rpc-url <url>] [--release] [--debug]]"
echo "$0 [deploy [version=HEAD] [--environment <name=devenv>] [--profile <name=devnet>] [--force-build-templates] [--no-logs-collection] [--datadog-key <key>] [--l1-rpc-url <url>] [--otel-collector-endpoint-url <url>] [--release] [--debug]]"
echo "$0 [destroy [--debug]] [--help]"
echo "$0 --help"
exit 1
Expand Down Expand Up @@ -216,6 +218,15 @@ parse_args() {
usage
fi
fi
if [[ $# -gt 0 && $1 == "--otel-collector-endpoint-url" ]]; then
if [[ $# -gt 1 && ! $2 =~ ^-- ]]; then
otel_collector_endpoint_url="$2"
shift 2
else
echo "Error: --otel-collector-endpoint-url requires a value."
usage
fi
fi
if [[ $# -gt 0 && $1 == "--release" ]]; then
release_flag=true
shift
Expand Down Expand Up @@ -272,6 +283,7 @@ main() {
[[ "${force_build_templates_flag}" == true ]] && flags+=("--extra-vars" "build_templates=true")
[[ -n "${datadog_key}" ]] && flags+=("--extra-vars" "datadog_key=${datadog_key}")
[[ -n "${l1_rpc_url}" ]] && flags+=("--extra-vars" "l1_rpc_url=${l1_rpc_url}")
[[ -n "${otel_collector_endpoint_url}" ]] && flags+=("--extra-vars" "otel_collector_endpoint_url=${otel_collector_endpoint_url}")
[[ "${release_flag}" == true ]] && flags+=("--extra-vars" "release=true")
;;
"${destroy_flag}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ job "{{ job.name }}" {
if job.get('env') and job.env.get('log-tags')
else 'service:' + job.name + '-{{ env "NOMAD_ALLOC_INDEX" }}'
}}"
EMULATOR_OTEL_COLLECTOR_ENDPOINT_URL="{{ job.env.get('otel-collector-endpoint-url', '') }}"
EMULATOR_OTEL_COLLECTOR_ENDPOINT_URL="{{ job.env.get('otel_collector_endpoint_url', '') }}"
{%- raw %}
{{- $idx := add (env "NOMAD_ALLOC_INDEX" | parseInt) 1 }}
{{- range nomadService (printf "%s%d" "{% endraw %}{{ job.target_name }}{% raw %}" $idx) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ job "{{ job.name }}" {
if job.env['log-tags'] is defined and job.env['log-tags']
else 'service:' + job.name + '-{{ env "NOMAD_ALLOC_INDEX" }}'
}}"
MEV_COMMIT_OTEL_COLLECTOR_ENDPOINT_URL="{{ job.env['otel-collector-endpoint-url'] }}"
MEV_COMMIT_OTEL_COLLECTOR_ENDPOINT_URL="{{ job.env.get('otel_collector_endpoint_url', '') }}"
{%- raw %}
MEV_COMMIT_KEYSTORE_PATH="/local/data-{{ env "NOMAD_ALLOC_INDEX" }}/keystore"
MEV_COMMIT_KEYSTORE_FILENAME="{{ with secret "secret/data/mev-commit" }}{{ .Data.data.{% endraw %}{{ job.artifacts | selectattr('keystore', 'defined') | map(attribute='keystore.name') | first }}{% raw %}_filename }}{{ end }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ job "{{ job.name }}" {
{% endif %}

artifact {
source = "https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.107.0/otelcol-contrib_0.107.0_linux_{{ 'x64' if target_system_architecture == 'x86_64' else 'arm64' }}.tar.gz"
source = "https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.107.0/otelcol-contrib_0.107.0_linux_{{ 'amd64' if target_system_architecture == 'x86_64' else 'arm64' }}.tar.gz"
}

template {
Expand Down
11 changes: 5 additions & 6 deletions infrastructure/nomad/playbooks/variables/profiles.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
datacenter: "dc1"
otel_collector_endpoint_url: "grpc://{{ ansible_facts['default_ipv4']['address'] }}:4317"

artifacts:
bidder_emulator: &bidder_emulator_artifact
Expand Down Expand Up @@ -146,7 +145,7 @@ jobs:
type: bootnode
tls_crt_file: "{{ tls_crt_file }}"
tls_key_file: "{{ tls_key_file }}"
otel-collector-endpoint-url: "{{ otel_collector_endpoint_url }}"
otel_collector_endpoint_url: "{{ otel_collector_endpoint_url }}"

mev_commit_provider_node1: &mev_commit_provider_node1_job
name: mev-commit-provider-node1
Expand All @@ -173,7 +172,7 @@ jobs:
nat_address: "{{ ansible_facts['default_ipv4']['address'] }}"
tls_crt_file: "{{ tls_crt_file }}"
tls_key_file: "{{ tls_key_file }}"
otel-collector-endpoint-url: "{{ otel_collector_endpoint_url }}"
otel_collector_endpoint_url: "{{ otel_collector_endpoint_url }}"

mev_commit_provider_node2: &mev_commit_provider_node2_job
name: mev-commit-provider-node2
Expand Down Expand Up @@ -257,7 +256,7 @@ jobs:
- metrics:
to: 8080
env:
otel-collector-endpoint-url: "{{ otel_collector_endpoint_url }}"
otel_collector_endpoint_url: "{{ otel_collector_endpoint_url }}"

mev-commit-provider-emulator-nodes: &mev_commit_provider_emulator_nodes_job
name: mev-commit-provider-emulator-nodes
Expand Down Expand Up @@ -295,7 +294,7 @@ jobs:
type: bidder
tls_crt_file: "{{ tls_crt_file }}"
tls_key_file: "{{ tls_key_file }}"
otel-collector-endpoint-url: "{{ otel_collector_endpoint_url }}"
otel_collector_endpoint_url: "{{ otel_collector_endpoint_url }}"

mev_commit_bidder_node2: &mev_commit_bidder_node2_job
name: mev-commit-bidder-node2
Expand Down Expand Up @@ -440,7 +439,7 @@ jobs:
to: 8080
env:
l1_rpc_url: "{{ l1_rpc_url }}"
otel-collector-endpoint-url: "{{ otel_collector_endpoint_url }}"
otel_collector_endpoint_url: "{{ otel_collector_endpoint_url }}"

mev_commit_bidder_emulator_nodes: &mev_commit_bidder_emulator_nodes_job
name: mev-commit-bidder-emulator-nodes
Expand Down

0 comments on commit 89399b3

Please sign in to comment.