Skip to content

Commit

Permalink
demo: generate correlation headers (#1074)
Browse files Browse the repository at this point in the history
This change mimics the HTTP headers sent by ARM in a real setup. It will
help verifying that request IDs are logged and propagated across
services in a development setup.

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
  • Loading branch information
simonpasquier authored Jan 10, 2025
1 parent bac3640 commit e6425f1
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 15 deletions.
4 changes: 3 additions & 1 deletion demo/01-register-sub.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

curl -i -X PUT "localhost:8443/subscriptions/1d3378d3-5a3f-4712-85a1-2485495dfc4b?api-version=2.0" --json '{"state":"Registered", "registrationDate": "now", "properties": { "tenantId": "64dc69e4-d083-49fc-9569-ebece1dd1408"}}'
source "$(dirname "$0")"/common.sh

correlation_headers | curl -si -H @- -X PUT "localhost:8443/subscriptions/1d3378d3-5a3f-4712-85a1-2485495dfc4b?api-version=2.0" --json '{"state":"Registered", "registrationDate": "now", "properties": { "tenantId": "64dc69e4-d083-49fc-9569-ebece1dd1408"}}'
7 changes: 3 additions & 4 deletions demo/03-create-cluster.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/bash

source env_vars

CURRENT_DATE=$(date -u +"%Y-%m-%dT%H:%M:%S+00:00")
source "$(dirname "$0")"/common.sh

CLUSTER_TMPL_FILE="cluster.tmpl.json"
CLUSTER_FILE="cluster.json"
Expand All @@ -17,6 +16,6 @@ jq \
--arg nsg_id "$NSG_ID" \
'.properties.spec.platform.managedResourceGroup = $managed_rg | .properties.spec.platform.subnetId = $subnet_id | .properties.spec.platform.networkSecurityGroupId = $nsg_id' "${CLUSTER_TMPL_FILE}" > ${CLUSTER_FILE}

curl -i -X PUT "localhost:8443/subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${CUSTOMER_RG_NAME}/providers/Microsoft.RedHatOpenshift/hcpOpenShiftClusters/${CLUSTER_NAME}?api-version=2024-06-10-preview" \
--header "X-Ms-Arm-Resource-System-Data: {\"createdBy\": \"${USER}\", \"createdByType\": \"User\", \"createdAt\": \"${CURRENT_DATE}\"}" \
(arm_system_data_header; correlation_headers) | curl -si -X PUT "localhost:8443/subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${CUSTOMER_RG_NAME}/providers/Microsoft.RedHatOpenshift/hcpOpenShiftClusters/${CLUSTER_NAME}?api-version=2024-06-10-preview" \
--header @- \
--json @${CLUSTER_FILE}
10 changes: 3 additions & 7 deletions demo/04-create-nodepool.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/bash

source env_vars

CURRENT_DATE=$(date -u +"%Y-%m-%dT%H:%M:%S+00:00")
source "$(dirname "$0")"/common.sh

NODEPOOL_TMPL_FILE="node_pool.tmpl.json"
NODEPOOL_FILE="node_pool.json"
Expand All @@ -11,12 +10,9 @@ SUBNET_ID=$(az network vnet subnet show -g ${CUSTOMER_RG_NAME} --vnet-name ${CUS
SUBSCRIPTION_ID=$(az account show --query id -o tsv)

jq \
--arg managed_rg "$MANAGED_RESOURCE_GROUP" \
--arg subnet_id "$SUBNET_ID" \
--arg nsg_id "$NSG_ID" \
'.properties.spec.platform.subnetId = $subnet_id' "${NODEPOOL_TMPL_FILE}" > ${NODEPOOL_FILE}


curl -i -X PUT "localhost:8443/subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${CUSTOMER_RG_NAME}/providers/Microsoft.RedHatOpenshift/hcpOpenShiftClusters/${CLUSTER_NAME}/nodePools/${NP_NAME}?api-version=2024-06-10-preview" \
--header "X-Ms-Arm-Resource-System-Data: {\"createdBy\": \"${USER}\", \"createdByType\": \"User\", \"createdAt\": \"${CURRENT_DATE}\"}" \
(arm_system_data_header; correlation_headers) | curl -si -X PUT "localhost:8443/subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${CUSTOMER_RG_NAME}/providers/Microsoft.RedHatOpenshift/hcpOpenShiftClusters/${CLUSTER_NAME}/nodePools/${NP_NAME}?api-version=2024-06-10-preview" \
--header @- \
--json @${NODEPOOL_FILE}
4 changes: 3 additions & 1 deletion demo/05-delete-cluster.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash

source env_vars
source "$(dirname "$0")"/common.sh

SUBSCRIPTION_ID=$(az account show --query id -o tsv)

curl -i -X DELETE "localhost:8443/subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${CUSTOMER_RG_NAME}/providers/Microsoft.RedHatOpenshift/hcpOpenShiftClusters/${CLUSTER_NAME}?api-version=2024-06-10-preview"
correlation_headers | curl -si -H @- -X DELETE "localhost:8443/subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${CUSTOMER_RG_NAME}/providers/Microsoft.RedHatOpenshift/hcpOpenShiftClusters/${CLUSTER_NAME}?api-version=2024-06-10-preview"
15 changes: 15 additions & 0 deletions demo/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

arm_system_data_header() {
echo "X-Ms-Arm-Resource-System-Data: {\"createdBy\": \"${USER}\", \"createdByType\": \"User\", \"createdAt\": \"$(date -u +"%Y-%m-%dT%H:%M:%S+00:00")\"}"
}

correlation_headers() {
local HEADERS=( )
if [ -n "$(which uuidgen 2> /dev/null)" ]; then
HEADERS+=( "X-Ms-Correlation-Request-Id: $(uuidgen)" )
HEADERS+=( "X-Ms-Client-Request-Id: $(uuidgen)" )
HEADERS+=( "X-Ms-Return-Client-Request-Id: true" )
fi
printf '%s\n' "${HEADERS[@]}"
}
3 changes: 2 additions & 1 deletion demo/query-cluster-rp.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash

source env_vars
source "$(dirname "$0")"/common.sh

SUBSCRIPTION_ID=$(az account show --query id -o tsv)

curl "localhost:8443/subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${CUSTOMER_RG_NAME}/providers/Microsoft.RedHatOpenshift/hcpOpenShiftClusters/${CLUSTER_NAME}?api-version=2024-06-10-preview" | jq
correlation_headers | curl -s -H @- "localhost:8443/subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${CUSTOMER_RG_NAME}/providers/Microsoft.RedHatOpenshift/hcpOpenShiftClusters/${CLUSTER_NAME}?api-version=2024-06-10-preview" | jq
3 changes: 2 additions & 1 deletion demo/query-nodepool-rp.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash

source env_vars
source "$(dirname "$0")"/common.sh

SUBSCRIPTION_ID=$(az account show --query id -o tsv)

curl "localhost:8443/subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${CUSTOMER_RG_NAME}/providers/Microsoft.RedHatOpenshift/hcpOpenShiftClusters/${CLUSTER_NAME}/nodePools/${NP_NAME}?api-version=2024-06-10-preview" | jq
correlation_headers | curl -s -H @- "localhost:8443/subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${CUSTOMER_RG_NAME}/providers/Microsoft.RedHatOpenshift/hcpOpenShiftClusters/${CLUSTER_NAME}/nodePools/${NP_NAME}?api-version=2024-06-10-preview" | jq

0 comments on commit e6425f1

Please sign in to comment.