1
- // Copyright (c) 2021, 2023 , Oracle and/or its affiliates.
1
+ // Copyright (c) 2021, 2024 , Oracle and/or its affiliates.
2
2
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3
3
4
4
package oracle .weblogic .kubernetes ;
16
16
import oracle .weblogic .kubernetes .annotations .Namespaces ;
17
17
import oracle .weblogic .kubernetes .logging .LoggingFacade ;
18
18
import oracle .weblogic .kubernetes .utils .ExecResult ;
19
+ import org .junit .jupiter .api .AfterAll ;
19
20
import org .junit .jupiter .api .BeforeAll ;
20
21
import org .junit .jupiter .api .DisplayName ;
21
22
import org .junit .jupiter .api .Tag ;
24
25
import static oracle .weblogic .kubernetes .TestConstants .ADMIN_PASSWORD_DEFAULT ;
25
26
import static oracle .weblogic .kubernetes .TestConstants .ADMIN_USERNAME_DEFAULT ;
26
27
import static oracle .weblogic .kubernetes .TestConstants .K8S_NODEPORT_HOST ;
28
+ import static oracle .weblogic .kubernetes .TestConstants .OKE_CLUSTER ;
29
+ import static oracle .weblogic .kubernetes .TestConstants .OKE_CLUSTER_PRIVATEIP ;
27
30
import static oracle .weblogic .kubernetes .TestConstants .RESULTS_ROOT ;
28
31
import static oracle .weblogic .kubernetes .TestConstants .TEST_IMAGES_REPO_SECRET_NAME ;
29
32
import static oracle .weblogic .kubernetes .TestConstants .WEBLOGIC_SLIM ;
30
33
import static oracle .weblogic .kubernetes .actions .ActionConstants .MODEL_DIR ;
31
34
import static oracle .weblogic .kubernetes .actions .ActionConstants .RESOURCE_DIR ;
32
35
import static oracle .weblogic .kubernetes .actions .TestActions .addLabelsToNamespace ;
36
+ import static oracle .weblogic .kubernetes .actions .TestActions .deleteImage ;
33
37
import static oracle .weblogic .kubernetes .utils .ApplicationUtils .checkAppUsingHostHeader ;
34
38
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .checkServiceExists ;
35
39
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .createTestWebAppWarFile ;
40
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .formatIPv6Host ;
36
41
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getImageBuilderExtraArgs ;
37
42
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getNextFreePort ;
43
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getServiceExtIPAddrtOke ;
44
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .startPortForwardProcess ;
45
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .stopPortForwardProcess ;
38
46
import static oracle .weblogic .kubernetes .utils .ConfigMapUtils .createConfigMapAndVerify ;
39
47
import static oracle .weblogic .kubernetes .utils .DeployUtil .deployToClusterUsingRest ;
48
+ import static oracle .weblogic .kubernetes .utils .DeployUtil .deployUsingRest ;
40
49
import static oracle .weblogic .kubernetes .utils .DomainUtils .createDomainAndVerify ;
41
50
import static oracle .weblogic .kubernetes .utils .FileUtils .generateFileFromTemplate ;
42
51
import static oracle .weblogic .kubernetes .utils .ImageUtils .createMiiImageAndVerify ;
54
63
import static oracle .weblogic .kubernetes .utils .MonitoringUtils .editPrometheusCM ;
55
64
import static oracle .weblogic .kubernetes .utils .OperatorUtils .installAndVerifyOperator ;
56
65
import static oracle .weblogic .kubernetes .utils .PodUtils .checkPodReady ;
66
+ import static oracle .weblogic .kubernetes .utils .PodUtils .getPodName ;
57
67
import static oracle .weblogic .kubernetes .utils .SecretUtils .createSecretWithUsernamePassword ;
58
68
import static oracle .weblogic .kubernetes .utils .ThreadSafeLogger .getLogger ;
59
69
import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
63
73
64
74
@ DisplayName ("Test the monitoring WebLogic Domain via istio provided Prometheus" )
65
75
@ IntegrationTest
66
- @ Tag ("oke-parallel " )
76
+ @ Tag ("oke-gate " )
67
77
@ Tag ("kind-parallel" )
68
78
@ Tag ("olcne-mrg" )
69
79
class ItIstioMonitoringExporter {
70
80
71
81
private static String opNamespace = null ;
72
82
private static String domain1Namespace = null ;
73
83
private static String domain2Namespace = null ;
84
+ private static String nginxNamespace = null ;
74
85
75
86
private String domain1Uid = "istio1-mii" ;
76
87
private String domain2Uid = "istio2-mii" ;
@@ -79,14 +90,22 @@ class ItIstioMonitoringExporter {
79
90
private final String workManagerName = "newWM" ;
80
91
private final int replicaCount = 2 ;
81
92
private static int prometheusPort ;
93
+ private static final String istioNamespace = "istio-system" ;
94
+ private static final String istioIngressServiceName = "istio-ingressgateway" ;
82
95
83
96
private boolean isPrometheusDeployed = false ;
97
+ private boolean isPrometheusPortForward = false ;
84
98
private static LoggingFacade logger = null ;
85
99
private static String oldRegex ;
100
+ private static String miiImageSideCar = null ;
101
+ private static String miiImageWebApp = null ;
102
+ private static String exporterImage = null ;
86
103
private static String sessionAppPrometheusSearchKey =
87
104
"wls_servlet_invocation_total_count%7Bapp%3D%22myear%22%7D%5B15s%5D" ;
88
105
89
106
private static String testWebAppWarLoc = null ;
107
+ private static String ingressIP = null ;
108
+ private static String hostPortPrometheus = null ;
90
109
91
110
/**
92
111
* Install Operator.
@@ -109,6 +128,7 @@ public static void initAll(@Namespaces(3) List<String> namespaces) {
109
128
assertNotNull (namespaces .get (2 ), "Namespace list is null" );
110
129
domain2Namespace = namespaces .get (2 );
111
130
131
+
112
132
// Label the domain/operator namespace with istio-injection=enabled
113
133
Map <String , String > labelMap = new HashMap <>();
114
134
labelMap .put ("istio-injection" , "enabled" );
@@ -141,10 +161,10 @@ public static void initAll(@Namespaces(3) List<String> namespaces) {
141
161
void testIstioPrometheusViaExporterWebApp () {
142
162
assertDoesNotThrow (() -> downloadMonitoringExporterApp (RESOURCE_DIR
143
163
+ "/exporter/exporter-config.yaml" , RESULTS_ROOT ), "Failed to download monitoring exporter application" );
144
- String miiImage = createAndVerifyMiiImageWithMonitoringExporter (RESULTS_ROOT + "/wls-exporter.war" ,
164
+ miiImageWebApp = createAndVerifyMiiImageWithMonitoringExporter (RESULTS_ROOT + "/wls-exporter.war" ,
145
165
MODEL_DIR + "/model.monexp.yaml" );
146
166
String managedServerPrefix = domain1Uid + "-cluster-1-managed-server" ;
147
- assertDoesNotThrow (() -> setupIstioModelInImageDomain (miiImage ,
167
+ assertDoesNotThrow (() -> setupIstioModelInImageDomain (miiImageWebApp ,
148
168
domain1Namespace ,domain1Uid , managedServerPrefix ), "setup for istio based domain failed" );
149
169
assertDoesNotThrow (() -> deployPrometheusAndVerify (domain1Namespace , domain1Uid , sessionAppPrometheusSearchKey ),
150
170
"failed to fetch expected metrics from Prometheus using monitoring exporter webapp" );
@@ -172,21 +192,21 @@ void testIstioPrometheusWithSideCar() {
172
192
173
193
// build the model file list
174
194
final List <String > modelList = Collections .singletonList (MODEL_DIR + "/model.sessmigr.yaml" );
175
- String miiImage =
195
+ miiImageSideCar =
176
196
createMiiImageAndVerify ("miimonexp-istio-image" , modelList , appList );
177
197
178
198
// repo login and push image to registry if necessary
179
- imageRepoLoginAndPushImageToRegistry (miiImage );
199
+ imageRepoLoginAndPushImageToRegistry (miiImageSideCar );
180
200
181
201
String monitoringExporterSrcDir = Paths .get (RESULTS_ROOT , "monitoringexp" , "srcdir" ).toString ();
182
202
cloneMonitoringExporter (monitoringExporterSrcDir );
183
- String exporterImage = assertDoesNotThrow (() ->
203
+ exporterImage = assertDoesNotThrow (() ->
184
204
buildMonitoringExporterCreateImageAndPushToRepo (monitoringExporterSrcDir , "exporter" ,
185
205
domain2Namespace , TEST_IMAGES_REPO_SECRET_NAME , getImageBuilderExtraArgs ()),
186
206
"Failed to create image for exporter" );
187
207
String exporterConfig = RESOURCE_DIR + "/exporter/exporter-config.yaml" ;
188
208
String managedServerPrefix = domain2Uid + "-managed-server" ;
189
- assertDoesNotThrow (() -> setupIstioModelInImageDomain (miiImage , domain2Namespace , domain2Uid , exporterConfig ,
209
+ assertDoesNotThrow (() -> setupIstioModelInImageDomain (miiImageSideCar , domain2Namespace , domain2Uid , exporterConfig ,
190
210
exporterImage , managedServerPrefix ), "setup for istio based domain failed" );
191
211
assertDoesNotThrow (() -> deployPrometheusAndVerify (domain2Namespace , domain2Uid , sessionAppPrometheusSearchKey ),
192
212
"failed to fetch expected metrics from Prometheus using monitoring exporter sidecar" );
@@ -198,18 +218,50 @@ private void deployPrometheusAndVerify(String domainNamespace, String domainUid,
198
218
String .valueOf (prometheusPort )), "failed to install istio prometheus" );
199
219
isPrometheusDeployed = true ;
200
220
oldRegex = String .format ("regex: %s;%s" , domainNamespace , domainUid );
221
+ //verify metrics via prometheus
222
+ String host = formatIPv6Host (K8S_NODEPORT_HOST );
223
+
224
+ // In internal OKE env, use Istio EXTERNAL-IP; in non-OKE env, use K8S_NODEPORT_HOST + ":" + istioIngressPort
225
+ hostPortPrometheus = getServiceExtIPAddrtOke (istioIngressServiceName , istioNamespace ) != null
226
+ ? getServiceExtIPAddrtOke (istioIngressServiceName , istioNamespace ) : host + ":" + prometheusPort ;
227
+
228
+ if (OKE_CLUSTER_PRIVATEIP ) {
229
+ String localhost = "localhost" ;
230
+ // Forward the non-ssl port 9090
231
+ String podName = getPodName (istioNamespace , "prometheus-" );
232
+ String forwardPort = startPortForwardProcess (localhost , istioNamespace , 9090 , podName );
233
+ assertNotNull (forwardPort , "port-forward fails to assign local port" );
234
+ logger .info ("Forwarded local port is {0}" , forwardPort );
235
+ hostPortPrometheus = localhost + ":" + forwardPort ;
236
+ isPrometheusPortForward = true ;
237
+
238
+ }
201
239
} else {
202
240
String newRegex = String .format ("regex: %s;%s" , domainNamespace , domainUid );
203
241
assertDoesNotThrow (() -> editPrometheusCM (oldRegex , newRegex , "istio-system" , "prometheus" ),
204
242
"Can't modify Prometheus CM, not possible to monitor " + domainUid );
205
243
}
206
- //verify metrics via prometheus
207
- String host = K8S_NODEPORT_HOST ;
208
- if (host .contains (":" )) {
209
- host = "[" + host + "]" ;
210
- }
244
+
211
245
checkMetricsViaPrometheus (searchKey , "sessmigr" ,
212
- host + ":" + prometheusPort );
246
+ hostPortPrometheus );
247
+ }
248
+
249
+ @ AfterAll
250
+ public void tearDownAll () {
251
+
252
+ // delete mii domain images created for parameterized test
253
+ if (miiImageWebApp != null ) {
254
+ deleteImage (miiImageWebApp );
255
+ }
256
+ if (miiImageSideCar != null ) {
257
+ deleteImage (miiImageSideCar );
258
+ }
259
+ if (exporterImage != null ) {
260
+ deleteImage (exporterImage );
261
+ }
262
+ if (OKE_CLUSTER_PRIVATEIP ) {
263
+ stopPortForwardProcess (istioNamespace );
264
+ }
213
265
}
214
266
215
267
/**
@@ -338,15 +390,16 @@ private void setupIstioModelInImageDomain(String miiImage, String domainNamespac
338
390
339
391
int istioIngressPort = getIstioHttpIngressPort ();
340
392
logger .info ("Istio Ingress Port is {0}" , istioIngressPort );
393
+ String host = formatIPv6Host (K8S_NODEPORT_HOST );
394
+
395
+ // In internal OKE env, use Istio EXTERNAL-IP; in non-OKE env, use K8S_NODEPORT_HOST + ":" + istioIngressPort
396
+ String hostAndPort = getServiceExtIPAddrtOke (istioIngressServiceName , istioNamespace ) != null
397
+ ? getServiceExtIPAddrtOke (istioIngressServiceName , istioNamespace ) : host + ":" + istioIngressPort ;
341
398
342
399
// We can not verify Rest Management console thru Adminstration NodePort
343
400
// in istio, as we can not enable Adminstration NodePort
344
401
if (!WEBLOGIC_SLIM ) {
345
- String host = K8S_NODEPORT_HOST ;
346
- if (host .contains (":" )) {
347
- host = "[" + host + "]" ;
348
- }
349
- String consoleUrl = "http://" + host + ":" + istioIngressPort + "/console/login/LoginForm.jsp" ;
402
+ String consoleUrl = "http://" + hostAndPort + "/console/login/LoginForm.jsp" ;
350
403
boolean checkConsole =
351
404
checkAppUsingHostHeader (consoleUrl , domainNamespace + ".org" );
352
405
assertTrue (checkConsole , "Failed to access WebLogic console" );
@@ -356,20 +409,21 @@ private void setupIstioModelInImageDomain(String miiImage, String domainNamespac
356
409
}
357
410
358
411
Path archivePath = Paths .get (testWebAppWarLoc );
359
- ExecResult result = null ;
360
- result = deployToClusterUsingRest (K8S_NODEPORT_HOST ,
412
+ String target = "{identity: [clusters,'" + clusterName + "']}" ;
413
+ ExecResult result = OKE_CLUSTER
414
+ ? deployUsingRest (hostAndPort , ADMIN_USERNAME_DEFAULT , ADMIN_PASSWORD_DEFAULT ,
415
+ target , archivePath , domainNamespace + ".org" , "testwebapp" )
416
+ : deployToClusterUsingRest (K8S_NODEPORT_HOST ,
361
417
String .valueOf (istioIngressPort ),
362
418
ADMIN_USERNAME_DEFAULT , ADMIN_PASSWORD_DEFAULT ,
363
419
clusterName , archivePath , domainNamespace + ".org" , "testwebapp" );
420
+
364
421
assertNotNull (result , "Application deployment failed" );
365
422
logger .info ("Application deployment returned {0}" , result .toString ());
366
423
assertEquals ("202" , result .stdout (), "Deployment didn't return HTTP status code 202" );
367
424
368
- String host = K8S_NODEPORT_HOST ;
369
- if (host .contains (":" )) {
370
- host = "[" + host + "]" ;
371
- }
372
- String url = "http://" + host + ":" + istioIngressPort + "/testwebapp/index.jsp" ;
425
+
426
+ String url = "http://" + hostAndPort + "/testwebapp/index.jsp" ;
373
427
logger .info ("Application Access URL {0}" , url );
374
428
}
375
429
0 commit comments