1- // Copyright (c) 2023, 2024 , Oracle and/or its affiliates.
1+ // Copyright (c) 2023, 2025 , Oracle and/or its affiliates.
22// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33
44package oracle .weblogic .kubernetes ;
4444import static oracle .weblogic .kubernetes .TestConstants .IT_MONITORINGEXPORTERMF_PROMETHEUS_HTTP_NODEPORT ;
4545import static oracle .weblogic .kubernetes .TestConstants .K8S_NODEPORT_HOST ;
4646import static oracle .weblogic .kubernetes .TestConstants .KIND_CLUSTER ;
47+ import static oracle .weblogic .kubernetes .TestConstants .MONITORING_EXPORTER_WEBAPP_VERSION ;
4748import static oracle .weblogic .kubernetes .TestConstants .OKD ;
4849import static oracle .weblogic .kubernetes .TestConstants .OKE_CLUSTER_PRIVATEIP ;
4950import static oracle .weblogic .kubernetes .TestConstants .PROMETHEUS_CHART_VERSION ;
5051import static oracle .weblogic .kubernetes .TestConstants .RESULTS_ROOT ;
5152import static oracle .weblogic .kubernetes .TestConstants .TRAEFIK_INGRESS_HTTPS_HOSTPORT ;
5253import static oracle .weblogic .kubernetes .TestConstants .TRAEFIK_INGRESS_HTTP_HOSTPORT ;
54+ import static oracle .weblogic .kubernetes .TestConstants .WEBLOGIC_IMAGE_TAG ;
5355import static oracle .weblogic .kubernetes .TestConstants .WLSIMG_BUILDER ;
5456import static oracle .weblogic .kubernetes .TestConstants .WLSIMG_BUILDER_DEFAULT ;
5557import static oracle .weblogic .kubernetes .actions .ActionConstants .MODEL_DIR ;
7274import static oracle .weblogic .kubernetes .utils .MonitoringUtils .installAndVerifyGrafana ;
7375import static oracle .weblogic .kubernetes .utils .MonitoringUtils .installAndVerifyPrometheus ;
7476import static oracle .weblogic .kubernetes .utils .MonitoringUtils .installMonitoringExporter ;
77+ import static oracle .weblogic .kubernetes .utils .MonitoringUtils .replaceValueInFile ;
7578import static oracle .weblogic .kubernetes .utils .MonitoringUtils .uninstallPrometheusGrafana ;
7679import static oracle .weblogic .kubernetes .utils .MonitoringUtils .verifyMonExpAppAccess ;
7780import static oracle .weblogic .kubernetes .utils .OKDUtils .createRouteForOKD ;
@@ -134,6 +137,7 @@ class ItMonitoringExporterMetricsFiltering {
134137 private static String grafanaReleaseName = "grafana" + releaseSuffix ;
135138 private static String monitoringExporterDir ;
136139 private static String hostPortPrometheus = null ;
140+ private static String servletPath = "com.oracle.wls.exporter" ;
137141
138142
139143 /**
@@ -223,6 +227,13 @@ public void initAll(@Namespaces(4) List<String> namespaces) throws IOException {
223227 }
224228 assertDoesNotThrow (() -> setupDomainAndMonitoringTools (domain1Namespace , domain1Uid ),
225229 "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+ }
226237 }
227238
228239 /**
@@ -249,11 +260,19 @@ void testFilterIIncludedKeysFromTopLevel() throws Exception {
249260 void testFilterIIncludedKeysFromSubLevel () throws Exception {
250261 logger .info ("Testing filtering only included specific app name in the metrics " );
251262 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 );
253266 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 ,
257276 checkIncluded , checkExcluded );
258277 }
259278
@@ -266,13 +285,19 @@ void testFilterIIncludedKeysFromSubLevel() throws Exception {
266285 void testFilterIIncludedKeysFromBothLevels () throws Exception {
267286 logger .info ("Testing filtering only included specific app name in the metrics " );
268287 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 );
270290 checkIncluded .add ("app=\" wls-exporter\" " );
271291 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 );
273294 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 );
276301 }
277302
278303 /**
@@ -299,11 +324,16 @@ void testFilterExcludedKeysFromTopLevel() throws Exception {
299324 void testFilterExcludedKeysFromSubLevel () throws Exception {
300325 logger .info ("Testing filtering only excluded specific app name in the metrics " );
301326 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 );
303329 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 ,
307337 checkIncluded , checkExcluded );
308338 }
309339
@@ -316,13 +346,19 @@ void testFilterExcludedKeysFromSubLevel() throws Exception {
316346 void testFilterExcludedKeysFromBothLevels () throws Exception {
317347 logger .info ("Testing filtering only excluded specific app name in the metrics " );
318348 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 );
320351 checkIncluded .add ("app=\" myear1\" " );
321352 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 );
323355 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 );
326362 }
327363
328364 /**
@@ -336,9 +372,13 @@ void testFilterIncludedTopExcludedKeysSubLevels() throws Exception {
336372 List <String > checkIncluded = new ArrayList <>();
337373 checkIncluded .add ("app=\" wls-exporter\" " );
338374 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 );
342382 }
343383
344384 /**
@@ -368,17 +408,21 @@ void testFilterIncludedExcludedKeysComboTopLevel() throws Exception {
368408 void testFilterIncludedExcludedKeysComboSubLevel () throws Exception {
369409 logger .info ("Testing filtering included and excluded specific app names in the metrics " );
370410 List <String > checkIncluded = new ArrayList <>();
371- checkIncluded .add ("servletName=\" com.oracle.wls.exporter.webapp" );
411+ checkIncluded .add ("servletName=\" " + servletPath );
372412 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 );
376420 }
377421
378422 /**
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+ */
382426 @ Test
383427 @ DisplayName ("Test Filtering of the Metrics with includedKeyValues for not existed key of Monitoring Exporter on "
384428 + " top level." )
@@ -728,17 +772,19 @@ private void replaceConfigurationWithFilter(String configurationFile,
728772 }
729773
730774 private static void verifyMetrics (List <String > checkIncluded , List <String > checkExcluded ) {
775+ boolean isRegexInc = false ;
776+ boolean isRegexExc = false ;
731777 for (String includedString : checkIncluded ) {
732778 assertTrue (verifyMonExpAppAccess ("wls-exporter/metrics" ,
733- includedString ,
779+ includedString , isRegexInc ,
734780 domain1Uid ,
735781 domain1Namespace ,
736782 false , cluster1Name ),
737783 "monitoring exporter metrics can't filter to included " + includedString );
738784 }
739785 for (String excludedString : checkExcluded ) {
740786 assertFalse (verifyMonExpAppAccess ("wls-exporter/metrics" ,
741- excludedString ,
787+ excludedString , isRegexExc ,
742788 domain1Uid ,
743789 domain1Namespace ,
744790 false , cluster1Name ),
@@ -781,5 +827,22 @@ private int getTraefikLbNodePort(boolean isHttps) {
781827 -> getServiceNodePort (traefikNamespace , traefikHelmParams .getReleaseName (), isHttps ? "websecure" : "web" ),
782828 "Getting web node port for Traefik loadbalancer failed" );
783829 }
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+ }
784847}
785848
0 commit comments