Skip to content

Commit 62ef3ef

Browse files
authored
Monitoring exporter improvements, including port configuration, Istio support, and validation (#2390)
* Monitoring exporter improvements, including port configuration, Istio support, and validation
1 parent 6bab4b0 commit 62ef3ef

21 files changed

+306
-90
lines changed

documentation/domains/Domain.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,10 @@
618618
"x-kubernetes-preserve-unknown-fields": "true",
619619
"description": "The configuration for the WebLogic Monitoring Exporter. If WebLogic Server instances are already running and have the monitoring exporter sidecar container, then changes to this field will be propagated to the exporter without requiring the restart of the WebLogic Server instances.",
620620
"$ref": "#/definitions/Map"
621+
},
622+
"port": {
623+
"description": "The port exposed by the WebLogic Monitoring Exporter running in the sidecar container. Defaults to 8080. The port value must not conflict with a port used by any WebLogic Server instance, including the ports of built-in channels or network access points (NAPs).",
624+
"type": "number"
621625
}
622626
}
623627
},

documentation/domains/Domain.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ The current status of the operation of the WebLogic domain. Updated automaticall
119119
| `configuration` | Map | The configuration for the WebLogic Monitoring Exporter. If WebLogic Server instances are already running and have the monitoring exporter sidecar container, then changes to this field will be propagated to the exporter without requiring the restart of the WebLogic Server instances. |
120120
| `image` | string | The WebLogic Monitoring Exporter sidecar container image name. Defaults to ghcr.io/oracle/weblogic-monitoring-exporter:2.0.2 |
121121
| `imagePullPolicy` | string | The image pull policy for the WebLogic Monitoring Exporter sidecar container image. Legal values are Always, Never, and IfNotPresent. Defaults to Always if image ends in :latest; IfNotPresent, otherwise. |
122+
| `port` | number | The port exposed by the WebLogic Monitoring Exporter running in the sidecar container. Defaults to 8080. The port value must not conflict with a port used by any WebLogic Server instance, including the ports of built-in channels or network access points (NAPs). |
122123

123124
### Server Pod
124125

documentation/domains/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,10 @@
15391539
"x-kubernetes-preserve-unknown-fields": "true",
15401540
"description": "The configuration for the WebLogic Monitoring Exporter. If WebLogic Server instances are already running and have the monitoring exporter sidecar container, then changes to this field will be propagated to the exporter without requiring the restart of the WebLogic Server instances.",
15411541
"$ref": "#/definitions/Map"
1542+
},
1543+
"port": {
1544+
"description": "The port exposed by the WebLogic Monitoring Exporter running in the sidecar container. Defaults to 8080 unless that port value is in use by a channel or network access point (NAP) of the WebLogic Server instance, in which case the next higher available port is selected. If a port value is specified then it must not conflict with a port used by the WebLogic Server instance.",
1545+
"type": "number"
15421546
}
15431547
}
15441548
},

kubernetes/crd/domain-crd.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ apiVersion: apiextensions.k8s.io/v1
55
kind: CustomResourceDefinition
66
metadata:
77
annotations:
8-
weblogic.sha256: e091b25f525f2d1a6b90729dcee23d63ead5beb23660912acebf921d1c0499a7
8+
weblogic.sha256: d1191a10f1c4843d11c897002f731292c9f580c6670a84e1ee8b5916e21f0a62
99
name: domains.weblogic.oracle
1010
spec:
1111
group: weblogic.oracle
@@ -59,6 +59,13 @@ spec:
5959
restart of the WebLogic Server instances.
6060
type: object
6161
x-kubernetes-preserve-unknown-fields: true
62+
port:
63+
description: The port exposed by the WebLogic Monitoring Exporter
64+
running in the sidecar container. Defaults to 8080. The port
65+
value must not conflict with a port used by any WebLogic Server
66+
instance, including the ports of built-in channels or network
67+
access points (NAPs).
68+
type: number
6269
type: object
6370
configuration:
6471
description: Models and overrides affecting the WebLogic domain configuration.

operator/src/main/java/oracle/kubernetes/operator/helpers/DomainValidationSteps.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
import oracle.kubernetes.operator.logging.LoggingFactory;
2626
import oracle.kubernetes.operator.logging.MessageKeys;
2727
import oracle.kubernetes.operator.steps.DefaultResponseStep;
28+
import oracle.kubernetes.operator.wlsconfig.WlsClusterConfig;
2829
import oracle.kubernetes.operator.wlsconfig.WlsDomainConfig;
30+
import oracle.kubernetes.operator.wlsconfig.WlsDynamicServersConfig;
31+
import oracle.kubernetes.operator.wlsconfig.WlsServerConfig;
2932
import oracle.kubernetes.operator.work.NextAction;
3033
import oracle.kubernetes.operator.work.Packet;
3134
import oracle.kubernetes.operator.work.Step;
@@ -192,6 +195,16 @@ private void validate(DomainPresenceInfo info, WlsDomainConfig wlsDomainConfig)
192195
// in the WebLogic domain
193196
domainSpec.getManagedServers().forEach(
194197
s -> warnIfServerDoesNotExist(wlsDomainConfig, s.getServerName(), info));
198+
199+
// log warning if monitoring exporter port is specified and it conflicts with a server port
200+
Optional.ofNullable(domainSpec.getMonitoringExporterPort()).ifPresent(port -> {
201+
wlsDomainConfig.getServerConfigs().values()
202+
.forEach(server -> warnIfMonitoringExporterPortConflicts(port, server, info));
203+
wlsDomainConfig.getClusterConfigs().values()
204+
.forEach(cluster -> Optional.ofNullable(cluster.getDynamicServersConfig())
205+
.map(WlsDynamicServersConfig::getServerTemplate)
206+
.ifPresent(template -> warnIfMonitoringExporterPortConflicts(port, cluster, template, info)));
207+
});
195208
}
196209

197210
private void warnIfClusterDoesNotExist(WlsDomainConfig domainConfig,
@@ -208,6 +221,43 @@ private void warnIfServerDoesNotExist(WlsDomainConfig domainConfig,
208221
}
209222
}
210223

224+
private void warnIfMonitoringExporterPortConflicts(
225+
Integer port, WlsServerConfig serverConfig, DomainPresenceInfo info) {
226+
warnIfMonitoringExporterPortConflicts(port, null, serverConfig, info);
227+
}
228+
229+
private void warnIfMonitoringExporterPortConflicts(
230+
Integer port, WlsClusterConfig cluster, WlsServerConfig serverConfig, DomainPresenceInfo info) {
231+
232+
if (port.equals(serverConfig.getListenPort())) {
233+
logAndAddValidationWarningExporter(port, cluster, serverConfig, serverConfig.getListenPort(), info);
234+
}
235+
if (port.equals(serverConfig.getSslListenPort())) {
236+
logAndAddValidationWarningExporter(port, cluster, serverConfig, serverConfig.getSslListenPort(), info);
237+
}
238+
if (port.equals(serverConfig.getAdminPort())) {
239+
logAndAddValidationWarningExporter(port, cluster, serverConfig, serverConfig.getAdminPort(), info);
240+
}
241+
Optional.ofNullable(serverConfig.getNetworkAccessPoints()).ifPresent(naps -> naps.forEach(nap -> {
242+
if (port.equals(nap.getListenPort())) {
243+
logAndAddValidationWarningExporter(port, cluster, serverConfig, nap.getListenPort(), info);
244+
}
245+
}));
246+
}
247+
248+
private void logAndAddValidationWarningExporter(
249+
Integer port, WlsClusterConfig cluster, WlsServerConfig serverConfig,
250+
Integer conflictPort, DomainPresenceInfo info) {
251+
if (cluster != null) {
252+
logAndAddValidationWarning(info, MessageKeys.MONITORING_EXPORTER_CONFLICT_DYNAMIC_CLUSTER,
253+
// Note: Using Integer.toString because default logger behavior formats with commas, e.g. "7,001"
254+
Integer.toString(port), cluster.getClusterName(), Integer.toString(conflictPort));
255+
} else {
256+
logAndAddValidationWarning(info, MessageKeys.MONITORING_EXPORTER_CONFLICT_SERVER,
257+
Integer.toString(port), serverConfig.getName(), Integer.toString(conflictPort));
258+
}
259+
}
260+
211261
@Override
212262
public NextAction apply(Packet packet) {
213263
DomainPresenceInfo info = packet.getSpi(DomainPresenceInfo.class);

operator/src/main/java/oracle/kubernetes/operator/helpers/PodStepContext.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ private Step getConflictStep() {
155155
}
156156

157157
ExporterContext createExporterContext() {
158-
return useSidecar() ? new SidecarExporterContext() : new WebAppExporterContext();
158+
return useSidecar()
159+
? new SidecarExporterContext(getMonitoringExporterSpecification()) : new WebAppExporterContext();
159160
}
160161

161162
// Use the monitoring exporter sidecar if an exporter configuration is part of the domain.
@@ -219,6 +220,10 @@ Integer getAsPort() {
219220
.getLocalAdminProtocolChannelPort();
220221
}
221222

223+
MonitoringExporterSpecification getMonitoringExporterSpecification() {
224+
return getDomain().getMonitoringExporterSpecification();
225+
}
226+
222227
/**
223228
* Check if the server is listening on a secure port. NOTE: If the targeted server is a managed
224229
* server, this method is overridden to check if the managed server has a secure listen port rather
@@ -1295,11 +1300,10 @@ void addContainer(List<V1Container> containers) {
12951300
}
12961301

12971302
class SidecarExporterContext extends ExporterContext {
1298-
private static final int DEBUG_PORT = 30055;
12991303
private final int metricsPort;
13001304

1301-
public SidecarExporterContext() {
1302-
metricsPort = MonitoringExporterSpecification.getRestPort(scan);
1305+
public SidecarExporterContext(MonitoringExporterSpecification specification) {
1306+
metricsPort = specification.getRestPort();
13031307
}
13041308

13051309
@Override
@@ -1328,8 +1332,12 @@ private V1Container createMonitoringExporterContainer() {
13281332
.image(getDomain().getMonitoringExporterImage())
13291333
.imagePullPolicy(getDomain().getMonitoringExporterImagePullPolicy())
13301334
.addEnvItem(new V1EnvVar().name("JAVA_OPTS").value(createJavaOptions()))
1331-
.addPortsItem(new V1ContainerPort().name("metrics").protocol("TCP").containerPort(getPort()))
1332-
.addPortsItem(new V1ContainerPort().name("debugger").protocol("TCP").containerPort(DEBUG_PORT));
1335+
.addPortsItem(new V1ContainerPort()
1336+
.name(getMetricsPortName()).protocol("TCP").containerPort(getPort()));
1337+
}
1338+
1339+
private String getMetricsPortName() {
1340+
return getDomain().isIstioEnabled() ? "http-metrics" : "metrics";
13331341
}
13341342

13351343
private String createJavaOptions() {
@@ -1342,13 +1350,8 @@ private String createJavaOptions() {
13421350
if (metricsPort != DEFAULT_EXPORTER_SIDECAR_PORT) {
13431351
args.add("-DEXPORTER_PORT=" + metricsPort);
13441352
}
1345-
args.add(getDebugOption());
13461353

13471354
return String.join(" ", args);
13481355
}
1349-
1350-
private String getDebugOption() {
1351-
return "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:" + DEBUG_PORT;
1352-
}
13531356
}
13541357
}

operator/src/main/java/oracle/kubernetes/operator/helpers/ServiceHelper.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import oracle.kubernetes.weblogic.domain.model.Channel;
4343
import oracle.kubernetes.weblogic.domain.model.ClusterSpec;
4444
import oracle.kubernetes.weblogic.domain.model.Domain;
45-
import oracle.kubernetes.weblogic.domain.model.MonitoringExporterSpecification;
4645
import oracle.kubernetes.weblogic.domain.model.ServerSpec;
4746
import org.apache.commons.lang3.builder.EqualsBuilder;
4847

@@ -62,7 +61,6 @@
6261
import static oracle.kubernetes.operator.logging.MessageKeys.MANAGED_SERVICE_CREATED;
6362
import static oracle.kubernetes.operator.logging.MessageKeys.MANAGED_SERVICE_EXISTS;
6463
import static oracle.kubernetes.operator.logging.MessageKeys.MANAGED_SERVICE_REPLACED;
65-
import static oracle.kubernetes.weblogic.domain.model.MonitoringExporterSpecification.EXPORTER_PORT_NAME;
6664

6765
public class ServiceHelper {
6866
public static final String CLUSTER_IP_TYPE = "ClusterIP";
@@ -420,9 +418,15 @@ void addServicePorts(List<V1ServicePort> ports, WlsServerConfig serverConfig) {
420418
addServicePortIfNeeded(ports, "default-admin", serverConfig.getAdminPort());
421419
}
422420

423-
if (getDomain().getMonitoringExporterConfiguration() != null) {
424-
addServicePortIfNeeded(ports, EXPORTER_PORT_NAME, MonitoringExporterSpecification.getRestPort(serverConfig));
425-
}
421+
Optional.ofNullable(getDomain().getMonitoringExporterSpecification()).ifPresent(specification -> {
422+
if (specification.getConfiguration() != null) {
423+
addServicePortIfNeeded(ports, getMetricsPortName(), specification.getRestPort());
424+
}
425+
});
426+
}
427+
428+
private String getMetricsPortName() {
429+
return getDomain().isIstioEnabled() ? "http-metrics" : "metrics";
426430
}
427431

428432
List<NetworkAccessPoint> getNetworkAccessPoints(@Nonnull WlsServerConfig config) {

operator/src/main/java/oracle/kubernetes/operator/logging/MessageKeys.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ public class MessageKeys {
168168
public static final String DUPLICATE_COMMON_MOUNT_PATH_FOUND = "WLSDO-0024";
169169
public static final String DUPLICATE_COMMON_MOUNT_VOLUME_FOUND = "WLSDO-0025";
170170
public static final String COMMON_MOUNT_VOLUME_NAME_NOT_DEFINED = "WLSDO-0026";
171+
public static final String MONITORING_EXPORTER_CONFLICT_SERVER = "WLSDO-0027";
172+
public static final String MONITORING_EXPORTER_CONFLICT_DYNAMIC_CLUSTER = "WLSDO-0028";
171173

172174
private MessageKeys() {
173175
}

operator/src/main/java/oracle/kubernetes/operator/steps/MonitoringExporterSteps.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
import static oracle.kubernetes.operator.ProcessingConstants.SERVER_NAME;
3737
import static oracle.kubernetes.operator.steps.HttpRequestProcessing.createRequestStep;
38-
import static oracle.kubernetes.weblogic.domain.model.MonitoringExporterSpecification.EXPORTER_PORT_NAME;
3938

4039
public class MonitoringExporterSteps {
4140

@@ -235,9 +234,11 @@ public NextAction apply(Packet packet) {
235234
}
236235

237236
private static class ExporterRequestProcessing extends HttpRequestProcessing {
237+
private final DomainPresenceInfo info;
238238

239239
ExporterRequestProcessing(Packet packet) {
240240
super(packet, getServerService(packet), getServerPod(packet));
241+
info = packet.getSpi(DomainPresenceInfo.class);
241242
}
242243

243244
private static V1Service getServerService(Packet packet) {
@@ -269,7 +270,15 @@ private List<V1ServicePort> getServicePorts() {
269270
}
270271

271272
private boolean isExporterPort(V1ServicePort servicePort) {
272-
return EXPORTER_PORT_NAME.equals(servicePort.getName());
273+
return getMetricsPortName().equals(servicePort.getName());
274+
}
275+
276+
Domain getDomain() {
277+
return info.getDomain();
278+
}
279+
280+
private String getMetricsPortName() {
281+
return getDomain().isIstioEnabled() ? "http-metrics" : "metrics";
273282
}
274283

275284
private HttpRequest createConfigurationQueryRequest() {

operator/src/main/java/oracle/kubernetes/operator/wlsconfig/WlsDynamicServersConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ public WlsServerConfig getServerTemplate() {
269269
return serverTemplate;
270270
}
271271

272+
public void setServerTemplate(WlsServerConfig serverTemplate) {
273+
this.serverTemplate = serverTemplate;
274+
}
275+
272276
public String getName() {
273277
return this.name;
274278
}

0 commit comments

Comments
 (0)