Executor metadata collection plugin (cloud + K8s)#62
Open
minskya wants to merge 10 commits into
Open
Conversation
Implement an ExecutorPlugin that collects machine metadata from each executor and reports it to the driver. When enabled via spark.dataflint.executor.metadata.enabled, each executor detects its cloud provider by reading /sys/class/dmi/id/sys_vendor, then fetches instance type and spot/on-demand status from the cloud metadata API. System basics (OS, JVM, CPU cores, memory) are always collected. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Return null from DriverPlugin.receive() since PluginContext.send() is fire-and-forget — returning a string caused a spurious warning. Relax broadcast join test assertions to duration >= 0 because the codegen sleep is only in doProduce path, not doExecute which broadcast joins use. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
`spark.dataflint.experimental.executor.metadata.enabled`
When running in K8s (detected via KUBERNETES_SERVICE_HOST env var), skip the cloud metadata service and read instance type, lifecycle, and cloud provider from user-configured env vars instead. The user is responsible for exposing node labels as env vars via the downward API in the pod spec. New configs: - spark.dataflint.experimental.executor.metadata.k8s.instanceType.envVar - spark.dataflint.experimental.executor.metadata.k8s.lifecycleType.envVar - spark.dataflint.experimental.executor.metadata.k8s.cloudProvider.envVar Add unit tests for CloudMetadataDetector JSON parsing and K8sMetadataDetector env-var lookup logic. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds an experimental Spark executor-side plugin that collects executor machine/runtime metadata (cloud VM via metadata service or Kubernetes via env vars) and reports it to the driver via Spark plugin RPC, then persists/exports it through the existing DataFlint listener → KVStore → extraction pipeline.
Changes:
- Introduces executor-side metadata collection (system + cloud/K8s detection) and a serializable executor→driver message.
- Adds driver-side RPC handling that posts a new
DataflintExecutorMetadataEvent, plus listener/store/export model plumbing. - Adds unit tests for cloud JSON parsing and Kubernetes env-var based detection; adjusts SQL node timing tests for joins.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| spark-plugin/pluginspark4/src/main/scala/io/dataflint/spark/SparkDataflintPlugin.scala | Enables executor plugin + passes extraConf; driver receive() converts RPC message into listener event |
| spark-plugin/pluginspark3/src/main/scala/io/dataflint/spark/SparkDataflintPlugin.scala | Same as Spark 4 variant for Spark 3 |
| spark-plugin/plugin/src/main/scala/org/apache/spark/dataflint/executor/CloudMetadataDetector.scala | Detects cloud provider via DMI vendor and runs provider-specific metadata curl via bash |
| spark-plugin/plugin/src/main/scala/org/apache/spark/dataflint/executor/K8sMetadataDetector.scala | Detects K8s and reads configured env vars for instance/lifecycle/provider |
| spark-plugin/plugin/src/main/scala/org/apache/spark/dataflint/executor/DataflintExecutorPlugin.scala | ExecutorPlugin that collects metadata and sends it to driver |
| spark-plugin/plugin/src/main/scala/org/apache/spark/dataflint/executor/ExecutorMetadataMessage.scala | Serializable RPC payload for executor→driver |
| spark-plugin/plugin/src/main/scala/org/apache/spark/dataflint/executor/DriverMetadataHelper.scala | Reads Spark configs and posts executor metadata events |
| spark-plugin/plugin/src/main/scala/org/apache/spark/dataflint/listener/model.scala | Adds executor metadata info/event/wrapper model types |
| spark-plugin/plugin/src/main/scala/org/apache/spark/dataflint/listener/DataflintListener.scala | Persists executor metadata events into KVStore |
| spark-plugin/plugin/src/main/scala/org/apache/spark/dataflint/listener/DataflintStore.scala | Adds query method to read executor metadata from KVStore |
| spark-plugin/plugin/src/main/scala/org/apache/spark/dataflint/saas/SparkRunStore.scala | Extends export model with executor metadata collection |
| spark-plugin/plugin/src/main/scala/org/apache/spark/dataflint/saas/StoreDataExtractor.scala | Extracts executor metadata wrappers into SparkRunStore |
| spark-plugin/plugin/src/test/scala/org/apache/spark/dataflint/executor/CloudMetadataDetectorSpec.scala | Unit tests for cloud JSON parsing/filtering |
| spark-plugin/plugin/src/test/scala/org/apache/spark/dataflint/executor/K8sMetadataDetectorSpec.scala | Unit tests for env-var based K8s metadata lookup |
| spark-plugin/pluginspark3/src/test/scala/org/apache/spark/dataflint/DataFlintSqlNodesSpec.scala | Refactors duration assertions to accommodate join exec paths without codegen sleep |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+37
to
+41
| } catch { | ||
| case e: Throwable => | ||
| logWarning("Failed to detect cloud metadata", e) | ||
| CloudMetadataDetector.CloudMetadata(None, None, None) | ||
| } |
Comment on lines
+26
to
+29
| val jvmVersion = System.getProperty("java.version", "unknown") | ||
| val availableProcessors = Runtime.getRuntime.availableProcessors() | ||
| val totalMemoryBytes = Runtime.getRuntime.maxMemory() | ||
|
|
Comment on lines
+19
to
+24
| private val COMMAND_TIMEOUT_MS = 5000L | ||
|
|
||
| private val SYS_VENDOR_PATH = "/sys/class/dmi/id/sys_vendor" | ||
|
|
||
| private val AWS_COMMAND = | ||
| """TOKEN=$(curl -sf -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600" --connect-timeout 1 --max-time 2 2>/dev/null) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an ExecutorPlugin that collects machine metadata (instance type, spot/on-demand, system info) from each executor and reports it to the driver via Spark's plugin RPC. Supports cloud VMs (AWS/GCP/Azure) and Kubernetes.
PluginContext.send()/DriverPlugin.receive()/sys/class/dmi/id/sys_vendorlocally to identify AWS/GCP/Azure, then runs a single provider-specific bash one-liner against the cloud metadata APIKUBERNETES_SERVICE_HOST, skips the metadata service, and reads from user-configured env vars (exposed from node labels via the downward API)spark.dataflint.experimental.executor.metadata.enabled=true(default: false)Changed files
executor/CloudMetadataDetector.scala/sys/class/dmi/id/sys_vendorto identify cloud, runs single bash one-liner for instance type + lifecycleexecutor/K8sMetadataDetector.scalaexecutor/DataflintExecutorPlugin.scalaexecutor/ExecutorMetadataMessage.scalaexecutor/DriverMetadataHelper.scalaspark.dataflint.experimental.executor.metadata.*configslistener/model.scalaDataflintExecutorMetadataInfo,DataflintExecutorMetadataEvent,DataflintExecutorMetadataWrapperlistener/DataflintListener.scalaonOtherEvent()listener/DataflintStore.scalaexecutorMetadata()query methodsaas/SparkRunStore.scaladataflintExecutorMetadatafield to export data modelsaas/StoreDataExtractor.scalareadAll[DataflintExecutorMetadataWrapper]to extractionSparkDataflintPlugin.scala(spark3 + spark4)DataflintExecutorPlugin, passes config viaextraConf, addsreceive()plugin/src/test/.../executor/CloudMetadataDetectorSpec.scalaplugin/src/test/.../executor/K8sMetadataDetectorSpec.scalaArchitecture
sequenceDiagram participant Driver as Driver (SparkDataflintDriverPlugin) participant Executor as Executor (DataflintExecutorPlugin) participant Cloud as Cloud Metadata API Driver->>Executor: init(extraConf: {enabled: true, k8s.*.envVar: ...}) Executor->>Executor: Collect system basics (OS, JVM, cores, memory) alt KUBERNETES_SERVICE_HOST set Executor->>Executor: Read configured env vars (no HTTP) else Cloud VM Executor->>Executor: Read /sys/class/dmi/id/sys_vendor alt AWS / GCP / Azure detected Executor->>Cloud: bash + curl to provider metadata API else No cloud detected Executor->>Executor: Skip cloud metadata end end Executor->>Driver: PluginContext.send(ExecutorMetadataMessage) Driver->>Driver: receive() → post DataflintExecutorMetadataEvent Driver->>Driver: DataflintListener → KVStore Driver->>Driver: StoreDataExtractor → SparkRunStore → S3 exportConfigs
spark.dataflint.experimental.executor.metadata.enabledfalsespark.dataflint.experimental.executor.metadata.k8s.instanceType.envVarspark.dataflint.experimental.executor.metadata.k8s.lifecycleType.envVarspark.dataflint.experimental.executor.metadata.k8s.cloudProvider.envVarK8s pod spec example (downward API)
Then set:
Collected Metadata
executorIdexecutorHostInetAddress.getLocalHostosNameSystem.getProperty("os.name")osArchSystem.getProperty("os.arch")jvmVersionSystem.getProperty("java.version")availableProcessorsRuntime.availableProcessors()totalMemoryBytesRuntime.maxMemory()cloudProvider/sys/class/dmi/id/sys_vendoror configured K8s env varinstanceTypelifecycleTypecollectionErrorTest plan
sbt pluginspark3/compilepassessbt pluginspark4/compilepassessbt plugin/test— all unit tests (including new ones) passsbt pluginspark3/test— all existing + new tests passaws / m5.large / spotwith full system info🤖 Generated with Claude Code