From 15cd9ff77d1ded178c4fa080d4a9f5c6997228d1 Mon Sep 17 00:00:00 2001 From: Stephen Pu Date: Wed, 18 Nov 2026 22:03:19 -0800 Subject: [PATCH 1/4] Parameterize shared Alluxio steps for a second pipeline MountBlobStorage takes the container, SAS variable and mount path, and derives the UFS and step names from the path, so one job can mount several containers. RecordRunConfiguration takes an optional benchmark record whose default reproduces the warp values; each recorded node pool carries its VM size's published network limit. The diagnostics step becomes the shared CollectDiagnostics. The warp pipeline's generated YAML changes only in its mount step and loses the documentation-link comment in the configuration step, which now lives in the KCL source. --- kcl/alluxio/warp/pipeline.k | 29 ++------ kcl/alluxio/warp/pipeline.yaml | 9 ++- kcl/lib/steps/alluxio/diagnostics.k | 31 ++++++++ kcl/lib/steps/alluxio/install.k | 19 +++-- .../steps/alluxio/record_run_configuration.k | 73 +++++++++++++++++-- 5 files changed, 120 insertions(+), 41 deletions(-) create mode 100644 kcl/lib/steps/alluxio/diagnostics.k diff --git a/kcl/alluxio/warp/pipeline.k b/kcl/alluxio/warp/pipeline.k index 4ea7b376c7..9f608eac7c 100644 --- a/kcl/alluxio/warp/pipeline.k +++ b/kcl/alluxio/warp/pipeline.k @@ -156,6 +156,9 @@ az aks create \\ alluxio.MountBlobStorage( const.DEFAULT_SERVICE_CONNECTION STORAGE_ACCOUNT + "warp-data" + "BLOB_SAS" + "/blob" "${CHECKS_DIR}/ufs.yaml" WORK_DIR RESULT_DIR @@ -192,30 +195,10 @@ kubectl exec -n alx-ns warp-client -c warp \\ CHECKS_DIR ) common.RecordCurrentTime("BENCHMARK_END_TIME") - azure.AzCli( + alluxio.CollectDiagnostics( const.DEFAULT_SERVICE_CONNECTION - "Collect safe deployment diagnostics" - alluxio.ShellSetup(WORK_DIR, RESULT_DIR) + """ -if [[ ! -s "$KUBECONFIG" ]]; then - echo '{"cluster_access":"not established"}' > "${RESULT_DIR}/diagnostics.json" - exit 0 -fi -for namespace in alx-ns alluxio-operator; do - kubectl get pods -n "$namespace" -o json | - jq --arg namespace "$namespace" '{ - ($namespace): [.items[] | { - name: .metadata.name, node: .spec.nodeName, phase: .status.phase, - containers: [(.status.containerStatuses // []) + (.status.initContainerStatuses // []) | .[] | - {name, ready, restarts: .restartCount, - state: (.state | with_entries(.value |= {reason, exitCode}))}] - }] - }' > "${WORK_DIR}/diagnostics-$namespace.json" -done -jq -s 'add' "${WORK_DIR}/diagnostics-alx-ns.json" "${WORK_DIR}/diagnostics-alluxio-operator.json" \\ - > "${RESULT_DIR}/diagnostics.json" -""" - condition = "always()" - stepName = "alluxio_diagnostics" + WORK_DIR + RESULT_DIR ) steps.Task { task = "PublishPipelineArtifact@1" diff --git a/kcl/alluxio/warp/pipeline.yaml b/kcl/alluxio/warp/pipeline.yaml index d410373ab8..32e8f13ae3 100644 --- a/kcl/alluxio/warp/pipeline.yaml +++ b/kcl/alluxio/warp/pipeline.yaml @@ -79,7 +79,6 @@ jobs: --arg operator_version "3.7.6" --arg warp_version "1.3.1" \ '$ARGS.named + { worker_cache: "8Gi", worker_cache_reserved: "1Gi", - # Published per-VM limit across all NICs: https://learn.microsoft.com/en-us/azure/virtual-machines/sizes/general-purpose/dsv6-series#tab/sizenetwork support_nodes: {count: 3, sku: "Standard_D8s_v6", max_egress_mbps_per_vm: 12500}, worker_nodes: {count: 1, sku: "Standard_D16s_v6", max_egress_mbps_per_vm: 12500}, client_nodes: {count: 1, sku: "Standard_D8s_v6", max_egress_mbps_per_vm: 12500} @@ -580,7 +579,9 @@ jobs: } require_secret BLOB_SAS ufs="$(jq -n --arg account "alx$(Build.BuildId)a$(System.JobAttempt)" '{ - spec: {path: ("abfs://" + $account + ".blob.core.windows.net/warp-data/"), + metadata: {name: "alluxio-blob"}, + spec: {mountPath: "/blob", + path: ("abfs://" + $account + ".blob.core.windows.net/warp-data/"), mountOptions: {"alluxio.underfs.abfs.sas.token": env.BLOB_SAS}} }' | kubectl patch --local --type=merge -f "$(Build.SourcesDirectory)/kcl/alluxio/warp/ufs.yaml" \ --patch-file /dev/stdin -o yaml 2> >(redact >&2))" @@ -591,10 +592,10 @@ jobs: wait_phase ufs alluxio-blob phase Ready kubectl exec -n alx-ns alluxio-coordinator-0 \ -c alluxio-coordinator -- alluxio fs ls /blob | redact - displayName: Mount Azure Blob in Alluxio + displayName: Mount Azure Blob at /blob env: BLOB_SAS: $(BLOB_SAS) - name: alluxio_mount + name: alluxio_mount_blob - task: AzureCLI@2 inputs: azureSubscription: Azure-for-Telescope-internal diff --git a/kcl/lib/steps/alluxio/diagnostics.k b/kcl/lib/steps/alluxio/diagnostics.k new file mode 100644 index 0000000000..b5d04821b0 --- /dev/null +++ b/kcl/lib/steps/alluxio/diagnostics.k @@ -0,0 +1,31 @@ +import azure_pipelines.ap.steps +import lib.steps.azure + +# Pod states of the Alluxio and operator namespaces; no logs, no secrets. Runs even when the job failed. +CollectDiagnostics = lambda serviceConnection: str, workDir: str, resultDir: str -> steps.Step { + azure.AzCli( + serviceConnection + "Collect safe deployment diagnostics" + ShellSetup(workDir, resultDir) + """ +if [[ ! -s "$KUBECONFIG" ]]; then + echo '{"cluster_access":"not established"}' > "${resultDir}/diagnostics.json" + exit 0 +fi +for namespace in alx-ns alluxio-operator; do + kubectl get pods -n "$namespace" -o json | + jq --arg namespace "$namespace" '{ + ($namespace): [.items[] | { + name: .metadata.name, node: .spec.nodeName, phase: .status.phase, + containers: [(.status.containerStatuses // []) + (.status.initContainerStatuses // []) | .[] | + {name, ready, restarts: .restartCount, + state: (.state | with_entries(.value |= {reason, exitCode}))}] + }] + }' > "${workDir}/diagnostics-$namespace.json" +done +jq -s 'add' "${workDir}/diagnostics-alx-ns.json" "${workDir}/diagnostics-alluxio-operator.json" \\ + > "${resultDir}/diagnostics.json" +""" + condition = "always()" + stepName = "alluxio_diagnostics" + ) +} diff --git a/kcl/lib/steps/alluxio/install.k b/kcl/lib/steps/alluxio/install.k index a99858a008..49f7ff7d23 100644 --- a/kcl/lib/steps/alluxio/install.k +++ b/kcl/lib/steps/alluxio/install.k @@ -63,14 +63,18 @@ done ) } -MountBlobStorage = lambda serviceConnection: str, storageAccount: str, manifest: str, workDir: str, resultDir: str -> steps.Step { +MountBlobStorage = lambda serviceConnection: str, storageAccount: str, container: str, sasVariable: str, mountPath: str, manifest: str, workDir: str, resultDir: str -> steps.Step { + # The UFS resource is named after the mount path: /blob becomes alluxio-blob. + ufsName = "alluxio" + mountPath.replace("/", "-") azure.AzCli( serviceConnection - "Mount Azure Blob in Alluxio" + "Mount Azure Blob at ${mountPath}" ShellSetup(workDir, resultDir) + ResourceCommands(workDir) + REDACT_OUTPUT + """ require_secret BLOB_SAS ufs="$(jq -n --arg account "${storageAccount}" '{ - spec: {path: ("abfs://" + $account + ".blob.core.windows.net/warp-data/"), + metadata: {name: "${ufsName}"}, + spec: {mountPath: "${mountPath}", + path: ("abfs://" + $account + ".blob.core.windows.net/${container}/"), mountOptions: {"alluxio.underfs.abfs.sas.token": env.BLOB_SAS}} }' | kubectl patch --local --type=merge -f "${manifest}" \\ --patch-file /dev/stdin -o yaml 2> >(redact >&2))" @@ -78,11 +82,12 @@ printf '%s\\n' "$ufs" | kubectl create --dry-run=server --validate=strict -f - > /dev/null 2> >(redact >&2) printf '%s\\n' "$ufs" | kubectl create -f - > /dev/null 2> >(redact >&2) unset ufs -wait_phase ufs alluxio-blob phase Ready +wait_phase ufs ${ufsName} phase Ready kubectl exec -n alx-ns alluxio-coordinator-0 \\ - -c alluxio-coordinator -- alluxio fs ls /blob | redact + -c alluxio-coordinator -- alluxio fs ls ${mountPath} | redact """ - stepName = "alluxio_mount" - env = {BLOB_SAS = "$(BLOB_SAS)"} + stepName = "alluxio_mount" + mountPath.replace("/", "_") + # Mapped to BLOB_SAS so the script and redact() handle every mount's token alike. + env = {BLOB_SAS = "$(${sasVariable})"} ) } diff --git a/kcl/lib/steps/alluxio/record_run_configuration.k b/kcl/lib/steps/alluxio/record_run_configuration.k index 11cf7d96fe..296b06629f 100644 --- a/kcl/lib/steps/alluxio/record_run_configuration.k +++ b/kcl/lib/steps/alluxio/record_run_configuration.k @@ -1,7 +1,67 @@ import azure_pipelines.ap.steps import lib.steps.azure -RecordRunConfiguration = lambda serviceConnection: str, registryName: str, registrySubscription: str, alluxioImage: str, operatorImage: str, operatorChart: str, subscription: str, resourceGroup: str, cluster: str, location: str, storageAccount: str, workDir: str, resultDir: str -> steps.Step { +# RecordedNodePool is a pool written to configuration.json with its VM size's published network +# limit, the maximum bandwidth per VM across all NICs (the "Max Network Bandwidth" column in the +# size series' Network tab, e.g. +# https://learn.microsoft.com/en-us/azure/virtual-machines/sizes/general-purpose/dsv6-series#tab/sizenetwork). +schema RecordedNodePool: + pool: azure.NodePool + maxEgressMbpsPerVm: int + +# RecordedNodePools are the pools whose sizes are written to configuration.json. +schema RecordedNodePools: + support: RecordedNodePool + worker: RecordedNodePool + client: RecordedNodePool + +WARP_NODE_POOLS = RecordedNodePools { + support = RecordedNodePool { + pool = azure.NodePool { + name = "systempool" + sku = "Standard_D8s_v6" + count = 3 + } + maxEgressMbpsPerVm = 12500 + } + worker = RecordedNodePool { + pool = azure.NodePool { + name = "workerpool" + sku = "Standard_D16s_v6" + count = 1 + } + maxEgressMbpsPerVm = 12500 + } + client = RecordedNodePool { + pool = azure.NodePool { + name = "clientpool" + sku = "Standard_D8s_v6" + count = 1 + } + maxEgressMbpsPerVm = 12500 + } +} + +# RecordedBenchmark is the benchmark-specific part of configuration.json: the node pools, the +# worker page-store sizes and the version of the load-generating client. Callers pass their own; +# the default is the warp pipeline's record. clientVersionKey names the JSON field that holds +# clientVersion (warp_version for warp, curl_version for the S3 read pipeline). +schema RecordedBenchmark: + nodePools: RecordedNodePools + workerCache: str + workerCacheReserved: str + clientVersionKey: "warp_version" | "curl_version" + clientVersion: str + +WARP_BENCHMARK = RecordedBenchmark { + nodePools = WARP_NODE_POOLS + workerCache = "8Gi" + workerCacheReserved = "1Gi" + clientVersionKey = "warp_version" + clientVersion = "1.3.1" +} + +RecordRunConfiguration = lambda serviceConnection: str, registryName: str, registrySubscription: str, alluxioImage: str, operatorImage: str, operatorChart: str, subscription: str, resourceGroup: str, cluster: str, location: str, storageAccount: str, workDir: str, resultDir: str, benchmark: RecordedBenchmark = WARP_BENCHMARK -> steps.Step { azure.AzCli( serviceConnection "Record run configuration and image digests" @@ -35,13 +95,12 @@ jq -n \\ --arg cluster "$cluster" --arg location "$location" --arg storage_account "${storageAccount}" \\ --argjson image_digests "$images" \\ --arg operator_chart "${operatorChart}" \\ - --arg operator_version "${OPERATOR_TAG}" --arg warp_version "1.3.1" \\ + --arg operator_version "${OPERATOR_TAG}" --arg ${benchmark.clientVersionKey} "${benchmark.clientVersion}" \\ '$ARGS.named + { - worker_cache: "8Gi", worker_cache_reserved: "1Gi", - # Published per-VM limit across all NICs: https://learn.microsoft.com/en-us/azure/virtual-machines/sizes/general-purpose/dsv6-series#tab/sizenetwork - support_nodes: {count: 3, sku: "Standard_D8s_v6", max_egress_mbps_per_vm: 12500}, - worker_nodes: {count: 1, sku: "Standard_D16s_v6", max_egress_mbps_per_vm: 12500}, - client_nodes: {count: 1, sku: "Standard_D8s_v6", max_egress_mbps_per_vm: 12500} + worker_cache: "${benchmark.workerCache}", worker_cache_reserved: "${benchmark.workerCacheReserved}", + support_nodes: {count: ${benchmark.nodePools.support.pool.count}, sku: "${benchmark.nodePools.support.pool.sku}", max_egress_mbps_per_vm: ${benchmark.nodePools.support.maxEgressMbpsPerVm}}, + worker_nodes: {count: ${benchmark.nodePools.worker.pool.count}, sku: "${benchmark.nodePools.worker.pool.sku}", max_egress_mbps_per_vm: ${benchmark.nodePools.worker.maxEgressMbpsPerVm}}, + client_nodes: {count: ${benchmark.nodePools.client.pool.count}, sku: "${benchmark.nodePools.client.pool.sku}", max_egress_mbps_per_vm: ${benchmark.nodePools.client.maxEgressMbpsPerVm}} }' > "${resultDir}/configuration.json" """ ) From ace3e6c60d5e41e8afb2e693fe9233522b6831b6 Mon Sep 17 00:00:00 2001 From: Stephen Pu Date: Wed, 18 Nov 2026 22:03:19 -0800 Subject: [PATCH 2/4] Add a curl client and result checks for S3 read benchmarks s3c.sh sends the same requests at the same concurrency to Alluxio's S3 API (SigV4) or to Azure Blob directly (REST + SAS); only the endpoint differs. Every request on both sides retries transient errors (408, 429, 500, 502, 503, 504, truncated bodies, connect timeouts) up to 3 times, as Azure Blob clients do; after retries it accepts only 200/206 with the exact expected size, and every request has a timeout. Each run reports its retries and its failed requests by status and size. Each curl run starts with an unmeasured HEAD to every host its requests use, so the measured requests reuse an open connection on both sides instead of paying for DNS, TCP and TLS on Blob and an in-cluster TCP connect on Alluxio. Each run reports how many measured requests still opened a connection, and its per-request time limit. HOST_OFFSET lets clients that read the same keys at the same time start on different hosts. checks.jq validates each run, checks that an Alluxio run read almost nothing from the UFS, summarizes the scenarios and attributes Blob egress for the checkpoint load. All jq runs on jq 1.6 and later. --- kcl/alluxio/s3_read/checks.jq | 239 +++++++++++++++++++++++++++++++ kcl/alluxio/s3_read/s3c.sh | 256 ++++++++++++++++++++++++++++++++++ 2 files changed, 495 insertions(+) create mode 100644 kcl/alluxio/s3_read/checks.jq create mode 100755 kcl/alluxio/s3_read/s3c.sh diff --git a/kcl/alluxio/s3_read/checks.jq b/kcl/alluxio/s3_read/checks.jq new file mode 100644 index 0000000000..1e593b7da5 --- /dev/null +++ b/kcl/alluxio/s3_read/checks.jq @@ -0,0 +1,239 @@ +# A directory marker is a blob whose name ends in "/" or that carries the +# hdi_isfolder metadata (requires `az storage blob list --include m`). +# abfs v2 would otherwise treat such a marker as a file. +def count_directory_markers: + [.[] | select((.name | endswith("/")) or (.metadata.hdi_isfolder == "true"))] | length; + +def validate_s3_read_dataset: + [range(0; 16) | "object-" + (if . < 10 then "0" else "" end) + tostring + ".bin"] as $big_names + | [range(0; 1024) | "small/obj-" + ("0000" + tostring | .[-4:]) + ".bin"] as $small_names + | if type == "array" and length == 1040 + and count_directory_markers == 0 + and ([.[] | select(.name | startswith("small/") | not)] | map(.name) | sort) == $big_names + and ([.[] | select(.name | startswith("small/"))] | map(.name) | sort) == $small_names + and all(.[] | select(.name | startswith("small/") | not); .properties.contentLength == 67108864) + and all(.[] | select(.name | startswith("small/")); .properties.contentLength == 1048576) + then . + else error("Blob dataset must contain exactly 16 objects of 64 MiB and 1024 small/ objects of 1 MiB, with no directory markers") + end; + +# Input: the checkpoint container as a list of {name, properties: {contentLength}, metadata}. +# It must hold exactly set-1..6 x part-0..7 (48 objects) of 2 GiB (2147483648 bytes) and no directory markers. +def validate_checkpoint_dataset: + [range(1; 7) as $set | range(0; 8) as $part | "set-\($set)/part-\($part).bin"] as $names + | if type == "array" + and (map(.name) | sort) == ($names | sort) + and count_directory_markers == 0 + and all(.[]; .properties.contentLength == 2147483648) + then . + else error("Checkpoint container must hold exactly 48 objects of 2147483648 bytes (set-1..6 x part-0..7) and no directory markers") + end; + +# One s3c.sh result line. s3c.sh already exits non-zero on errors; this re-checks the +# artifact itself so a result that was edited or truncated cannot pass. +# new_connections (ok requests that opened a connection despite the warm-up) is reported, not judged. +def validate_s3c_run: + if type == "object" + and .err == 0 + and (.ok | type == "number" and . > 0) + and (.bytes | type == "number" and . > 0) + and (.retries | type == "number" and . >= 0) + and (.failures | type == "object") + and (.new_connections | type == "number" and . >= 0) + and (.max_time_seconds | type == "number" and . > 0) + # Timed runs request 60 s and stop starting batches then. The batch in flight can still run: 30 s + # covers the rest of a batch (the pipeline sizes batches to finish within about 23 s), and one request + # that retries can take up to about twice max_time_seconds (see s3c.sh). + and (.kind == "onepass" or (.max_time_seconds as $max_time | .wall_seconds | type == "number" and . >= 55 and . <= 90 + 2 * $max_time)) + then . + else error("S3 read run must have err 0, ok > 0, bytes > 0, retries >= 0, new_connections >= 0, max_time_seconds > 0, a failures object and, for timed runs, wall_seconds in [55, 90 + 2 * max_time_seconds]") + end; + +# Input: an Alluxio s3c.sh result for a preloaded dataset. $ufs_bytes is how much the workers' UFS-read +# counter grew during the run. A read served from the cache reads nothing from Blob, so more than 1% of +# the bytes the clients read means reads went to Blob; a negative value means a worker restarted. +def served_from_cache($ufs_bytes): + $ufs_bytes >= 0 and $ufs_bytes <= 0.01 * .bytes; + +# Input: the text of `alluxio fs check-cached --recursive` (read with jq -Rs) for a mount +# holding the 1,040-object dataset (16 big + 1,024 small). Every file must be fully cached. +def validate_all_cached: + . as $report + | { + total: "Total files checked", + all: "Fully cached on all replicas files count", + one: "Fully cached on at least 1 replica files count", + partial: "Partially cached files count", + uncached: "Not cached files count", + failed: "Failed files count" + } + | with_entries( + .value as $field_name + | .value = ($report | capture("(?m)^\\s*" + $field_name + ":\\s*(?[0-9]+)\\s*$").count | tonumber) + ) + | if .total == 1040 and .all == 1040 and .one == 0 and .partial == 0 and .uncached == 0 and .failed == 0 + then . + else error("All 1040 dataset files must be fully cached on all replicas") + end; + +# az may print timeStamp as ...Z, ...+00:00 or with fractional seconds; fromdateiso8601 only takes the plain Z form. +def azure_epoch: sub("\\+00:00$"; "Z") | sub("\\.[0-9]+Z$"; "Z") | fromdateiso8601; + +def minute_start: (. / 60 | floor) * 60; + +def median: + sort as $sorted + | ($sorted | length) as $count + | if $count == 0 then error("median of an empty list") + elif $count % 2 == 1 then $sorted[($count - 1) / 2] + else ($sorted[$count / 2 - 1] + $sorted[$count / 2]) / 2 + end; + +# Input: {index, metrics}. index holds one {side, rep, pod, start, end} per client run (ISO-8601 UTC); +# metrics is the `az monitor metrics list` output for Egress with 1-minute totals. +# Azure Monitor reports a minute about one minute late, so a run's first bucket is the minute after its +# earliest start: minute_start(earliest start) + 60 s. The (side, rep) groups are ordered by that start and +# the windows are contiguous: each group owns the buckets from its own first bucket up to, but excluding, +# the next group's first bucket. Egress is recorded after the client has finished and can spill into later +# minutes, so the spill stays with the run that caused it; no bucket between two runs belongs to nobody. +# Consecutive runs start at least 70 s apart in the pipeline, so their first buckets differ and no bucket +# is counted twice. The last group owns the buckets up to minute_start(latest end) + 60 s plus 3 trailing +# minutes, because the final egress has nothing after it to bound it. A window with no data point carrying +# a "total" is an error, never 0. Output: [{side, rep, blob_bytes}] sorted by side, rep. +def attribute_egress: + [.metrics.value[0].timeseries[]?.data[]? + | select(.total != null) + | {at: (.timeStamp | azure_epoch), total: .total}] as $points + | [.index | group_by([.side, .rep])[] + | { + side: .[0].side, + rep: .[0].rep, + from: (((map(.start | fromdateiso8601) | min) | minute_start) + 60), + last_end: (((map(.end | fromdateiso8601) | max) | minute_start) + 60) + }] + | sort_by(.from) as $ordered + | [range(0; $ordered | length) as $i + | $ordered[$i] + | . as $window + | (if $i + 1 < ($ordered | length) + then {to: $ordered[$i + 1].from, inclusive: false} + else {to: ($window.last_end + 180), inclusive: true} + end) as $limit + | [$points[] | select(.at >= $window.from and (if $limit.inclusive then .at <= $limit.to else .at < $limit.to end)) | .total] as $totals + | if ($totals | length) == 0 + then error("No Egress data point for \($window.side) rep \($window.rep); the metric is late or missing") + else {side: $window.side, rep: $window.rep, blob_bytes: ($totals | add)} + end] + | sort_by([.side, .rep]); + +# Input: {index, metrics, runs, worker_ufs}. runs is one {side, rep, pod, wall_seconds, retries} per client run; +# worker_ufs is [{rep, bytes}], the Alluxio workers' UFS-read counter difference for each Alluxio rep. +# Each side must have exactly 3 reps. completion_spread_seconds is the gap between the first and +# last pod to finish (from index ends). Ratios use the medians over the 3 reps; both are oriented so +# that a value above 1 favours Alluxio: blob_bytes_ratio is Blob egress / Alluxio egress and +# completion_speedup is the slowest Blob client's time / the slowest Alluxio client's time. +# retries is the sum of the request retries over the rep's clients. +# +# Sanity bounds on the attributed egress, per rep. One client reads 8 x 2 GiB = 17179869184 bytes, +# and the 5 clients together read 5 times that. +# - Blob side: every client reads straight from Blob, so the account must serve at least 5 x 17179869184. +# - Alluxio side: the workers must have fetched at least one copy (17179869184), and Blob must have +# served at least 95% of what the workers counted as read from the UFS. +# An undercount means a late or partial metric, which would otherwise be reported as a result. +def checkpoint_summary: + . as $input + | attribute_egress as $egress + | def worker_ufs_bytes($rep): [$input.worker_ufs[] | select(.rep == $rep) | .bytes][0]; + def check_bounds($side): + if $side == "blob" and .blob_bytes < 5 * 17179869184 + then error("Blob egress for blob rep \(.rep) is \(.blob_bytes) bytes, below the 5 x 17179869184 the clients read; the metric is late or partial") + elif $side == "alluxio" and .blob_bytes < 17179869184 + then error("Blob egress for alluxio rep \(.rep) is \(.blob_bytes) bytes, below the 17179869184 the workers must fetch; the metric is late or partial") + elif $side == "alluxio" and .blob_bytes < 0.95 * worker_ufs_bytes(.rep) + then error("Blob egress for alluxio rep \(.rep) is \(.blob_bytes) bytes, below 95% of the \(worker_ufs_bytes(.rep)) bytes the workers read from Blob; the metric is late or partial") + # More than 5% above what the workers read means other traffic on the account was counted (the + # Alluxio reps move little data, so earlier traffic would distort them most). + elif $side == "alluxio" and .blob_bytes > 1.05 * worker_ufs_bytes(.rep) + then error("Blob egress for alluxio rep \(.rep) is \(.blob_bytes) bytes, more than 5% above the \(worker_ufs_bytes(.rep)) bytes the workers read from Blob; other traffic on the account was counted") + else . + end; + def side_reps($side): + [$egress[] | select(.side == $side)] as $reps + | if ($reps | map(.rep) | sort) != [1, 2, 3] + then error("Side \($side) must have exactly reps 1, 2 and 3") + else [$reps[] | check_bounds($side) | . as $rep + | [$input.index[] | select(.side == $side and .rep == $rep.rep) | .end | fromdateiso8601] as $ends + | { + rep: $rep.rep, + blob_bytes: $rep.blob_bytes, + slowest_client_seconds: ([$input.runs[] | select(.side == $side and .rep == $rep.rep) | .wall_seconds] | max), + retries: ([$input.runs[] | select(.side == $side and .rep == $rep.rep) | .retries] | add), + completion_spread_seconds: (($ends | max) - ($ends | min)) + } + + (if $side == "alluxio" + then {worker_ufs_bytes: worker_ufs_bytes($rep.rep)} + else {} end)] + end; + side_reps("alluxio") as $alluxio + | side_reps("blob") as $blob + | { + alluxio: $alluxio, + blob: $blob, + blob_bytes_ratio: (($blob | map(.blob_bytes) | median) / ($alluxio | map(.blob_bytes) | median)), + completion_speedup: (($blob | map(.slowest_client_seconds) | median) / ($alluxio | map(.slowest_client_seconds) | median)) + }; + +# Input: one object per scenario 1-10 run, the runs/index.jsonl entry {id, name, kind, dataset, concurrency, +# rangeBytes, side, rep, start, end}, plus worker_ufs {before, after, bytes} on the alluxio side, merged with +# that run's s3c.sh result (runs/--.json). +# Every id needs exactly reps 1, 2 and 3 on both the alluxio and the blob side. +# Output: [{id, name, kind, dataset, concurrency, rangeBytes, alluxio, blob, retries, new_connections, +# worker_ufs_bytes, throughput_ratio, ttfb_p99_ratio, latency_p99_ratio}] sorted by id. alluxio and blob hold the +# median over the 3 reps of each metric; retries and new_connections hold, per side, the sums over the 3 reps. +# worker_ufs_bytes lists, for Alluxio reps 1-3, what the workers read from Blob during the rep; every rep is +# re-checked with served_from_cache. +# Throughput ratio is alluxio / blob (higher is better for Alluxio); the latency ratios are blob / alluxio, +# so a value above 1 favours Alluxio. +def scenario_summary: + def cache_hit_bytes: + if (.worker_ufs.bytes | type) == "number" and served_from_cache(.worker_ufs.bytes) + then .worker_ufs.bytes + else error("Scenario \(.id) alluxio rep \(.rep) must record worker_ufs.bytes of at most 1% of its \(.bytes) bytes") + end; + def side_median($runs; $id; $side): + [$runs[] | select(.id == $id and .side == $side)] as $reps + | if ($reps | map(.rep) | sort) != [1, 2, 3] + then error("Scenario \($id) side \($side) must have exactly reps 1, 2 and 3") + else + ["mebibytes_per_second", "operations_per_second", "ttfb_p50_ms", "ttfb_p99_ms", "latency_p50_ms", "latency_p99_ms"] + | map(. as $metric | {key: $metric, value: ($reps | map(.[$metric]) | median)}) + | from_entries + end; + . as $runs + | [$runs[].id] | unique + | map(. as $id + | side_median($runs; $id; "alluxio") as $alluxio + | side_median($runs; $id; "blob") as $blob + | ([$runs[] | select(.id == $id)][0]) as $first + | { + id: $id, + name: $first.name, + kind: $first.kind, + dataset: $first.dataset, + concurrency: $first.concurrency, + rangeBytes: $first.rangeBytes, + alluxio: $alluxio, + blob: $blob, + retries: { + alluxio: ([$runs[] | select(.id == $id and .side == "alluxio") | .retries] | add), + blob: ([$runs[] | select(.id == $id and .side == "blob") | .retries] | add) + }, + new_connections: { + alluxio: ([$runs[] | select(.id == $id and .side == "alluxio") | .new_connections] | add), + blob: ([$runs[] | select(.id == $id and .side == "blob") | .new_connections] | add) + }, + worker_ufs_bytes: ([$runs[] | select(.id == $id and .side == "alluxio")] | sort_by(.rep) | map(cache_hit_bytes)), + throughput_ratio: ($alluxio.mebibytes_per_second / $blob.mebibytes_per_second), + ttfb_p99_ratio: ($blob.ttfb_p99_ms / $alluxio.ttfb_p99_ms), + latency_p99_ratio: ($blob.latency_p99_ms / $alluxio.latency_p99_ms) + }); diff --git a/kcl/alluxio/s3_read/s3c.sh b/kcl/alluxio/s3_read/s3c.sh new file mode 100755 index 0000000000..8ecc14033e --- /dev/null +++ b/kcl/alluxio/s3_read/s3c.sh @@ -0,0 +1,256 @@ +#!/bin/sh +# Identical curl client for Alluxio's S3 API (MODE=alluxio) and Azure Blob REST (MODE=blob). +# Runs in curlimages/curl 8.9.0 or later (busybox sh and awk). Prints one JSON line on stdout. +# +# KIND=get CONCURRENCY workers GET random keys for DURATION_SECONDS +# KIND=range like get, each request reads RANGE_BYTES at a random 4096-aligned offset inside OBJECT_BYTES +# KIND=onepass every key in KEYS_FILE is read exactly once, split over CONCURRENCY workers +# +# Required: MODE KIND CONCURRENCY KEYS_FILE BATCH_REQUESTS OBJECT_BYTES (the size of every object in KEYS_FILE) +# get/range: DURATION_SECONDS +# range: RANGE_BYTES +# MODE=blob: ACCOUNT CONTAINER SAS_FILE +# MODE=alluxio: HOSTS (comma-separated host:port, exactly EXPECTED_HOSTS of them) EXPECTED_HOSTS BUCKET +# Optional: BLOB_ENDPOINT (default https://${ACCOUNT}.blob.core.windows.net) points the blob side at another server. +# MAX_REQUESTS_PER_WORKER (default 20000) caps the requests prepared per worker for get/range. +# CURL_MAX_TIME seconds allowed per attempt of a request (default 30 for get/range; for onepass 120, +# or 1800 when a request moves more than 64 MiB). The result reports it as max_time_seconds. +# HOST_OFFSET (default 0, MODE=alluxio) shifts which host each request goes to. Clients that read the +# same keys at the same time pass different offsets so they do not all send a key to the same host. +# +# Every request, on both sides, is retried up to 3 times with curl's default backoff, which honors +# Retry-After. Azure Blob clients (the Azure SDK, BlobFuse2, azcopy) retry transient errors by default too. +# curl retries a transfer error such as a body cut short or a connect timeout, and HTTP 408, 429, 500, 502, +# 503 and 504; any other status, such as 403 or 404, is not retried. retry-max-time equals max-time, so an +# attempt that hits max-time is not retried, and no retry starts once max-time has passed since the first +# attempt. A retry that starts just before then still gets a full max-time, so one request, retries included, +# ends within about twice max-time. A retried request reports the timings and size of its last attempt, so the +# time spent on earlier attempts lowers the throughput but not the latency percentiles. +# +# Each curl run first sends an unmeasured HEAD to every host its measured requests will use, so the measured +# requests reuse a connection that is already open: without it, the first request of every run would also pay +# for DNS, TCP and, on the Blob side, TLS, while on the Alluxio side it opens a plain in-cluster TCP connection. +# A HEAD returns only the object's metadata, so it neither loads data into Alluxio's cache nor reads object +# data from Blob. The result's new_connections counts the ok requests that still opened a connection. +# +# A request counts as ok only if, after its retries, it returned 206 with RANGE_BYTES bytes (KIND=range) or +# 200 with OBJECT_BYTES bytes (get, onepass). Anything else, including a timeout, counts as err. Only the +# measured requests count; a warm-up HEAD that fails changes nothing but the connection reuse. +# The result has retries, the sum of every request's retries, and failures, which counts the failed requests +# by " " (000 when no response arrived) and the curl runs that exited non-zero +# under "curl_exit"; it is {} when nothing failed. +# Exit status is 0 only if err is 0 and at least one request succeeded; +# otherwise ALLUXIO S3 READ FAILED: is written to stderr. +set -u + +fail() { + echo "ALLUXIO S3 READ FAILED: $*" >&2 + exit 1 +} +require() { + for variable_name in "$@"; do + eval "variable_value=\${$variable_name:-}" + [ -n "$variable_value" ] || fail "required variable $variable_name is not set" + done +} + +require MODE KIND CONCURRENCY KEYS_FILE BATCH_REQUESTS OBJECT_BYTES +[ -s "$KEYS_FILE" ] || fail "KEYS_FILE $KEYS_FILE is missing or empty" +case $MODE in + blob) + require ACCOUNT CONTAINER SAS_FILE + [ -s "$SAS_FILE" ] || fail "SAS_FILE $SAS_FILE is missing or empty" + ;; + alluxio) + require HOSTS EXPECTED_HOSTS BUCKET + host_count=$(echo "$HOSTS" | awk -F, '{print NF}') + [ "$host_count" -eq "$EXPECTED_HOSTS" ] || fail "HOSTS lists $host_count hosts, expected $EXPECTED_HOSTS: $HOSTS" + ;; + *) fail "MODE must be alluxio or blob, got $MODE" ;; +esac +case $KIND in + get) require DURATION_SECONDS ;; + range) require DURATION_SECONDS RANGE_BYTES ;; + onepass) ;; + *) fail "KIND must be get, range or onepass, got $KIND" ;; +esac + +MAX_REQUESTS_PER_WORKER=${MAX_REQUESTS_PER_WORKER:-20000} +if [ "$KIND" = range ]; then + request_bytes=$RANGE_BYTES + expected_status=206 +else + request_bytes=$OBJECT_BYTES + expected_status=200 +fi +# A timed run stops starting batches at DURATION_SECONDS, but a request it has started may still retry, so +# its wall time can exceed DURATION_SECONDS by up to about twice max-time (see the header); checks.jq allows +# for that. 30 s keeps that overrun short yet is more than 5 times the slowest p99 latency seen in a full run +# (5.7 s, a cross-region 64 MiB GET from Blob at 16 concurrent requests). A onepass run has no window: +# 120 s lets a 64 MiB request finish at about 0.5 MiB/s, and the 2 GiB checkpoint objects get 1800 s +# (about 1.2 MiB/s). CURL_MAX_TIME is exported for the awk program that writes every request's config. +if [ "$KIND" != onepass ]; then + default_max_time=30 +elif [ "$request_bytes" -gt 67108864 ]; then + default_max_time=1800 +else + default_max_time=120 +fi +export CURL_MAX_TIME=${CURL_MAX_TIME:-$default_max_time} +HOST_OFFSET=${HOST_OFFSET:-0} +export BLOB_BASE_URL=${BLOB_ENDPOINT:-https://${ACCOUNT:-}.blob.core.windows.net} +export SAS_QUERY="" +[ "$MODE" = blob ] && SAS_QUERY=$(cat "$SAS_FILE") + +work_dir=$(mktemp -d) +trap 'rm -rf "$work_dir"' EXIT # the per-request configs embed the SAS query + +# One curl config per batch of BATCH_REQUESTS requests (a whole file for onepass). A batch is collected +# first, so that its config can start with the warm-up HEADs for the hosts the batch uses. +for worker in $(seq 1 "$CONCURRENCY"); do + awk -v worker="$worker" -v worker_count="$CONCURRENCY" -v mode="$MODE" -v kind="$KIND" \ + -v max_requests="$MAX_REQUESTS_PER_WORKER" -v batch="$BATCH_REQUESTS" -v work_dir="$work_dir" \ + -v object_bytes="${OBJECT_BYTES:-0}" -v range_bytes="${RANGE_BYTES:-0}" -v host_offset="$HOST_OFFSET" \ + -v container="${CONTAINER:-}" -v bucket="${BUCKET:-}" -v hosts="${HOSTS:-}" ' + BEGIN { srand(worker * 7919 + 1); host_count = split(hosts, host_list, ","); blob_base = ENVIRON["BLOB_BASE_URL"] } + { keys[NR] = $0 } + END { + key_count = NR + if (kind == "onepass") { + for (index_in_file = 1; index_in_file <= key_count; index_in_file++) + if ((index_in_file - 1) % worker_count == worker - 1) add_request(keys[index_in_file], "", index_in_file - 1) + write_batch(work_dir "/config" worker) + } else { + for (request = 0; request < max_requests; request++) { + key = keys[int(rand() * key_count) + 1] + byte_range = "" + if (kind == "range") { + offset = int(rand() * ((object_bytes - range_bytes) / 4096)) * 4096 + byte_range = offset "-" (offset + range_bytes - 1) + } + # Round-robin over the hosts; the worker number staggers the workers so they do not all hit one host at once. + add_request(key, byte_range, request + worker - 1) + if (request_count == batch) write_batch(work_dir "/config" worker "." int(request / batch)) + } + write_batch(work_dir "/config" worker "." int((max_requests - 1) / batch)) + } + } + function add_request(key, byte_range, host_index) { + request_count++ + request_key[request_count] = key + request_range[request_count] = byte_range + request_host[request_count] = host_index + host_offset + } + # Writes the collected requests to config_file: first one HEAD per distinct host, for the first key that + # host serves, then the measured requests. curl keeps at most 5 idle connections in a run and has no + # option to raise that, so with more than 5 hosts some measured requests reconnect; new_connections shows it. + function write_batch(config_file, request, host) { + if (request_count == 0) return + split("", warmed) + for (request = 1; request <= request_count; request++) { + host = (mode == "blob") ? blob_base : host_list[request_host[request] % host_count + 1] + if (!(host in warmed)) { + warmed[host] = 1 + write_request(config_file, request_key[request], "", request_host[request], 0) + } + } + for (request = 1; request <= request_count; request++) + write_request(config_file, request_key[request], request_range[request], request_host[request], 1) + close(config_file) + request_count = 0 + } + function write_request(config_file, key, byte_range, host_index, measured) { + if (config_file in has_request) printf "next\n" > config_file # a trailing next would make curl run an empty transfer + has_request[config_file] = 1 + if (mode == "blob") + printf "url = \"%s/%s/%s?%s\"\n", blob_base, container, key, ENVIRON["SAS_QUERY"] > config_file + else { + printf "url = \"http://%s/%s/%s\"\n", host_list[host_index % host_count + 1], bucket, key > config_file + printf "aws-sigv4 = \"aws:amz:us-east-1:s3\"\nuser = \"warp:benchmark\"\n" > config_file + } + if (!measured) printf "head\n" > config_file + if (byte_range != "") printf "range = \"%s\"\n", byte_range > config_file + # next resets the options, so every request carries its own. + # retry-max-time stops new retries once a request has used its max-time (see the header). + printf "connect-timeout = 10\nmax-time = %d\nretry = 3\nretry-all-errors\nretry-max-time = %d\n", ENVIRON["CURL_MAX_TIME"], ENVIRON["CURL_MAX_TIME"] > config_file + # A warm-up HEAD writes no result line. The body goes to stdout, which the caller discards. With + # output = "/dev/null", curl would truncate the output before a retry, fail on /dev/null and drop the + # request without writing its result line. + if (measured) + printf "write-out = \"%%output{>>%s/results%d}%%{http_code} %%{time_starttransfer} %%{time_total} %%{size_download} %%{num_retries} %%{num_connects}\\n\"\n", work_dir, worker > config_file + }' "$KEYS_FILE" +done + +# Killing curl at the deadline would cut off the requests in flight; instead each worker +# runs short batches (each its own curl run, warmed up as described in the header) and stops starting new +# ones once time is up. +start_seconds=$(cut -d" " -f1 /proc/uptime) +end_seconds=$(awk -v start="$start_seconds" -v duration="${DURATION_SECONDS:-0}" 'BEGIN { print start + duration }') +for worker in $(seq 1 "$CONCURRENCY"); do + if [ "$KIND" = onepass ]; then + if [ -f "$work_dir/config$worker" ]; then + (curl -s -K "$work_dir/config$worker" > /dev/null 2>&1 || echo failed >> "$work_dir/curl_failures$worker") & + fi + else + ( + batch_index=0 + while [ -f "$work_dir/config$worker.$batch_index" ] && awk -v end="$end_seconds" '{ exit !($1 < end) }' /proc/uptime; do + curl -s -K "$work_dir/config$worker.$batch_index" > /dev/null 2>&1 || echo failed >> "$work_dir/curl_failures$worker" + batch_index=$((batch_index + 1)) + done + [ -f "$work_dir/config$worker.$batch_index" ] || echo exhausted > "$work_dir/exhausted$worker" + ) & + fi +done +wait +stop_seconds=$(cut -d" " -f1 /proc/uptime) + +if ls "$work_dir"/exhausted* >/dev/null 2>&1; then + fail "request budget exhausted before DURATION_SECONDS; raise MAX_REQUESTS_PER_WORKER (currently $MAX_REQUESTS_PER_WORKER)" +fi + +touch "$work_dir/results0" "$work_dir/curl_failures0" +cat "$work_dir"/results* > "$work_dir/all_results" +awk -v status="$expected_status" -v size="$request_bytes" '$1 == status && $4 == size' "$work_dir/all_results" > "$work_dir/ok" +ok=$(wc -l < "$work_dir/ok") +http_errors=$(awk -v status="$expected_status" -v size="$request_bytes" '!($1 == status && $4 == size)' "$work_dir/all_results" | wc -l) +transport_errors=$(cat "$work_dir"/curl_failures* | wc -l) +err=$((http_errors + transport_errors)) +retries=$(awk '{ sum += $5 } END { printf "%d", sum }' "$work_dir/all_results") +new_connections=$(awk '$6 > 0 { count++ } END { printf "%d", count }' "$work_dir/ok") +failures=$(awk -v status="$expected_status" -v size="$request_bytes" -v curl_exit="$transport_errors" ' + !($1 == status && $4 == size) { count[$1 " " $4]++ } + END { + if (curl_exit > 0) count["curl_exit"] = curl_exit + printf "{" + for (key in count) { printf "%s\"%s\":%d", separator, key, count[key]; separator = "," } + printf "}" + }' "$work_dir/all_results") + +percentile_ms() { + sort_column=$1 + fraction=$2 + awk -v column="$sort_column" '{ print $column }' "$work_dir/ok" | sort -n \ + | awk -v count="$ok" -v fraction="$fraction" 'NR == int(count * fraction) + 1 { printf "%.2f", $1 * 1000 }' +} +ttfb_p50=$(percentile_ms 2 0.50) +ttfb_p99=$(percentile_ms 2 0.99) +latency_p50=$(percentile_ms 3 0.50) +latency_p99=$(percentile_ms 3 0.99) + +awk -v start="$start_seconds" -v stop="$stop_seconds" -v ok="$ok" -v err="$err" -v mode="$MODE" -v kind="$KIND" \ + -v concurrency="$CONCURRENCY" -v retries="$retries" -v failures="$failures" \ + -v new_connections="$new_connections" -v max_time="$CURL_MAX_TIME" \ + -v ttfb_p50="${ttfb_p50:-null}" -v ttfb_p99="${ttfb_p99:-null}" \ + -v latency_p50="${latency_p50:-null}" -v latency_p99="${latency_p99:-null}" \ + '{ bytes += $4 } + END { + wall = stop - start + printf "{\"mode\":\"%s\",\"kind\":\"%s\",\"concurrency\":%d,\"ok\":%d,\"err\":%d,\"bytes\":%.0f,\"wall_seconds\":%.2f,", mode, kind, concurrency, ok, err, bytes, wall + printf "\"retries\":%d,\"failures\":%s,\"new_connections\":%d,\"max_time_seconds\":%d,", retries, failures, new_connections, max_time + printf "\"operations_per_second\":%.1f,\"mebibytes_per_second\":%.1f,", ok / wall, bytes / 1048576 / wall + printf "\"ttfb_p50_ms\":%s,\"ttfb_p99_ms\":%s,\"latency_p50_ms\":%s,\"latency_p99_ms\":%s}\n", ttfb_p50, ttfb_p99, latency_p50, latency_p99 + }' "$work_dir/ok" + +[ "$err" -eq 0 ] || fail "$err of $((ok + err)) requests did not return $expected_status with $request_bytes bytes; failures: $failures" +[ "$ok" -gt 0 ] || fail "no request succeeded" From c79c0ac0a31f3792025baec4b5b9b850da97fcac Mon Sep 17 00:00:00 2001 From: Stephen Pu Date: Wed, 18 Nov 2026 22:03:19 -0800 Subject: [PATCH 3/4] Add an Alluxio S3 read pipeline with a direct-Blob baseline kcl/alluxio/s3_read runs read scenarios through Alluxio's S3 API and, in the same run, against Azure Blob directly, alternating the two sides: cross-region repeated reads, same-region small objects and range reads, large-object GETs at 1/4/16 concurrent requests, and five clients loading the same checkpoint at once (bytes read from Blob and completion times). Both datasets of scenarios 1-10 are loaded into the cache first, so every Alluxio rep reads the workers' UFS-read counter before and after and fails if the workers read more than 1% of the rep's bytes from Blob; the counts go into summary.json. In the checkpoint load each client starts at a different worker, so every worker serves the same share. Five workers keep their page store on the local NVMe disk. The cluster uses NOSASL: with several workers and redirect disabled, a worker relays reads to the worker that owns the file, and under SIMPLE that internal connection is rejected, so reads fall back silently. --- kcl/alluxio/s3_read/clients.yaml | 36 + kcl/alluxio/s3_read/cluster.yaml | 45 + kcl/alluxio/s3_read/nvme.yaml | 61 + kcl/alluxio/s3_read/pipeline.k | 309 ++++ kcl/alluxio/s3_read/pipeline.yaml | 2252 ++++++++++++++++++++++++++ kcl/lib/steps/alluxio/s3_read.k | 777 +++++++++ kcl/lib/steps/alluxio/s3_read_test.k | 85 + 7 files changed, 3565 insertions(+) create mode 100644 kcl/alluxio/s3_read/clients.yaml create mode 100644 kcl/alluxio/s3_read/cluster.yaml create mode 100644 kcl/alluxio/s3_read/nvme.yaml create mode 100644 kcl/alluxio/s3_read/pipeline.k create mode 100755 kcl/alluxio/s3_read/pipeline.yaml create mode 100644 kcl/lib/steps/alluxio/s3_read.k create mode 100644 kcl/lib/steps/alluxio/s3_read_test.k diff --git a/kcl/alluxio/s3_read/clients.yaml b/kcl/alluxio/s3_read/clients.yaml new file mode 100644 index 0000000000..0dfe8a343c --- /dev/null +++ b/kcl/alluxio/s3_read/clients.yaml @@ -0,0 +1,36 @@ +# Template for the S3 read client pods s3c-1 ... s3c-N, N being S3_READ_CLIENT_COUNT in +# kcl/lib/steps/alluxio/s3_read.k. The pipeline renames +# one copy per clientpool node; the anti-affinity rule enforces one pod per node. +apiVersion: v1 +kind: Pod +metadata: + name: s3c + namespace: alx-ns + labels: {app: s3c} +spec: + restartPolicy: Never + automountServiceAccountToken: false + nodeSelector: {agentpool: clientpool} + tolerations: + - {key: warp, operator: Equal, value: "true", effect: NoSchedule} + affinity: + podAntiAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: {matchLabels: {app: s3c}} + topologyKey: kubernetes.io/hostname + volumes: + - {name: script, configMap: {name: s3c-script}} + - {name: sas, secret: {secretName: s3c-sas}} + # Checkpoint generation writes up to 8 parallel 2 GiB temp files per pod, so 16 GiB plus headroom. + - {name: scratch, emptyDir: {sizeLimit: 20Gi}} + containers: + - name: s3c + image: curlimages/curl:8.12.1 + # 20000 s outlives the 240-minute (14400 s) job timeout. + command: [sh, -c, "sleep 20000"] + resources: + requests: {cpu: "4", memory: 4Gi} + volumeMounts: + - {name: script, mountPath: /scripts, readOnly: true} + - {name: sas, mountPath: /sas, readOnly: true} + - {name: scratch, mountPath: /scratch} diff --git a/kcl/alluxio/s3_read/cluster.yaml b/kcl/alluxio/s3_read/cluster.yaml new file mode 100644 index 0000000000..360a8bd8a2 --- /dev/null +++ b/kcl/alluxio/s3_read/cluster.yaml @@ -0,0 +1,45 @@ +apiVersion: k8s-operator.alluxio.com/v1 +kind: AlluxioCluster +metadata: + name: alluxio + namespace: alx-ns +spec: + image: REPLACE_ME.azurecr.io/alluxio-enterprise + imageTag: AI-3.8-15.1.28 + imagePullSecrets: [alluxio-acr] + properties: + alluxio.worker.s3.api.enabled: "true" + alluxio.worker.s3.redirect.enabled: "false" + # NOSASL: with several workers and redirect disabled, a worker relays reads to the worker that owns + # the file; under SIMPLE that internal connection is rejected ("request doesn't have a security token") + # and reads fall back, so caching and throughput are wrong. + alluxio.security.authentication.type: NOSASL + alluxio.underfs.abfs.sdk.version: "2" + # Off by default; on, the client reuses connections instead of opening one per request. + alluxio.worker.s3.connection.keep.alive.enabled: "true" + coordinator: + nodeSelector: {agentpool: systempool} + resources: + requests: {cpu: "4", memory: 12Gi} + limits: {cpu: "4", memory: 12Gi} + jvmOptions: ["-Xmx4g", "-Xms4g", "-XX:MaxDirectMemorySize=4g"] + worker: + # Must equal S3_READ_WORKER_COUNT in kcl/lib/steps/alluxio/s3_read.k. + count: 5 + nodeSelector: {agentpool: workerpool} + tolerations: + - {key: alluxio, operator: Equal, value: "true", effect: NoSchedule} + resources: + requests: {cpu: "8", memory: 24Gi} + limits: {cpu: "8", memory: 24Gi} + jvmOptions: ["-Xmx8g", "-Xms8g", "-XX:MaxDirectMemorySize=12g"] + # Standard_D16ds_v6 has two local NVMe disks of 440 GiB each (Microsoft Learn, "Ddsv6 series", + # temp storage table); the page store uses one, and 396Gi leaves about 10% for ext4 overhead. + pagestore: {type: hostPath, hostPath: /mnt/alluxio-nvme/pagestore, size: 396Gi, reservedSize: 1Gi} + # A single etcd replica is sufficient for this disposable, non-HA PoC. + etcd: + replicaCount: 1 + nodeSelector: {agentpool: systempool} + persistence: {storageClass: managed-csi, size: 10Gi} + prometheus: {enabled: false} + grafana: {enabled: false} diff --git a/kcl/alluxio/s3_read/nvme.yaml b/kcl/alluxio/s3_read/nvme.yaml new file mode 100644 index 0000000000..c9109d4692 --- /dev/null +++ b/kcl/alluxio/s3_read/nvme.yaml @@ -0,0 +1,61 @@ +# Formats the local NVMe temp disk of every workerpool node and mounts it at +# /mnt/alluxio-nvme on the host, where the Alluxio worker keeps its page store. +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: alluxio-nvme + namespace: kube-system +spec: + selector: + matchLabels: {app: alluxio-nvme} + template: + metadata: + labels: {app: alluxio-nvme} + spec: + nodeSelector: {agentpool: workerpool} + tolerations: + - {key: alluxio, operator: Equal, value: "true", effect: NoSchedule} + containers: + - name: prepare + image: debian:12.9-slim + securityContext: + privileged: true + command: [bash, -c] + args: + - | + set -Eeuo pipefail + target=/host-mnt/alluxio-nvme + fail() { + echo "ALLUXIO S3 READ FAILED: $*" >&2 + exit 1 + } + if ! mountpoint -q "$target"; then + mkdir -p "$target" + device="" + # Select by model, never by device name: NVMe numbering is not stable across nodes. + for model_file in /sys/block/nvme*/device/model; do + [[ -e "$model_file" ]] || continue + model="$(tr -d '\n' < "$model_file")" + if [[ "$model" == "Microsoft NVMe Direct Disk"* ]]; then + device="/dev/$(basename "$(dirname "$(dirname "$model_file")")")" + break + fi + done + [[ -n "$device" ]] || fail "no local NVMe disk" + # A restarted pod must not wipe a disk that already holds a filesystem. + blkid "$device" > /dev/null || mkfs.ext4 -F -q "$device" + mount "$device" "$target" + echo "Mounted $device" + fi + echo "NVME READY /mnt/alluxio-nvme" + exec sleep infinity + readinessProbe: + exec: + command: [mountpoint, -q, /host-mnt/alluxio-nvme] + periodSeconds: 5 + volumeMounts: + # Bidirectional makes the mount below appear on the host, not just in this container. + - {name: host-mnt, mountPath: /host-mnt, mountPropagation: Bidirectional} + volumes: + - name: host-mnt + hostPath: {path: /mnt} diff --git a/kcl/alluxio/s3_read/pipeline.k b/kcl/alluxio/s3_read/pipeline.k new file mode 100644 index 0000000000..42d78f7459 --- /dev/null +++ b/kcl/alluxio/s3_read/pipeline.k @@ -0,0 +1,309 @@ +import azure_pipelines.ap +import azure_pipelines.ap.jobs.job +import azure_pipelines.ap.steps +import lib.const +import lib.steps.alluxio +import lib.steps.azure +import lib.steps.common +import lib.steps.k8s + +# Images and the OCI Helm chart are staged in the existing Telescope registry. +ACR_NAME = "telescope" +ACR_SUBSCRIPTION_ID = "137f0351-8235-42a6-ac7a-6b46be2d21c7" +ALLUXIO_IMAGE_REPOSITORY = "${ACR_NAME}.azurecr.io/alluxio-enterprise" +OPERATOR_IMAGE_REPOSITORY = "${ACR_NAME}.azurecr.io/alluxio-operator" +OPERATOR_CHART_REPOSITORY = "oci://${ACR_NAME}.azurecr.io/helm/alluxio-operator" + +# The cluster and the same-region storage account live in LOCATION. westeurope matches the warp +# pipeline, whose subscription is known to have the quota. +LOCATION = "westeurope" +# The cross-region storage account lives in REMOTE_LOCATION. eastus is about 80 ms from westeurope, +# the round trip that makes a cross-region read slow enough for a cache to matter. A region in +# Europe would be closer and shrink the difference being measured. +REMOTE_LOCATION = "eastus" + +RESOURCE_GROUP = "alluxio-s3-read-$(RUN_ID)-$(System.JobAttempt)" +CLUSTER = "alluxio-s3-read" +# Storage account names are at most 24 lowercase alphanumerics and globally unique; the build ID +# and job attempt make them unique, and the l/r marker tells the two accounts apart. +LOCAL_ACCOUNT = "alx$(Build.BuildId)l$(System.JobAttempt)" +REMOTE_ACCOUNT = "alx$(Build.BuildId)r$(System.JobAttempt)" +WORK_DIR = "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" +RESULT_DIR = "$(Build.ArtifactStagingDirectory)/alluxio-s3-read" +CHECKS_DIR = "$(Build.SourcesDirectory)/kcl/alluxio/s3_read" +# The License manifest is not specific to a workload, so the warp pipeline's copy is reused. +LICENSE_MANIFEST = "$(Build.SourcesDirectory)/kcl/alluxio/warp/license.yaml" +# The UnderFileSystem manifest is not specific to a workload either. +UFS_MANIFEST = "$(Build.SourcesDirectory)/kcl/alluxio/warp/ufs.yaml" + +# Three pools keep the load generators off the Alluxio workers. Each value is defined once and +# used both to create the pool and to record it in configuration.json. +# 3 system nodes: etcd needs at least 2, and the warp pipeline uses 3 on the same SKU. +SYSTEM_POOL = azure.NodePool { + name = "systempool" + sku = "Standard_D8s_v6" + count = 3 +} +# One worker per client node, so each client has its own worker and the page store is spread +# evenly. 16 concurrent GETs from one client and the checkpoint load from every client exceed +# what the network of a single worker can carry. D16ds_v6 has two 440 GiB local NVMe disks and the page +# store uses one; Managed keeps AKS from taking a disk for an ephemeral OS disk. +WORKER_POOL = azure.NodePool { + name = "workerpool" + sku = "Standard_D16ds_v6" + count = alluxio.S3_READ_WORKER_COUNT + taintPrefix = "alluxio" + osDiskType = "Managed" +} +# One client per worker. The checkpoint load reads from all of them at the same time. +# The taint prefix matches the warp pipeline. +CLIENT_POOL = azure.NodePool { + name = "clientpool" + sku = "Standard_D8s_v6" + count = alluxio.S3_READ_CLIENT_COUNT + taintPrefix = "warp" +} + +output = ap.Pipeline { + name = "Alluxio S3 read vs Azure Blob" + trigger = "none" + pr = "none" + pool = const.DEFAULT_POOL + jobs = [job.Job { + job = "alluxio_s3_read" + displayName = "Alluxio S3 API reads compared with direct Azure Blob reads" + # About 3 hours are expected: 60 minutes setup and data generation, about 105 minutes for + # scenarios 1-10 with warm-up and gaps (103 minutes in a full run), 15 minutes for scenarios + # 11-12, then the resource group delete. 240 minutes is that estimate plus a margin. + timeoutInMinutes = 240 + cancelTimeoutInMinutes = 30 + steps = [ + common.SetRunId() + k8s.InstallHelm() + steps.Task { + task = "KubeloginInstaller@0" + displayName = "Install kubelogin" + } + alluxio.RecordRunConfiguration( + const.DEFAULT_SERVICE_CONNECTION + ACR_NAME + ACR_SUBSCRIPTION_ID + ALLUXIO_IMAGE_REPOSITORY + OPERATOR_IMAGE_REPOSITORY + OPERATOR_CHART_REPOSITORY + const.DEFAULT_SUBSCRIPTION_ID + RESOURCE_GROUP + CLUSTER + LOCATION + LOCAL_ACCOUNT + WORK_DIR + RESULT_DIR + alluxio.RecordedBenchmark { + # Published per-VM network limits: D8s_v6 and D16ds_v6 are both 12,500 Mbps. + nodePools = alluxio.RecordedNodePools { + support = alluxio.RecordedNodePool {pool = SYSTEM_POOL, maxEgressMbpsPerVm = 12500} + worker = alluxio.RecordedNodePool {pool = WORKER_POOL, maxEgressMbpsPerVm = 12500} + client = alluxio.RecordedNodePool {pool = CLIENT_POOL, maxEgressMbpsPerVm = 12500} + } + # Must equal pagestore.size and pagestore.reservedSize in cluster.yaml. + workerCache = "396Gi" + workerCacheReserved = "1Gi" + clientVersionKey = "curl_version" + # Must equal the curlimages/curl tag in clients.yaml. + clientVersion = "8.12.1" + } + ) + azure.CreateResourceGroup( + const.DEFAULT_SERVICE_CONNECTION + RESOURCE_GROUP + LOCATION + const.DEFAULT_SUBSCRIPTION_ID + ) + azure.AzCli( + const.DEFAULT_SERVICE_CONNECTION + "Create cluster" + """ +az aks create \\ + --subscription "${const.DEFAULT_SUBSCRIPTION_ID}" \\ + --resource-group "${RESOURCE_GROUP}" \\ + --name "${CLUSTER}" \\ + --location "${LOCATION}" \\ + --kubernetes-version "1.36" \\ + --nodepool-name ${SYSTEM_POOL.name} \\ + --node-count ${SYSTEM_POOL.count} \\ + --node-vm-size ${SYSTEM_POOL.sku} \\ + --network-plugin azure \\ + --network-plugin-mode overlay \\ + --enable-managed-identity \\ + --enable-aad \\ + --enable-azure-rbac \\ + --disable-local-accounts \\ + --no-ssh-key \\ + --tier standard \\ + --yes +""" + ) + azure.CreateNodePool( + const.DEFAULT_SERVICE_CONNECTION + CLUSTER + RESOURCE_GROUP + const.DEFAULT_SUBSCRIPTION_ID + WORKER_POOL + ) + azure.CreateNodePool( + const.DEFAULT_SERVICE_CONNECTION + CLUSTER + RESOURCE_GROUP + const.DEFAULT_SUBSCRIPTION_ID + CLIENT_POOL + ) + azure.GetCredentials( + const.DEFAULT_SERVICE_CONNECTION + CLUSTER + RESOURCE_GROUP + const.DEFAULT_SUBSCRIPTION_ID + ) + azure.AzCli( + const.DEFAULT_SERVICE_CONNECTION + "Convert kubeconfig to Entra ID login" + 'kubelogin convert-kubeconfig -l azurecli' + ) + alluxio.ConfigureImagePullAccess( + const.DEFAULT_SERVICE_CONNECTION + ACR_NAME + ACR_SUBSCRIPTION_ID + WORK_DIR + RESULT_DIR + ) + alluxio.SeedS3ReadData( + const.DEFAULT_SERVICE_CONNECTION + const.DEFAULT_SUBSCRIPTION_ID + RESOURCE_GROUP + LOCATION + REMOTE_LOCATION + LOCAL_ACCOUNT + REMOTE_ACCOUNT + WORK_DIR + RESULT_DIR + CHECKS_DIR + ) + # The page-store disk must be mounted before the workers start. + alluxio.PrepareWorkerNvme( + const.DEFAULT_SERVICE_CONNECTION + "${CHECKS_DIR}/nvme.yaml" + WORK_DIR + RESULT_DIR + ) + alluxio.InstallOperator( + const.DEFAULT_SERVICE_CONNECTION + ACR_NAME + ACR_SUBSCRIPTION_ID + OPERATOR_IMAGE_REPOSITORY + OPERATOR_CHART_REPOSITORY + WORK_DIR + RESULT_DIR + ) + alluxio.CreateAlluxioCluster( + const.DEFAULT_SERVICE_CONNECTION + ALLUXIO_IMAGE_REPOSITORY + "${CHECKS_DIR}/cluster.yaml" + LICENSE_MANIFEST + WORK_DIR + RESULT_DIR + ) + alluxio.MountBlobStorage( + const.DEFAULT_SERVICE_CONNECTION + LOCAL_ACCOUNT + "s3-data" + "LOCAL_DATA_SAS" + "/blob" + UFS_MANIFEST + WORK_DIR + RESULT_DIR + ) + alluxio.MountBlobStorage( + const.DEFAULT_SERVICE_CONNECTION + REMOTE_ACCOUNT + "s3-data" + "REMOTE_DATA_SAS" + "/xregion" + UFS_MANIFEST + WORK_DIR + RESULT_DIR + ) + alluxio.MountBlobStorage( + const.DEFAULT_SERVICE_CONNECTION + LOCAL_ACCOUNT + "checkpoint" + "CHECKPOINT_READ_SAS" + "/ckpt" + UFS_MANIFEST + WORK_DIR + RESULT_DIR + ) + alluxio.CreateS3ReadClients( + const.DEFAULT_SERVICE_CONNECTION + "${CHECKS_DIR}/clients.yaml" + "${CHECKS_DIR}/s3c.sh" + WORK_DIR + RESULT_DIR + ) + alluxio.SeedCheckpointSets( + const.DEFAULT_SERVICE_CONNECTION + LOCAL_ACCOUNT + WORK_DIR + RESULT_DIR + CHECKS_DIR + ) + common.RecordCurrentTime("BENCHMARK_START_TIME") + *[alluxio.RunS3ReadScenarios( + const.DEFAULT_SERVICE_CONNECTION + LOCAL_ACCOUNT + REMOTE_ACCOUNT + WORK_DIR + RESULT_DIR + CHECKS_DIR + ids + ) for ids in alluxio.S3_READ_SCENARIO_GROUPS] + alluxio.RunCheckpointLoad( + const.DEFAULT_SERVICE_CONNECTION + const.DEFAULT_SUBSCRIPTION_ID + RESOURCE_GROUP + LOCAL_ACCOUNT + WORK_DIR + RESULT_DIR + CHECKS_DIR + ) + common.RecordCurrentTime("BENCHMARK_END_TIME") + alluxio.SummarizeS3Read( + WORK_DIR + RESULT_DIR + CHECKS_DIR + ) + alluxio.CollectDiagnostics( + const.DEFAULT_SERVICE_CONNECTION + WORK_DIR + RESULT_DIR + ) + alluxio.RefuseSasInResults( + WORK_DIR + RESULT_DIR + ) + steps.Task { + task = "PublishPipelineArtifact@1" + displayName = "Publish S3 read results and diagnostics" + condition = "always()" + inputs = { + targetPath = RESULT_DIR + artifact = "alluxio-s3-read-$(System.JobAttempt)" + } + } + azure.DeleteResourceGroup( + const.DEFAULT_SERVICE_CONNECTION + RESOURCE_GROUP + const.DEFAULT_SUBSCRIPTION_ID + condition = "and(always(), eq(variables['SHOULD_CLEAN_UP_RESOURCE_GROUP'], 'true'))" + ) + ] + }] +} diff --git a/kcl/alluxio/s3_read/pipeline.yaml b/kcl/alluxio/s3_read/pipeline.yaml new file mode 100755 index 0000000000..66c7690118 --- /dev/null +++ b/kcl/alluxio/s3_read/pipeline.yaml @@ -0,0 +1,2252 @@ +name: Alluxio S3 read vs Azure Blob +pool: AKS-Telescope-Airlock +trigger: none +pr: none +jobs: +- job: alluxio_s3_read + displayName: Alluxio S3 API reads compared with direct Azure Blob reads + timeoutInMinutes: 240 + cancelTimeoutInMinutes: 30 + steps: + - bash: | + set -eo pipefail + + job_id="$(System.JobId)" + RUN_ID=$(Build.BuildId)-${job_id:0:8} + echo "Run ID: $RUN_ID" + + echo "##vso[task.setvariable variable=RUN_ID]$RUN_ID" + displayName: Set Run ID + - bash: |- + set -euo pipefail + if ! command -v helm >/dev/null 2>&1; then + curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash + fi + helm version --short + displayName: Install Helm + - task: KubeloginInstaller@0 + displayName: Install kubelogin + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -exo pipefail + set +x + set -Eeuo pipefail + umask 077 + mkdir -p -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" "$(Build.ArtifactStagingDirectory)/alluxio-s3-read" + chmod 700 "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" + export AZURE_CORE_ONLY_SHOW_ERRORS=true AZURE_CORE_OUTPUT=json + export KUBECONFIG="$HOME/.kube/config" + # Avoid WebSocket stream closures during long-running AKS exec commands. + export KUBECTL_REMOTE_COMMAND_WEBSOCKETS=false + fail() { + echo "ALLUXIO WARP FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO WARP FAILED: command at line $LINENO exited with status $?" >&2' ERR + trap 'rm -f -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/blob.bin" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/helm-registry.json"' EXIT + alluxio_image="telescope.azurecr.io/alluxio-enterprise" + operator_image="telescope.azurecr.io/alluxio-operator" + subscription="b8ceb4e5-f05b-4562-a9f5-14acb1f24219" + resource_group="alluxio-s3-read-$(RUN_ID)-$(System.JobAttempt)" + cluster="alluxio-s3-read" + location="westeurope" + images='{}' + for image in "$alluxio_image" "$operator_image"; do + tag="AI-3.8-15.1.28" + if [[ "$image" == "$operator_image" ]]; then tag="3.7.6"; fi + digest="$(az acr repository show \ + --name "telescope" \ + --subscription "137f0351-8235-42a6-ac7a-6b46be2d21c7" \ + --image "${image#*/}:$tag" | jq -er '.digest')" + images="$(jq --arg image "$image:$tag" --arg digest "$digest" '. + {($image): $digest}' <<< "$images")" + done + exists="$(az group exists \ + --name "$resource_group" \ + --subscription "$subscription")" + [[ "$exists" == false ]] || fail "Resource group already exists or could not be verified; refusing to provision into it" + echo '##vso[task.setvariable variable=SHOULD_CLEAN_UP_RESOURCE_GROUP]true' + + jq -n \ + --arg acr_name "telescope" --arg acr_subscription "137f0351-8235-42a6-ac7a-6b46be2d21c7" \ + --arg alluxio_image "$alluxio_image" --arg operator_image "$operator_image" \ + --arg resource_group "$resource_group" --arg subscription "$subscription" \ + --arg cluster "$cluster" --arg location "$location" --arg storage_account "alx$(Build.BuildId)l$(System.JobAttempt)" \ + --argjson image_digests "$images" \ + --arg operator_chart "oci://telescope.azurecr.io/helm/alluxio-operator" \ + --arg operator_version "3.7.6" --arg curl_version "8.12.1" \ + '$ARGS.named + { + worker_cache: "396Gi", worker_cache_reserved: "1Gi", + support_nodes: {count: 3, sku: "Standard_D8s_v6", max_egress_mbps_per_vm: 12500}, + worker_nodes: {count: 5, sku: "Standard_D16ds_v6", max_egress_mbps_per_vm: 12500}, + client_nodes: {count: 5, sku: "Standard_D8s_v6", max_egress_mbps_per_vm: 12500} + }' > "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/configuration.json" + displayName: Record run configuration and image digests + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: |+ + set -exo pipefail + az group create \ + --name "alluxio-s3-read-$(RUN_ID)-$(System.JobAttempt)" \ + --location "westeurope" \ + --subscription "b8ceb4e5-f05b-4562-a9f5-14acb1f24219" \ + + displayName: Create resource group in westeurope (b8ceb4e5-f05b-4562-a9f5-14acb1f24219) + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -exo pipefail + az aks create \ + --subscription "b8ceb4e5-f05b-4562-a9f5-14acb1f24219" \ + --resource-group "alluxio-s3-read-$(RUN_ID)-$(System.JobAttempt)" \ + --name "alluxio-s3-read" \ + --location "westeurope" \ + --kubernetes-version "1.36" \ + --nodepool-name systempool \ + --node-count 3 \ + --node-vm-size Standard_D8s_v6 \ + --network-plugin azure \ + --network-plugin-mode overlay \ + --enable-managed-identity \ + --enable-aad \ + --enable-azure-rbac \ + --disable-local-accounts \ + --no-ssh-key \ + --tier standard \ + --yes + displayName: Create cluster + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -exo pipefail + create_node_pool() { + local deadline sleep_between=30 attempt=0 output rc now remaining_retry_seconds + deadline=$(($(date +%s) + 600)) + while :; do + attempt=$((attempt + 1)) + if output=$(az aks nodepool add "$@" 2>&1); then + rc=0 + else + rc=$? + fi + echo "$output" + if [ "$rc" -eq 0 ]; then + return 0 + fi + if echo "$output" | grep -qiE "OperationNotAllowed"; then + now=$(date +%s) + if [ "$now" -ge "$deadline" ]; then + echo "Retriable error persisted past 600s retry window ($attempt attempts); giving up." + return "$rc" + fi + remaining_retry_seconds=$((deadline - now)) + echo "Attempt $attempt matched retriable pattern; retrying in $sleep_between seconds ($remaining_retry_seconds seconds remain in retry window)." + sleep "$sleep_between" + else + echo "Non-retriable error (rc=$rc); giving up after attempt $attempt." + return "$rc" + fi + done + } + + + create_node_pool \ + --cluster-name "alluxio-s3-read" \ + --resource-group "alluxio-s3-read-$(RUN_ID)-$(System.JobAttempt)" \ + --subscription "b8ceb4e5-f05b-4562-a9f5-14acb1f24219" \ + --name "workerpool" \ + --node-count 5 \ + --node-vm-size "Standard_D16ds_v6" \ + --mode User \ + --node-taints alluxio=true:NoSchedule \ + --node-osdisk-type Managed + displayName: Create node pool workerpool + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -exo pipefail + create_node_pool() { + local deadline sleep_between=30 attempt=0 output rc now remaining_retry_seconds + deadline=$(($(date +%s) + 600)) + while :; do + attempt=$((attempt + 1)) + if output=$(az aks nodepool add "$@" 2>&1); then + rc=0 + else + rc=$? + fi + echo "$output" + if [ "$rc" -eq 0 ]; then + return 0 + fi + if echo "$output" | grep -qiE "OperationNotAllowed"; then + now=$(date +%s) + if [ "$now" -ge "$deadline" ]; then + echo "Retriable error persisted past 600s retry window ($attempt attempts); giving up." + return "$rc" + fi + remaining_retry_seconds=$((deadline - now)) + echo "Attempt $attempt matched retriable pattern; retrying in $sleep_between seconds ($remaining_retry_seconds seconds remain in retry window)." + sleep "$sleep_between" + else + echo "Non-retriable error (rc=$rc); giving up after attempt $attempt." + return "$rc" + fi + done + } + + + create_node_pool \ + --cluster-name "alluxio-s3-read" \ + --resource-group "alluxio-s3-read-$(RUN_ID)-$(System.JobAttempt)" \ + --subscription "b8ceb4e5-f05b-4562-a9f5-14acb1f24219" \ + --name "clientpool" \ + --node-count 5 \ + --node-vm-size "Standard_D8s_v6" \ + --mode User \ + --node-taints warp=true:NoSchedule + displayName: Create node pool clientpool + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -exo pipefail + az aks get-credentials \ + --name "alluxio-s3-read" \ + --resource-group "alluxio-s3-read-$(RUN_ID)-$(System.JobAttempt)" \ + --subscription "b8ceb4e5-f05b-4562-a9f5-14acb1f24219" \ + --overwrite-existing + displayName: Get credentials for alluxio-s3-read + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: |- + set -exo pipefail + kubelogin convert-kubeconfig -l azurecli + displayName: Convert kubeconfig to Entra ID login + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -exo pipefail + set +x + set -Eeuo pipefail + umask 077 + mkdir -p -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" "$(Build.ArtifactStagingDirectory)/alluxio-s3-read" + chmod 700 "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" + export AZURE_CORE_ONLY_SHOW_ERRORS=true AZURE_CORE_OUTPUT=json + export KUBECONFIG="$HOME/.kube/config" + # Avoid WebSocket stream closures during long-running AKS exec commands. + export KUBECTL_REMOTE_COMMAND_WEBSOCKETS=false + fail() { + echo "ALLUXIO WARP FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO WARP FAILED: command at line $LINENO exited with status $?" >&2' ERR + trap 'rm -f -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/blob.bin" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/helm-registry.json"' EXIT + private_command() { + if "$@" > "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" 2> "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err"; then + cat "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" + else + fail "$1 failed; secret-bearing output withheld" + fi + } + require_secret() { + [[ -n "${!1:-}" && "${!1}" != '$('* ]] || fail "Required secret pipeline variable $1 is missing" + } + # The shared registry has a delete lock; keep credentials inside the disposable cluster instead of creating RBAC grants. + login_server="$(az acr show --name "telescope" --subscription "137f0351-8235-42a6-ac7a-6b46be2d21c7" | jq -er '.loginServer')" + REGISTRY_TOKEN="$(private_command az acr login \ + --name "telescope" \ + --subscription "137f0351-8235-42a6-ac7a-6b46be2d21c7" \ + --expose-token --query accessToken --output tsv)" + export REGISTRY_TOKEN + for namespace in alx-ns alluxio-operator; do + kubectl create namespace "$namespace" + pull_secret="$(jq -n --arg server "$login_server" --arg namespace "$namespace" '{ + apiVersion: "v1", kind: "Secret", + metadata: {name: "alluxio-acr", namespace: $namespace}, + type: "kubernetes.io/dockerconfigjson", + stringData: {".dockerconfigjson": ({ + auths: {($server): { + username: "00000000-0000-0000-0000-000000000000", + password: env.REGISTRY_TOKEN, + auth: ("00000000-0000-0000-0000-000000000000:" + env.REGISTRY_TOKEN | @base64) + }} + } | tojson)} + }')" + printf '%s\n' "$pull_secret" | + private_command kubectl create --validate=strict -f - > /dev/null + done + unset REGISTRY_TOKEN pull_secret + displayName: Configure short-lived ACR image pull credentials + name: alluxio_acr_credentials + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -exo pipefail + set +x + set -Eeuo pipefail + umask 077 + mkdir -p -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" "$(Build.ArtifactStagingDirectory)/alluxio-s3-read" + chmod 700 "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" + export AZURE_CORE_ONLY_SHOW_ERRORS=true AZURE_CORE_OUTPUT=json + export KUBECONFIG="$HOME/.kube/config" + # Avoid WebSocket stream closures during long-running AKS exec commands. + export KUBECTL_REMOTE_COMMAND_WEBSOCKETS=false + fail() { + echo "ALLUXIO WARP FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO WARP FAILED: command at line $LINENO exited with status $?" >&2' ERR + trap 'rm -f -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/blob.bin" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/helm-registry.json"' EXIT + fail() { + echo "ALLUXIO S3 READ FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO S3 READ FAILED: command at line $LINENO exited with status $?" >&2' ERR + private_command() { + if "$@" > "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" 2> "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err"; then + cat "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" + else + fail "$1 failed; secret-bearing output withheld" + fi + } + require_secret() { + [[ -n "${!1:-}" && "${!1}" != '$('* ]] || fail "Required secret pipeline variable $1 is missing" + } + # Prints a container SAS for the account selected by AZURE_STORAGE_ACCOUNT/KEY. + # $1 container, $2 permissions, $3 lifetime in hours. + make_sas() { + az storage container generate-sas \ + --name "$1" \ + --permissions "$2" \ + --expiry "$(date -u -d "+$3 hours" +%Y-%m-%dT%H:%MZ)" \ + --https-only 2> /dev/null | + jq -er 'select(type == "string" and length > 0)' 2> /dev/null + } + # Exports $2 as a secret pipeline variable named $1; the value never reaches the log. + publish_secret() { + local value="$2" + value="${value//'%'/'%AZP25'}" + value="${value//$'\n'/'%0A'}" + value="${value//$'\r'/'%0D'}" + printf '##vso[task.setvariable variable=%s;issecret=true]%s\n' "$1" "$value" + } + seed_account() { + local account="$1" location="$2" index + az storage account create \ + --name "$account" \ + --resource-group "alluxio-s3-read-$(RUN_ID)-$(System.JobAttempt)" \ + --subscription "b8ceb4e5-f05b-4562-a9f5-14acb1f24219" \ + --location "$location" \ + --kind StorageV2 \ + --sku Standard_LRS \ + --https-only true \ + --min-tls-version TLS1_2 \ + --allow-blob-public-access false \ + --hns false > /dev/null + export AZURE_STORAGE_ACCOUNT="$account" + AZURE_STORAGE_KEY="$(private_command az storage account keys list \ + --account-name "$account" \ + --resource-group "alluxio-s3-read-$(RUN_ID)-$(System.JobAttempt)" \ + --subscription "b8ceb4e5-f05b-4562-a9f5-14acb1f24219" | jq -er '.[0].value')" + export AZURE_STORAGE_KEY + az storage container create \ + --name s3-data \ + --public-access off > /dev/null + for ((index = 0; index < 16; index++)); do + # Fixed per-object keys produce deterministic, nonzero 64 MiB payloads. + head -c 67108864 /dev/zero | + openssl enc -aes-256-ctr -K "$(printf '%064x' "$index")" \ + -iv 00000000000000000000000000000000 > "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/blob.bin" + az storage blob upload \ + --container-name s3-data \ + --name "$(printf 'object-%02d.bin' "$index")" \ + --file "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/blob.bin" \ + --overwrite false > /dev/null + done + rm -f -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/blob.bin" + mkdir -p -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/small" + for ((index = 0; index < 1024; index++)); do + # Offset the key so small objects differ from the big ones; 1 MiB each. + head -c 1048576 /dev/zero | + openssl enc -aes-256-ctr -K "$(printf '%064x' "$((index + 16))")" \ + -iv 00000000000000000000000000000000 > "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/small/$(printf 'obj-%04d.bin' "$index")" + done + # One batch upload: each single `az storage blob upload` costs about 2 s of fixed overhead. + az storage blob upload-batch \ + --destination s3-data \ + --destination-path small \ + --source "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/small" \ + --overwrite false > /dev/null + rm -rf -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/small" + # --include m exposes metadata.hdi_isfolder; --num-results is explicit so a truncated listing cannot pass. + az storage blob list \ + --container-name s3-data \ + --include m \ + --num-results 5000 | + jq -e -L "$(Build.SourcesDirectory)/kcl/alluxio/s3_read" 'include "checks"; validate_s3_read_dataset' > /dev/null + } + seed_account "alx$(Build.BuildId)l$(System.JobAttempt)" "westeurope" + # The reads cover the whole 240-minute job timeout; an 8-hour read SAS is twice that, + # so it cannot expire mid-run. The write SAS is used by SeedCheckpointSets, which runs soon + # after this step; 2 hours covers it. + local_data_sas="$(make_sas s3-data rl 8)" || fail "Could not generate the local data SAS; secret-bearing output withheld" + az storage container create \ + --name checkpoint \ + --public-access off > /dev/null + checkpoint_read_sas="$(make_sas checkpoint rl 8)" || fail "Could not generate the checkpoint read SAS; secret-bearing output withheld" + checkpoint_write_sas="$(make_sas checkpoint cw 2)" || fail "Could not generate the checkpoint write SAS; secret-bearing output withheld" + unset AZURE_STORAGE_KEY + seed_account "alx$(Build.BuildId)r$(System.JobAttempt)" "eastus" + remote_data_sas="$(make_sas s3-data rl 8)" || fail "Could not generate the remote data SAS; secret-bearing output withheld" + unset AZURE_STORAGE_KEY + publish_secret LOCAL_DATA_SAS "$local_data_sas" + publish_secret REMOTE_DATA_SAS "$remote_data_sas" + publish_secret CHECKPOINT_READ_SAS "$checkpoint_read_sas" + publish_secret CHECKPOINT_WRITE_SAS "$checkpoint_write_sas" + unset local_data_sas remote_data_sas checkpoint_read_sas checkpoint_write_sas + jq -n \ + --arg local_account "alx$(Build.BuildId)l$(System.JobAttempt)" --arg local_location "westeurope" \ + --arg remote_account "alx$(Build.BuildId)r$(System.JobAttempt)" --arg remote_location "eastus" \ + '$ARGS.named + {container: "s3-data", big_object_count: 16, big_object_bytes: 67108864, small_object_count: 1024, small_object_bytes: 1048576}' \ + > "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/dataset.json" + displayName: Create local and remote Blob datasets for S3 reads + name: s3_read_dataset + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -exo pipefail + set +x + set -Eeuo pipefail + umask 077 + mkdir -p -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" "$(Build.ArtifactStagingDirectory)/alluxio-s3-read" + chmod 700 "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" + export AZURE_CORE_ONLY_SHOW_ERRORS=true AZURE_CORE_OUTPUT=json + export KUBECONFIG="$HOME/.kube/config" + # Avoid WebSocket stream closures during long-running AKS exec commands. + export KUBECTL_REMOTE_COMMAND_WEBSOCKETS=false + fail() { + echo "ALLUXIO WARP FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO WARP FAILED: command at line $LINENO exited with status $?" >&2' ERR + trap 'rm -f -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/blob.bin" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/helm-registry.json"' EXIT + fail() { + echo "ALLUXIO S3 READ FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO S3 READ FAILED: command at line $LINENO exited with status $?" >&2' ERR + kubectl create -f "$(Build.SourcesDirectory)/kcl/alluxio/s3_read/nvme.yaml" > /dev/null + # One pod per workerpool node. + kubectl rollout status daemonset/alluxio-nvme -n kube-system --timeout=600s + [[ "$(kubectl get daemonset alluxio-nvme -n kube-system -o jsonpath='{.status.numberReady}')" == 5 ]] || + fail "expected 5 ready NVMe pods" + for pod in $(kubectl get pods -n kube-system -l app=alluxio-nvme -o name); do + kubectl logs -n kube-system "$pod" | grep -q 'NVME READY /mnt/alluxio-nvme' || + fail "$pod did not report NVME READY" + done + displayName: Mount the local NVMe disk on every worker node + name: alluxio_nvme + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -exo pipefail + set +x + set -Eeuo pipefail + umask 077 + mkdir -p -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" "$(Build.ArtifactStagingDirectory)/alluxio-s3-read" + chmod 700 "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" + export AZURE_CORE_ONLY_SHOW_ERRORS=true AZURE_CORE_OUTPUT=json + export KUBECONFIG="$HOME/.kube/config" + # Avoid WebSocket stream closures during long-running AKS exec commands. + export KUBECTL_REMOTE_COMMAND_WEBSOCKETS=false + fail() { + echo "ALLUXIO WARP FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO WARP FAILED: command at line $LINENO exited with status $?" >&2' ERR + trap 'rm -f -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/blob.bin" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/helm-registry.json"' EXIT + private_command() { + if "$@" > "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" 2> "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err"; then + cat "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" + else + fail "$1 failed; secret-bearing output withheld" + fi + } + require_secret() { + [[ -n "${!1:-}" && "${!1}" != '$('* ]] || fail "Required secret pipeline variable $1 is missing" + } + login_server="$(az acr show --name "telescope" --subscription "137f0351-8235-42a6-ac7a-6b46be2d21c7" | jq -er '.loginServer')" + registry_token="$(private_command az acr login \ + --name "telescope" \ + --subscription "137f0351-8235-42a6-ac7a-6b46be2d21c7" \ + --expose-token --query accessToken --output tsv)" + printf '%s' "$registry_token" | + private_command helm registry login "$login_server" \ + --username 00000000-0000-0000-0000-000000000000 \ + --password-stdin --registry-config "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/helm-registry.json" > /dev/null + unset registry_token + jq -n --arg image "telescope.azurecr.io/alluxio-operator" --arg tag "3.7.6" \ + '{global: {image: $image, imageTag: $tag, imagePullSecrets: ["alluxio-acr"]}}' > "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/operator-values.json" + helm install operator "oci://telescope.azurecr.io/helm/alluxio-operator" \ + --version "3.7.6" \ + --registry-config "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/helm-registry.json" \ + --namespace alluxio-operator \ + --create-namespace \ + --values "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/operator-values.json" \ + --wait + for crd in alluxioclusters licenses underfilesystems; do + kubectl wait --for=condition=Established \ + "crd/$crd.k8s-operator.alluxio.com" --timeout=120s + done + displayName: Install the Alluxio operator + name: alluxio_operator + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -exo pipefail + set +x + set -Eeuo pipefail + umask 077 + mkdir -p -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" "$(Build.ArtifactStagingDirectory)/alluxio-s3-read" + chmod 700 "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" + export AZURE_CORE_ONLY_SHOW_ERRORS=true AZURE_CORE_OUTPUT=json + export KUBECONFIG="$HOME/.kube/config" + # Avoid WebSocket stream closures during long-running AKS exec commands. + export KUBECTL_REMOTE_COMMAND_WEBSOCKETS=false + fail() { + echo "ALLUXIO WARP FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO WARP FAILED: command at line $LINENO exited with status $?" >&2' ERR + trap 'rm -f -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/blob.bin" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/helm-registry.json"' EXIT + private_command() { + if "$@" > "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" 2> "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err"; then + cat "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" + else + fail "$1 failed; secret-bearing output withheld" + fi + } + require_secret() { + [[ -n "${!1:-}" && "${!1}" != '$('* ]] || fail "Required secret pipeline variable $1 is missing" + } + wait_phase() { + local kind="$1" name="$2" field="$3" expected="$4" phase deadline=$((SECONDS + 900)) + while :; do + phase="$(kubectl get \ + "$kind" "$name" -n alx-ns -o "jsonpath={.status.$field}")" + [[ "$phase" != "$expected" ]] || return 0 + case "$phase" in + Failed|Error|Terminated) fail "$kind/$name failed; inspect securely in cluster" ;; + esac + (( SECONDS < deadline )) || fail "$kind/$name did not reach $expected before timeout" + sleep 10 + done + } + redact() { + local line secret + while IFS= read -r line || [[ -n "$line" ]]; do + for secret in "${ALLUXIO_LICENSE_STRING:-}" "${BLOB_SAS:-}"; do + if [[ -n "$secret" ]]; then line="${line//"$secret"/}"; fi + done + printf '%s\n' "$line" + done + } + require_secret ALLUXIO_LICENSE_STRING + patch="$(jq -n --arg image "telescope.azurecr.io/alluxio-enterprise" --arg tag "AI-3.8-15.1.28" \ + '{spec: {image: $image, imageTag: $tag}}')" + cluster="$(kubectl patch --local --type=merge -f "$(Build.SourcesDirectory)/kcl/alluxio/s3_read/cluster.yaml" -p "$patch" -o yaml)" + printf '%s\n' "$cluster" | kubectl create --dry-run=server --validate=strict -f - > /dev/null + printf '%s\n' "$cluster" | kubectl create -f - > /dev/null + license="$(jq -n '{spec: {licenseString: env.ALLUXIO_LICENSE_STRING}}' | + kubectl patch --local --type=merge -f "$(Build.SourcesDirectory)/kcl/alluxio/warp/license.yaml" \ + --patch-file /dev/stdin -o yaml 2> >(redact >&2))" + printf '%s\n' "$license" | + kubectl create --dry-run=server --validate=strict -f - > /dev/null 2> >(redact >&2) + printf '%s\n' "$license" | kubectl create -f - > /dev/null 2> >(redact >&2) + unset license + wait_phase license alluxio-license phase Completed + wait_phase alluxiocluster alluxio phase Ready + for pod in alluxio-coordinator-0 alluxio-worker-0; do + kubectl wait -n alx-ns --for=condition=Ready "pod/$pod" --timeout=600s + done + displayName: Create Alluxio and apply the deployment license + env: + ALLUXIO_LICENSE_STRING: $(ALLUXIO_LICENSE_STRING) + name: alluxio_cluster + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -exo pipefail + set +x + set -Eeuo pipefail + umask 077 + mkdir -p -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" "$(Build.ArtifactStagingDirectory)/alluxio-s3-read" + chmod 700 "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" + export AZURE_CORE_ONLY_SHOW_ERRORS=true AZURE_CORE_OUTPUT=json + export KUBECONFIG="$HOME/.kube/config" + # Avoid WebSocket stream closures during long-running AKS exec commands. + export KUBECTL_REMOTE_COMMAND_WEBSOCKETS=false + fail() { + echo "ALLUXIO WARP FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO WARP FAILED: command at line $LINENO exited with status $?" >&2' ERR + trap 'rm -f -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/blob.bin" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/helm-registry.json"' EXIT + private_command() { + if "$@" > "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" 2> "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err"; then + cat "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" + else + fail "$1 failed; secret-bearing output withheld" + fi + } + require_secret() { + [[ -n "${!1:-}" && "${!1}" != '$('* ]] || fail "Required secret pipeline variable $1 is missing" + } + wait_phase() { + local kind="$1" name="$2" field="$3" expected="$4" phase deadline=$((SECONDS + 900)) + while :; do + phase="$(kubectl get \ + "$kind" "$name" -n alx-ns -o "jsonpath={.status.$field}")" + [[ "$phase" != "$expected" ]] || return 0 + case "$phase" in + Failed|Error|Terminated) fail "$kind/$name failed; inspect securely in cluster" ;; + esac + (( SECONDS < deadline )) || fail "$kind/$name did not reach $expected before timeout" + sleep 10 + done + } + redact() { + local line secret + while IFS= read -r line || [[ -n "$line" ]]; do + for secret in "${ALLUXIO_LICENSE_STRING:-}" "${BLOB_SAS:-}"; do + if [[ -n "$secret" ]]; then line="${line//"$secret"/}"; fi + done + printf '%s\n' "$line" + done + } + require_secret BLOB_SAS + ufs="$(jq -n --arg account "alx$(Build.BuildId)l$(System.JobAttempt)" '{ + metadata: {name: "alluxio-blob"}, + spec: {mountPath: "/blob", + path: ("abfs://" + $account + ".blob.core.windows.net/s3-data/"), + mountOptions: {"alluxio.underfs.abfs.sas.token": env.BLOB_SAS}} + }' | kubectl patch --local --type=merge -f "$(Build.SourcesDirectory)/kcl/alluxio/warp/ufs.yaml" \ + --patch-file /dev/stdin -o yaml 2> >(redact >&2))" + printf '%s\n' "$ufs" | + kubectl create --dry-run=server --validate=strict -f - > /dev/null 2> >(redact >&2) + printf '%s\n' "$ufs" | kubectl create -f - > /dev/null 2> >(redact >&2) + unset ufs + wait_phase ufs alluxio-blob phase Ready + kubectl exec -n alx-ns alluxio-coordinator-0 \ + -c alluxio-coordinator -- alluxio fs ls /blob | redact + displayName: Mount Azure Blob at /blob + env: + BLOB_SAS: $(LOCAL_DATA_SAS) + name: alluxio_mount_blob + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -exo pipefail + set +x + set -Eeuo pipefail + umask 077 + mkdir -p -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" "$(Build.ArtifactStagingDirectory)/alluxio-s3-read" + chmod 700 "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" + export AZURE_CORE_ONLY_SHOW_ERRORS=true AZURE_CORE_OUTPUT=json + export KUBECONFIG="$HOME/.kube/config" + # Avoid WebSocket stream closures during long-running AKS exec commands. + export KUBECTL_REMOTE_COMMAND_WEBSOCKETS=false + fail() { + echo "ALLUXIO WARP FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO WARP FAILED: command at line $LINENO exited with status $?" >&2' ERR + trap 'rm -f -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/blob.bin" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/helm-registry.json"' EXIT + private_command() { + if "$@" > "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" 2> "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err"; then + cat "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" + else + fail "$1 failed; secret-bearing output withheld" + fi + } + require_secret() { + [[ -n "${!1:-}" && "${!1}" != '$('* ]] || fail "Required secret pipeline variable $1 is missing" + } + wait_phase() { + local kind="$1" name="$2" field="$3" expected="$4" phase deadline=$((SECONDS + 900)) + while :; do + phase="$(kubectl get \ + "$kind" "$name" -n alx-ns -o "jsonpath={.status.$field}")" + [[ "$phase" != "$expected" ]] || return 0 + case "$phase" in + Failed|Error|Terminated) fail "$kind/$name failed; inspect securely in cluster" ;; + esac + (( SECONDS < deadline )) || fail "$kind/$name did not reach $expected before timeout" + sleep 10 + done + } + redact() { + local line secret + while IFS= read -r line || [[ -n "$line" ]]; do + for secret in "${ALLUXIO_LICENSE_STRING:-}" "${BLOB_SAS:-}"; do + if [[ -n "$secret" ]]; then line="${line//"$secret"/}"; fi + done + printf '%s\n' "$line" + done + } + require_secret BLOB_SAS + ufs="$(jq -n --arg account "alx$(Build.BuildId)r$(System.JobAttempt)" '{ + metadata: {name: "alluxio-xregion"}, + spec: {mountPath: "/xregion", + path: ("abfs://" + $account + ".blob.core.windows.net/s3-data/"), + mountOptions: {"alluxio.underfs.abfs.sas.token": env.BLOB_SAS}} + }' | kubectl patch --local --type=merge -f "$(Build.SourcesDirectory)/kcl/alluxio/warp/ufs.yaml" \ + --patch-file /dev/stdin -o yaml 2> >(redact >&2))" + printf '%s\n' "$ufs" | + kubectl create --dry-run=server --validate=strict -f - > /dev/null 2> >(redact >&2) + printf '%s\n' "$ufs" | kubectl create -f - > /dev/null 2> >(redact >&2) + unset ufs + wait_phase ufs alluxio-xregion phase Ready + kubectl exec -n alx-ns alluxio-coordinator-0 \ + -c alluxio-coordinator -- alluxio fs ls /xregion | redact + displayName: Mount Azure Blob at /xregion + env: + BLOB_SAS: $(REMOTE_DATA_SAS) + name: alluxio_mount_xregion + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -exo pipefail + set +x + set -Eeuo pipefail + umask 077 + mkdir -p -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" "$(Build.ArtifactStagingDirectory)/alluxio-s3-read" + chmod 700 "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" + export AZURE_CORE_ONLY_SHOW_ERRORS=true AZURE_CORE_OUTPUT=json + export KUBECONFIG="$HOME/.kube/config" + # Avoid WebSocket stream closures during long-running AKS exec commands. + export KUBECTL_REMOTE_COMMAND_WEBSOCKETS=false + fail() { + echo "ALLUXIO WARP FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO WARP FAILED: command at line $LINENO exited with status $?" >&2' ERR + trap 'rm -f -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/blob.bin" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/helm-registry.json"' EXIT + private_command() { + if "$@" > "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" 2> "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err"; then + cat "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" + else + fail "$1 failed; secret-bearing output withheld" + fi + } + require_secret() { + [[ -n "${!1:-}" && "${!1}" != '$('* ]] || fail "Required secret pipeline variable $1 is missing" + } + wait_phase() { + local kind="$1" name="$2" field="$3" expected="$4" phase deadline=$((SECONDS + 900)) + while :; do + phase="$(kubectl get \ + "$kind" "$name" -n alx-ns -o "jsonpath={.status.$field}")" + [[ "$phase" != "$expected" ]] || return 0 + case "$phase" in + Failed|Error|Terminated) fail "$kind/$name failed; inspect securely in cluster" ;; + esac + (( SECONDS < deadline )) || fail "$kind/$name did not reach $expected before timeout" + sleep 10 + done + } + redact() { + local line secret + while IFS= read -r line || [[ -n "$line" ]]; do + for secret in "${ALLUXIO_LICENSE_STRING:-}" "${BLOB_SAS:-}"; do + if [[ -n "$secret" ]]; then line="${line//"$secret"/}"; fi + done + printf '%s\n' "$line" + done + } + require_secret BLOB_SAS + ufs="$(jq -n --arg account "alx$(Build.BuildId)l$(System.JobAttempt)" '{ + metadata: {name: "alluxio-ckpt"}, + spec: {mountPath: "/ckpt", + path: ("abfs://" + $account + ".blob.core.windows.net/checkpoint/"), + mountOptions: {"alluxio.underfs.abfs.sas.token": env.BLOB_SAS}} + }' | kubectl patch --local --type=merge -f "$(Build.SourcesDirectory)/kcl/alluxio/warp/ufs.yaml" \ + --patch-file /dev/stdin -o yaml 2> >(redact >&2))" + printf '%s\n' "$ufs" | + kubectl create --dry-run=server --validate=strict -f - > /dev/null 2> >(redact >&2) + printf '%s\n' "$ufs" | kubectl create -f - > /dev/null 2> >(redact >&2) + unset ufs + wait_phase ufs alluxio-ckpt phase Ready + kubectl exec -n alx-ns alluxio-coordinator-0 \ + -c alluxio-coordinator -- alluxio fs ls /ckpt | redact + displayName: Mount Azure Blob at /ckpt + env: + BLOB_SAS: $(CHECKPOINT_READ_SAS) + name: alluxio_mount_ckpt + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -exo pipefail + set +x + set -Eeuo pipefail + umask 077 + mkdir -p -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" "$(Build.ArtifactStagingDirectory)/alluxio-s3-read" + chmod 700 "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" + export AZURE_CORE_ONLY_SHOW_ERRORS=true AZURE_CORE_OUTPUT=json + export KUBECONFIG="$HOME/.kube/config" + # Avoid WebSocket stream closures during long-running AKS exec commands. + export KUBECTL_REMOTE_COMMAND_WEBSOCKETS=false + fail() { + echo "ALLUXIO WARP FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO WARP FAILED: command at line $LINENO exited with status $?" >&2' ERR + trap 'rm -f -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/blob.bin" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/helm-registry.json"' EXIT + fail() { + echo "ALLUXIO S3 READ FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO S3 READ FAILED: command at line $LINENO exited with status $?" >&2' ERR + private_command() { + if "$@" > "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" 2> "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err"; then + cat "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" + else + fail "$1 failed; secret-bearing output withheld" + fi + } + require_secret() { + [[ -n "${!1:-}" && "${!1}" != '$('* ]] || fail "Required secret pipeline variable $1 is missing" + } + worker_hosts() { + local pods ready_ips count + pods="$(kubectl get pods -n alx-ns -l app.kubernetes.io/component=worker -o json)" || + fail "could not list the Alluxio worker pods" + ready_ips="$(jq -c '[.items[] | + select(.status.phase == "Running" and + any(.status.conditions[]?; .type == "Ready" and .status == "True")) | + .status.podIP | select(. != null and . != "")] | sort' <<< "$pods")" + count="$(jq 'length' <<< "$ready_ips")" + # A different count means a worker is missing or restarting. + [[ "$count" == 5 ]] || fail "expected 5 ready Alluxio workers, found $count: $ready_ips" + # 29998 is the Alluxio worker S3 port. + jq -r 'map(. + ":29998") | join(",")' <<< "$ready_ips" + } + worker_ufs_bytes() { + local workers worker count=0 total=0 value + workers="$(kubectl get pods -n alx-ns -l app.kubernetes.io/component=worker -o jsonpath='{.items[*].metadata.name}')" + for worker in $workers; do + value="$(kubectl get --raw "/api/v1/namespaces/alx-ns/pods/$worker:30000/proxy/metrics/" | + awk -v name="alluxio_external_data_read_bytes_total" ' + $1 == name || index($1, name "{") == 1 { sum += $NF; found = 1 } + END { if (!found) exit 1; printf "%.0f", sum }')" || + fail "worker $worker does not expose alluxio_external_data_read_bytes_total" + total=$((total + value)) + count=$((count + 1)) + done + (( count == 5 )) || fail "expected 5 Alluxio workers for the metrics scrape, found $count" + printf '%s\n' "$total" + } + redact() { + local line secret + while IFS= read -r line || [[ -n "$line" ]]; do + for secret in "${LOCAL_DATA_SAS:-}" "${REMOTE_DATA_SAS:-}" "${CHECKPOINT_READ_SAS:-}" "${CHECKPOINT_WRITE_SAS:-}"; do + if [[ -n "$secret" ]]; then line="${line//"$secret"/}"; fi + done + printf '%s\n' "$line" + done + } + for variable in LOCAL_DATA_SAS REMOTE_DATA_SAS CHECKPOINT_READ_SAS CHECKPOINT_WRITE_SAS; do + require_secret "$variable" + done + kubectl create configmap s3c-script -n alx-ns --from-file=s3c.sh="$(Build.SourcesDirectory)/kcl/alluxio/s3_read/s3c.sh" > /dev/null + # Process substitution keeps every SAS off argv and off disk; the secret is created, never applied. + kubectl create secret generic s3c-sas -n alx-ns \ + --from-file=local-data=<(printf '%s' "$LOCAL_DATA_SAS") \ + --from-file=remote-data=<(printf '%s' "$REMOTE_DATA_SAS") \ + --from-file=checkpoint-read=<(printf '%s' "$CHECKPOINT_READ_SAS") \ + --from-file=checkpoint-write=<(printf '%s' "$CHECKPOINT_WRITE_SAS") \ + > /dev/null 2> >(redact >&2) + for index in $(seq 1 5); do + patch="$(jq -n --arg name "s3c-$index" '{metadata: {name: $name}}')" + pod="$(kubectl patch --local --type=merge -f "$(Build.SourcesDirectory)/kcl/alluxio/s3_read/clients.yaml" -p "$patch" -o yaml)" + printf '%s\n' "$pod" | kubectl create --dry-run=server --validate=strict -f - > /dev/null + printf '%s\n' "$pod" | kubectl create -f - > /dev/null + done + kubectl wait -n alx-ns --for=condition=Ready pod -l app=s3c --timeout=600s + # The anti-affinity rule must have put the client pods on different nodes. + kubectl get pods -n alx-ns -l app=s3c -o json | + jq -e '[.items[].spec.nodeName] | unique | length == 5' > /dev/null || + fail "the 5 client pods are not on 5 different nodes" + key_script="$(cat <<'KEYS' + set -eu + seq 0 15 | awk '{printf "object-%02d.bin\n", $1}' > /tmp/big.txt + seq 0 1023 | awk '{printf "small/obj-%04d.bin\n", $1}' > /tmp/small.txt + for set in 1 2 3 4 5 6; do + seq 0 7 | awk -v set="$set" '{printf "set-%d/part-%d.bin\n", set, $1}' > "/tmp/checkpoint-$set.txt" + done + KEYS + )" + for index in $(seq 1 5); do + kubectl exec -n alx-ns "s3c-$index" -c s3c -- sh -c "$key_script" + done + displayName: Create the S3 read client pods + env: + LOCAL_DATA_SAS: $(LOCAL_DATA_SAS) + REMOTE_DATA_SAS: $(REMOTE_DATA_SAS) + CHECKPOINT_READ_SAS: $(CHECKPOINT_READ_SAS) + CHECKPOINT_WRITE_SAS: $(CHECKPOINT_WRITE_SAS) + name: s3_read_clients + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -exo pipefail + set +x + set -Eeuo pipefail + umask 077 + mkdir -p -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" "$(Build.ArtifactStagingDirectory)/alluxio-s3-read" + chmod 700 "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" + export AZURE_CORE_ONLY_SHOW_ERRORS=true AZURE_CORE_OUTPUT=json + export KUBECONFIG="$HOME/.kube/config" + # Avoid WebSocket stream closures during long-running AKS exec commands. + export KUBECTL_REMOTE_COMMAND_WEBSOCKETS=false + fail() { + echo "ALLUXIO WARP FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO WARP FAILED: command at line $LINENO exited with status $?" >&2' ERR + trap 'rm -f -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/blob.bin" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/helm-registry.json"' EXIT + fail() { + echo "ALLUXIO S3 READ FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO S3 READ FAILED: command at line $LINENO exited with status $?" >&2' ERR + private_command() { + if "$@" > "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" 2> "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err"; then + cat "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" + else + fail "$1 failed; secret-bearing output withheld" + fi + } + require_secret() { + [[ -n "${!1:-}" && "${!1}" != '$('* ]] || fail "Required secret pipeline variable $1 is missing" + } + worker_hosts() { + local pods ready_ips count + pods="$(kubectl get pods -n alx-ns -l app.kubernetes.io/component=worker -o json)" || + fail "could not list the Alluxio worker pods" + ready_ips="$(jq -c '[.items[] | + select(.status.phase == "Running" and + any(.status.conditions[]?; .type == "Ready" and .status == "True")) | + .status.podIP | select(. != null and . != "")] | sort' <<< "$pods")" + count="$(jq 'length' <<< "$ready_ips")" + # A different count means a worker is missing or restarting. + [[ "$count" == 5 ]] || fail "expected 5 ready Alluxio workers, found $count: $ready_ips" + # 29998 is the Alluxio worker S3 port. + jq -r 'map(. + ":29998") | join(",")' <<< "$ready_ips" + } + worker_ufs_bytes() { + local workers worker count=0 total=0 value + workers="$(kubectl get pods -n alx-ns -l app.kubernetes.io/component=worker -o jsonpath='{.items[*].metadata.name}')" + for worker in $workers; do + value="$(kubectl get --raw "/api/v1/namespaces/alx-ns/pods/$worker:30000/proxy/metrics/" | + awk -v name="alluxio_external_data_read_bytes_total" ' + $1 == name || index($1, name "{") == 1 { sum += $NF; found = 1 } + END { if (!found) exit 1; printf "%.0f", sum }')" || + fail "worker $worker does not expose alluxio_external_data_read_bytes_total" + total=$((total + value)) + count=$((count + 1)) + done + (( count == 5 )) || fail "expected 5 Alluxio workers for the metrics scrape, found $count" + printf '%s\n' "$total" + } + redact() { + local line secret + while IFS= read -r line || [[ -n "$line" ]]; do + for secret in "${LOCAL_DATA_SAS:-}" "${REMOTE_DATA_SAS:-}" "${CHECKPOINT_READ_SAS:-}" "${CHECKPOINT_WRITE_SAS:-}"; do + if [[ -n "$secret" ]]; then line="${line//"$secret"/}"; fi + done + printf '%s\n' "$line" + done + } + seed_script="$(cat <<'SEED' + set -eu + umask 077 + account=$1 + shift + sas="$(cat /sas/checkpoint-write)" + trap 'rm -f /scratch/*.bin /scratch/*.curl' EXIT + upload_part() { + local set="$1" part="$2" + local file="/scratch/set-$set-part-$part.bin" config="/scratch/set-$set-part-$part.curl" + # /dev/urandom, not openssl: the client image has no openssl, and reads only need incompressible bytes. + dd if=/dev/urandom of="$file" bs=1048576 count=2048 2> /dev/null + [ "$(wc -c < "$file")" -eq 2147483648 ] || { echo "ALLUXIO S3 READ FAILED: short temp file $file" >&2; exit 1; } + # The SAS goes into a 0600 curl config, not onto argv. Put Blob needs a Content-Length, + # so the body is a file (-T), not a pipe; x-ms-version 2019-12-12 allows a single 5000 MiB Put Blob. + printf 'url = "https://%s.blob.core.windows.net/checkpoint/set-%s/part-%s.bin?%s"\n' \ + "$account" "$set" "$part" "$sas" > "$config" + # Each 2 GiB attempt is capped at 30 minutes and no retry starts after 30 minutes, + # so a stalled upload fails the step long before the job timeout. + curl --silent --show-error --fail --retry 3 --retry-delay 5 --max-time 1800 --retry-max-time 1800 --config "$config" \ + -T "$file" \ + -H 'x-ms-blob-type: BlockBlob' \ + -H 'x-ms-version: 2019-12-12' > /dev/null || { echo "ALLUXIO S3 READ FAILED: upload of set-$set/part-$part failed" >&2; exit 1; } + rm -f "$file" "$config" + } + for set in "$@"; do + pids="" + for part in 0 1 2 3 4 5 6 7; do + upload_part "$set" "$part" & + pids="$pids $!" + done + for pid in $pids; do + wait "$pid" || { echo "ALLUXIO S3 READ FAILED: set $set did not finish uploading" >&2; exit 1; } + done + echo "set-$set uploaded" + done + SEED + )" + # A kubectl exec stream can drop during a long upload and still return 0 while the upload keeps running + # in the pod. So the upload runs detached in the pod (setsid, stdio not tied to the exec) and writes its + # log and exit status to /scratch; short execs poll for the status file. + # The sets a pod printed as uploaded are then counted against the sets assigned to it. + seed_run='sh /scratch/seed.sh "$@" > /scratch/seed.log 2>&1 + echo $? > /scratch/seed.rc' + seed_pod() { + local index="$1" rc="" deadline + local pod="s3c-$index" + shift + # One short exec writes both scripts (passed as arguments, not stdin) and starts the upload detached. + kubectl exec -n alx-ns "$pod" -c s3c -- sh -c 'printf "%s\n" "$1" > /scratch/seed.sh + printf "%s\n" "$2" > /scratch/seed-run.sh + shift 2 + rm -f /scratch/seed.rc /scratch/seed.log + setsid sh /scratch/seed-run.sh "$@" < /dev/null > /dev/null 2>&1 &' sh "$seed_script" "$seed_run" "alx$(Build.BuildId)l$(System.JobAttempt)" "$@" + # A pod uploads at most 2 sets of 16 GiB, which takes a few minutes; 40 minutes is a generous bound. + deadline=$((SECONDS + 2400)) + until rc="$(kubectl exec -n alx-ns "$pod" -c s3c -- cat /scratch/seed.rc 2> /dev/null)"; do + if (( SECONDS >= deadline )); then + rc=timeout + break + fi + sleep 15 + done + kubectl exec -n alx-ns "$pod" -c s3c -- cat /scratch/seed.log 2>&1 | redact > "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/checkpoint-seed-$pod.log" || true + echo "$rc" > "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/checkpoint-seed-$pod.rc" + } + pids=() + assigned=() + for index in $(seq 1 5); do + sets="" + for set in 1 2 3 4 5 6; do + if (( (set - 1) % 5 + 1 == index )); then + sets="$sets $set" + fi + done + assigned[index]="$sets" + rm -f "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/checkpoint-seed-s3c-$index.rc" + seed_pod "$index" $sets & + pids+=($!) + done + for pid in "${pids[@]}"; do + wait "$pid" || true + done + seed_failed=0 + for index in $(seq 1 5); do + pod="s3c-$index" + log="$(Build.ArtifactStagingDirectory)/alluxio-s3-read/checkpoint-seed-$pod.log" + rc="$(cat "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/checkpoint-seed-$pod.rc" 2> /dev/null || echo missing)" + uploaded="$(sed -n 's/^\(set-[0-9][0-9]*\) uploaded$/\1/p' "$log" | paste -sd, -)" + count="$(grep -c '^set-[0-9]* uploaded$' "$log" || true)" + want="$(wc -w <<< "${assigned[index]}" | tr -d ' ')" + echo "$pod: exit $rc, uploaded sets: ${uploaded:-none}" + if [[ "$rc" != 0 ]] || (( count < want )); then + echo "ALLUXIO S3 READ FAILED: $pod uploaded $count of $want assigned sets (exit $rc)" >&2 + seed_failed=1 + fi + done + (( seed_failed == 0 )) || exit 1 + list_script="$(cat <<'LIST' + set -eu + umask 077 + sas="$(cat /sas/checkpoint-read)" + trap 'rm -f /scratch/list.curl' EXIT + printf 'url = "https://%s.blob.core.windows.net/checkpoint?restype=container&comp=list&include=metadata&maxresults=5000&%s"\n' \ + "$1" "$sas" > /scratch/list.curl + # One tab-separated line per blob: name, size, hdi_isfolder metadata. A non-empty NextMarker means a truncated listing. + curl --silent --show-error --fail --max-time 120 --config /scratch/list.curl -H 'x-ms-version: 2019-12-12' | + awk 'BEGIN { RS = "<" } + { gsub(/[\r\n]/, "") } + /^Blob>/ { name = ""; size = ""; folder = "" } + /^Name>/ { name = substr($0, 6) } + /^Content-Length>/ { size = substr($0, 16) } + /^hdi_isfolder>/ { folder = substr($0, 14) } + /^NextMarker>/ { print "#truncated" } + /^\/Blob>/ { printf "%s\t%s\t%s\n", name, size, folder }' + LIST + )" + listing="$(kubectl exec -n alx-ns s3c-1 -c s3c -- sh -c "$list_script" sh "alx$(Build.BuildId)l$(System.JobAttempt)" 2> >(redact >&2))" || + fail "could not list the checkpoint container" + # Keep what the container holds (name, size, marker; no SAS) so a failed validation can be inspected. + printf '%s\n' "$listing" | grep -v '^$' > "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/checkpoint-listing.tsv" || true + echo "checkpoint container: $(wc -l < "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/checkpoint-listing.tsv" | tr -d ' ') blobs, distinct sizes: $(cut -f2 "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/checkpoint-listing.tsv" | sort -u | paste -sd, -)" + [[ "$listing" != *'#truncated'* ]] || fail "the checkpoint listing is truncated" + # Each listing line is name, size and hdi_isfolder metadata; checks.jq decides whether the container is right. + printf '%s\n' "$listing" | jq -R -s -L "$(Build.SourcesDirectory)/kcl/alluxio/s3_read" ' + include "checks"; + [split("\n")[] | select(length > 0) | split("\t") | { + name: .[0], + properties: {contentLength: (.[1] | tonumber)}, + metadata: (if .[2] == "" then null else {hdi_isfolder: .[2]} end)}] + | validate_checkpoint_dataset' > /dev/null || fail "checkpoint container validation failed" + jq -n '{checkpoint_sets: 6, checkpoint_parts_per_set: 8, checkpoint_object_count: 48, checkpoint_object_bytes: 2147483648}' \ + > "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/checkpoint.json" + displayName: Generate the checkpoint sets in the clients + env: + CHECKPOINT_READ_SAS: $(CHECKPOINT_READ_SAS) + CHECKPOINT_WRITE_SAS: $(CHECKPOINT_WRITE_SAS) + name: s3_read_checkpoint + - bash: | + set -exo pipefail + TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%S.000Z") + echo "BENCHMARK_START_TIME: $TIMESTAMP" + echo "##vso[task.setvariable variable=BENCHMARK_START_TIME]$TIMESTAMP" + displayName: Record current time as BENCHMARK_START_TIME + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -exo pipefail + set +x + set -Eeuo pipefail + umask 077 + mkdir -p -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" "$(Build.ArtifactStagingDirectory)/alluxio-s3-read" + chmod 700 "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" + export AZURE_CORE_ONLY_SHOW_ERRORS=true AZURE_CORE_OUTPUT=json + export KUBECONFIG="$HOME/.kube/config" + # Avoid WebSocket stream closures during long-running AKS exec commands. + export KUBECTL_REMOTE_COMMAND_WEBSOCKETS=false + fail() { + echo "ALLUXIO WARP FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO WARP FAILED: command at line $LINENO exited with status $?" >&2' ERR + trap 'rm -f -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/blob.bin" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/helm-registry.json"' EXIT + fail() { + echo "ALLUXIO S3 READ FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO S3 READ FAILED: command at line $LINENO exited with status $?" >&2' ERR + private_command() { + if "$@" > "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" 2> "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err"; then + cat "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" + else + fail "$1 failed; secret-bearing output withheld" + fi + } + require_secret() { + [[ -n "${!1:-}" && "${!1}" != '$('* ]] || fail "Required secret pipeline variable $1 is missing" + } + worker_hosts() { + local pods ready_ips count + pods="$(kubectl get pods -n alx-ns -l app.kubernetes.io/component=worker -o json)" || + fail "could not list the Alluxio worker pods" + ready_ips="$(jq -c '[.items[] | + select(.status.phase == "Running" and + any(.status.conditions[]?; .type == "Ready" and .status == "True")) | + .status.podIP | select(. != null and . != "")] | sort' <<< "$pods")" + count="$(jq 'length' <<< "$ready_ips")" + # A different count means a worker is missing or restarting. + [[ "$count" == 5 ]] || fail "expected 5 ready Alluxio workers, found $count: $ready_ips" + # 29998 is the Alluxio worker S3 port. + jq -r 'map(. + ":29998") | join(",")' <<< "$ready_ips" + } + worker_ufs_bytes() { + local workers worker count=0 total=0 value + workers="$(kubectl get pods -n alx-ns -l app.kubernetes.io/component=worker -o jsonpath='{.items[*].metadata.name}')" + for worker in $workers; do + value="$(kubectl get --raw "/api/v1/namespaces/alx-ns/pods/$worker:30000/proxy/metrics/" | + awk -v name="alluxio_external_data_read_bytes_total" ' + $1 == name || index($1, name "{") == 1 { sum += $NF; found = 1 } + END { if (!found) exit 1; printf "%.0f", sum }')" || + fail "worker $worker does not expose alluxio_external_data_read_bytes_total" + total=$((total + value)) + count=$((count + 1)) + done + (( count == 5 )) || fail "expected 5 Alluxio workers for the metrics scrape, found $count" + printf '%s\n' "$total" + } + redact() { + local line secret + while IFS= read -r line || [[ -n "$line" ]]; do + for secret in "${LOCAL_DATA_SAS:-}" "${REMOTE_DATA_SAS:-}" "${CHECKPOINT_READ_SAS:-}" "${CHECKPOINT_WRITE_SAS:-}"; do + if [[ -n "$secret" ]]; then line="${line//"$secret"/}"; fi + done + printf '%s\n' "$line" + done + } + mkdir -p -- "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/runs" + : > "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/runs/index.jsonl" + alluxio() { + kubectl exec -n alx-ns alluxio-coordinator-0 \ + -c alluxio-coordinator -- alluxio "$@" + } + # Runs s3c.sh once in client pod s3c-1; the JSON result goes to stdout, redacted. + # $1 side (alluxio|blob), then the scenario parameters of run_scenario after the metadata. + run_s3c() { + local side="$1" kind="$2" bucket="$3" account="$4" sas="$5" keys="$6" object_bytes="$7" + local concurrency="$8" range_bytes="$9" batch="${10}" budget="${11}" duration="${12}" hosts + local args=(MODE="$side" KIND="$kind" CONCURRENCY="$concurrency" DURATION_SECONDS="$duration" + KEYS_FILE="$keys" OBJECT_BYTES="$object_bytes" RANGE_BYTES="$range_bytes" + BATCH_REQUESTS="$batch" MAX_REQUESTS_PER_WORKER="$budget") + if [[ "$side" == alluxio ]]; then + # Re-read the worker list for every run: a worker that restarted since the last run must fail the step. + hosts="$(worker_hosts)" + args+=(HOSTS="$hosts" EXPECTED_HOSTS=5 BUCKET="$bucket") + else + args+=(ACCOUNT="$account" CONTAINER=s3-data SAS_FILE="/sas/$sas") + fi + kubectl exec -n alx-ns s3c-1 -c s3c -- env "${args[@]}" sh /scripts/s3c.sh 2> >(redact >&2) + } + # $1 scenario metadata (JSON), $2 side, $3 rep, then run_s3c arguments after the side. + # s3c.sh already retries every failed request, with the same policy on both sides, so a run is not + # repeated: an error left after those retries, on either side, fails the step. + # Both datasets are loaded and checked as fully cached before scenario 1, and every scenario reads one of + # them, so every Alluxio rep must be served from the cache. Alluxio can fall back to reading Blob while + # every response still looks fine, so the workers' UFS-read counter is read before and after each Alluxio + # rep; if they read more than 1% of the bytes the client read (served_from_cache in checks.jq), the step + # fails. The counters go into the rep's index entry as worker_ufs, and from there into summary.json. + run_and_record() { + local scenario="$1" side="$2" rep="$3" id start end out status=0 run_file ufs_before ufs_after worker_ufs='{}' + id="$(jq -r '.id' <<< "$scenario")" + shift 3 + run_file="$(Build.ArtifactStagingDirectory)/alluxio-s3-read/runs/$id-$side-$rep.json" + if [[ "$side" == alluxio ]]; then + ufs_before="$(worker_ufs_bytes)" + fi + start="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + out="$(run_s3c "$side" "$@" 60)" || status=$? + end="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + # s3c.sh prints its JSON result before it fails; keep that result for diagnosis. + printf '%s\n' "$out" | redact > "$run_file" + if (( status != 0 )) || ! jq -e -L "$(Build.SourcesDirectory)/kcl/alluxio/s3_read" 'include "checks"; validate_s3c_run' "$run_file" > /dev/null; then + fail "scenario $id $side rep $rep failed or produced an invalid result" + fi + if [[ "$side" == alluxio ]]; then + ufs_after="$(worker_ufs_bytes)" + worker_ufs="$(jq -nc --argjson before "$ufs_before" --argjson after "$ufs_after" \ + '{worker_ufs: {before: $before, after: $after, bytes: ($after - $before)}}')" + jq -e -L "$(Build.SourcesDirectory)/kcl/alluxio/s3_read" --argjson ufs_bytes "$((ufs_after - ufs_before))" \ + 'include "checks"; served_from_cache($ufs_bytes)' "$run_file" > /dev/null || + fail "scenario $id alluxio rep $rep: the workers read $((ufs_after - ufs_before)) bytes from Blob while the client read $(jq -r '.bytes' "$run_file"); more than 1% (or a negative count, from a restarted worker) means the rep was not served from the preloaded cache" + fi + jq -nc --argjson scenario "$scenario" --arg side "$side" --argjson rep "$rep" --arg started "$start" --arg ended "$end" \ + --argjson worker_ufs "$worker_ufs" \ + '$scenario + {side: $side, rep: $rep, start: $started, end: $ended} + $worker_ufs' >> "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/runs/index.jsonl" + } + # $1 scenario metadata (JSON), then the arguments of run_s3c after the side. + run_scenario() { + local scenario="$1" rep + shift + # Alternate Alluxio and Blob reps so that drift over time affects both sides. + for rep in 1 2 3; do + run_and_record "$scenario" alluxio "$rep" "$@" + run_and_record "$scenario" blob "$rep" "$@" + done + } + # $1 dataset name, $2 mount path. + # The dataset is warmed with Alluxio's distributed load, not with client reads. With + # alluxio.worker.s3.redirect.enabled=false a read through a worker that does not own the file is + # relayed and does not populate the cache, so one pass of client reads cannot cache every file. + warm_dataset() { + local name="$1" mount="$2" attempt state failed deadline + alluxio job load --path "$mount" --submit | redact > "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/preload-submit-$name.txt" + # Bound the wait to 10 minutes; a load still not finished then fails the step. + deadline=$((SECONDS + 600)) + while :; do + alluxio job load --path "$mount" --progress | redact > "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/preload-$name.txt" + # A job waits (WAITING) until the scheduler picks it up and may verify (VERIFYING) before it ends. + # The state can be followed by a note, as in "Job State: SUCCEEDED (3 directories failed to index; ...)", + # so only the first word is the state. + state="$(sed -nE 's/^[[:space:]]*Job State:[[:space:]]*([A-Z_]+).*$/\1/p' "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/preload-$name.txt")" + case "$state" in + CREATED|WAITING|RUNNING|VERIFYING|SUCCEEDED) ;; + *) fail "preload of the $name dataset failed or returned an unrecognized job state" ;; + esac + failed="$(sed -nE 's/^[[:space:]]*Files Failed:[[:space:]]*([0-9]+)[[:space:]]*$/\1/p' "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/preload-$name.txt")" + [[ "$failed" == 0 ]] || fail "preload of the $name dataset must report zero failed files" + [[ "$state" == SUCCEEDED ]] && break + (( SECONDS < deadline )) || fail "preload of the $name dataset did not finish within 10 minutes" + sleep 10 + done + # --limit 1041 exceeds the 1,040 objects (16 big + 1,024 small), so the report is not truncated. + # Cache population can lag the end of the load job, so poll: at most 6 checks 10 s apart (about 1 minute), + # then a real shortfall fails the step. + for attempt in 1 2 3 4 5 6; do + if alluxio fs check-cached --path "$mount" --recursive --limit 1041 | redact > "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/cache-$name.txt" && + jq -Rse -L "$(Build.SourcesDirectory)/kcl/alluxio/s3_read" 'include "checks"; validate_all_cached' "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/cache-$name.txt" > /dev/null; then + return 0 + fi + (( attempt == 6 )) || sleep 10 + done + fail "the $name dataset is not fully cached after 6 checks over about a minute" + } + warm_dataset local /blob + warm_dataset remote /xregion + run_scenario '{"id": 1, "name": "remote small get", "kind": "get", "dataset": "remote", "concurrency": 16, "rangeBytes": 0}' get xregion alx$(Build.BuildId)r$(System.JobAttempt) remote-data /tmp/small.txt 1048576 16 0 50 100000 + run_scenario '{"id": 2, "name": "remote big get", "kind": "get", "dataset": "remote", "concurrency": 16, "rangeBytes": 0}' get xregion alx$(Build.BuildId)r$(System.JobAttempt) remote-data /tmp/big.txt 67108864 16 0 4 2000 + run_scenario '{"id": 3, "name": "range 256 KiB", "kind": "range", "dataset": "local", "concurrency": 16, "rangeBytes": 262144}' range blob alx$(Build.BuildId)l$(System.JobAttempt) local-data /tmp/big.txt 67108864 16 262144 50 100000 + displayName: Run S3 read scenarios 1-3 against Alluxio and Blob + env: + LOCAL_DATA_SAS: $(LOCAL_DATA_SAS) + REMOTE_DATA_SAS: $(REMOTE_DATA_SAS) + CHECKPOINT_READ_SAS: $(CHECKPOINT_READ_SAS) + CHECKPOINT_WRITE_SAS: $(CHECKPOINT_WRITE_SAS) + name: s3_read_scenarios_1_3 + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -exo pipefail + set +x + set -Eeuo pipefail + umask 077 + mkdir -p -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" "$(Build.ArtifactStagingDirectory)/alluxio-s3-read" + chmod 700 "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" + export AZURE_CORE_ONLY_SHOW_ERRORS=true AZURE_CORE_OUTPUT=json + export KUBECONFIG="$HOME/.kube/config" + # Avoid WebSocket stream closures during long-running AKS exec commands. + export KUBECTL_REMOTE_COMMAND_WEBSOCKETS=false + fail() { + echo "ALLUXIO WARP FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO WARP FAILED: command at line $LINENO exited with status $?" >&2' ERR + trap 'rm -f -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/blob.bin" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/helm-registry.json"' EXIT + fail() { + echo "ALLUXIO S3 READ FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO S3 READ FAILED: command at line $LINENO exited with status $?" >&2' ERR + private_command() { + if "$@" > "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" 2> "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err"; then + cat "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" + else + fail "$1 failed; secret-bearing output withheld" + fi + } + require_secret() { + [[ -n "${!1:-}" && "${!1}" != '$('* ]] || fail "Required secret pipeline variable $1 is missing" + } + worker_hosts() { + local pods ready_ips count + pods="$(kubectl get pods -n alx-ns -l app.kubernetes.io/component=worker -o json)" || + fail "could not list the Alluxio worker pods" + ready_ips="$(jq -c '[.items[] | + select(.status.phase == "Running" and + any(.status.conditions[]?; .type == "Ready" and .status == "True")) | + .status.podIP | select(. != null and . != "")] | sort' <<< "$pods")" + count="$(jq 'length' <<< "$ready_ips")" + # A different count means a worker is missing or restarting. + [[ "$count" == 5 ]] || fail "expected 5 ready Alluxio workers, found $count: $ready_ips" + # 29998 is the Alluxio worker S3 port. + jq -r 'map(. + ":29998") | join(",")' <<< "$ready_ips" + } + worker_ufs_bytes() { + local workers worker count=0 total=0 value + workers="$(kubectl get pods -n alx-ns -l app.kubernetes.io/component=worker -o jsonpath='{.items[*].metadata.name}')" + for worker in $workers; do + value="$(kubectl get --raw "/api/v1/namespaces/alx-ns/pods/$worker:30000/proxy/metrics/" | + awk -v name="alluxio_external_data_read_bytes_total" ' + $1 == name || index($1, name "{") == 1 { sum += $NF; found = 1 } + END { if (!found) exit 1; printf "%.0f", sum }')" || + fail "worker $worker does not expose alluxio_external_data_read_bytes_total" + total=$((total + value)) + count=$((count + 1)) + done + (( count == 5 )) || fail "expected 5 Alluxio workers for the metrics scrape, found $count" + printf '%s\n' "$total" + } + redact() { + local line secret + while IFS= read -r line || [[ -n "$line" ]]; do + for secret in "${LOCAL_DATA_SAS:-}" "${REMOTE_DATA_SAS:-}" "${CHECKPOINT_READ_SAS:-}" "${CHECKPOINT_WRITE_SAS:-}"; do + if [[ -n "$secret" ]]; then line="${line//"$secret"/}"; fi + done + printf '%s\n' "$line" + done + } + mkdir -p -- "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/runs" + [[ -s "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/runs/index.jsonl" ]] || fail "the first scenario group has not run" + alluxio() { + kubectl exec -n alx-ns alluxio-coordinator-0 \ + -c alluxio-coordinator -- alluxio "$@" + } + # Runs s3c.sh once in client pod s3c-1; the JSON result goes to stdout, redacted. + # $1 side (alluxio|blob), then the scenario parameters of run_scenario after the metadata. + run_s3c() { + local side="$1" kind="$2" bucket="$3" account="$4" sas="$5" keys="$6" object_bytes="$7" + local concurrency="$8" range_bytes="$9" batch="${10}" budget="${11}" duration="${12}" hosts + local args=(MODE="$side" KIND="$kind" CONCURRENCY="$concurrency" DURATION_SECONDS="$duration" + KEYS_FILE="$keys" OBJECT_BYTES="$object_bytes" RANGE_BYTES="$range_bytes" + BATCH_REQUESTS="$batch" MAX_REQUESTS_PER_WORKER="$budget") + if [[ "$side" == alluxio ]]; then + # Re-read the worker list for every run: a worker that restarted since the last run must fail the step. + hosts="$(worker_hosts)" + args+=(HOSTS="$hosts" EXPECTED_HOSTS=5 BUCKET="$bucket") + else + args+=(ACCOUNT="$account" CONTAINER=s3-data SAS_FILE="/sas/$sas") + fi + kubectl exec -n alx-ns s3c-1 -c s3c -- env "${args[@]}" sh /scripts/s3c.sh 2> >(redact >&2) + } + # $1 scenario metadata (JSON), $2 side, $3 rep, then run_s3c arguments after the side. + # s3c.sh already retries every failed request, with the same policy on both sides, so a run is not + # repeated: an error left after those retries, on either side, fails the step. + # Both datasets are loaded and checked as fully cached before scenario 1, and every scenario reads one of + # them, so every Alluxio rep must be served from the cache. Alluxio can fall back to reading Blob while + # every response still looks fine, so the workers' UFS-read counter is read before and after each Alluxio + # rep; if they read more than 1% of the bytes the client read (served_from_cache in checks.jq), the step + # fails. The counters go into the rep's index entry as worker_ufs, and from there into summary.json. + run_and_record() { + local scenario="$1" side="$2" rep="$3" id start end out status=0 run_file ufs_before ufs_after worker_ufs='{}' + id="$(jq -r '.id' <<< "$scenario")" + shift 3 + run_file="$(Build.ArtifactStagingDirectory)/alluxio-s3-read/runs/$id-$side-$rep.json" + if [[ "$side" == alluxio ]]; then + ufs_before="$(worker_ufs_bytes)" + fi + start="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + out="$(run_s3c "$side" "$@" 60)" || status=$? + end="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + # s3c.sh prints its JSON result before it fails; keep that result for diagnosis. + printf '%s\n' "$out" | redact > "$run_file" + if (( status != 0 )) || ! jq -e -L "$(Build.SourcesDirectory)/kcl/alluxio/s3_read" 'include "checks"; validate_s3c_run' "$run_file" > /dev/null; then + fail "scenario $id $side rep $rep failed or produced an invalid result" + fi + if [[ "$side" == alluxio ]]; then + ufs_after="$(worker_ufs_bytes)" + worker_ufs="$(jq -nc --argjson before "$ufs_before" --argjson after "$ufs_after" \ + '{worker_ufs: {before: $before, after: $after, bytes: ($after - $before)}}')" + jq -e -L "$(Build.SourcesDirectory)/kcl/alluxio/s3_read" --argjson ufs_bytes "$((ufs_after - ufs_before))" \ + 'include "checks"; served_from_cache($ufs_bytes)' "$run_file" > /dev/null || + fail "scenario $id alluxio rep $rep: the workers read $((ufs_after - ufs_before)) bytes from Blob while the client read $(jq -r '.bytes' "$run_file"); more than 1% (or a negative count, from a restarted worker) means the rep was not served from the preloaded cache" + fi + jq -nc --argjson scenario "$scenario" --arg side "$side" --argjson rep "$rep" --arg started "$start" --arg ended "$end" \ + --argjson worker_ufs "$worker_ufs" \ + '$scenario + {side: $side, rep: $rep, start: $started, end: $ended} + $worker_ufs' >> "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/runs/index.jsonl" + } + # $1 scenario metadata (JSON), then the arguments of run_s3c after the side. + run_scenario() { + local scenario="$1" rep + shift + # Alternate Alluxio and Blob reps so that drift over time affects both sides. + for rep in 1 2 3; do + run_and_record "$scenario" alluxio "$rep" "$@" + run_and_record "$scenario" blob "$rep" "$@" + done + } + # $1 dataset name, $2 mount path. + # The dataset is warmed with Alluxio's distributed load, not with client reads. With + # alluxio.worker.s3.redirect.enabled=false a read through a worker that does not own the file is + # relayed and does not populate the cache, so one pass of client reads cannot cache every file. + warm_dataset() { + local name="$1" mount="$2" attempt state failed deadline + alluxio job load --path "$mount" --submit | redact > "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/preload-submit-$name.txt" + # Bound the wait to 10 minutes; a load still not finished then fails the step. + deadline=$((SECONDS + 600)) + while :; do + alluxio job load --path "$mount" --progress | redact > "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/preload-$name.txt" + # A job waits (WAITING) until the scheduler picks it up and may verify (VERIFYING) before it ends. + # The state can be followed by a note, as in "Job State: SUCCEEDED (3 directories failed to index; ...)", + # so only the first word is the state. + state="$(sed -nE 's/^[[:space:]]*Job State:[[:space:]]*([A-Z_]+).*$/\1/p' "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/preload-$name.txt")" + case "$state" in + CREATED|WAITING|RUNNING|VERIFYING|SUCCEEDED) ;; + *) fail "preload of the $name dataset failed or returned an unrecognized job state" ;; + esac + failed="$(sed -nE 's/^[[:space:]]*Files Failed:[[:space:]]*([0-9]+)[[:space:]]*$/\1/p' "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/preload-$name.txt")" + [[ "$failed" == 0 ]] || fail "preload of the $name dataset must report zero failed files" + [[ "$state" == SUCCEEDED ]] && break + (( SECONDS < deadline )) || fail "preload of the $name dataset did not finish within 10 minutes" + sleep 10 + done + # --limit 1041 exceeds the 1,040 objects (16 big + 1,024 small), so the report is not truncated. + # Cache population can lag the end of the load job, so poll: at most 6 checks 10 s apart (about 1 minute), + # then a real shortfall fails the step. + for attempt in 1 2 3 4 5 6; do + if alluxio fs check-cached --path "$mount" --recursive --limit 1041 | redact > "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/cache-$name.txt" && + jq -Rse -L "$(Build.SourcesDirectory)/kcl/alluxio/s3_read" 'include "checks"; validate_all_cached' "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/cache-$name.txt" > /dev/null; then + return 0 + fi + (( attempt == 6 )) || sleep 10 + done + fail "the $name dataset is not fully cached after 6 checks over about a minute" + } + run_scenario '{"id": 4, "name": "range 1 MiB", "kind": "range", "dataset": "local", "concurrency": 16, "rangeBytes": 1048576}' range blob alx$(Build.BuildId)l$(System.JobAttempt) local-data /tmp/big.txt 67108864 16 1048576 50 100000 + run_scenario '{"id": 5, "name": "local small get", "kind": "get", "dataset": "local", "concurrency": 16, "rangeBytes": 0}' get blob alx$(Build.BuildId)l$(System.JobAttempt) local-data /tmp/small.txt 1048576 16 0 50 100000 + displayName: Run S3 read scenarios 4-5 against Alluxio and Blob + env: + LOCAL_DATA_SAS: $(LOCAL_DATA_SAS) + REMOTE_DATA_SAS: $(REMOTE_DATA_SAS) + CHECKPOINT_READ_SAS: $(CHECKPOINT_READ_SAS) + CHECKPOINT_WRITE_SAS: $(CHECKPOINT_WRITE_SAS) + name: s3_read_scenarios_4_5 + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -exo pipefail + set +x + set -Eeuo pipefail + umask 077 + mkdir -p -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" "$(Build.ArtifactStagingDirectory)/alluxio-s3-read" + chmod 700 "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" + export AZURE_CORE_ONLY_SHOW_ERRORS=true AZURE_CORE_OUTPUT=json + export KUBECONFIG="$HOME/.kube/config" + # Avoid WebSocket stream closures during long-running AKS exec commands. + export KUBECTL_REMOTE_COMMAND_WEBSOCKETS=false + fail() { + echo "ALLUXIO WARP FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO WARP FAILED: command at line $LINENO exited with status $?" >&2' ERR + trap 'rm -f -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/blob.bin" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/helm-registry.json"' EXIT + fail() { + echo "ALLUXIO S3 READ FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO S3 READ FAILED: command at line $LINENO exited with status $?" >&2' ERR + private_command() { + if "$@" > "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" 2> "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err"; then + cat "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" + else + fail "$1 failed; secret-bearing output withheld" + fi + } + require_secret() { + [[ -n "${!1:-}" && "${!1}" != '$('* ]] || fail "Required secret pipeline variable $1 is missing" + } + worker_hosts() { + local pods ready_ips count + pods="$(kubectl get pods -n alx-ns -l app.kubernetes.io/component=worker -o json)" || + fail "could not list the Alluxio worker pods" + ready_ips="$(jq -c '[.items[] | + select(.status.phase == "Running" and + any(.status.conditions[]?; .type == "Ready" and .status == "True")) | + .status.podIP | select(. != null and . != "")] | sort' <<< "$pods")" + count="$(jq 'length' <<< "$ready_ips")" + # A different count means a worker is missing or restarting. + [[ "$count" == 5 ]] || fail "expected 5 ready Alluxio workers, found $count: $ready_ips" + # 29998 is the Alluxio worker S3 port. + jq -r 'map(. + ":29998") | join(",")' <<< "$ready_ips" + } + worker_ufs_bytes() { + local workers worker count=0 total=0 value + workers="$(kubectl get pods -n alx-ns -l app.kubernetes.io/component=worker -o jsonpath='{.items[*].metadata.name}')" + for worker in $workers; do + value="$(kubectl get --raw "/api/v1/namespaces/alx-ns/pods/$worker:30000/proxy/metrics/" | + awk -v name="alluxio_external_data_read_bytes_total" ' + $1 == name || index($1, name "{") == 1 { sum += $NF; found = 1 } + END { if (!found) exit 1; printf "%.0f", sum }')" || + fail "worker $worker does not expose alluxio_external_data_read_bytes_total" + total=$((total + value)) + count=$((count + 1)) + done + (( count == 5 )) || fail "expected 5 Alluxio workers for the metrics scrape, found $count" + printf '%s\n' "$total" + } + redact() { + local line secret + while IFS= read -r line || [[ -n "$line" ]]; do + for secret in "${LOCAL_DATA_SAS:-}" "${REMOTE_DATA_SAS:-}" "${CHECKPOINT_READ_SAS:-}" "${CHECKPOINT_WRITE_SAS:-}"; do + if [[ -n "$secret" ]]; then line="${line//"$secret"/}"; fi + done + printf '%s\n' "$line" + done + } + mkdir -p -- "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/runs" + [[ -s "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/runs/index.jsonl" ]] || fail "the first scenario group has not run" + alluxio() { + kubectl exec -n alx-ns alluxio-coordinator-0 \ + -c alluxio-coordinator -- alluxio "$@" + } + # Runs s3c.sh once in client pod s3c-1; the JSON result goes to stdout, redacted. + # $1 side (alluxio|blob), then the scenario parameters of run_scenario after the metadata. + run_s3c() { + local side="$1" kind="$2" bucket="$3" account="$4" sas="$5" keys="$6" object_bytes="$7" + local concurrency="$8" range_bytes="$9" batch="${10}" budget="${11}" duration="${12}" hosts + local args=(MODE="$side" KIND="$kind" CONCURRENCY="$concurrency" DURATION_SECONDS="$duration" + KEYS_FILE="$keys" OBJECT_BYTES="$object_bytes" RANGE_BYTES="$range_bytes" + BATCH_REQUESTS="$batch" MAX_REQUESTS_PER_WORKER="$budget") + if [[ "$side" == alluxio ]]; then + # Re-read the worker list for every run: a worker that restarted since the last run must fail the step. + hosts="$(worker_hosts)" + args+=(HOSTS="$hosts" EXPECTED_HOSTS=5 BUCKET="$bucket") + else + args+=(ACCOUNT="$account" CONTAINER=s3-data SAS_FILE="/sas/$sas") + fi + kubectl exec -n alx-ns s3c-1 -c s3c -- env "${args[@]}" sh /scripts/s3c.sh 2> >(redact >&2) + } + # $1 scenario metadata (JSON), $2 side, $3 rep, then run_s3c arguments after the side. + # s3c.sh already retries every failed request, with the same policy on both sides, so a run is not + # repeated: an error left after those retries, on either side, fails the step. + # Both datasets are loaded and checked as fully cached before scenario 1, and every scenario reads one of + # them, so every Alluxio rep must be served from the cache. Alluxio can fall back to reading Blob while + # every response still looks fine, so the workers' UFS-read counter is read before and after each Alluxio + # rep; if they read more than 1% of the bytes the client read (served_from_cache in checks.jq), the step + # fails. The counters go into the rep's index entry as worker_ufs, and from there into summary.json. + run_and_record() { + local scenario="$1" side="$2" rep="$3" id start end out status=0 run_file ufs_before ufs_after worker_ufs='{}' + id="$(jq -r '.id' <<< "$scenario")" + shift 3 + run_file="$(Build.ArtifactStagingDirectory)/alluxio-s3-read/runs/$id-$side-$rep.json" + if [[ "$side" == alluxio ]]; then + ufs_before="$(worker_ufs_bytes)" + fi + start="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + out="$(run_s3c "$side" "$@" 60)" || status=$? + end="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + # s3c.sh prints its JSON result before it fails; keep that result for diagnosis. + printf '%s\n' "$out" | redact > "$run_file" + if (( status != 0 )) || ! jq -e -L "$(Build.SourcesDirectory)/kcl/alluxio/s3_read" 'include "checks"; validate_s3c_run' "$run_file" > /dev/null; then + fail "scenario $id $side rep $rep failed or produced an invalid result" + fi + if [[ "$side" == alluxio ]]; then + ufs_after="$(worker_ufs_bytes)" + worker_ufs="$(jq -nc --argjson before "$ufs_before" --argjson after "$ufs_after" \ + '{worker_ufs: {before: $before, after: $after, bytes: ($after - $before)}}')" + jq -e -L "$(Build.SourcesDirectory)/kcl/alluxio/s3_read" --argjson ufs_bytes "$((ufs_after - ufs_before))" \ + 'include "checks"; served_from_cache($ufs_bytes)' "$run_file" > /dev/null || + fail "scenario $id alluxio rep $rep: the workers read $((ufs_after - ufs_before)) bytes from Blob while the client read $(jq -r '.bytes' "$run_file"); more than 1% (or a negative count, from a restarted worker) means the rep was not served from the preloaded cache" + fi + jq -nc --argjson scenario "$scenario" --arg side "$side" --argjson rep "$rep" --arg started "$start" --arg ended "$end" \ + --argjson worker_ufs "$worker_ufs" \ + '$scenario + {side: $side, rep: $rep, start: $started, end: $ended} + $worker_ufs' >> "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/runs/index.jsonl" + } + # $1 scenario metadata (JSON), then the arguments of run_s3c after the side. + run_scenario() { + local scenario="$1" rep + shift + # Alternate Alluxio and Blob reps so that drift over time affects both sides. + for rep in 1 2 3; do + run_and_record "$scenario" alluxio "$rep" "$@" + run_and_record "$scenario" blob "$rep" "$@" + done + } + # $1 dataset name, $2 mount path. + # The dataset is warmed with Alluxio's distributed load, not with client reads. With + # alluxio.worker.s3.redirect.enabled=false a read through a worker that does not own the file is + # relayed and does not populate the cache, so one pass of client reads cannot cache every file. + warm_dataset() { + local name="$1" mount="$2" attempt state failed deadline + alluxio job load --path "$mount" --submit | redact > "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/preload-submit-$name.txt" + # Bound the wait to 10 minutes; a load still not finished then fails the step. + deadline=$((SECONDS + 600)) + while :; do + alluxio job load --path "$mount" --progress | redact > "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/preload-$name.txt" + # A job waits (WAITING) until the scheduler picks it up and may verify (VERIFYING) before it ends. + # The state can be followed by a note, as in "Job State: SUCCEEDED (3 directories failed to index; ...)", + # so only the first word is the state. + state="$(sed -nE 's/^[[:space:]]*Job State:[[:space:]]*([A-Z_]+).*$/\1/p' "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/preload-$name.txt")" + case "$state" in + CREATED|WAITING|RUNNING|VERIFYING|SUCCEEDED) ;; + *) fail "preload of the $name dataset failed or returned an unrecognized job state" ;; + esac + failed="$(sed -nE 's/^[[:space:]]*Files Failed:[[:space:]]*([0-9]+)[[:space:]]*$/\1/p' "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/preload-$name.txt")" + [[ "$failed" == 0 ]] || fail "preload of the $name dataset must report zero failed files" + [[ "$state" == SUCCEEDED ]] && break + (( SECONDS < deadline )) || fail "preload of the $name dataset did not finish within 10 minutes" + sleep 10 + done + # --limit 1041 exceeds the 1,040 objects (16 big + 1,024 small), so the report is not truncated. + # Cache population can lag the end of the load job, so poll: at most 6 checks 10 s apart (about 1 minute), + # then a real shortfall fails the step. + for attempt in 1 2 3 4 5 6; do + if alluxio fs check-cached --path "$mount" --recursive --limit 1041 | redact > "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/cache-$name.txt" && + jq -Rse -L "$(Build.SourcesDirectory)/kcl/alluxio/s3_read" 'include "checks"; validate_all_cached' "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/cache-$name.txt" > /dev/null; then + return 0 + fi + (( attempt == 6 )) || sleep 10 + done + fail "the $name dataset is not fully cached after 6 checks over about a minute" + } + run_scenario '{"id": 6, "name": "range 4 MiB", "kind": "range", "dataset": "local", "concurrency": 16, "rangeBytes": 4194304}' range blob alx$(Build.BuildId)l$(System.JobAttempt) local-data /tmp/big.txt 67108864 16 4194304 50 100000 + run_scenario '{"id": 7, "name": "range 16 MiB", "kind": "range", "dataset": "local", "concurrency": 16, "rangeBytes": 16777216}' range blob alx$(Build.BuildId)l$(System.JobAttempt) local-data /tmp/big.txt 67108864 16 16777216 16 100000 + displayName: Run S3 read scenarios 6-7 against Alluxio and Blob + env: + LOCAL_DATA_SAS: $(LOCAL_DATA_SAS) + REMOTE_DATA_SAS: $(REMOTE_DATA_SAS) + CHECKPOINT_READ_SAS: $(CHECKPOINT_READ_SAS) + CHECKPOINT_WRITE_SAS: $(CHECKPOINT_WRITE_SAS) + name: s3_read_scenarios_6_7 + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -exo pipefail + set +x + set -Eeuo pipefail + umask 077 + mkdir -p -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" "$(Build.ArtifactStagingDirectory)/alluxio-s3-read" + chmod 700 "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" + export AZURE_CORE_ONLY_SHOW_ERRORS=true AZURE_CORE_OUTPUT=json + export KUBECONFIG="$HOME/.kube/config" + # Avoid WebSocket stream closures during long-running AKS exec commands. + export KUBECTL_REMOTE_COMMAND_WEBSOCKETS=false + fail() { + echo "ALLUXIO WARP FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO WARP FAILED: command at line $LINENO exited with status $?" >&2' ERR + trap 'rm -f -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/blob.bin" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/helm-registry.json"' EXIT + fail() { + echo "ALLUXIO S3 READ FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO S3 READ FAILED: command at line $LINENO exited with status $?" >&2' ERR + private_command() { + if "$@" > "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" 2> "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err"; then + cat "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" + else + fail "$1 failed; secret-bearing output withheld" + fi + } + require_secret() { + [[ -n "${!1:-}" && "${!1}" != '$('* ]] || fail "Required secret pipeline variable $1 is missing" + } + worker_hosts() { + local pods ready_ips count + pods="$(kubectl get pods -n alx-ns -l app.kubernetes.io/component=worker -o json)" || + fail "could not list the Alluxio worker pods" + ready_ips="$(jq -c '[.items[] | + select(.status.phase == "Running" and + any(.status.conditions[]?; .type == "Ready" and .status == "True")) | + .status.podIP | select(. != null and . != "")] | sort' <<< "$pods")" + count="$(jq 'length' <<< "$ready_ips")" + # A different count means a worker is missing or restarting. + [[ "$count" == 5 ]] || fail "expected 5 ready Alluxio workers, found $count: $ready_ips" + # 29998 is the Alluxio worker S3 port. + jq -r 'map(. + ":29998") | join(",")' <<< "$ready_ips" + } + worker_ufs_bytes() { + local workers worker count=0 total=0 value + workers="$(kubectl get pods -n alx-ns -l app.kubernetes.io/component=worker -o jsonpath='{.items[*].metadata.name}')" + for worker in $workers; do + value="$(kubectl get --raw "/api/v1/namespaces/alx-ns/pods/$worker:30000/proxy/metrics/" | + awk -v name="alluxio_external_data_read_bytes_total" ' + $1 == name || index($1, name "{") == 1 { sum += $NF; found = 1 } + END { if (!found) exit 1; printf "%.0f", sum }')" || + fail "worker $worker does not expose alluxio_external_data_read_bytes_total" + total=$((total + value)) + count=$((count + 1)) + done + (( count == 5 )) || fail "expected 5 Alluxio workers for the metrics scrape, found $count" + printf '%s\n' "$total" + } + redact() { + local line secret + while IFS= read -r line || [[ -n "$line" ]]; do + for secret in "${LOCAL_DATA_SAS:-}" "${REMOTE_DATA_SAS:-}" "${CHECKPOINT_READ_SAS:-}" "${CHECKPOINT_WRITE_SAS:-}"; do + if [[ -n "$secret" ]]; then line="${line//"$secret"/}"; fi + done + printf '%s\n' "$line" + done + } + mkdir -p -- "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/runs" + [[ -s "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/runs/index.jsonl" ]] || fail "the first scenario group has not run" + alluxio() { + kubectl exec -n alx-ns alluxio-coordinator-0 \ + -c alluxio-coordinator -- alluxio "$@" + } + # Runs s3c.sh once in client pod s3c-1; the JSON result goes to stdout, redacted. + # $1 side (alluxio|blob), then the scenario parameters of run_scenario after the metadata. + run_s3c() { + local side="$1" kind="$2" bucket="$3" account="$4" sas="$5" keys="$6" object_bytes="$7" + local concurrency="$8" range_bytes="$9" batch="${10}" budget="${11}" duration="${12}" hosts + local args=(MODE="$side" KIND="$kind" CONCURRENCY="$concurrency" DURATION_SECONDS="$duration" + KEYS_FILE="$keys" OBJECT_BYTES="$object_bytes" RANGE_BYTES="$range_bytes" + BATCH_REQUESTS="$batch" MAX_REQUESTS_PER_WORKER="$budget") + if [[ "$side" == alluxio ]]; then + # Re-read the worker list for every run: a worker that restarted since the last run must fail the step. + hosts="$(worker_hosts)" + args+=(HOSTS="$hosts" EXPECTED_HOSTS=5 BUCKET="$bucket") + else + args+=(ACCOUNT="$account" CONTAINER=s3-data SAS_FILE="/sas/$sas") + fi + kubectl exec -n alx-ns s3c-1 -c s3c -- env "${args[@]}" sh /scripts/s3c.sh 2> >(redact >&2) + } + # $1 scenario metadata (JSON), $2 side, $3 rep, then run_s3c arguments after the side. + # s3c.sh already retries every failed request, with the same policy on both sides, so a run is not + # repeated: an error left after those retries, on either side, fails the step. + # Both datasets are loaded and checked as fully cached before scenario 1, and every scenario reads one of + # them, so every Alluxio rep must be served from the cache. Alluxio can fall back to reading Blob while + # every response still looks fine, so the workers' UFS-read counter is read before and after each Alluxio + # rep; if they read more than 1% of the bytes the client read (served_from_cache in checks.jq), the step + # fails. The counters go into the rep's index entry as worker_ufs, and from there into summary.json. + run_and_record() { + local scenario="$1" side="$2" rep="$3" id start end out status=0 run_file ufs_before ufs_after worker_ufs='{}' + id="$(jq -r '.id' <<< "$scenario")" + shift 3 + run_file="$(Build.ArtifactStagingDirectory)/alluxio-s3-read/runs/$id-$side-$rep.json" + if [[ "$side" == alluxio ]]; then + ufs_before="$(worker_ufs_bytes)" + fi + start="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + out="$(run_s3c "$side" "$@" 60)" || status=$? + end="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + # s3c.sh prints its JSON result before it fails; keep that result for diagnosis. + printf '%s\n' "$out" | redact > "$run_file" + if (( status != 0 )) || ! jq -e -L "$(Build.SourcesDirectory)/kcl/alluxio/s3_read" 'include "checks"; validate_s3c_run' "$run_file" > /dev/null; then + fail "scenario $id $side rep $rep failed or produced an invalid result" + fi + if [[ "$side" == alluxio ]]; then + ufs_after="$(worker_ufs_bytes)" + worker_ufs="$(jq -nc --argjson before "$ufs_before" --argjson after "$ufs_after" \ + '{worker_ufs: {before: $before, after: $after, bytes: ($after - $before)}}')" + jq -e -L "$(Build.SourcesDirectory)/kcl/alluxio/s3_read" --argjson ufs_bytes "$((ufs_after - ufs_before))" \ + 'include "checks"; served_from_cache($ufs_bytes)' "$run_file" > /dev/null || + fail "scenario $id alluxio rep $rep: the workers read $((ufs_after - ufs_before)) bytes from Blob while the client read $(jq -r '.bytes' "$run_file"); more than 1% (or a negative count, from a restarted worker) means the rep was not served from the preloaded cache" + fi + jq -nc --argjson scenario "$scenario" --arg side "$side" --argjson rep "$rep" --arg started "$start" --arg ended "$end" \ + --argjson worker_ufs "$worker_ufs" \ + '$scenario + {side: $side, rep: $rep, start: $started, end: $ended} + $worker_ufs' >> "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/runs/index.jsonl" + } + # $1 scenario metadata (JSON), then the arguments of run_s3c after the side. + run_scenario() { + local scenario="$1" rep + shift + # Alternate Alluxio and Blob reps so that drift over time affects both sides. + for rep in 1 2 3; do + run_and_record "$scenario" alluxio "$rep" "$@" + run_and_record "$scenario" blob "$rep" "$@" + done + } + # $1 dataset name, $2 mount path. + # The dataset is warmed with Alluxio's distributed load, not with client reads. With + # alluxio.worker.s3.redirect.enabled=false a read through a worker that does not own the file is + # relayed and does not populate the cache, so one pass of client reads cannot cache every file. + warm_dataset() { + local name="$1" mount="$2" attempt state failed deadline + alluxio job load --path "$mount" --submit | redact > "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/preload-submit-$name.txt" + # Bound the wait to 10 minutes; a load still not finished then fails the step. + deadline=$((SECONDS + 600)) + while :; do + alluxio job load --path "$mount" --progress | redact > "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/preload-$name.txt" + # A job waits (WAITING) until the scheduler picks it up and may verify (VERIFYING) before it ends. + # The state can be followed by a note, as in "Job State: SUCCEEDED (3 directories failed to index; ...)", + # so only the first word is the state. + state="$(sed -nE 's/^[[:space:]]*Job State:[[:space:]]*([A-Z_]+).*$/\1/p' "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/preload-$name.txt")" + case "$state" in + CREATED|WAITING|RUNNING|VERIFYING|SUCCEEDED) ;; + *) fail "preload of the $name dataset failed or returned an unrecognized job state" ;; + esac + failed="$(sed -nE 's/^[[:space:]]*Files Failed:[[:space:]]*([0-9]+)[[:space:]]*$/\1/p' "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/preload-$name.txt")" + [[ "$failed" == 0 ]] || fail "preload of the $name dataset must report zero failed files" + [[ "$state" == SUCCEEDED ]] && break + (( SECONDS < deadline )) || fail "preload of the $name dataset did not finish within 10 minutes" + sleep 10 + done + # --limit 1041 exceeds the 1,040 objects (16 big + 1,024 small), so the report is not truncated. + # Cache population can lag the end of the load job, so poll: at most 6 checks 10 s apart (about 1 minute), + # then a real shortfall fails the step. + for attempt in 1 2 3 4 5 6; do + if alluxio fs check-cached --path "$mount" --recursive --limit 1041 | redact > "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/cache-$name.txt" && + jq -Rse -L "$(Build.SourcesDirectory)/kcl/alluxio/s3_read" 'include "checks"; validate_all_cached' "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/cache-$name.txt" > /dev/null; then + return 0 + fi + (( attempt == 6 )) || sleep 10 + done + fail "the $name dataset is not fully cached after 6 checks over about a minute" + } + run_scenario '{"id": 8, "name": "big get concurrency 1", "kind": "get", "dataset": "local", "concurrency": 1, "rangeBytes": 0}' get blob alx$(Build.BuildId)l$(System.JobAttempt) local-data /tmp/big.txt 67108864 1 0 4 2000 + run_scenario '{"id": 9, "name": "big get concurrency 4", "kind": "get", "dataset": "local", "concurrency": 4, "rangeBytes": 0}' get blob alx$(Build.BuildId)l$(System.JobAttempt) local-data /tmp/big.txt 67108864 4 0 4 2000 + run_scenario '{"id": 10, "name": "big get concurrency 16", "kind": "get", "dataset": "local", "concurrency": 16, "rangeBytes": 0}' get blob alx$(Build.BuildId)l$(System.JobAttempt) local-data /tmp/big.txt 67108864 16 0 4 2000 + displayName: Run S3 read scenarios 8-10 against Alluxio and Blob + env: + LOCAL_DATA_SAS: $(LOCAL_DATA_SAS) + REMOTE_DATA_SAS: $(REMOTE_DATA_SAS) + CHECKPOINT_READ_SAS: $(CHECKPOINT_READ_SAS) + CHECKPOINT_WRITE_SAS: $(CHECKPOINT_WRITE_SAS) + name: s3_read_scenarios_8_10 + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -exo pipefail + set +x + set -Eeuo pipefail + umask 077 + mkdir -p -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" "$(Build.ArtifactStagingDirectory)/alluxio-s3-read" + chmod 700 "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" + export AZURE_CORE_ONLY_SHOW_ERRORS=true AZURE_CORE_OUTPUT=json + export KUBECONFIG="$HOME/.kube/config" + # Avoid WebSocket stream closures during long-running AKS exec commands. + export KUBECTL_REMOTE_COMMAND_WEBSOCKETS=false + fail() { + echo "ALLUXIO WARP FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO WARP FAILED: command at line $LINENO exited with status $?" >&2' ERR + trap 'rm -f -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/blob.bin" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/helm-registry.json"' EXIT + fail() { + echo "ALLUXIO S3 READ FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO S3 READ FAILED: command at line $LINENO exited with status $?" >&2' ERR + worker_hosts() { + local pods ready_ips count + pods="$(kubectl get pods -n alx-ns -l app.kubernetes.io/component=worker -o json)" || + fail "could not list the Alluxio worker pods" + ready_ips="$(jq -c '[.items[] | + select(.status.phase == "Running" and + any(.status.conditions[]?; .type == "Ready" and .status == "True")) | + .status.podIP | select(. != null and . != "")] | sort' <<< "$pods")" + count="$(jq 'length' <<< "$ready_ips")" + # A different count means a worker is missing or restarting. + [[ "$count" == 5 ]] || fail "expected 5 ready Alluxio workers, found $count: $ready_ips" + # 29998 is the Alluxio worker S3 port. + jq -r 'map(. + ":29998") | join(",")' <<< "$ready_ips" + } + worker_ufs_bytes() { + local workers worker count=0 total=0 value + workers="$(kubectl get pods -n alx-ns -l app.kubernetes.io/component=worker -o jsonpath='{.items[*].metadata.name}')" + for worker in $workers; do + value="$(kubectl get --raw "/api/v1/namespaces/alx-ns/pods/$worker:30000/proxy/metrics/" | + awk -v name="alluxio_external_data_read_bytes_total" ' + $1 == name || index($1, name "{") == 1 { sum += $NF; found = 1 } + END { if (!found) exit 1; printf "%.0f", sum }')" || + fail "worker $worker does not expose alluxio_external_data_read_bytes_total" + total=$((total + value)) + count=$((count + 1)) + done + (( count == 5 )) || fail "expected 5 Alluxio workers for the metrics scrape, found $count" + printf '%s\n' "$total" + } + checkpoint_dir="$(Build.ArtifactStagingDirectory)/alluxio-s3-read/checkpoint" + mkdir -p -- "$checkpoint_dir" + : > "$checkpoint_dir/index.jsonl" + : > "$checkpoint_dir/worker-ufs.jsonl" + # 8 objects of 2 GiB (2147483648 bytes) are read once per pod. + expected_bytes=17179869184 + # $1 side, $2 rep, $3 pod, then the s3c.sh environment. Runs in the background, one per pod. + read_one() { + local side="$1" rep="$2" pod="$3" start end out + shift 3 + start="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + if ! out="$(kubectl exec -n alx-ns "$pod" -c s3c -- env "$@" sh /scripts/s3c.sh)"; then + # s3c.sh prints its JSON result before it fails; keep it. It holds only counters, no SAS. + printf '%s\n' "$out" > "$checkpoint_dir/$side-$rep-$pod.json" + exit 1 + fi + end="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + printf '%s\n' "$out" > "$checkpoint_dir/$side-$rep-$pod.json" + jq -nc --arg side "$side" --argjson rep "$rep" --arg pod "$pod" --arg started "$start" --arg ended "$end" \ + '{side: $side, rep: $rep, pod: $pod, start: $started, end: $ended}' > "$checkpoint_dir/$side-$rep-$pod.index" + } + # $1 side (alluxio|blob), $2 rep, $3 checkpoint set. All client pods read the set at the same time. + read_set() { + local side="$1" rep="$2" set="$3" index pid status=0 pids=() + local args=(KIND=onepass CONCURRENCY=8 KEYS_FILE="/tmp/checkpoint-$set.txt" + OBJECT_BYTES=2147483648 BATCH_REQUESTS=1) + if [[ "$side" == alluxio ]]; then + # Re-read the worker list for every rep: a restarted worker must fail the step. + args+=(MODE=alluxio HOSTS="$(worker_hosts)" EXPECTED_HOSTS=5 BUCKET=ckpt) + else + args+=(MODE=blob ACCOUNT="alx$(Build.BuildId)l$(System.JobAttempt)" CONTAINER=checkpoint SAS_FILE=/sas/checkpoint-read) + fi + for index in $(seq 1 5); do + # Every pod reads the same keys; each starts at a different worker, so on the Alluxio side every + # worker serves the same share of the requests (with 5 pods and 5 workers, 8 each). + read_one "$side" "$rep" "s3c-$index" "${args[@]}" HOST_OFFSET=$((index - 1)) & + pids+=($!) + done + for pid in "${pids[@]}"; do + wait "$pid" || status=1 + done + (( status == 0 )) || fail "checkpoint $side rep $rep: at least one client failed" + for index in $(seq 1 5); do + jq -e -L "$(Build.SourcesDirectory)/kcl/alluxio/s3_read" --argjson expected "$expected_bytes" \ + 'include "checks"; validate_s3c_run | .bytes == $expected' \ + "$checkpoint_dir/$side-$rep-s3c-$index.json" > /dev/null || + fail "checkpoint $side rep $rep s3c-$index produced an invalid result" + cat "$checkpoint_dir/$side-$rep-s3c-$index.index" >> "$checkpoint_dir/index.jsonl" + rm -f -- "$checkpoint_dir/$side-$rep-s3c-$index.index" + done + } + resource_id="$(az storage account show \ + --name "alx$(Build.BuildId)l$(System.JobAttempt)" \ + --resource-group "alluxio-s3-read-$(RUN_ID)-$(System.JobAttempt)" \ + --subscription "b8ceb4e5-f05b-4562-a9f5-14acb1f24219" \ + --query id \ + --output tsv)" + [[ -n "$resource_id" ]] || fail "could not resolve the resource ID of alx$(Build.BuildId)l$(System.JobAttempt)" + # Egress is per storage account and arrives about a minute late, and scenarios 1-10 just read this + # account; wait so their last reads fall before the first rep's window. + sleep 180 + step_start="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + for rep in 1 2 3; do + before="$(worker_ufs_bytes)" + read_set alluxio "$rep" "$rep" + after="$(worker_ufs_bytes)" + jq -nc --argjson rep "$rep" --argjson before "$before" --argjson after "$after" \ + '{rep: $rep, before: $before, after: $after, bytes: ($after - $before)}' >> "$checkpoint_dir/worker-ufs.jsonl" + # Azure Monitor reports Egress per minute; runs at least 70 s apart start in different minute windows. + sleep 70 + read_set blob "$rep" "$((rep + 3))" + (( rep == 3 )) || sleep 70 + done + last_rep_end=$SECONDS + : > "$checkpoint_dir/runs.jsonl" + for file in "$checkpoint_dir"/*-s3c-*.json; do + name="$(basename "$file" .json)" + jq -c --arg name "$name" \ + '($name | capture("^(?[a-z]+)-(?[0-9]+)-(?.+)$")) as $id + | {side: $id.side, rep: ($id.rep | tonumber), pod: $id.pod, wall_seconds: .wall_seconds, retries: .retries}' \ + "$file" >> "$checkpoint_dir/runs.jsonl" + done + # Egress minute metrics arrive about 1 minute late; the first query waits 3 minutes after the last rep. + # Then query every 60 s until every window has data and checks.jq's bounds hold, for up to 10 minutes + # after the last rep. egress.json ends up as the output of the last query. + sleep 180 + while :; do + step_end="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + az monitor metrics list \ + --resource "$resource_id" \ + --metric Egress \ + --interval PT1M \ + --aggregation Total \ + --start-time "$step_start" \ + --end-time "$step_end" > "$checkpoint_dir/egress.json" + if jq -n -L "$(Build.SourcesDirectory)/kcl/alluxio/s3_read" \ + --slurpfile index "$checkpoint_dir/index.jsonl" \ + --slurpfile runs "$checkpoint_dir/runs.jsonl" \ + --slurpfile worker_ufs "$checkpoint_dir/worker-ufs.jsonl" \ + --slurpfile metrics "$checkpoint_dir/egress.json" \ + 'include "checks"; {index: $index, runs: $runs, worker_ufs: $worker_ufs, metrics: $metrics[0]} | checkpoint_summary' \ + > "$checkpoint_dir/summary.json" 2> "$checkpoint_dir/summary.err"; then + break + fi + if (( SECONDS >= last_rep_end + 600 )); then + cat "$checkpoint_dir/summary.err" >&2 + fail "could not attribute Blob egress within 10 minutes of the last rep; see $checkpoint_dir/egress.json" + fi + echo "Blob egress is not complete yet: $(tail -n 1 "$checkpoint_dir/summary.err")" + sleep 60 + done + rm -f -- "$checkpoint_dir/summary.err" + displayName: Load checkpoints from 5 clients and attribute Blob egress + name: s3_read_checkpoint_load + - bash: | + set -exo pipefail + TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%S.000Z") + echo "BENCHMARK_END_TIME: $TIMESTAMP" + echo "##vso[task.setvariable variable=BENCHMARK_END_TIME]$TIMESTAMP" + displayName: Record current time as BENCHMARK_END_TIME + - bash: | + set +x + set -Eeuo pipefail + umask 077 + mkdir -p -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" "$(Build.ArtifactStagingDirectory)/alluxio-s3-read" + chmod 700 "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" + export AZURE_CORE_ONLY_SHOW_ERRORS=true AZURE_CORE_OUTPUT=json + export KUBECONFIG="$HOME/.kube/config" + # Avoid WebSocket stream closures during long-running AKS exec commands. + export KUBECTL_REMOTE_COMMAND_WEBSOCKETS=false + fail() { + echo "ALLUXIO WARP FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO WARP FAILED: command at line $LINENO exited with status $?" >&2' ERR + trap 'rm -f -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/blob.bin" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/helm-registry.json"' EXIT + fail() { + echo "ALLUXIO S3 READ FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO S3 READ FAILED: command at line $LINENO exited with status $?" >&2' ERR + runs_file="$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/summary-runs.jsonl" + : > "$runs_file" + while IFS= read -r entry; do + run_file="$(Build.ArtifactStagingDirectory)/alluxio-s3-read/runs/$(jq -r '"\(.id)-\(.side)-\(.rep)"' <<< "$entry").json" + jq -c --argjson entry "$entry" '$entry + .' "$run_file" >> "$runs_file" + done < "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/runs/index.jsonl" + [[ -s "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/checkpoint/summary.json" ]] || fail "the checkpoint summary is missing" + jq -s -L "$(Build.SourcesDirectory)/kcl/alluxio/s3_read" 'include "checks"; scenario_summary' "$runs_file" > "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/scenarios.json" + # Scenarios 1-10 must all be present. + jq -e 'map(.id) == [range(1; 11)]' "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/scenarios.json" > /dev/null || + fail "the summary does not cover exactly scenarios 1-10" + jq -n \ + --slurpfile scenarios "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/scenarios.json" \ + --slurpfile checkpoint "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/checkpoint/summary.json" \ + '{scenarios: $scenarios[0], checkpoint: $checkpoint[0]}' > "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/summary.json" + rm -f -- "$runs_file" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/scenarios.json" + displayName: Summarize the S3 read results + name: s3_read_summary + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -exo pipefail + set +x + set -Eeuo pipefail + umask 077 + mkdir -p -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" "$(Build.ArtifactStagingDirectory)/alluxio-s3-read" + chmod 700 "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" + export AZURE_CORE_ONLY_SHOW_ERRORS=true AZURE_CORE_OUTPUT=json + export KUBECONFIG="$HOME/.kube/config" + # Avoid WebSocket stream closures during long-running AKS exec commands. + export KUBECTL_REMOTE_COMMAND_WEBSOCKETS=false + fail() { + echo "ALLUXIO WARP FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO WARP FAILED: command at line $LINENO exited with status $?" >&2' ERR + trap 'rm -f -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/blob.bin" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/helm-registry.json"' EXIT + if [[ ! -s "$KUBECONFIG" ]]; then + echo '{"cluster_access":"not established"}' > "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/diagnostics.json" + exit 0 + fi + for namespace in alx-ns alluxio-operator; do + kubectl get pods -n "$namespace" -o json | + jq --arg namespace "$namespace" '{ + ($namespace): [.items[] | { + name: .metadata.name, node: .spec.nodeName, phase: .status.phase, + containers: [(.status.containerStatuses // []) + (.status.initContainerStatuses // []) | .[] | + {name, ready, restarts: .restartCount, + state: (.state | with_entries(.value |= {reason, exitCode}))}] + }] + }' > "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/diagnostics-$namespace.json" + done + jq -s 'add' "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/diagnostics-alx-ns.json" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/diagnostics-alluxio-operator.json" \ + > "$(Build.ArtifactStagingDirectory)/alluxio-s3-read/diagnostics.json" + condition: always() + displayName: Collect safe deployment diagnostics + name: alluxio_diagnostics + - bash: | + set +x + set -Eeuo pipefail + umask 077 + mkdir -p -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" "$(Build.ArtifactStagingDirectory)/alluxio-s3-read" + chmod 700 "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)" + export AZURE_CORE_ONLY_SHOW_ERRORS=true AZURE_CORE_OUTPUT=json + export KUBECONFIG="$HOME/.kube/config" + # Avoid WebSocket stream closures during long-running AKS exec commands. + export KUBECTL_REMOTE_COMMAND_WEBSOCKETS=false + fail() { + echo "ALLUXIO WARP FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO WARP FAILED: command at line $LINENO exited with status $?" >&2' ERR + trap 'rm -f -- "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.out" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/command.err" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/blob.bin" "$(Agent.TempDirectory)/alluxio-$(System.JobId)-$(System.JobAttempt)/helm-registry.json"' EXIT + fail() { + echo "ALLUXIO S3 READ FAILED: $*" >&2 + exit 1 + } + trap 'echo "ALLUXIO S3 READ FAILED: command at line $LINENO exited with status $?" >&2' ERR + if grep -rq 'sig=' "$(Build.ArtifactStagingDirectory)/alluxio-s3-read"; then + find "$(Build.ArtifactStagingDirectory)/alluxio-s3-read" -mindepth 1 -delete + echo "ALLUXIO S3 READ FAILED: a SAS signature (sig=) was present in the results; the results were deleted, not published" >&2 + exit 1 + fi + condition: always() + displayName: Refuse to publish results that contain a SAS signature + name: s3_read_sas_check + - task: PublishPipelineArtifact@1 + inputs: + targetPath: $(Build.ArtifactStagingDirectory)/alluxio-s3-read + artifact: alluxio-s3-read-$(System.JobAttempt) + condition: always() + displayName: Publish S3 read results and diagnostics + - task: AzureCLI@2 + inputs: + azureSubscription: Azure-for-Telescope-internal + scriptType: bash + scriptLocation: inlineScript + inlineScript: | + set -exo pipefail + for NODE_RG in $(az aks list \ + --resource-group "alluxio-s3-read-$(RUN_ID)-$(System.JobAttempt)" \ + --subscription "b8ceb4e5-f05b-4562-a9f5-14acb1f24219" \ + --query "[].nodeResourceGroup" \ + --output tsv); do + echo "Checking VMSS rolling upgrades in node resource group: $NODE_RG" + for VMSS in $(az vmss list \ + --resource-group "$NODE_RG" \ + --subscription "b8ceb4e5-f05b-4562-a9f5-14acb1f24219" \ + --query "[].name" \ + --output tsv); do + echo "Attempting to cancel rolling upgrade for VMSS: $VMSS" + az vmss rolling-upgrade cancel \ + --resource-group "$NODE_RG" \ + --name "$VMSS" \ + --subscription "b8ceb4e5-f05b-4562-a9f5-14acb1f24219" \ + && echo "Cancelled rolling upgrade for $VMSS." \ + || echo "No active rolling upgrade to cancel for $VMSS (or cancel not applicable)." + done + done + + az group delete --name "alluxio-s3-read-$(RUN_ID)-$(System.JobAttempt)" --subscription "b8ceb4e5-f05b-4562-a9f5-14acb1f24219" --yes + condition: and(always(), eq(variables['SHOULD_CLEAN_UP_RESOURCE_GROUP'], 'true')) + displayName: Delete resource group (b8ceb4e5-f05b-4562-a9f5-14acb1f24219) diff --git a/kcl/lib/steps/alluxio/s3_read.k b/kcl/lib/steps/alluxio/s3_read.k new file mode 100644 index 0000000000..7c9e08bb44 --- /dev/null +++ b/kcl/lib/steps/alluxio/s3_read.k @@ -0,0 +1,777 @@ +import azure_pipelines.ap.steps +import json +import lib.steps.azure + +# The workerpool and the clientpool have this many nodes, with one Alluxio worker and one client pod +# on each. kcl/alluxio/s3_read/cluster.yaml must set worker.count to S3_READ_WORKER_COUNT. +S3_READ_WORKER_COUNT = 5 +S3_READ_CLIENT_COUNT = 5 + +# ShellSetup plus this pipeline's failure marker for fail() and the ERR trap. Steps shared with the +# warp pipeline (install, mount, diagnostics) keep ShellSetup's own marker. +S3ReadShellSetup = lambda workDir: str, resultDir: str -> str { + ShellSetup(workDir, resultDir) + """ +fail() { + echo "ALLUXIO S3 READ FAILED: $*" >&2 + exit 1 +} +trap 'echo "ALLUXIO S3 READ FAILED: command at line $LINENO exited with status $?" >&2' ERR +""" +} + +schema S3ReadScenario: + id: int + name: str + kind: "get" | "range" + dataset: "local" | "remote" + objects: "big" | "small" + concurrency: int + rangeBytes: int = 0 + + check: + 1 <= id <= 10 + concurrency > 0 + (rangeBytes > 0) == (kind == "range"), "rangeBytes must be set exactly for range scenarios" + +# Scenarios 11 and 12 are not in this table; they are executed separately +# because they are measured through Azure Monitor egress rather than client timing. +S3_READ_SCENARIOS: [S3ReadScenario] = [ + S3ReadScenario {id = 1, name = "remote small get", kind = "get", dataset = "remote", objects = "small", concurrency = 16} + S3ReadScenario {id = 2, name = "remote big get", kind = "get", dataset = "remote", objects = "big", concurrency = 16} + S3ReadScenario {id = 3, name = "range 256 KiB", kind = "range", dataset = "local", objects = "big", concurrency = 16, rangeBytes = 262144} + S3ReadScenario {id = 4, name = "range 1 MiB", kind = "range", dataset = "local", objects = "big", concurrency = 16, rangeBytes = 1048576} + S3ReadScenario {id = 5, name = "local small get", kind = "get", dataset = "local", objects = "small", concurrency = 16} + S3ReadScenario {id = 6, name = "range 4 MiB", kind = "range", dataset = "local", objects = "big", concurrency = 16, rangeBytes = 4194304} + S3ReadScenario {id = 7, name = "range 16 MiB", kind = "range", dataset = "local", objects = "big", concurrency = 16, rangeBytes = 16777216} + S3ReadScenario {id = 8, name = "big get concurrency 1", kind = "get", dataset = "local", objects = "big", concurrency = 1} + S3ReadScenario {id = 9, name = "big get concurrency 4", kind = "get", dataset = "local", objects = "big", concurrency = 4} + S3ReadScenario {id = 10, name = "big get concurrency 16", kind = "get", dataset = "local", objects = "big", concurrency = 16} +] + +# The scenario ids each RunS3ReadScenarios step runs, in order. Every AzCli step signs in once and +# kubectl reuses that Entra ID login; a workload identity login in a pipeline task can fail after +# about an hour, so each step must finish well within that. In a full run scenarios 1-10 took 103 +# minutes in all and scenario 7 alone 21 minutes; each of these groups took 33 minutes or less. +S3_READ_SCENARIO_GROUPS: [[int]] = [[1, 2, 3], [4, 5], [6, 7], [8, 9, 10]] + +SeedS3ReadData = lambda serviceConnection: str, subscription: str, resourceGroup: str, localLocation: str, remoteLocation: str, localAccount: str, remoteAccount: str, workDir: str, resultDir: str, checksDir: str -> steps.Step { + assert localAccount != remoteAccount, "the local and remote storage accounts must differ" + azure.AzCli( + serviceConnection + "Create local and remote Blob datasets for S3 reads" + S3ReadShellSetup(workDir, resultDir) + SecretCommands(workDir) + """ +# Prints a container SAS for the account selected by AZURE_STORAGE_ACCOUNT/KEY. +# $1 container, $2 permissions, $3 lifetime in hours. +make_sas() { + az storage container generate-sas \\ + --name "$1" \\ + --permissions "$2" \\ + --expiry "$(date -u -d "+$3 hours" +%Y-%m-%dT%H:%MZ)" \\ + --https-only 2> /dev/null | + jq -er 'select(type == "string" and length > 0)' 2> /dev/null +} +# Exports $2 as a secret pipeline variable named $1; the value never reaches the log. +publish_secret() { + local value="$2" + value="\${value//'%'/'%AZP25'}" + value="\${value//$'\\n'/'%0A'}" + value="\${value//$'\\r'/'%0D'}" + printf '##vso[task.setvariable variable=%s;issecret=true]%s\\n' "$1" "$value" +} +seed_account() { + local account="$1" location="$2" index + az storage account create \\ + --name "$account" \\ + --resource-group "${resourceGroup}" \\ + --subscription "${subscription}" \\ + --location "$location" \\ + --kind StorageV2 \\ + --sku Standard_LRS \\ + --https-only true \\ + --min-tls-version TLS1_2 \\ + --allow-blob-public-access false \\ + --hns false > /dev/null + export AZURE_STORAGE_ACCOUNT="$account" + AZURE_STORAGE_KEY="$(private_command az storage account keys list \\ + --account-name "$account" \\ + --resource-group "${resourceGroup}" \\ + --subscription "${subscription}" | jq -er '.[0].value')" + export AZURE_STORAGE_KEY + az storage container create \\ + --name s3-data \\ + --public-access off > /dev/null + for ((index = 0; index < 16; index++)); do + # Fixed per-object keys produce deterministic, nonzero 64 MiB payloads. + head -c 67108864 /dev/zero | + openssl enc -aes-256-ctr -K "$(printf '%064x' "$index")" \\ + -iv 00000000000000000000000000000000 > "${workDir}/blob.bin" + az storage blob upload \\ + --container-name s3-data \\ + --name "$(printf 'object-%02d.bin' "$index")" \\ + --file "${workDir}/blob.bin" \\ + --overwrite false > /dev/null + done + rm -f -- "${workDir}/blob.bin" + mkdir -p -- "${workDir}/small" + for ((index = 0; index < 1024; index++)); do + # Offset the key so small objects differ from the big ones; 1 MiB each. + head -c 1048576 /dev/zero | + openssl enc -aes-256-ctr -K "$(printf '%064x' "$((index + 16))")" \\ + -iv 00000000000000000000000000000000 > "${workDir}/small/$(printf 'obj-%04d.bin' "$index")" + done + # One batch upload: each single `az storage blob upload` costs about 2 s of fixed overhead. + az storage blob upload-batch \\ + --destination s3-data \\ + --destination-path small \\ + --source "${workDir}/small" \\ + --overwrite false > /dev/null + rm -rf -- "${workDir}/small" + # --include m exposes metadata.hdi_isfolder; --num-results is explicit so a truncated listing cannot pass. + az storage blob list \\ + --container-name s3-data \\ + --include m \\ + --num-results 5000 | + jq -e -L "${checksDir}" 'include "checks"; validate_s3_read_dataset' > /dev/null +} +seed_account "${localAccount}" "${localLocation}" +# The reads cover the whole 240-minute job timeout; an 8-hour read SAS is twice that, +# so it cannot expire mid-run. The write SAS is used by SeedCheckpointSets, which runs soon +# after this step; 2 hours covers it. +local_data_sas="$(make_sas s3-data rl 8)" || fail "Could not generate the local data SAS; secret-bearing output withheld" +az storage container create \\ + --name checkpoint \\ + --public-access off > /dev/null +checkpoint_read_sas="$(make_sas checkpoint rl 8)" || fail "Could not generate the checkpoint read SAS; secret-bearing output withheld" +checkpoint_write_sas="$(make_sas checkpoint cw 2)" || fail "Could not generate the checkpoint write SAS; secret-bearing output withheld" +unset AZURE_STORAGE_KEY +seed_account "${remoteAccount}" "${remoteLocation}" +remote_data_sas="$(make_sas s3-data rl 8)" || fail "Could not generate the remote data SAS; secret-bearing output withheld" +unset AZURE_STORAGE_KEY +publish_secret LOCAL_DATA_SAS "$local_data_sas" +publish_secret REMOTE_DATA_SAS "$remote_data_sas" +publish_secret CHECKPOINT_READ_SAS "$checkpoint_read_sas" +publish_secret CHECKPOINT_WRITE_SAS "$checkpoint_write_sas" +unset local_data_sas remote_data_sas checkpoint_read_sas checkpoint_write_sas +jq -n \\ + --arg local_account "${localAccount}" --arg local_location "${localLocation}" \\ + --arg remote_account "${remoteAccount}" --arg remote_location "${remoteLocation}" \\ + '$ARGS.named + {container: "s3-data", big_object_count: 16, big_object_bytes: 67108864, small_object_count: 1024, small_object_bytes: 1048576}' \\ + > "${resultDir}/dataset.json" +""" + stepName = "s3_read_dataset" + ) +} + +PrepareWorkerNvme = lambda serviceConnection: str, manifest: str, workDir: str, resultDir: str -> steps.Step { + azure.AzCli( + serviceConnection + "Mount the local NVMe disk on every worker node" + S3ReadShellSetup(workDir, resultDir) + """ +kubectl create -f "${manifest}" > /dev/null +# One pod per workerpool node. +kubectl rollout status daemonset/alluxio-nvme -n kube-system --timeout=600s +[[ "$(kubectl get daemonset alluxio-nvme -n kube-system -o jsonpath='{.status.numberReady}')" == ${S3_READ_WORKER_COUNT} ]] || + fail "expected ${S3_READ_WORKER_COUNT} ready NVMe pods" +for pod in $(kubectl get pods -n kube-system -l app=alluxio-nvme -o name); do + kubectl logs -n kube-system "$pod" | grep -q 'NVME READY /mnt/alluxio-nvme' || + fail "$pod did not report NVME READY" +done +""" + stepName = "alluxio_nvme" + ) +} + +# Worker counter of bytes read from the UFS (here Blob); its difference around an Alluxio run +# is what the workers fetched from Blob. Workers may label it and may print it in E-notation +# (for example 1.5E10); the awk sum in worker_ufs_bytes handles both. +UFS_READ_METRIC = "alluxio_external_data_read_bytes_total" + +# Shared by every step that talks to the workers: worker_hosts prints the ready workers' S3 addresses +# and fails unless there are exactly S3_READ_WORKER_COUNT; worker_ufs_bytes prints the sum of +# UFS_READ_METRIC over the workers. +WORKER_SHELL = """ +worker_hosts() { + local pods ready_ips count + pods="$(kubectl get pods -n alx-ns -l app.kubernetes.io/component=worker -o json)" || + fail "could not list the Alluxio worker pods" + ready_ips="$(jq -c '[.items[] | + select(.status.phase == "Running" and + any(.status.conditions[]?; .type == "Ready" and .status == "True")) | + .status.podIP | select(. != null and . != "")] | sort' <<< "$pods")" + count="$(jq 'length' <<< "$ready_ips")" + # A different count means a worker is missing or restarting. + [[ "$count" == ${S3_READ_WORKER_COUNT} ]] || fail "expected ${S3_READ_WORKER_COUNT} ready Alluxio workers, found $count: $ready_ips" + # 29998 is the Alluxio worker S3 port. + jq -r 'map(. + ":29998") | join(",")' <<< "$ready_ips" +} +worker_ufs_bytes() { + local workers worker count=0 total=0 value + workers="$(kubectl get pods -n alx-ns -l app.kubernetes.io/component=worker -o jsonpath='{.items[*].metadata.name}')" + for worker in $workers; do + value="$(kubectl get --raw "/api/v1/namespaces/alx-ns/pods/$worker:30000/proxy/metrics/" | + awk -v name="${UFS_READ_METRIC}" ' + $1 == name || index($1, name "{") == 1 { sum += $NF; found = 1 } + END { if (!found) exit 1; printf "%.0f", sum }')" || + fail "worker $worker does not expose ${UFS_READ_METRIC}" + total=$((total + value)) + count=$((count + 1)) + done + (( count == ${S3_READ_WORKER_COUNT} )) || fail "expected ${S3_READ_WORKER_COUNT} Alluxio workers for the metrics scrape, found $count" + printf '%s\\n' "$total" +} +""" + +# The base redact only knows the license and BLOB_SAS, so this one masks the four SAS variables. +S3ReadSetup = lambda workDir: str, resultDir: str -> str { + S3ReadShellSetup(workDir, resultDir) + SecretCommands(workDir) + WORKER_SHELL + """ +redact() { + local line secret + while IFS= read -r line || [[ -n "$line" ]]; do + for secret in "\\${LOCAL_DATA_SAS:-}" "\\${REMOTE_DATA_SAS:-}" "\\${CHECKPOINT_READ_SAS:-}" "\\${CHECKPOINT_WRITE_SAS:-}"; do + if [[ -n "$secret" ]]; then line="\\${line//"$secret"/}"; fi + done + printf '%s\\n' "$line" + done +} +""" +} + +CreateS3ReadClients = lambda serviceConnection: str, manifest: str, script: str, workDir: str, resultDir: str -> steps.Step { + azure.AzCli( + serviceConnection + "Create the S3 read client pods" + S3ReadSetup(workDir, resultDir) + """ +for variable in LOCAL_DATA_SAS REMOTE_DATA_SAS CHECKPOINT_READ_SAS CHECKPOINT_WRITE_SAS; do + require_secret "$variable" +done +kubectl create configmap s3c-script -n alx-ns --from-file=s3c.sh="${script}" > /dev/null +# Process substitution keeps every SAS off argv and off disk; the secret is created, never applied. +kubectl create secret generic s3c-sas -n alx-ns \\ + --from-file=local-data=<(printf '%s' "$LOCAL_DATA_SAS") \\ + --from-file=remote-data=<(printf '%s' "$REMOTE_DATA_SAS") \\ + --from-file=checkpoint-read=<(printf '%s' "$CHECKPOINT_READ_SAS") \\ + --from-file=checkpoint-write=<(printf '%s' "$CHECKPOINT_WRITE_SAS") \\ + > /dev/null 2> >(redact >&2) +for index in $(seq 1 ${S3_READ_CLIENT_COUNT}); do + patch="$(jq -n --arg name "s3c-$index" '{metadata: {name: $name}}')" + pod="$(kubectl patch --local --type=merge -f "${manifest}" -p "$patch" -o yaml)" + printf '%s\\n' "$pod" | kubectl create --dry-run=server --validate=strict -f - > /dev/null + printf '%s\\n' "$pod" | kubectl create -f - > /dev/null +done +kubectl wait -n alx-ns --for=condition=Ready pod -l app=s3c --timeout=600s +# The anti-affinity rule must have put the client pods on different nodes. +kubectl get pods -n alx-ns -l app=s3c -o json | + jq -e '[.items[].spec.nodeName] | unique | length == ${S3_READ_CLIENT_COUNT}' > /dev/null || + fail "the ${S3_READ_CLIENT_COUNT} client pods are not on ${S3_READ_CLIENT_COUNT} different nodes" +key_script="$(cat <<'KEYS' +set -eu +seq 0 15 | awk '{printf "object-%02d.bin\\n", $1}' > /tmp/big.txt +seq 0 1023 | awk '{printf "small/obj-%04d.bin\\n", $1}' > /tmp/small.txt +for set in 1 2 3 4 5 6; do + seq 0 7 | awk -v set="$set" '{printf "set-%d/part-%d.bin\\n", set, $1}' > "/tmp/checkpoint-$set.txt" +done +KEYS +)" +for index in $(seq 1 ${S3_READ_CLIENT_COUNT}); do + kubectl exec -n alx-ns "s3c-$index" -c s3c -- sh -c "$key_script" +done +""" + stepName = "s3_read_clients" + env = { + LOCAL_DATA_SAS = "$(LOCAL_DATA_SAS)" + REMOTE_DATA_SAS = "$(REMOTE_DATA_SAS)" + CHECKPOINT_READ_SAS = "$(CHECKPOINT_READ_SAS)" + CHECKPOINT_WRITE_SAS = "$(CHECKPOINT_WRITE_SAS)" + } + ) +} + +# Checkpoint objects are set-<1..6>/part-<0..7>.bin; set n is written by pod s3c-((n - 1) % S3_READ_CLIENT_COUNT + 1). +SeedCheckpointSets = lambda serviceConnection: str, localAccount: str, workDir: str, resultDir: str, checksDir: str -> steps.Step { + azure.AzCli( + serviceConnection + "Generate the checkpoint sets in the clients" + S3ReadSetup(workDir, resultDir) + """ +seed_script="$(cat <<'SEED' +set -eu +umask 077 +account=$1 +shift +sas="$(cat /sas/checkpoint-write)" +trap 'rm -f /scratch/*.bin /scratch/*.curl' EXIT +upload_part() { + local set="$1" part="$2" + local file="/scratch/set-$set-part-$part.bin" config="/scratch/set-$set-part-$part.curl" + # /dev/urandom, not openssl: the client image has no openssl, and reads only need incompressible bytes. + dd if=/dev/urandom of="$file" bs=1048576 count=2048 2> /dev/null + [ "$(wc -c < "$file")" -eq 2147483648 ] || { echo "ALLUXIO S3 READ FAILED: short temp file $file" >&2; exit 1; } + # The SAS goes into a 0600 curl config, not onto argv. Put Blob needs a Content-Length, + # so the body is a file (-T), not a pipe; x-ms-version 2019-12-12 allows a single 5000 MiB Put Blob. + printf 'url = "https://%s.blob.core.windows.net/checkpoint/set-%s/part-%s.bin?%s"\\n' \\ + "$account" "$set" "$part" "$sas" > "$config" + # Each 2 GiB attempt is capped at 30 minutes and no retry starts after 30 minutes, + # so a stalled upload fails the step long before the job timeout. + curl --silent --show-error --fail --retry 3 --retry-delay 5 --max-time 1800 --retry-max-time 1800 --config "$config" \\ + -T "$file" \\ + -H 'x-ms-blob-type: BlockBlob' \\ + -H 'x-ms-version: 2019-12-12' > /dev/null || { echo "ALLUXIO S3 READ FAILED: upload of set-$set/part-$part failed" >&2; exit 1; } + rm -f "$file" "$config" +} +for set in "$@"; do + pids="" + for part in 0 1 2 3 4 5 6 7; do + upload_part "$set" "$part" & + pids="$pids $!" + done + for pid in $pids; do + wait "$pid" || { echo "ALLUXIO S3 READ FAILED: set $set did not finish uploading" >&2; exit 1; } + done + echo "set-$set uploaded" +done +SEED +)" +# A kubectl exec stream can drop during a long upload and still return 0 while the upload keeps running +# in the pod. So the upload runs detached in the pod (setsid, stdio not tied to the exec) and writes its +# log and exit status to /scratch; short execs poll for the status file. +# The sets a pod printed as uploaded are then counted against the sets assigned to it. +seed_run='sh /scratch/seed.sh "$@" > /scratch/seed.log 2>&1 +echo $? > /scratch/seed.rc' +seed_pod() { + local index="$1" rc="" deadline + local pod="s3c-$index" + shift + # One short exec writes both scripts (passed as arguments, not stdin) and starts the upload detached. + kubectl exec -n alx-ns "$pod" -c s3c -- sh -c 'printf "%s\\n" "$1" > /scratch/seed.sh + printf "%s\\n" "$2" > /scratch/seed-run.sh + shift 2 + rm -f /scratch/seed.rc /scratch/seed.log + setsid sh /scratch/seed-run.sh "$@" < /dev/null > /dev/null 2>&1 &' sh "$seed_script" "$seed_run" "${localAccount}" "$@" + # A pod uploads at most 2 sets of 16 GiB, which takes a few minutes; 40 minutes is a generous bound. + deadline=$((SECONDS + 2400)) + until rc="$(kubectl exec -n alx-ns "$pod" -c s3c -- cat /scratch/seed.rc 2> /dev/null)"; do + if (( SECONDS >= deadline )); then + rc=timeout + break + fi + sleep 15 + done + kubectl exec -n alx-ns "$pod" -c s3c -- cat /scratch/seed.log 2>&1 | redact > "${resultDir}/checkpoint-seed-$pod.log" || true + echo "$rc" > "${workDir}/checkpoint-seed-$pod.rc" +} +pids=() +assigned=() +for index in $(seq 1 ${S3_READ_CLIENT_COUNT}); do + sets="" + for set in 1 2 3 4 5 6; do + if (( (set - 1) % ${S3_READ_CLIENT_COUNT} + 1 == index )); then + sets="$sets $set" + fi + done + assigned[index]="$sets" + rm -f "${workDir}/checkpoint-seed-s3c-$index.rc" + seed_pod "$index" $sets & + pids+=($!) +done +for pid in "\\${pids[@]}"; do + wait "$pid" || true +done +seed_failed=0 +for index in $(seq 1 ${S3_READ_CLIENT_COUNT}); do + pod="s3c-$index" + log="${resultDir}/checkpoint-seed-$pod.log" + rc="$(cat "${workDir}/checkpoint-seed-$pod.rc" 2> /dev/null || echo missing)" + uploaded="$(sed -n 's/^\\(set-[0-9][0-9]*\\) uploaded$/\\1/p' "$log" | paste -sd, -)" + count="$(grep -c '^set-[0-9]* uploaded$' "$log" || true)" + want="$(wc -w <<< "\\${assigned[index]}" | tr -d ' ')" + echo "$pod: exit $rc, uploaded sets: \\${uploaded:-none}" + if [[ "$rc" != 0 ]] || (( count < want )); then + echo "ALLUXIO S3 READ FAILED: $pod uploaded $count of $want assigned sets (exit $rc)" >&2 + seed_failed=1 + fi +done +(( seed_failed == 0 )) || exit 1 +list_script="$(cat <<'LIST' +set -eu +umask 077 +sas="$(cat /sas/checkpoint-read)" +trap 'rm -f /scratch/list.curl' EXIT +printf 'url = "https://%s.blob.core.windows.net/checkpoint?restype=container&comp=list&include=metadata&maxresults=5000&%s"\\n' \\ + "$1" "$sas" > /scratch/list.curl +# One tab-separated line per blob: name, size, hdi_isfolder metadata. A non-empty NextMarker means a truncated listing. +curl --silent --show-error --fail --max-time 120 --config /scratch/list.curl -H 'x-ms-version: 2019-12-12' | + awk 'BEGIN { RS = "<" } + { gsub(/[\\r\\n]/, "") } + /^Blob>/ { name = ""; size = ""; folder = "" } + /^Name>/ { name = substr($0, 6) } + /^Content-Length>/ { size = substr($0, 16) } + /^hdi_isfolder>/ { folder = substr($0, 14) } + /^NextMarker>/ { print "#truncated" } + /^\\/Blob>/ { printf "%s\\t%s\\t%s\\n", name, size, folder }' +LIST +)" +listing="$(kubectl exec -n alx-ns s3c-1 -c s3c -- sh -c "$list_script" sh "${localAccount}" 2> >(redact >&2))" || + fail "could not list the checkpoint container" +# Keep what the container holds (name, size, marker; no SAS) so a failed validation can be inspected. +printf '%s\\n' "$listing" | grep -v '^$' > "${resultDir}/checkpoint-listing.tsv" || true +echo "checkpoint container: $(wc -l < "${resultDir}/checkpoint-listing.tsv" | tr -d ' ') blobs, distinct sizes: $(cut -f2 "${resultDir}/checkpoint-listing.tsv" | sort -u | paste -sd, -)" +[[ "$listing" != *'#truncated'* ]] || fail "the checkpoint listing is truncated" +# Each listing line is name, size and hdi_isfolder metadata; checks.jq decides whether the container is right. +printf '%s\\n' "$listing" | jq -R -s -L "${checksDir}" ' + include "checks"; + [split("\\n")[] | select(length > 0) | split("\\t") | { + name: .[0], + properties: {contentLength: (.[1] | tonumber)}, + metadata: (if .[2] == "" then null else {hdi_isfolder: .[2]} end)}] + | validate_checkpoint_dataset' > /dev/null || fail "checkpoint container validation failed" +jq -n '{checkpoint_sets: 6, checkpoint_parts_per_set: 8, checkpoint_object_count: 48, checkpoint_object_bytes: 2147483648}' \\ + > "${resultDir}/checkpoint.json" +""" + stepName = "s3_read_checkpoint" + env = { + CHECKPOINT_READ_SAS = "$(CHECKPOINT_READ_SAS)" + CHECKPOINT_WRITE_SAS = "$(CHECKPOINT_WRITE_SAS)" + } + ) +} + +# Runs the scenarios with the given ids (one group of S3_READ_SCENARIO_GROUPS) in pod s3c-1, +# against Alluxio and direct Blob. The first group also starts runs/index.jsonl and warms both +# datasets; later groups append to that index. Dataset local is Alluxio bucket "blob" (mount +# /blob) and the local account; remote is bucket "xregion" (mount /xregion) and the remote account. +RunS3ReadScenarios = lambda serviceConnection: str, localAccount: str, remoteAccount: str, workDir: str, resultDir: str, checksDir: str, ids: [int] -> steps.Step { + assert localAccount != remoteAccount, "the local and remote storage accounts must differ" + scenarios = [scenario for scenario in S3_READ_SCENARIOS if scenario.id in ids] + assert [scenario.id for scenario in scenarios] == ids, "ids must be scenario ids in S3_READ_SCENARIOS order" + first = ids[0] == S3_READ_SCENARIOS[0].id + label = "${ids[0]}-${ids[-1]}" if len(ids) > 1 else "${ids[0]}" + # Per dataset: Alluxio bucket, mount path, Blob account and the SAS file in the client pods (see CreateS3ReadClients). + datasets = { + local = {bucket = "blob", mount = "/blob", account = localAccount, sas = "local-data"} + remote = {bucket = "xregion", mount = "/xregion", account = remoteAccount, sas = "remote-data"} + } + scenario_call = lambda scenario: S3ReadScenario -> str { + dataset = datasets[scenario.dataset] + big_get = scenario.kind == "get" and scenario.objects == "big" + object_bytes = 67108864 if scenario.objects == "big" else 1048576 + request_bytes = scenario.rangeBytes if scenario.kind == "range" else object_bytes + # Each worker runs its requests in batches, one curl run per batch. Every batch opens its connections + # and sends a warm-up HEAD per host (see s3c.sh); that is kept out of the latency percentiles but not + # out of the run's wall time, so larger batches spread it over more requests. A worker starts no new + # batch after 60 s, so the last batch in flight overruns the window. Size batches by bytes, about + # 256 MiB per batch and at most 50 requests: the slowest requests seen in a full run were + # cross-region 64 MiB GETs from Blob at 16 concurrent requests (p99 5.7 s), so a batch of four ends + # within about 23 s, inside the 30 s checks.jq allows for the rest of a batch. + # Examples: 256 KiB, 1 MiB and 4 MiB requests 50, 16 MiB 16, a 64 MiB get 4. + batch = max(min(268435456 // request_bytes, 50), 1) + # s3c.sh fails when the budget runs out before 60 s, so it must exceed the fastest scenario: + # 100000 requests per worker over 60 s is about 1,667 requests/s per worker. A 64 MiB get + # cannot come close to that (about 10 per second from the cache at one request at a time), + # so its budget is small: 2000, a whole number of batches of four. + budget = 2000 if big_get else 100000 + # The scenario's fields go into runs/index.jsonl and from there into summary.json. + metadata = json.encode({ + id = scenario.id + name = scenario.name + kind = scenario.kind + dataset = scenario.dataset + concurrency = scenario.concurrency + rangeBytes = scenario.rangeBytes + }) + "run_scenario '${metadata}' ${scenario.kind} ${dataset.bucket} ${dataset.account} ${dataset.sas} /tmp/${scenario.objects}.txt ${object_bytes} ${scenario.concurrency} ${scenario.rangeBytes} ${batch} ${budget}" + } + scenario_calls = "\n".join([scenario_call(scenario) for scenario in scenarios]) + azure.AzCli( + serviceConnection + "Run S3 read scenarios ${label} against Alluxio and Blob" + S3ReadSetup(workDir, resultDir) + """ +mkdir -p -- "${resultDir}/runs" +""" + (''': > "${resultDir}/runs/index.jsonl" +''' if first else '''[[ -s "${resultDir}/runs/index.jsonl" ]] || fail "the first scenario group has not run" +''') + """ +alluxio() { + kubectl exec -n alx-ns alluxio-coordinator-0 \\ + -c alluxio-coordinator -- alluxio "$@" +} +# Runs s3c.sh once in client pod s3c-1; the JSON result goes to stdout, redacted. +# $1 side (alluxio|blob), then the scenario parameters of run_scenario after the metadata. +run_s3c() { + local side="$1" kind="$2" bucket="$3" account="$4" sas="$5" keys="$6" object_bytes="$7" + local concurrency="$8" range_bytes="$9" batch="\${10}" budget="\${11}" duration="\${12}" hosts + local args=(MODE="$side" KIND="$kind" CONCURRENCY="$concurrency" DURATION_SECONDS="$duration" + KEYS_FILE="$keys" OBJECT_BYTES="$object_bytes" RANGE_BYTES="$range_bytes" + BATCH_REQUESTS="$batch" MAX_REQUESTS_PER_WORKER="$budget") + if [[ "$side" == alluxio ]]; then + # Re-read the worker list for every run: a worker that restarted since the last run must fail the step. + hosts="$(worker_hosts)" + args+=(HOSTS="$hosts" EXPECTED_HOSTS=${S3_READ_WORKER_COUNT} BUCKET="$bucket") + else + args+=(ACCOUNT="$account" CONTAINER=s3-data SAS_FILE="/sas/$sas") + fi + kubectl exec -n alx-ns s3c-1 -c s3c -- env "\${args[@]}" sh /scripts/s3c.sh 2> >(redact >&2) +} +# $1 scenario metadata (JSON), $2 side, $3 rep, then run_s3c arguments after the side. +# s3c.sh already retries every failed request, with the same policy on both sides, so a run is not +# repeated: an error left after those retries, on either side, fails the step. +# Both datasets are loaded and checked as fully cached before scenario 1, and every scenario reads one of +# them, so every Alluxio rep must be served from the cache. Alluxio can fall back to reading Blob while +# every response still looks fine, so the workers' UFS-read counter is read before and after each Alluxio +# rep; if they read more than 1% of the bytes the client read (served_from_cache in checks.jq), the step +# fails. The counters go into the rep's index entry as worker_ufs, and from there into summary.json. +run_and_record() { + local scenario="$1" side="$2" rep="$3" id start end out status=0 run_file ufs_before ufs_after worker_ufs='{}' + id="$(jq -r '.id' <<< "$scenario")" + shift 3 + run_file="${resultDir}/runs/$id-$side-$rep.json" + if [[ "$side" == alluxio ]]; then + ufs_before="$(worker_ufs_bytes)" + fi + start="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + out="$(run_s3c "$side" "$@" 60)" || status=$? + end="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + # s3c.sh prints its JSON result before it fails; keep that result for diagnosis. + printf '%s\\n' "$out" | redact > "$run_file" + if (( status != 0 )) || ! jq -e -L "${checksDir}" 'include "checks"; validate_s3c_run' "$run_file" > /dev/null; then + fail "scenario $id $side rep $rep failed or produced an invalid result" + fi + if [[ "$side" == alluxio ]]; then + ufs_after="$(worker_ufs_bytes)" + worker_ufs="$(jq -nc --argjson before "$ufs_before" --argjson after "$ufs_after" \\ + '{worker_ufs: {before: $before, after: $after, bytes: ($after - $before)}}')" + jq -e -L "${checksDir}" --argjson ufs_bytes "$((ufs_after - ufs_before))" \\ + 'include "checks"; served_from_cache($ufs_bytes)' "$run_file" > /dev/null || + fail "scenario $id alluxio rep $rep: the workers read $((ufs_after - ufs_before)) bytes from Blob while the client read $(jq -r '.bytes' "$run_file"); more than 1% (or a negative count, from a restarted worker) means the rep was not served from the preloaded cache" + fi + jq -nc --argjson scenario "$scenario" --arg side "$side" --argjson rep "$rep" --arg started "$start" --arg ended "$end" \\ + --argjson worker_ufs "$worker_ufs" \\ + '$scenario + {side: $side, rep: $rep, start: $started, end: $ended} + $worker_ufs' >> "${resultDir}/runs/index.jsonl" +} +# $1 scenario metadata (JSON), then the arguments of run_s3c after the side. +run_scenario() { + local scenario="$1" rep + shift + # Alternate Alluxio and Blob reps so that drift over time affects both sides. + for rep in 1 2 3; do + run_and_record "$scenario" alluxio "$rep" "$@" + run_and_record "$scenario" blob "$rep" "$@" + done +} +# $1 dataset name, $2 mount path. +# The dataset is warmed with Alluxio's distributed load, not with client reads. With +# alluxio.worker.s3.redirect.enabled=false a read through a worker that does not own the file is +# relayed and does not populate the cache, so one pass of client reads cannot cache every file. +warm_dataset() { + local name="$1" mount="$2" attempt state failed deadline + alluxio job load --path "$mount" --submit | redact > "${resultDir}/preload-submit-$name.txt" + # Bound the wait to 10 minutes; a load still not finished then fails the step. + deadline=$((SECONDS + 600)) + while :; do + alluxio job load --path "$mount" --progress | redact > "${resultDir}/preload-$name.txt" + # A job waits (WAITING) until the scheduler picks it up and may verify (VERIFYING) before it ends. + # The state can be followed by a note, as in "Job State: SUCCEEDED (3 directories failed to index; ...)", + # so only the first word is the state. + state="$(sed -nE 's/^[[:space:]]*Job State:[[:space:]]*([A-Z_]+).*$/\\1/p' "${resultDir}/preload-$name.txt")" + case "$state" in + CREATED|WAITING|RUNNING|VERIFYING|SUCCEEDED) ;; + *) fail "preload of the $name dataset failed or returned an unrecognized job state" ;; + esac + failed="$(sed -nE 's/^[[:space:]]*Files Failed:[[:space:]]*([0-9]+)[[:space:]]*$/\\1/p' "${resultDir}/preload-$name.txt")" + [[ "$failed" == 0 ]] || fail "preload of the $name dataset must report zero failed files" + [[ "$state" == SUCCEEDED ]] && break + (( SECONDS < deadline )) || fail "preload of the $name dataset did not finish within 10 minutes" + sleep 10 + done + # --limit 1041 exceeds the 1,040 objects (16 big + 1,024 small), so the report is not truncated. + # Cache population can lag the end of the load job, so poll: at most 6 checks 10 s apart (about 1 minute), + # then a real shortfall fails the step. + for attempt in 1 2 3 4 5 6; do + if alluxio fs check-cached --path "$mount" --recursive --limit 1041 | redact > "${resultDir}/cache-$name.txt" && + jq -Rse -L "${checksDir}" 'include "checks"; validate_all_cached' "${resultDir}/cache-$name.txt" > /dev/null; then + return 0 + fi + (( attempt == 6 )) || sleep 10 + done + fail "the $name dataset is not fully cached after 6 checks over about a minute" +} +""" + ("warm_dataset local ${datasets.local.mount}\nwarm_dataset remote ${datasets.remote.mount}\n" if first else "") + scenario_calls + "\n" + stepName = "s3_read_scenarios_" + label.replace("-", "_") + env = { + LOCAL_DATA_SAS = "$(LOCAL_DATA_SAS)" + REMOTE_DATA_SAS = "$(REMOTE_DATA_SAS)" + CHECKPOINT_READ_SAS = "$(CHECKPOINT_READ_SAS)" + CHECKPOINT_WRITE_SAS = "$(CHECKPOINT_WRITE_SAS)" + } + ) +} + +# Scenarios 11 and 12: all client pods read the same 8 x 2 GiB checkpoint set at the same time. +# Alluxio reads sets 1-3 (bucket ckpt), direct Blob reads sets 4-6, one set per rep. The bytes the +# Blob account served are attributed to each rep from the Azure Monitor Egress metric. +# It needs no SAS: the SAS files are mounted in the client pods, so the step handles no secret +# and needs no redact. +RunCheckpointLoad = lambda serviceConnection: str, subscription: str, resourceGroup: str, localAccount: str, workDir: str, resultDir: str, checksDir: str -> steps.Step { + assert localAccount != "", "the local storage account name must be set" + azure.AzCli( + serviceConnection + "Load checkpoints from ${S3_READ_CLIENT_COUNT} clients and attribute Blob egress" + S3ReadShellSetup(workDir, resultDir) + WORKER_SHELL + """ +checkpoint_dir="${resultDir}/checkpoint" +mkdir -p -- "$checkpoint_dir" +: > "$checkpoint_dir/index.jsonl" +: > "$checkpoint_dir/worker-ufs.jsonl" +# 8 objects of 2 GiB (2147483648 bytes) are read once per pod. +expected_bytes=17179869184 +# $1 side, $2 rep, $3 pod, then the s3c.sh environment. Runs in the background, one per pod. +read_one() { + local side="$1" rep="$2" pod="$3" start end out + shift 3 + start="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + if ! out="$(kubectl exec -n alx-ns "$pod" -c s3c -- env "$@" sh /scripts/s3c.sh)"; then + # s3c.sh prints its JSON result before it fails; keep it. It holds only counters, no SAS. + printf '%s\\n' "$out" > "$checkpoint_dir/$side-$rep-$pod.json" + exit 1 + fi + end="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + printf '%s\\n' "$out" > "$checkpoint_dir/$side-$rep-$pod.json" + jq -nc --arg side "$side" --argjson rep "$rep" --arg pod "$pod" --arg started "$start" --arg ended "$end" \\ + '{side: $side, rep: $rep, pod: $pod, start: $started, end: $ended}' > "$checkpoint_dir/$side-$rep-$pod.index" +} +# $1 side (alluxio|blob), $2 rep, $3 checkpoint set. All client pods read the set at the same time. +read_set() { + local side="$1" rep="$2" set="$3" index pid status=0 pids=() + local args=(KIND=onepass CONCURRENCY=8 KEYS_FILE="/tmp/checkpoint-$set.txt" + OBJECT_BYTES=2147483648 BATCH_REQUESTS=1) + if [[ "$side" == alluxio ]]; then + # Re-read the worker list for every rep: a restarted worker must fail the step. + args+=(MODE=alluxio HOSTS="$(worker_hosts)" EXPECTED_HOSTS=${S3_READ_WORKER_COUNT} BUCKET=ckpt) + else + args+=(MODE=blob ACCOUNT="${localAccount}" CONTAINER=checkpoint SAS_FILE=/sas/checkpoint-read) + fi + for index in $(seq 1 ${S3_READ_CLIENT_COUNT}); do + # Every pod reads the same keys; each starts at a different worker, so on the Alluxio side every + # worker serves the same share of the requests (with 5 pods and 5 workers, 8 each). + read_one "$side" "$rep" "s3c-$index" "\\${args[@]}" HOST_OFFSET=$((index - 1)) & + pids+=($!) + done + for pid in "\\${pids[@]}"; do + wait "$pid" || status=1 + done + (( status == 0 )) || fail "checkpoint $side rep $rep: at least one client failed" + for index in $(seq 1 ${S3_READ_CLIENT_COUNT}); do + jq -e -L "${checksDir}" --argjson expected "$expected_bytes" \\ + 'include "checks"; validate_s3c_run | .bytes == $expected' \\ + "$checkpoint_dir/$side-$rep-s3c-$index.json" > /dev/null || + fail "checkpoint $side rep $rep s3c-$index produced an invalid result" + cat "$checkpoint_dir/$side-$rep-s3c-$index.index" >> "$checkpoint_dir/index.jsonl" + rm -f -- "$checkpoint_dir/$side-$rep-s3c-$index.index" + done +} +resource_id="$(az storage account show \\ + --name "${localAccount}" \\ + --resource-group "${resourceGroup}" \\ + --subscription "${subscription}" \\ + --query id \\ + --output tsv)" +[[ -n "$resource_id" ]] || fail "could not resolve the resource ID of ${localAccount}" +# Egress is per storage account and arrives about a minute late, and scenarios 1-10 just read this +# account; wait so their last reads fall before the first rep's window. +sleep 180 +step_start="$(date -u +%Y-%m-%dT%H:%M:%SZ)" +for rep in 1 2 3; do + before="$(worker_ufs_bytes)" + read_set alluxio "$rep" "$rep" + after="$(worker_ufs_bytes)" + jq -nc --argjson rep "$rep" --argjson before "$before" --argjson after "$after" \\ + '{rep: $rep, before: $before, after: $after, bytes: ($after - $before)}' >> "$checkpoint_dir/worker-ufs.jsonl" + # Azure Monitor reports Egress per minute; runs at least 70 s apart start in different minute windows. + sleep 70 + read_set blob "$rep" "$((rep + 3))" + (( rep == 3 )) || sleep 70 +done +last_rep_end=$SECONDS +: > "$checkpoint_dir/runs.jsonl" +for file in "$checkpoint_dir"/*-s3c-*.json; do + name="$(basename "$file" .json)" + jq -c --arg name "$name" \\ + '($name | capture("^(?[a-z]+)-(?[0-9]+)-(?.+)$")) as $id + | {side: $id.side, rep: ($id.rep | tonumber), pod: $id.pod, wall_seconds: .wall_seconds, retries: .retries}' \\ + "$file" >> "$checkpoint_dir/runs.jsonl" +done +# Egress minute metrics arrive about 1 minute late; the first query waits 3 minutes after the last rep. +# Then query every 60 s until every window has data and checks.jq's bounds hold, for up to 10 minutes +# after the last rep. egress.json ends up as the output of the last query. +sleep 180 +while :; do + step_end="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + az monitor metrics list \\ + --resource "$resource_id" \\ + --metric Egress \\ + --interval PT1M \\ + --aggregation Total \\ + --start-time "$step_start" \\ + --end-time "$step_end" > "$checkpoint_dir/egress.json" + if jq -n -L "${checksDir}" \\ + --slurpfile index "$checkpoint_dir/index.jsonl" \\ + --slurpfile runs "$checkpoint_dir/runs.jsonl" \\ + --slurpfile worker_ufs "$checkpoint_dir/worker-ufs.jsonl" \\ + --slurpfile metrics "$checkpoint_dir/egress.json" \\ + 'include "checks"; {index: $index, runs: $runs, worker_ufs: $worker_ufs, metrics: $metrics[0]} | checkpoint_summary' \\ + > "$checkpoint_dir/summary.json" 2> "$checkpoint_dir/summary.err"; then + break + fi + if (( SECONDS >= last_rep_end + 600 )); then + cat "$checkpoint_dir/summary.err" >&2 + fail "could not attribute Blob egress within 10 minutes of the last rep; see $checkpoint_dir/egress.json" + fi + echo "Blob egress is not complete yet: $(tail -n 1 "$checkpoint_dir/summary.err")" + sleep 60 +done +rm -f -- "$checkpoint_dir/summary.err" +""" + stepName = "s3_read_checkpoint_load" + ) +} + +# Merges the scenario 1-10 medians with the checkpoint summary into summary.json. +# runs/index.jsonl has one entry per run (scenario fields, side, rep, start, end); each entry is +# merged with runs/--.json. +SummarizeS3Read = lambda workDir: str, resultDir: str, checksDir: str -> steps.Bash { + steps.Bash { + name = "s3_read_summary" + displayName = "Summarize the S3 read results" + bash = S3ReadShellSetup(workDir, resultDir) + """ +runs_file="${workDir}/summary-runs.jsonl" +: > "$runs_file" +while IFS= read -r entry; do + run_file="${resultDir}/runs/$(jq -r '"\\(.id)-\\(.side)-\\(.rep)"' <<< "$entry").json" + jq -c --argjson entry "$entry" '$entry + .' "$run_file" >> "$runs_file" +done < "${resultDir}/runs/index.jsonl" +[[ -s "${resultDir}/checkpoint/summary.json" ]] || fail "the checkpoint summary is missing" +jq -s -L "${checksDir}" 'include "checks"; scenario_summary' "$runs_file" > "${workDir}/scenarios.json" +# Scenarios 1-10 must all be present. +jq -e 'map(.id) == [range(1; 11)]' "${workDir}/scenarios.json" > /dev/null || + fail "the summary does not cover exactly scenarios 1-10" +jq -n \\ + --slurpfile scenarios "${workDir}/scenarios.json" \\ + --slurpfile checkpoint "${resultDir}/checkpoint/summary.json" \\ + '{scenarios: $scenarios[0], checkpoint: $checkpoint[0]}' > "${resultDir}/summary.json" +rm -f -- "$runs_file" "${workDir}/scenarios.json" +""" + } +} + +# Runs last before the results are published. A SAS signature (sig=) anywhere in the result +# directory means a secret leaked, so the directory is emptied and the job fails. +RefuseSasInResults = lambda workDir: str, resultDir: str -> steps.Bash { + steps.Bash { + name = "s3_read_sas_check" + displayName = "Refuse to publish results that contain a SAS signature" + condition = "always()" + bash = S3ReadShellSetup(workDir, resultDir) + """ +if grep -rq 'sig=' "${resultDir}"; then + find "${resultDir}" -mindepth 1 -delete + echo "ALLUXIO S3 READ FAILED: a SAS signature (sig=) was present in the results; the results were deleted, not published" >&2 + exit 1 +fi +""" + } +} diff --git a/kcl/lib/steps/alluxio/s3_read_test.k b/kcl/lib/steps/alluxio/s3_read_test.k new file mode 100644 index 0000000000..4c49da4050 --- /dev/null +++ b/kcl/lib/steps/alluxio/s3_read_test.k @@ -0,0 +1,85 @@ +import runtime + +test_s3_read_scenarios = lambda { + assert S3_READ_SCENARIOS == [ + S3ReadScenario {id = 1, name = "remote small get", kind = "get", dataset = "remote", objects = "small", concurrency = 16} + S3ReadScenario {id = 2, name = "remote big get", kind = "get", dataset = "remote", objects = "big", concurrency = 16} + S3ReadScenario {id = 3, name = "range 256 KiB", kind = "range", dataset = "local", objects = "big", concurrency = 16, rangeBytes = 262144} + S3ReadScenario {id = 4, name = "range 1 MiB", kind = "range", dataset = "local", objects = "big", concurrency = 16, rangeBytes = 1048576} + S3ReadScenario {id = 5, name = "local small get", kind = "get", dataset = "local", objects = "small", concurrency = 16} + S3ReadScenario {id = 6, name = "range 4 MiB", kind = "range", dataset = "local", objects = "big", concurrency = 16, rangeBytes = 4194304} + S3ReadScenario {id = 7, name = "range 16 MiB", kind = "range", dataset = "local", objects = "big", concurrency = 16, rangeBytes = 16777216} + S3ReadScenario {id = 8, name = "big get concurrency 1", kind = "get", dataset = "local", objects = "big", concurrency = 1} + S3ReadScenario {id = 9, name = "big get concurrency 4", kind = "get", dataset = "local", objects = "big", concurrency = 4} + S3ReadScenario {id = 10, name = "big get concurrency 16", kind = "get", dataset = "local", objects = "big", concurrency = 16} + ] +} + +test_s3_read_scenario_groups = lambda { + # Every scenario runs exactly once, in S3_READ_SCENARIOS order. + assert [id for group in S3_READ_SCENARIO_GROUPS for id in group] == [scenario.id for scenario in S3_READ_SCENARIOS] + steps = [RunS3ReadScenarios("sc", "local", "remote", "w", "r", "c", group) for group in S3_READ_SCENARIO_GROUPS] + assert [step.name for step in steps] == ["s3_read_scenarios_1_3", "s3_read_scenarios_4_5", "s3_read_scenarios_6_7", "s3_read_scenarios_8_10"] + # Only the first group starts the index and warms the datasets. + assert [": > \"r/runs/index.jsonl\"" in step.inputs.inlineScript for step in steps] == [True, False, False, False] + assert ["\nwarm_dataset local /blob\n" in step.inputs.inlineScript for step in steps] == [True, False, False, False] +} + +test_s3_read_scenarios_rejects_unknown_ids = lambda { + failure = runtime.catch(lambda { + RunS3ReadScenarios("sc", "local", "remote", "w", "r", "c", [3, 2]) + }) + assert "ids must be scenario ids" in failure, failure +} + +test_summary_and_sas_check_need_no_azure_login = lambda { + # Neither step uses az or kubectl, so neither depends on the service connection signing in; + # the SAS check must run before results are published even when that sign-in fails. + assert SummarizeS3Read("w", "r", "c").bash + assert RefuseSasInResults("w", "r").bash +} + +test_range_requires_size = lambda { + failure = runtime.catch(lambda { + S3ReadScenario { + id = 1 + name = "range without size" + kind = "range" + dataset = "local" + objects = "big" + concurrency = 16 + rangeBytes = 0 + } + }) + assert failure != "" +} + +test_get_rejects_range_size = lambda { + failure = runtime.catch(lambda { + S3ReadScenario { + id = 1 + name = "get with size" + kind = "get" + dataset = "local" + objects = "big" + concurrency = 16 + rangeBytes = 1024 + } + }) + assert failure != "" +} + +test_scenario_steps_check_the_cache_hit = lambda { + # Every scenario group reads the workers' UFS counter around each Alluxio rep and fails a rep that read + # from Blob; the helper is defined once per step. + scripts = [RunS3ReadScenarios("sc", "local", "remote", "w", "r", "c", group).inputs.inlineScript for group in S3_READ_SCENARIO_GROUPS] + assert all script in scripts { + len(script.split("\nworker_ufs_bytes() {")) == 2 and "served_from_cache($ufs_bytes)" in script + } +} + +test_checkpoint_load_spreads_pods_over_workers = lambda { + script = RunCheckpointLoad("sc", "sub", "rg", "local", "w", "r", "c").inputs.inlineScript + assert len(script.split("\nworker_ufs_bytes() {")) == 2 + assert "HOST_OFFSET=$((index - 1))" in script +} From f7f49183de14fe709fadb1b93753a76d1cc3d9ef Mon Sep 17 00:00:00 2001 From: Lei Yao Date: Fri, 27 Nov 2026 23:12:46 +1100 Subject: [PATCH 4/4] Log redacted Alluxio resource failure diagnostics Include status and bounded license-controller logs on failure or timeout before cleanup. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- kcl/alluxio/posix_read/pipeline.yaml | 80 +++++++++++++- kcl/alluxio/s3_read/pipeline.yaml | 160 +++++++++++++++++++++++++-- kcl/alluxio/warp/pipeline.yaml | 80 +++++++++++++- kcl/lib/steps/alluxio/utils.k | 40 ++++++- 4 files changed, 342 insertions(+), 18 deletions(-) diff --git a/kcl/alluxio/posix_read/pipeline.yaml b/kcl/alluxio/posix_read/pipeline.yaml index 815ae617a1..dedf020174 100755 --- a/kcl/alluxio/posix_read/pipeline.yaml +++ b/kcl/alluxio/posix_read/pipeline.yaml @@ -3462,6 +3462,36 @@ jobs: require_secret() { [[ -n "${!1:-}" && "${!1}" != '$('* ]] || fail "Required secret pipeline variable $1 is missing" } + resource_failure_details() { + local kind="$1" name="$2" pods pod + # Project status only: the resource spec and annotations can contain the license or SAS. + if ! kubectl get "$kind" "$name" -n alx-ns -o json | + jq '{ + name: .metadata.name, + status: (.status | {phase, state, reason, message, error, conditions}) + } | walk(if type == "string" then + reduce ([env.ALLUXIO_LICENSE_STRING, env.BLOB_SAS][] | select(. != null and . != "")) as $secret + (.; split($secret) | join("")) + else . end)' | redact >&2; then + echo "Could not collect status for $kind/$name" >&2 + fi + if [[ "$kind" == license ]]; then + if ! pods="$(kubectl get pods -n alluxio-operator -o json | + jq -r '.items[] | select(.metadata.name | startswith("alluxio-license-controller-")) | .metadata.name')"; then + echo "Could not list the license-controller pods" >&2 + return 0 + fi + [[ -n "$pods" ]] || echo "No license-controller pods found" >&2 + for pod in $pods; do + echo "Recent license-controller logs: $pod" >&2 + if ! kubectl logs -n alluxio-operator "$pod" --all-containers=true --tail=100 --since=10m | + jq -Rs -r 'reduce ([env.ALLUXIO_LICENSE_STRING, env.BLOB_SAS][] | select(. != null and . != "")) as $secret + (.; split($secret) | join(""))' | redact >&2; then + echo "Could not collect logs for $pod" >&2 + fi + done + fi + } wait_phase() { local kind="$1" name="$2" field="$3" expected="$4" phase deadline=$((SECONDS + 900)) while :; do @@ -3469,9 +3499,15 @@ jobs: "$kind" "$name" -n alx-ns -o "jsonpath={.status.$field}")" [[ "$phase" != "$expected" ]] || return 0 case "$phase" in - Failed|Error|Terminated) fail "$kind/$name failed; inspect securely in cluster" ;; + Failed|Error|Terminated) + resource_failure_details "$kind" "$name" + fail "$kind/$name failed; see status and controller diagnostics above" + ;; esac - (( SECONDS < deadline )) || fail "$kind/$name did not reach $expected before timeout" + if (( SECONDS >= deadline )); then + resource_failure_details "$kind" "$name" + fail "$kind/$name did not reach $expected before timeout; see diagnostics above" + fi sleep 10 done } @@ -3538,6 +3574,36 @@ jobs: require_secret() { [[ -n "${!1:-}" && "${!1}" != '$('* ]] || fail "Required secret pipeline variable $1 is missing" } + resource_failure_details() { + local kind="$1" name="$2" pods pod + # Project status only: the resource spec and annotations can contain the license or SAS. + if ! kubectl get "$kind" "$name" -n alx-ns -o json | + jq '{ + name: .metadata.name, + status: (.status | {phase, state, reason, message, error, conditions}) + } | walk(if type == "string" then + reduce ([env.ALLUXIO_LICENSE_STRING, env.BLOB_SAS][] | select(. != null and . != "")) as $secret + (.; split($secret) | join("")) + else . end)' | redact >&2; then + echo "Could not collect status for $kind/$name" >&2 + fi + if [[ "$kind" == license ]]; then + if ! pods="$(kubectl get pods -n alluxio-operator -o json | + jq -r '.items[] | select(.metadata.name | startswith("alluxio-license-controller-")) | .metadata.name')"; then + echo "Could not list the license-controller pods" >&2 + return 0 + fi + [[ -n "$pods" ]] || echo "No license-controller pods found" >&2 + for pod in $pods; do + echo "Recent license-controller logs: $pod" >&2 + if ! kubectl logs -n alluxio-operator "$pod" --all-containers=true --tail=100 --since=10m | + jq -Rs -r 'reduce ([env.ALLUXIO_LICENSE_STRING, env.BLOB_SAS][] | select(. != null and . != "")) as $secret + (.; split($secret) | join(""))' | redact >&2; then + echo "Could not collect logs for $pod" >&2 + fi + done + fi + } wait_phase() { local kind="$1" name="$2" field="$3" expected="$4" phase deadline=$((SECONDS + 900)) while :; do @@ -3545,9 +3611,15 @@ jobs: "$kind" "$name" -n alx-ns -o "jsonpath={.status.$field}")" [[ "$phase" != "$expected" ]] || return 0 case "$phase" in - Failed|Error|Terminated) fail "$kind/$name failed; inspect securely in cluster" ;; + Failed|Error|Terminated) + resource_failure_details "$kind" "$name" + fail "$kind/$name failed; see status and controller diagnostics above" + ;; esac - (( SECONDS < deadline )) || fail "$kind/$name did not reach $expected before timeout" + if (( SECONDS >= deadline )); then + resource_failure_details "$kind" "$name" + fail "$kind/$name did not reach $expected before timeout; see diagnostics above" + fi sleep 10 done } diff --git a/kcl/alluxio/s3_read/pipeline.yaml b/kcl/alluxio/s3_read/pipeline.yaml index 8da634adc4..495fe5052f 100755 --- a/kcl/alluxio/s3_read/pipeline.yaml +++ b/kcl/alluxio/s3_read/pipeline.yaml @@ -565,6 +565,36 @@ jobs: require_secret() { [[ -n "${!1:-}" && "${!1}" != '$('* ]] || fail "Required secret pipeline variable $1 is missing" } + resource_failure_details() { + local kind="$1" name="$2" pods pod + # Project status only: the resource spec and annotations can contain the license or SAS. + if ! kubectl get "$kind" "$name" -n alx-ns -o json | + jq '{ + name: .metadata.name, + status: (.status | {phase, state, reason, message, error, conditions}) + } | walk(if type == "string" then + reduce ([env.ALLUXIO_LICENSE_STRING, env.BLOB_SAS][] | select(. != null and . != "")) as $secret + (.; split($secret) | join("")) + else . end)' | redact >&2; then + echo "Could not collect status for $kind/$name" >&2 + fi + if [[ "$kind" == license ]]; then + if ! pods="$(kubectl get pods -n alluxio-operator -o json | + jq -r '.items[] | select(.metadata.name | startswith("alluxio-license-controller-")) | .metadata.name')"; then + echo "Could not list the license-controller pods" >&2 + return 0 + fi + [[ -n "$pods" ]] || echo "No license-controller pods found" >&2 + for pod in $pods; do + echo "Recent license-controller logs: $pod" >&2 + if ! kubectl logs -n alluxio-operator "$pod" --all-containers=true --tail=100 --since=10m | + jq -Rs -r 'reduce ([env.ALLUXIO_LICENSE_STRING, env.BLOB_SAS][] | select(. != null and . != "")) as $secret + (.; split($secret) | join(""))' | redact >&2; then + echo "Could not collect logs for $pod" >&2 + fi + done + fi + } wait_phase() { local kind="$1" name="$2" field="$3" expected="$4" phase deadline=$((SECONDS + 900)) while :; do @@ -572,9 +602,15 @@ jobs: "$kind" "$name" -n alx-ns -o "jsonpath={.status.$field}")" [[ "$phase" != "$expected" ]] || return 0 case "$phase" in - Failed|Error|Terminated) fail "$kind/$name failed; inspect securely in cluster" ;; + Failed|Error|Terminated) + resource_failure_details "$kind" "$name" + fail "$kind/$name failed; see status and controller diagnostics above" + ;; esac - (( SECONDS < deadline )) || fail "$kind/$name did not reach $expected before timeout" + if (( SECONDS >= deadline )); then + resource_failure_details "$kind" "$name" + fail "$kind/$name did not reach $expected before timeout; see diagnostics above" + fi sleep 10 done } @@ -641,6 +677,36 @@ jobs: require_secret() { [[ -n "${!1:-}" && "${!1}" != '$('* ]] || fail "Required secret pipeline variable $1 is missing" } + resource_failure_details() { + local kind="$1" name="$2" pods pod + # Project status only: the resource spec and annotations can contain the license or SAS. + if ! kubectl get "$kind" "$name" -n alx-ns -o json | + jq '{ + name: .metadata.name, + status: (.status | {phase, state, reason, message, error, conditions}) + } | walk(if type == "string" then + reduce ([env.ALLUXIO_LICENSE_STRING, env.BLOB_SAS][] | select(. != null and . != "")) as $secret + (.; split($secret) | join("")) + else . end)' | redact >&2; then + echo "Could not collect status for $kind/$name" >&2 + fi + if [[ "$kind" == license ]]; then + if ! pods="$(kubectl get pods -n alluxio-operator -o json | + jq -r '.items[] | select(.metadata.name | startswith("alluxio-license-controller-")) | .metadata.name')"; then + echo "Could not list the license-controller pods" >&2 + return 0 + fi + [[ -n "$pods" ]] || echo "No license-controller pods found" >&2 + for pod in $pods; do + echo "Recent license-controller logs: $pod" >&2 + if ! kubectl logs -n alluxio-operator "$pod" --all-containers=true --tail=100 --since=10m | + jq -Rs -r 'reduce ([env.ALLUXIO_LICENSE_STRING, env.BLOB_SAS][] | select(. != null and . != "")) as $secret + (.; split($secret) | join(""))' | redact >&2; then + echo "Could not collect logs for $pod" >&2 + fi + done + fi + } wait_phase() { local kind="$1" name="$2" field="$3" expected="$4" phase deadline=$((SECONDS + 900)) while :; do @@ -648,9 +714,15 @@ jobs: "$kind" "$name" -n alx-ns -o "jsonpath={.status.$field}")" [[ "$phase" != "$expected" ]] || return 0 case "$phase" in - Failed|Error|Terminated) fail "$kind/$name failed; inspect securely in cluster" ;; + Failed|Error|Terminated) + resource_failure_details "$kind" "$name" + fail "$kind/$name failed; see status and controller diagnostics above" + ;; esac - (( SECONDS < deadline )) || fail "$kind/$name did not reach $expected before timeout" + if (( SECONDS >= deadline )); then + resource_failure_details "$kind" "$name" + fail "$kind/$name did not reach $expected before timeout; see diagnostics above" + fi sleep 10 done } @@ -714,6 +786,36 @@ jobs: require_secret() { [[ -n "${!1:-}" && "${!1}" != '$('* ]] || fail "Required secret pipeline variable $1 is missing" } + resource_failure_details() { + local kind="$1" name="$2" pods pod + # Project status only: the resource spec and annotations can contain the license or SAS. + if ! kubectl get "$kind" "$name" -n alx-ns -o json | + jq '{ + name: .metadata.name, + status: (.status | {phase, state, reason, message, error, conditions}) + } | walk(if type == "string" then + reduce ([env.ALLUXIO_LICENSE_STRING, env.BLOB_SAS][] | select(. != null and . != "")) as $secret + (.; split($secret) | join("")) + else . end)' | redact >&2; then + echo "Could not collect status for $kind/$name" >&2 + fi + if [[ "$kind" == license ]]; then + if ! pods="$(kubectl get pods -n alluxio-operator -o json | + jq -r '.items[] | select(.metadata.name | startswith("alluxio-license-controller-")) | .metadata.name')"; then + echo "Could not list the license-controller pods" >&2 + return 0 + fi + [[ -n "$pods" ]] || echo "No license-controller pods found" >&2 + for pod in $pods; do + echo "Recent license-controller logs: $pod" >&2 + if ! kubectl logs -n alluxio-operator "$pod" --all-containers=true --tail=100 --since=10m | + jq -Rs -r 'reduce ([env.ALLUXIO_LICENSE_STRING, env.BLOB_SAS][] | select(. != null and . != "")) as $secret + (.; split($secret) | join(""))' | redact >&2; then + echo "Could not collect logs for $pod" >&2 + fi + done + fi + } wait_phase() { local kind="$1" name="$2" field="$3" expected="$4" phase deadline=$((SECONDS + 900)) while :; do @@ -721,9 +823,15 @@ jobs: "$kind" "$name" -n alx-ns -o "jsonpath={.status.$field}")" [[ "$phase" != "$expected" ]] || return 0 case "$phase" in - Failed|Error|Terminated) fail "$kind/$name failed; inspect securely in cluster" ;; + Failed|Error|Terminated) + resource_failure_details "$kind" "$name" + fail "$kind/$name failed; see status and controller diagnostics above" + ;; esac - (( SECONDS < deadline )) || fail "$kind/$name did not reach $expected before timeout" + if (( SECONDS >= deadline )); then + resource_failure_details "$kind" "$name" + fail "$kind/$name did not reach $expected before timeout; see diagnostics above" + fi sleep 10 done } @@ -787,6 +895,36 @@ jobs: require_secret() { [[ -n "${!1:-}" && "${!1}" != '$('* ]] || fail "Required secret pipeline variable $1 is missing" } + resource_failure_details() { + local kind="$1" name="$2" pods pod + # Project status only: the resource spec and annotations can contain the license or SAS. + if ! kubectl get "$kind" "$name" -n alx-ns -o json | + jq '{ + name: .metadata.name, + status: (.status | {phase, state, reason, message, error, conditions}) + } | walk(if type == "string" then + reduce ([env.ALLUXIO_LICENSE_STRING, env.BLOB_SAS][] | select(. != null and . != "")) as $secret + (.; split($secret) | join("")) + else . end)' | redact >&2; then + echo "Could not collect status for $kind/$name" >&2 + fi + if [[ "$kind" == license ]]; then + if ! pods="$(kubectl get pods -n alluxio-operator -o json | + jq -r '.items[] | select(.metadata.name | startswith("alluxio-license-controller-")) | .metadata.name')"; then + echo "Could not list the license-controller pods" >&2 + return 0 + fi + [[ -n "$pods" ]] || echo "No license-controller pods found" >&2 + for pod in $pods; do + echo "Recent license-controller logs: $pod" >&2 + if ! kubectl logs -n alluxio-operator "$pod" --all-containers=true --tail=100 --since=10m | + jq -Rs -r 'reduce ([env.ALLUXIO_LICENSE_STRING, env.BLOB_SAS][] | select(. != null and . != "")) as $secret + (.; split($secret) | join(""))' | redact >&2; then + echo "Could not collect logs for $pod" >&2 + fi + done + fi + } wait_phase() { local kind="$1" name="$2" field="$3" expected="$4" phase deadline=$((SECONDS + 900)) while :; do @@ -794,9 +932,15 @@ jobs: "$kind" "$name" -n alx-ns -o "jsonpath={.status.$field}")" [[ "$phase" != "$expected" ]] || return 0 case "$phase" in - Failed|Error|Terminated) fail "$kind/$name failed; inspect securely in cluster" ;; + Failed|Error|Terminated) + resource_failure_details "$kind" "$name" + fail "$kind/$name failed; see status and controller diagnostics above" + ;; esac - (( SECONDS < deadline )) || fail "$kind/$name did not reach $expected before timeout" + if (( SECONDS >= deadline )); then + resource_failure_details "$kind" "$name" + fail "$kind/$name did not reach $expected before timeout; see diagnostics above" + fi sleep 10 done } diff --git a/kcl/alluxio/warp/pipeline.yaml b/kcl/alluxio/warp/pipeline.yaml index 32e8f13ae3..4e2646b87c 100644 --- a/kcl/alluxio/warp/pipeline.yaml +++ b/kcl/alluxio/warp/pipeline.yaml @@ -479,6 +479,36 @@ jobs: require_secret() { [[ -n "${!1:-}" && "${!1}" != '$('* ]] || fail "Required secret pipeline variable $1 is missing" } + resource_failure_details() { + local kind="$1" name="$2" pods pod + # Project status only: the resource spec and annotations can contain the license or SAS. + if ! kubectl get "$kind" "$name" -n alx-ns -o json | + jq '{ + name: .metadata.name, + status: (.status | {phase, state, reason, message, error, conditions}) + } | walk(if type == "string" then + reduce ([env.ALLUXIO_LICENSE_STRING, env.BLOB_SAS][] | select(. != null and . != "")) as $secret + (.; split($secret) | join("")) + else . end)' | redact >&2; then + echo "Could not collect status for $kind/$name" >&2 + fi + if [[ "$kind" == license ]]; then + if ! pods="$(kubectl get pods -n alluxio-operator -o json | + jq -r '.items[] | select(.metadata.name | startswith("alluxio-license-controller-")) | .metadata.name')"; then + echo "Could not list the license-controller pods" >&2 + return 0 + fi + [[ -n "$pods" ]] || echo "No license-controller pods found" >&2 + for pod in $pods; do + echo "Recent license-controller logs: $pod" >&2 + if ! kubectl logs -n alluxio-operator "$pod" --all-containers=true --tail=100 --since=10m | + jq -Rs -r 'reduce ([env.ALLUXIO_LICENSE_STRING, env.BLOB_SAS][] | select(. != null and . != "")) as $secret + (.; split($secret) | join(""))' | redact >&2; then + echo "Could not collect logs for $pod" >&2 + fi + done + fi + } wait_phase() { local kind="$1" name="$2" field="$3" expected="$4" phase deadline=$((SECONDS + 900)) while :; do @@ -486,9 +516,15 @@ jobs: "$kind" "$name" -n alx-ns -o "jsonpath={.status.$field}")" [[ "$phase" != "$expected" ]] || return 0 case "$phase" in - Failed|Error|Terminated) fail "$kind/$name failed; inspect securely in cluster" ;; + Failed|Error|Terminated) + resource_failure_details "$kind" "$name" + fail "$kind/$name failed; see status and controller diagnostics above" + ;; esac - (( SECONDS < deadline )) || fail "$kind/$name did not reach $expected before timeout" + if (( SECONDS >= deadline )); then + resource_failure_details "$kind" "$name" + fail "$kind/$name did not reach $expected before timeout; see diagnostics above" + fi sleep 10 done } @@ -555,6 +591,36 @@ jobs: require_secret() { [[ -n "${!1:-}" && "${!1}" != '$('* ]] || fail "Required secret pipeline variable $1 is missing" } + resource_failure_details() { + local kind="$1" name="$2" pods pod + # Project status only: the resource spec and annotations can contain the license or SAS. + if ! kubectl get "$kind" "$name" -n alx-ns -o json | + jq '{ + name: .metadata.name, + status: (.status | {phase, state, reason, message, error, conditions}) + } | walk(if type == "string" then + reduce ([env.ALLUXIO_LICENSE_STRING, env.BLOB_SAS][] | select(. != null and . != "")) as $secret + (.; split($secret) | join("")) + else . end)' | redact >&2; then + echo "Could not collect status for $kind/$name" >&2 + fi + if [[ "$kind" == license ]]; then + if ! pods="$(kubectl get pods -n alluxio-operator -o json | + jq -r '.items[] | select(.metadata.name | startswith("alluxio-license-controller-")) | .metadata.name')"; then + echo "Could not list the license-controller pods" >&2 + return 0 + fi + [[ -n "$pods" ]] || echo "No license-controller pods found" >&2 + for pod in $pods; do + echo "Recent license-controller logs: $pod" >&2 + if ! kubectl logs -n alluxio-operator "$pod" --all-containers=true --tail=100 --since=10m | + jq -Rs -r 'reduce ([env.ALLUXIO_LICENSE_STRING, env.BLOB_SAS][] | select(. != null and . != "")) as $secret + (.; split($secret) | join(""))' | redact >&2; then + echo "Could not collect logs for $pod" >&2 + fi + done + fi + } wait_phase() { local kind="$1" name="$2" field="$3" expected="$4" phase deadline=$((SECONDS + 900)) while :; do @@ -562,9 +628,15 @@ jobs: "$kind" "$name" -n alx-ns -o "jsonpath={.status.$field}")" [[ "$phase" != "$expected" ]] || return 0 case "$phase" in - Failed|Error|Terminated) fail "$kind/$name failed; inspect securely in cluster" ;; + Failed|Error|Terminated) + resource_failure_details "$kind" "$name" + fail "$kind/$name failed; see status and controller diagnostics above" + ;; esac - (( SECONDS < deadline )) || fail "$kind/$name did not reach $expected before timeout" + if (( SECONDS >= deadline )); then + resource_failure_details "$kind" "$name" + fail "$kind/$name did not reach $expected before timeout; see diagnostics above" + fi sleep 10 done } diff --git a/kcl/lib/steps/alluxio/utils.k b/kcl/lib/steps/alluxio/utils.k index e75a5fd3d2..91a20d73cb 100644 --- a/kcl/lib/steps/alluxio/utils.k +++ b/kcl/lib/steps/alluxio/utils.k @@ -47,6 +47,36 @@ require_secret() { ResourceCommands = lambda workDir: str -> str { SecretCommands(workDir) + """ +resource_failure_details() { + local kind="$1" name="$2" pods pod + # Project status only: the resource spec and annotations can contain the license or SAS. + if ! kubectl get "$kind" "$name" -n alx-ns -o json | + jq '{ + name: .metadata.name, + status: (.status | {phase, state, reason, message, error, conditions}) + } | walk(if type == "string" then + reduce ([env.ALLUXIO_LICENSE_STRING, env.BLOB_SAS][] | select(. != null and . != "")) as $secret + (.; split($secret) | join("")) + else . end)' | redact >&2; then + echo "Could not collect status for $kind/$name" >&2 + fi + if [[ "$kind" == license ]]; then + if ! pods="$(kubectl get pods -n alluxio-operator -o json | + jq -r '.items[] | select(.metadata.name | startswith("alluxio-license-controller-")) | .metadata.name')"; then + echo "Could not list the license-controller pods" >&2 + return 0 + fi + [[ -n "$pods" ]] || echo "No license-controller pods found" >&2 + for pod in $pods; do + echo "Recent license-controller logs: $pod" >&2 + if ! kubectl logs -n alluxio-operator "$pod" --all-containers=true --tail=100 --since=10m | + jq -Rs -r 'reduce ([env.ALLUXIO_LICENSE_STRING, env.BLOB_SAS][] | select(. != null and . != "")) as $secret + (.; split($secret) | join(""))' | redact >&2; then + echo "Could not collect logs for $pod" >&2 + fi + done + fi +} wait_phase() { local kind="$1" name="$2" field="$3" expected="$4" phase deadline=$((SECONDS + 900)) while :; do @@ -54,9 +84,15 @@ wait_phase() { "$kind" "$name" -n alx-ns -o "jsonpath={.status.$field}")" [[ "$phase" != "$expected" ]] || return 0 case "$phase" in - Failed|Error|Terminated) fail "$kind/$name failed; inspect securely in cluster" ;; + Failed|Error|Terminated) + resource_failure_details "$kind" "$name" + fail "$kind/$name failed; see status and controller diagnostics above" + ;; esac - (( SECONDS < deadline )) || fail "$kind/$name did not reach $expected before timeout" + if (( SECONDS >= deadline )); then + resource_failure_details "$kind" "$name" + fail "$kind/$name did not reach $expected before timeout; see diagnostics above" + fi sleep 10 done }