Repository navigation
[SPARK-58691] Add configurable worker metrics NetworkPolicy ingress #794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
685e783
86d8492
e459158
7aee5ea
533786f
79d6571
d9dde07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: jmx-exporter-config | ||
| data: | ||
| jmx-exporter-config.yaml: | | ||
| includeObjectNames: ["metrics:type=gauges,*"] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: the example asks the user to bake their own A minimum version next to the jar path comment would close this, e.g. "requires jmx_prometheus_javaagent 1.x; the |
||
| rules: | ||
| - pattern: 'metrics<name=worker\.(\w+), type=gauges><>Value' | ||
| name: spark_worker_$1 | ||
| type: GAUGE | ||
| --- | ||
| apiVersion: spark.apache.org/v1 | ||
| kind: SparkCluster | ||
| metadata: | ||
| name: cluster-with-jmx-exporter | ||
| spec: | ||
| runtimeVersions: | ||
| sparkVersion: "4.2.0" | ||
| clusterTolerations: | ||
| instanceConfig: | ||
| initWorkers: 1 | ||
| minWorkers: 1 | ||
| maxWorkers: 1 | ||
| workerSpec: | ||
| networkPolicy: | ||
| metricsPort: 9404 | ||
| # Allow scraper pods in "monitoring", in addition to the default cluster/driver peers. | ||
| metricsIngress: | ||
| - namespaceSelector: | ||
| matchLabels: | ||
| kubernetes.io/metadata.name: "monitoring" | ||
| statefulSetSpec: | ||
| template: | ||
| spec: | ||
| containers: | ||
| - name: worker | ||
| # Requires a custom image that has jmx_prometheus_javaagent pre-baked at this path | ||
| # (the stock apache/spark image does not include it). | ||
| env: | ||
| - name: SPARK_DAEMON_JAVA_OPTS | ||
| value: "-javaagent:/opt/jmx_exporter/jmx_prometheus_javaagent.jar=9404:/etc/metrics/jmx-exporter-config.yaml" | ||
| ports: | ||
| - name: jmx-metrics | ||
| containerPort: 9404 | ||
| volumeMounts: | ||
| - name: jmx-exporter-config | ||
| mountPath: /etc/metrics | ||
| readOnly: true | ||
| volumes: | ||
| - name: jmx-exporter-config | ||
| configMap: | ||
| name: jmx-exporter-config | ||
| sparkConf: | ||
| spark.metrics.conf.worker.sink.jmx.class: "org.apache.spark.metrics.sink.JmxSink" | ||
| # Replace with a custom Spark image containing /opt/jmx_exporter/jmx_prometheus_javaagent.jar. | ||
| spark.kubernetes.container.image: "apache/spark:{{SPARK_VERSION}}-scala" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.k8s.operator.spec; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
| import io.fabric8.generator.annotation.Max; | ||
| import io.fabric8.generator.annotation.Min; | ||
| import io.fabric8.generator.annotation.Required; | ||
| import io.fabric8.generator.annotation.Size; | ||
| import io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyPeer; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| /** | ||
| * Network policy for the Spark workers. | ||
| * | ||
| * @since 1.1.0 | ||
| */ | ||
| @Data | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Builder | ||
| @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| public class WorkerNetworkPolicySpec { | ||
| /** | ||
| * Port of a metrics endpoint (e.g. a JMX-to-Prometheus exporter agent) running in the worker | ||
| * container. This should be a dedicated exporter port, not the worker web UI port; the operator | ||
| * does not verify this. The caller is responsible for making the container listen on this port. | ||
| */ | ||
| @Required | ||
| @Min(1) | ||
| @Max(65535) | ||
| protected Integer metricsPort; | ||
|
yalindogusahin marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Sources allowed to scrape {@link #metricsPort} on the worker pods, in addition to the sources | ||
| * the generated worker NetworkPolicy admits by default. At least one peer is required. | ||
| */ | ||
| @Required | ||
| @Size(min = 1) | ||
| protected List<NetworkPolicyPeer> metricsIngress; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This describes the wrong failure mode. The operator does not replace a user-provided
SPARK_WORKER_OPTS; it appends a second env entry with the same name (addNewEnv()inSparkClusterResourceSpec.java:340), andClusterInitStepapplies the StatefulSet withserverSideApply(), which rejects duplicate keys in theenvassociative list.Checked against a live API server:
So a reader who takes "would be overwritten" at face value and sets it anyway does not get a silently ignored value. The whole worker StatefulSet apply is rejected, the cluster goes to
SchedulingFailureand thenFailed, and the status message is a stack trace that never mentions the duplicate variable.The advice to use
SPARK_DAEMON_JAVA_OPTSis right, only the reason is wrong. Something like: "SPARK_WORKER_OPTSmust not be set there: the operator appends its own, and server-side apply rejects duplicate env names."