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,13 @@ 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
+ if (!isVersionAtLeast (MONITORING_EXPORTER_WEBAPP_VERSION , "2.3.0" )) {
231
+ logger .info ("Monitoting Exporter Version is less than 2.3.0" );
232
+ servletPath = "com.oracle.wls.exporter.webapp" ;
233
+ } else {
234
+ servletPath = servletPath + ((WEBLOGIC_IMAGE_TAG .contains ("14.1" )
235
+ || WEBLOGIC_IMAGE_TAG .contains ("12." )) ? ".javax" : ".jakarta" );
236
+ }
226
237
}
227
238
228
239
/**
@@ -249,11 +260,19 @@ void testFilterIIncludedKeysFromTopLevel() throws Exception {
249
260
void testFilterIIncludedKeysFromSubLevel () throws Exception {
250
261
logger .info ("Testing filtering only included specific app name in the metrics " );
251
262
List <String > checkIncluded = new ArrayList <>();
252
- checkIncluded .add ("servletName=\" com.oracle.wls.exporter.webapp.ExporterServlet\" " );
263
+ // Regular expression pattern to match servletName="ANYTHING.ExporterServlet"
264
+ String checkKey1 = "servletName=\" " + servletPath + ".ExporterServlet\" " ;
265
+ checkIncluded .add (checkKey1 );
253
266
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" ,
267
+ // Regular expression pattern to match servletName="ANYTHING.ExporterServlet"
268
+ String checkKey2 = "servletName=\" " + servletPath + ".MainServlet\" " ;
269
+ checkExcluded .add (checkKey2 );
270
+
271
+ String configurationFile = replaceValueInFile (
272
+ "ItMonitoringExporterMetricsFiltering/testFilterIIncludedKeysFromSubLevel" ,
273
+ "rest_filter_included_servlet_name.yaml" ,
274
+ "com.oracle.wls.exporter.webapp" , servletPath );
275
+ replaceConfigurationWithFilter (configurationFile ,
257
276
checkIncluded , checkExcluded );
258
277
}
259
278
@@ -266,13 +285,19 @@ void testFilterIIncludedKeysFromSubLevel() throws Exception {
266
285
void testFilterIIncludedKeysFromBothLevels () throws Exception {
267
286
logger .info ("Testing filtering only included specific app name in the metrics " );
268
287
List <String > checkIncluded = new ArrayList <>();
269
- checkIncluded .add ("servletName=\" com.oracle.wls.exporter.webapp.ExporterServlet\" " );
288
+ String checkKey1 = "servletName=\" " + servletPath + ".ExporterServlet\" " ;
289
+ checkIncluded .add (checkKey1 );
270
290
checkIncluded .add ("app=\" wls-exporter\" " );
271
291
List <String > checkExcluded = new ArrayList <>();
272
- checkExcluded .add ("servletName=\" com.oracle.wls.exporter.webapp.MainServlet\" " );
292
+ String checkKey2 = "servletName=\" " + servletPath + ".MainServlet\" " ;
293
+ checkExcluded .add (checkKey2 );
273
294
checkExcluded .add ("app=\" myear1\" " );
274
- replaceConfigurationWithFilter (RESOURCE_DIR
275
- + "/exporter/rest_filter_included_webapp_and_servlet_names.yaml" ,checkIncluded , checkExcluded );
295
+ String configurationFile = replaceValueInFile (
296
+ "ItMonitoringExporterMetricsFiltering/testFilterIIncludedKeysFromBothLevels" ,
297
+ "rest_filter_included_webapp_and_servlet_names.yaml" ,
298
+ "com.oracle.wls.exporter.webapp" , servletPath );
299
+ replaceConfigurationWithFilter (configurationFile ,
300
+ checkIncluded , checkExcluded );
276
301
}
277
302
278
303
/**
@@ -299,11 +324,16 @@ void testFilterExcludedKeysFromTopLevel() throws Exception {
299
324
void testFilterExcludedKeysFromSubLevel () throws Exception {
300
325
logger .info ("Testing filtering only excluded specific app name in the metrics " );
301
326
List <String > checkIncluded = new ArrayList <>();
302
- checkIncluded .add ("servletName=\" com.oracle.wls.exporter.webapp.MainServlet\" " );
327
+ String checkKey1 = "servletName=\" " + servletPath + ".MainServlet\" " ;
328
+ checkIncluded .add (checkKey1 );
303
329
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" ,
330
+ String checkKey2 = "servletName=\" " + servletPath + ".ExporterServlet\" " ;
331
+ checkExcluded .add (checkKey2 );
332
+ String configurationFile = replaceValueInFile (
333
+ "ItMonitoringExporterMetricsFiltering/testFilterExcludedKeysFromSubLevel" ,
334
+ "rest_filter_excluded_servlet_name.yaml" ,
335
+ "com.oracle.wls.exporter.webapp" , servletPath );
336
+ replaceConfigurationWithFilter (configurationFile ,
307
337
checkIncluded , checkExcluded );
308
338
}
309
339
@@ -316,13 +346,19 @@ void testFilterExcludedKeysFromSubLevel() throws Exception {
316
346
void testFilterExcludedKeysFromBothLevels () throws Exception {
317
347
logger .info ("Testing filtering only excluded specific app name in the metrics " );
318
348
List <String > checkIncluded = new ArrayList <>();
319
- checkIncluded .add ("servletName=\" com.oracle.wls.exporter.webapp.ExporterServlet\" " );
349
+ String checkKey1 = "servletName=\" " + servletPath + ".ExporterServlet\" " ;
350
+ checkIncluded .add (checkKey1 );
320
351
checkIncluded .add ("app=\" myear1\" " );
321
352
List <String > checkExcluded = new ArrayList <>();
322
- checkExcluded .add ("servletName=\" com.oracle.wls.exporter.webapp.MainServlet\" " );
353
+ String checkKey2 = "servletName=\" " + servletPath + ".MainServlet\" " ;
354
+ checkExcluded .add (checkKey2 );
323
355
checkExcluded .add ("app=\" myear123\" " );
324
- replaceConfigurationWithFilter (RESOURCE_DIR
325
- + "/exporter/rest_filter_excluded_webapp_and_servlet_names.yaml" ,checkIncluded , checkExcluded );
356
+ String configurationFile = replaceValueInFile (
357
+ "ItMonitoringExporterMetricsFiltering/testFilterExcludedKeysFromBothLevels" ,
358
+ "rest_filter_excluded_webapp_and_servlet_names.yaml" ,
359
+ "com.oracle.wls.exporter.webapp" , servletPath );
360
+ replaceConfigurationWithFilter (configurationFile ,
361
+ checkIncluded , checkExcluded );
326
362
}
327
363
328
364
/**
@@ -336,9 +372,13 @@ void testFilterIncludedTopExcludedKeysSubLevels() throws Exception {
336
372
List <String > checkIncluded = new ArrayList <>();
337
373
checkIncluded .add ("app=\" wls-exporter\" " );
338
374
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 );
375
+ checkExcluded .add ("servletName=\" " + servletPath + ".ExporterServlet\" " );
376
+ String configurationFile = replaceValueInFile (
377
+ "ItMonitoringExporterMetricsFiltering/testFilterIncludedTopExcludedKeysSubLevels" ,
378
+ "rest_filter_included_webapp_excluded_servlet_name.yaml" ,
379
+ "com.oracle.wls.exporter.webapp" , servletPath );
380
+ replaceConfigurationWithFilter (configurationFile ,
381
+ checkIncluded , checkExcluded );
342
382
}
343
383
344
384
/**
@@ -368,17 +408,21 @@ void testFilterIncludedExcludedKeysComboTopLevel() throws Exception {
368
408
void testFilterIncludedExcludedKeysComboSubLevel () throws Exception {
369
409
logger .info ("Testing filtering included and excluded specific app names in the metrics " );
370
410
List <String > checkIncluded = new ArrayList <>();
371
- checkIncluded .add ("servletName=\" com.oracle.wls.exporter.webapp" );
411
+ checkIncluded .add ("servletName=\" " + servletPath );
372
412
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 );
413
+ checkExcluded .add ("servletName=\" " + servletPath + ".ExporterServlet\" " );
414
+ String configurationFile = replaceValueInFile (
415
+ "ItMonitoringExporterMetricsFiltering/testFilterIncludedExcludedKeysComboSubLevel" ,
416
+ "rest_filter_included_excluded_servlet_name.yaml" ,
417
+ "com.oracle.wls.exporter.webapp" , servletPath );
418
+ replaceConfigurationWithFilter (configurationFile ,
419
+ checkIncluded , checkExcluded );
376
420
}
377
421
378
422
/**
379
- * Check filtering functionality of monitoring exporter for
380
- * not existed includedKeyValues .
381
- */
423
+ * Check filtering functionality of monitoring exporter for
424
+ * not existed includedKeyValues .
425
+ */
382
426
@ Test
383
427
@ DisplayName ("Test Filtering of the Metrics with includedKeyValues for not existed key of Monitoring Exporter on "
384
428
+ " top level." )
@@ -728,17 +772,19 @@ private void replaceConfigurationWithFilter(String configurationFile,
728
772
}
729
773
730
774
private static void verifyMetrics (List <String > checkIncluded , List <String > checkExcluded ) {
775
+ boolean isRegexInc = false ;
776
+ boolean isRegexExc = false ;
731
777
for (String includedString : checkIncluded ) {
732
778
assertTrue (verifyMonExpAppAccess ("wls-exporter/metrics" ,
733
- includedString ,
779
+ includedString , isRegexInc ,
734
780
domain1Uid ,
735
781
domain1Namespace ,
736
782
false , cluster1Name ),
737
783
"monitoring exporter metrics can't filter to included " + includedString );
738
784
}
739
785
for (String excludedString : checkExcluded ) {
740
786
assertFalse (verifyMonExpAppAccess ("wls-exporter/metrics" ,
741
- excludedString ,
787
+ excludedString , isRegexExc ,
742
788
domain1Uid ,
743
789
domain1Namespace ,
744
790
false , cluster1Name ),
@@ -781,5 +827,22 @@ private int getTraefikLbNodePort(boolean isHttps) {
781
827
-> getServiceNodePort (traefikNamespace , traefikHelmParams .getReleaseName (), isHttps ? "websecure" : "web" ),
782
828
"Getting web node port for Traefik loadbalancer failed" );
783
829
}
830
+
831
+ private static boolean isVersionAtLeast (String version , String minVersion ) {
832
+ String [] versionParts = version .split ("\\ ." );
833
+ String [] minVersionParts = minVersion .split ("\\ ." );
834
+
835
+ for (int i = 0 ; i < 3 ; i ++) {
836
+ int verPart = Integer .parseInt (versionParts [i ]); // Convert to integer
837
+ int minVPart = Integer .parseInt (minVersionParts [i ]);
838
+
839
+ if (verPart > minVPart ) {
840
+ return true ;
841
+ } else if (verPart < minVPart ) {
842
+ return false ;
843
+ }
844
+ }
845
+ return true ; // Versions are equal
846
+ }
784
847
}
785
848
0 commit comments