Skip to content

Commit 007f613

Browse files
committed
addressing review comments
1 parent b2cf0a0 commit 007f613

File tree

5 files changed

+102
-39
lines changed

5 files changed

+102
-39
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
package io.kubernetes.client.apimachinery;
14+
15+
public class GroupVersionKind {
16+
17+
private final String group;
18+
private final String version;
19+
private final String kind;
20+
21+
public GroupVersionKind(String group, String version, String kind) {
22+
this.group = group;
23+
this.version = version;
24+
this.kind = kind;
25+
}
26+
27+
public String getGroup() {
28+
return group;
29+
}
30+
31+
public String getVersion() {
32+
return version;
33+
}
34+
35+
public String getKind() {
36+
return kind;
37+
}
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
package io.kubernetes.client.apimachinery;
14+
15+
public class GroupVersionResource {
16+
17+
private final String group;
18+
private final String version;
19+
private final String resource;
20+
21+
public GroupVersionResource(String group, String version, String resource) {
22+
this.group = group;
23+
this.version = version;
24+
this.resource = resource;
25+
}
26+
27+
public String getGroup() {
28+
return group;
29+
}
30+
31+
public String getVersion() {
32+
return version;
33+
}
34+
35+
public String getResource() {
36+
return resource;
37+
}
38+
}

util/src/main/java/io/kubernetes/client/apimachinery/KubernetesRequestDigest.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,23 @@ public String toString() {
102102
}
103103

104104
String groupVersion;
105-
if (Strings.isNullOrEmpty(resourceMeta.getApiGroup())) { // core resource
105+
if (Strings.isNullOrEmpty(resourceMeta.getGroupVersionResource().getGroup())) { // core resource
106106
groupVersion = "";
107107
} else { // regular resource
108-
groupVersion = resourceMeta.getApiGroup() + "/" + resourceMeta.getApiVersion();
108+
groupVersion =
109+
resourceMeta.getGroupVersionResource().getGroup()
110+
+ "/"
111+
+ resourceMeta.getGroupVersionResource().getVersion();
109112
}
110113

111114
String targetResourceName;
112115
if (Strings.isNullOrEmpty(resourceMeta.getSubResource())) {
113-
targetResourceName = resourceMeta.getResource();
116+
targetResourceName = resourceMeta.getGroupVersionResource().getResource();
114117
} else { // subresource
115-
targetResourceName = resourceMeta.getResource() + "/" + resourceMeta.getSubResource();
118+
targetResourceName =
119+
resourceMeta.getGroupVersionResource().getResource()
120+
+ "/"
121+
+ resourceMeta.getSubResource();
116122
}
117123

118124
return new StringBuilder()

util/src/main/java/io/kubernetes/client/apimachinery/KubernetesResource.java

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ public static KubernetesResource parseCoreResource(String urlPath)
3333
}
3434
KubernetesResource resource =
3535
new KubernetesResource(
36-
"",
37-
"v1",
38-
matcher.group("resource"),
36+
new GroupVersionResource("", "v1", matcher.group("resource")),
3937
matcher.group("subresource"),
4038
matcher.group("namespace"),
4139
matcher.group("name"));
@@ -50,48 +48,29 @@ public static KubernetesResource parseRegularResource(String urlPath)
5048
}
5149
KubernetesResource resource =
5250
new KubernetesResource(
53-
matcher.group("group"),
54-
matcher.group("version"),
55-
matcher.group("resource"),
51+
new GroupVersionResource(
52+
matcher.group("group"), matcher.group("version"), matcher.group("resource")),
5653
matcher.group("subresource"),
5754
matcher.group("namespace"),
5855
matcher.group("name"));
5956
return resource;
6057
}
6158

62-
KubernetesResource(
63-
String apiGroup,
64-
String apiVersion,
65-
String resource,
66-
String subResource,
67-
String namespace,
68-
String name) {
69-
this.apiGroup = apiGroup;
70-
this.apiVersion = apiVersion;
71-
this.resource = resource;
59+
KubernetesResource(GroupVersionResource gvr, String subResource, String namespace, String name) {
60+
this.groupVersionResource = gvr;
7261
this.subResource = subResource;
7362
this.namespace = namespace;
7463
this.name = name;
7564
}
7665

77-
private final String apiGroup;
78-
private final String apiVersion;
79-
private final String resource;
66+
private final GroupVersionResource groupVersionResource;
8067
private final String subResource;
8168

8269
private final String namespace;
8370
private final String name;
8471

85-
public String getApiGroup() {
86-
return apiGroup;
87-
}
88-
89-
public String getApiVersion() {
90-
return apiVersion;
91-
}
92-
93-
public String getResource() {
94-
return resource;
72+
public GroupVersionResource getGroupVersionResource() {
73+
return groupVersionResource;
9574
}
9675

9776
public String getSubResource() {

util/src/main/java/io/kubernetes/client/monitoring/PrometheusInterceptor.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public class PrometheusInterceptor implements Interceptor {
4242
.help("Kubernetes resource request latency (seconds)")
4343
.labelNames(
4444
"http_response_code",
45-
"api_group",
46-
"api_version",
45+
"group",
46+
"version",
4747
"resource",
4848
"subresource",
4949
"api_verb",
@@ -73,7 +73,6 @@ public Response intercept(Interceptor.Chain chain) throws IOException {
7373
}
7474

7575
codes.labels(Integer.toString(response.code())).inc();
76-
;
7776

7877
if (requestDigest.isNonResourceRequest()) {
7978
nonResourceRequestLatencyHistogram
@@ -83,9 +82,12 @@ public Response intercept(Interceptor.Chain chain) throws IOException {
8382
resourceRequestLatencyHistogram
8483
.labels(
8584
Integer.toString(response.code()),
86-
Strings.nullToEmpty(requestDigest.getResourceMeta().getApiGroup()),
87-
Strings.nullToEmpty(requestDigest.getResourceMeta().getApiVersion()),
88-
Strings.nullToEmpty(requestDigest.getResourceMeta().getResource()),
85+
Strings.nullToEmpty(
86+
requestDigest.getResourceMeta().getGroupVersionResource().getGroup()),
87+
Strings.nullToEmpty(
88+
requestDigest.getResourceMeta().getGroupVersionResource().getVersion()),
89+
Strings.nullToEmpty(
90+
requestDigest.getResourceMeta().getGroupVersionResource().getResource()),
8991
Strings.nullToEmpty(requestDigest.getResourceMeta().getSubResource()),
9092
requestDigest.getVerb().value(),
9193
Strings.nullToEmpty(requestDigest.getResourceMeta().getNamespace()))

0 commit comments

Comments
 (0)