Skip to content

Commit 61d013d

Browse files
jiangzhodongjoon-hyun
authored andcommitted
[SPARK-48984] Add Controller Metrics System and Utils
### What changes were proposed in this pull request? This is a breakdown PR of #12 - defines metrics system and utils classes to be used by the reconcilers. It also refactors a few methods in previous utils class `org.apache.spark.k8s.operator.reconciler.SparkReconcilerUtils` into common utils package. ### Why are the changes needed? Breakdown PRs help us to move with more flexibility. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? CIs ### Was this patch authored or co-authored using generative AI tooling? No Closes #23 from jiangzho/controller_utils. Authored-by: zhou-jiang <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent f3d31d2 commit 61d013d

29 files changed

+2867
-0
lines changed

spark-operator/build.gradle

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ dependencies {
2121
implementation("org.apache.logging.log4j:log4j-1.2-api:$log4jVersion")
2222
implementation("org.apache.logging.log4j:log4j-layout-template-json:$log4jVersion")
2323

24+
// metrics
25+
implementation("io.dropwizard.metrics:metrics-core:$dropwizardMetricsVersion")
26+
implementation("io.dropwizard.metrics:metrics-jvm:$dropwizardMetricsVersion")
27+
compileOnly("org.apache.spark:spark-core_$scalaVersion:$sparkVersion") {
28+
exclude group: 'com.squareup.okio'
29+
exclude group: 'com.squareup.okhttp3'
30+
exclude group: "org.apache.logging.log4j"
31+
exclude group: "org.slf4j"
32+
}
2433
compileOnly("org.projectlombok:lombok:$lombokVersion")
2534

2635
annotationProcessor("org.projectlombok:lombok:$lombokVersion")
@@ -30,6 +39,17 @@ dependencies {
3039
exclude group: 'com.squareup.okio'
3140
exclude group: 'io.fabric8'
3241
}
42+
testImplementation("io.fabric8:kubernetes-server-mock:$fabric8Version") {
43+
exclude group: 'junit'
44+
exclude group: 'com.squareup.okhttp3'
45+
}
46+
testImplementation("org.apache.spark:spark-core_$scalaVersion:$sparkVersion") {
47+
exclude group: 'com.squareup.okio'
48+
exclude group: 'com.squareup.okhttp3'
49+
exclude group: "org.apache.logging.log4j"
50+
exclude group: "org.slf4j"
51+
}
52+
testImplementation("com.squareup.okhttp3:mockwebserver:$okHttpVersion")
3353
testImplementation platform("org.junit:junit-bom:$junitVersion")
3454
testImplementation("org.junit.jupiter:junit-jupiter:$junitVersion")
3555
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package org.apache.spark.k8s.operator.client;
20+
21+
import java.util.List;
22+
23+
import io.fabric8.kubernetes.client.Config;
24+
import io.fabric8.kubernetes.client.KubernetesClient;
25+
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
26+
import io.fabric8.kubernetes.client.okhttp.OkHttpClientFactory;
27+
import okhttp3.Interceptor;
28+
import okhttp3.OkHttpClient;
29+
30+
/** Build Kubernetes Client with metrics configured */
31+
public class KubernetesClientFactory {
32+
public static KubernetesClient buildKubernetesClient(final List<Interceptor> interceptors) {
33+
return buildKubernetesClient(interceptors, null);
34+
}
35+
36+
public static KubernetesClient buildKubernetesClient(
37+
final List<Interceptor> interceptors, final Config kubernetesClientConfig) {
38+
return new KubernetesClientBuilder()
39+
.withConfig(kubernetesClientConfig)
40+
.withHttpClientFactory(
41+
new OkHttpClientFactory() {
42+
@Override
43+
protected void additionalConfig(OkHttpClient.Builder builder) {
44+
for (Interceptor interceptor : interceptors) {
45+
builder.addInterceptor(interceptor);
46+
}
47+
}
48+
})
49+
.build();
50+
}
51+
}

0 commit comments

Comments
 (0)