1
- // Copyright (c) 2023, 2024 , Oracle and/or its affiliates.
1
+ // Copyright (c) 2023, 2025 , 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 ;
44
44
import static oracle .weblogic .kubernetes .TestConstants .IT_MONITORINGEXPORTERMF_PROMETHEUS_HTTP_NODEPORT ;
45
45
import static oracle .weblogic .kubernetes .TestConstants .K8S_NODEPORT_HOST ;
46
46
import static oracle .weblogic .kubernetes .TestConstants .KIND_CLUSTER ;
47
+ import static oracle .weblogic .kubernetes .TestConstants .MONITORING_EXPORTER_WEBAPP_VERSION ;
47
48
import static oracle .weblogic .kubernetes .TestConstants .OKD ;
48
49
import static oracle .weblogic .kubernetes .TestConstants .OKE_CLUSTER_PRIVATEIP ;
49
50
import static oracle .weblogic .kubernetes .TestConstants .PROMETHEUS_CHART_VERSION ;
50
51
import static oracle .weblogic .kubernetes .TestConstants .RESULTS_ROOT ;
51
52
import static oracle .weblogic .kubernetes .TestConstants .TRAEFIK_INGRESS_HTTPS_HOSTPORT ;
52
53
import static oracle .weblogic .kubernetes .TestConstants .TRAEFIK_INGRESS_HTTP_HOSTPORT ;
54
+ import static oracle .weblogic .kubernetes .TestConstants .WEBLOGIC_IMAGE_TAG ;
53
55
import static oracle .weblogic .kubernetes .TestConstants .WLSIMG_BUILDER ;
54
56
import static oracle .weblogic .kubernetes .TestConstants .WLSIMG_BUILDER_DEFAULT ;
55
57
import static oracle .weblogic .kubernetes .actions .ActionConstants .MODEL_DIR ;
72
74
import static oracle .weblogic .kubernetes .utils .MonitoringUtils .installAndVerifyGrafana ;
73
75
import static oracle .weblogic .kubernetes .utils .MonitoringUtils .installAndVerifyPrometheus ;
74
76
import static oracle .weblogic .kubernetes .utils .MonitoringUtils .installMonitoringExporter ;
77
+ import static oracle .weblogic .kubernetes .utils .MonitoringUtils .replaceValueInFile ;
75
78
import static oracle .weblogic .kubernetes .utils .MonitoringUtils .uninstallPrometheusGrafana ;
76
79
import static oracle .weblogic .kubernetes .utils .MonitoringUtils .verifyMonExpAppAccess ;
77
80
import static oracle .weblogic .kubernetes .utils .OKDUtils .createRouteForOKD ;
@@ -134,6 +137,7 @@ class ItMonitoringExporterMetricsFiltering {
134
137
private static String grafanaReleaseName = "grafana" + releaseSuffix ;
135
138
private static String monitoringExporterDir ;
136
139
private static String hostPortPrometheus = null ;
140
+ private static String servletPath = "com.oracle.wls.exporter" ;
137
141
138
142
139
143
/**
@@ -223,6 +227,14 @@ public void initAll(@Namespaces(4) List<String> namespaces) throws IOException {
223
227
}
224
228
assertDoesNotThrow (() -> setupDomainAndMonitoringTools (domain1Namespace , domain1Uid ),
225
229
"failed to setup domain and monitoring tools" );
230
+
231
+ if (!isVersionAtLeast (MONITORING_EXPORTER_WEBAPP_VERSION , "2.3.0" )) {
232
+ logger .info ("Monitoting Exporter Version is less than 2.3.0" );
233
+ servletPath = "com.oracle.wls.exporter.webapp" ;
234
+ } else {
235
+ servletPath = servletPath + ((WEBLOGIC_IMAGE_TAG .contains ("14.1" )
236
+ || WEBLOGIC_IMAGE_TAG .contains ("12." )) ? ".javax" : ".jakarta" );
237
+ }
226
238
}
227
239
228
240
/**
@@ -249,12 +261,21 @@ void testFilterIIncludedKeysFromTopLevel() throws Exception {
249
261
void testFilterIIncludedKeysFromSubLevel () throws Exception {
250
262
logger .info ("Testing filtering only included specific app name in the metrics " );
251
263
List <String > checkIncluded = new ArrayList <>();
252
- checkIncluded .add ("servletName=\" com.oracle.wls.exporter.webapp.ExporterServlet\" " );
264
+ // Regular expression pattern to match servletName="ANYTHING.ExporterServlet"
265
+ String checkKey1 = "servletName=\" " + servletPath + ".ExporterServlet\" " ;
266
+ checkIncluded .add (checkKey1 );
253
267
List <String > checkExcluded = new ArrayList <>();
254
- checkExcluded .add ("servletName=\" com.oracle.wls.exporter.webapp.MainServlet\" " );
255
-
256
- replaceConfigurationWithFilter (RESOURCE_DIR + "/exporter/rest_filter_included_servlet_name.yaml" ,
268
+ // Regular expression pattern to match servletName="ANYTHING.ExporterServlet"
269
+ String checkKey2 = "servletName=\" " + servletPath + ".MainServlet\" " ;
270
+ checkExcluded .add (checkKey2 );
271
+
272
+ String configurationFile = replaceValueInFile (
273
+ "ItMonitoringExporterMetricsFiltering/testFilterIIncludedKeysFromSubLevel" ,
274
+ "rest_filter_included_servlet_name.yaml" ,
275
+ "com.oracle.wls.exporter.webapp" , servletPath );
276
+ replaceConfigurationWithFilter (configurationFile ,
257
277
checkIncluded , checkExcluded );
278
+
258
279
}
259
280
260
281
/**
@@ -266,13 +287,20 @@ void testFilterIIncludedKeysFromSubLevel() throws Exception {
266
287
void testFilterIIncludedKeysFromBothLevels () throws Exception {
267
288
logger .info ("Testing filtering only included specific app name in the metrics " );
268
289
List <String > checkIncluded = new ArrayList <>();
269
- checkIncluded .add ("servletName=\" com.oracle.wls.exporter.webapp.ExporterServlet\" " );
290
+ String checkKey1 = "servletName=\" " + servletPath + ".ExporterServlet\" " ;
291
+ checkIncluded .add (checkKey1 );
270
292
checkIncluded .add ("app=\" wls-exporter\" " );
271
293
List <String > checkExcluded = new ArrayList <>();
272
- checkExcluded .add ("servletName=\" com.oracle.wls.exporter.webapp.MainServlet\" " );
294
+ String checkKey2 = "servletName=\" " + servletPath + ".MainServlet\" " ;
295
+ checkExcluded .add (checkKey2 );
273
296
checkExcluded .add ("app=\" myear1\" " );
274
- replaceConfigurationWithFilter (RESOURCE_DIR
275
- + "/exporter/rest_filter_included_webapp_and_servlet_names.yaml" ,checkIncluded , checkExcluded );
297
+ String configurationFile = replaceValueInFile (
298
+ "ItMonitoringExporterMetricsFiltering/testFilterIIncludedKeysFromBothLevels" ,
299
+ "rest_filter_included_webapp_and_servlet_names.yaml" ,
300
+ "com.oracle.wls.exporter.webapp" , servletPath );
301
+ replaceConfigurationWithFilter (configurationFile ,
302
+ checkIncluded , checkExcluded );
303
+
276
304
}
277
305
278
306
/**
@@ -299,11 +327,16 @@ void testFilterExcludedKeysFromTopLevel() throws Exception {
299
327
void testFilterExcludedKeysFromSubLevel () throws Exception {
300
328
logger .info ("Testing filtering only excluded specific app name in the metrics " );
301
329
List <String > checkIncluded = new ArrayList <>();
302
- checkIncluded .add ("servletName=\" com.oracle.wls.exporter.webapp.MainServlet\" " );
330
+ String checkKey1 = "servletName=\" " + servletPath + ".MainServlet\" " ;
331
+ checkIncluded .add (checkKey1 );
303
332
List <String > checkExcluded = new ArrayList <>();
304
- checkExcluded .add ("servletName=\" com.oracle.wls.exporter.webapp.ExporterServlet\" " );
305
-
306
- replaceConfigurationWithFilter (RESOURCE_DIR + "/exporter/rest_filter_excluded_servlet_name.yaml" ,
333
+ String checkKey2 = "servletName=\" " + servletPath + ".ExporterServlet\" " ;
334
+ checkExcluded .add (checkKey2 );
335
+ String configurationFile = replaceValueInFile (
336
+ "ItMonitoringExporterMetricsFiltering/testFilterExcludedKeysFromSubLevel" ,
337
+ "rest_filter_excluded_servlet_name.yaml" ,
338
+ "com.oracle.wls.exporter.webapp" , servletPath );
339
+ replaceConfigurationWithFilter (configurationFile ,
307
340
checkIncluded , checkExcluded );
308
341
}
309
342
@@ -316,13 +349,19 @@ void testFilterExcludedKeysFromSubLevel() throws Exception {
316
349
void testFilterExcludedKeysFromBothLevels () throws Exception {
317
350
logger .info ("Testing filtering only excluded specific app name in the metrics " );
318
351
List <String > checkIncluded = new ArrayList <>();
319
- checkIncluded .add ("servletName=\" com.oracle.wls.exporter.webapp.ExporterServlet\" " );
352
+ String checkKey1 = "servletName=\" " + servletPath + ".ExporterServlet\" " ;
353
+ checkIncluded .add (checkKey1 );
320
354
checkIncluded .add ("app=\" myear1\" " );
321
355
List <String > checkExcluded = new ArrayList <>();
322
- checkExcluded .add ("servletName=\" com.oracle.wls.exporter.webapp.MainServlet\" " );
356
+ String checkKey2 = "servletName=\" " + servletPath + ".MainServlet\" " ;
357
+ checkExcluded .add (checkKey2 );
323
358
checkExcluded .add ("app=\" myear123\" " );
324
- replaceConfigurationWithFilter (RESOURCE_DIR
325
- + "/exporter/rest_filter_excluded_webapp_and_servlet_names.yaml" ,checkIncluded , checkExcluded );
359
+ String configurationFile = replaceValueInFile (
360
+ "ItMonitoringExporterMetricsFiltering/testFilterExcludedKeysFromBothLevels" ,
361
+ "rest_filter_excluded_webapp_and_servlet_names.yaml" ,
362
+ "com.oracle.wls.exporter.webapp" , servletPath );
363
+ replaceConfigurationWithFilter (configurationFile ,
364
+ checkIncluded , checkExcluded );
326
365
}
327
366
328
367
/**
@@ -336,9 +375,13 @@ void testFilterIncludedTopExcludedKeysSubLevels() throws Exception {
336
375
List <String > checkIncluded = new ArrayList <>();
337
376
checkIncluded .add ("app=\" wls-exporter\" " );
338
377
List <String > checkExcluded = new ArrayList <>();
339
- checkExcluded .add ("servletName=\" com.oracle.wls.exporter.webapp.ExporterServlet\" " );
340
- replaceConfigurationWithFilter (RESOURCE_DIR
341
- + "/exporter/rest_filter_included_webapp_excluded_servlet_name.yaml" ,checkIncluded , checkExcluded );
378
+ checkExcluded .add ("servletName=\" " + servletPath + ".ExporterServlet\" " );
379
+ String configurationFile = replaceValueInFile (
380
+ "ItMonitoringExporterMetricsFiltering/testFilterIncludedTopExcludedKeysSubLevels" ,
381
+ "rest_filter_included_webapp_excluded_servlet_name.yaml" ,
382
+ "com.oracle.wls.exporter.webapp" , servletPath );
383
+ replaceConfigurationWithFilter (configurationFile ,
384
+ checkIncluded , checkExcluded );
342
385
}
343
386
344
387
/**
@@ -368,11 +411,16 @@ void testFilterIncludedExcludedKeysComboTopLevel() throws Exception {
368
411
void testFilterIncludedExcludedKeysComboSubLevel () throws Exception {
369
412
logger .info ("Testing filtering included and excluded specific app names in the metrics " );
370
413
List <String > checkIncluded = new ArrayList <>();
371
- checkIncluded .add ("servletName=\" com.oracle.wls.exporter.webapp" );
414
+ checkIncluded .add ("servletName=\" " + servletPath );
372
415
List <String > checkExcluded = new ArrayList <>();
373
- checkExcluded .add ("servletName=\" com.oracle.wls.exporter.webapp.ExporterServlet\" " );
374
- replaceConfigurationWithFilter (RESOURCE_DIR
375
- + "/exporter/rest_filter_included_excluded_servlet_name.yaml" ,checkIncluded , checkExcluded );
416
+ checkExcluded .add ("servletName=\" " + servletPath + ".ExporterServlet\" " );
417
+ String configurationFile = replaceValueInFile (
418
+ "ItMonitoringExporterMetricsFiltering/testFilterIncludedExcludedKeysComboSubLevel" ,
419
+ "rest_filter_included_excluded_servlet_name.yaml" ,
420
+ "com.oracle.wls.exporter.webapp" , servletPath );
421
+ replaceConfigurationWithFilter (configurationFile ,
422
+ checkIncluded , checkExcluded );
423
+
376
424
}
377
425
378
426
/**
@@ -728,17 +776,21 @@ private void replaceConfigurationWithFilter(String configurationFile,
728
776
}
729
777
730
778
private static void verifyMetrics (List <String > checkIncluded , List <String > checkExcluded ) {
779
+ boolean isRegexInc = false ;
780
+ boolean isRegexExc = false ;
731
781
for (String includedString : checkIncluded ) {
782
+
732
783
assertTrue (verifyMonExpAppAccess ("wls-exporter/metrics" ,
733
- includedString ,
784
+ includedString , isRegexInc ,
734
785
domain1Uid ,
735
786
domain1Namespace ,
736
787
false , cluster1Name ),
737
788
"monitoring exporter metrics can't filter to included " + includedString );
738
789
}
739
790
for (String excludedString : checkExcluded ) {
791
+
740
792
assertFalse (verifyMonExpAppAccess ("wls-exporter/metrics" ,
741
- excludedString ,
793
+ excludedString , isRegexExc ,
742
794
domain1Uid ,
743
795
domain1Namespace ,
744
796
false , cluster1Name ),
@@ -759,7 +811,6 @@ private void appendConfiguration(String configFile) throws Exception {
759
811
"Page does not contain expected Unable to Update Configuration" );
760
812
}
761
813
762
-
763
814
private static void installTraefikIngressController () throws IOException {
764
815
// install and verify Traefik
765
816
logger .info ("Installing Traefik controller using helm" );
@@ -781,5 +832,22 @@ private int getTraefikLbNodePort(boolean isHttps) {
781
832
-> getServiceNodePort (traefikNamespace , traefikHelmParams .getReleaseName (), isHttps ? "websecure" : "web" ),
782
833
"Getting web node port for Traefik loadbalancer failed" );
783
834
}
835
+
836
+ private static boolean isVersionAtLeast (String version , String minVersion ) {
837
+ String [] versionParts = version .split ("\\ ." );
838
+ String [] minVersionParts = minVersion .split ("\\ ." );
839
+
840
+ for (int i = 0 ; i < 3 ; i ++) {
841
+ int verPart = Integer .parseInt (versionParts [i ]); // Convert to integer
842
+ int minVPart = Integer .parseInt (minVersionParts [i ]);
843
+
844
+ if (verPart > minVPart ) {
845
+ return true ;
846
+ } else if (verPart < minVPart ) {
847
+ return false ;
848
+ }
849
+ }
850
+ return true ; // Versions are equal
851
+ }
784
852
}
785
853
0 commit comments