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,14 @@ 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+
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+ }
226238 }
227239
228240 /**
@@ -249,12 +261,21 @@ void testFilterIIncludedKeysFromTopLevel() throws Exception {
249261 void testFilterIIncludedKeysFromSubLevel () throws Exception {
250262 logger .info ("Testing filtering only included specific app name in the metrics " );
251263 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 );
253267 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 ,
257277 checkIncluded , checkExcluded );
278+
258279 }
259280
260281 /**
@@ -266,13 +287,20 @@ void testFilterIIncludedKeysFromSubLevel() throws Exception {
266287 void testFilterIIncludedKeysFromBothLevels () throws Exception {
267288 logger .info ("Testing filtering only included specific app name in the metrics " );
268289 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 );
270292 checkIncluded .add ("app=\" wls-exporter\" " );
271293 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 );
273296 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+
276304 }
277305
278306 /**
@@ -299,11 +327,16 @@ void testFilterExcludedKeysFromTopLevel() throws Exception {
299327 void testFilterExcludedKeysFromSubLevel () throws Exception {
300328 logger .info ("Testing filtering only excluded specific app name in the metrics " );
301329 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 );
303332 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 ,
307340 checkIncluded , checkExcluded );
308341 }
309342
@@ -316,13 +349,19 @@ void testFilterExcludedKeysFromSubLevel() throws Exception {
316349 void testFilterExcludedKeysFromBothLevels () throws Exception {
317350 logger .info ("Testing filtering only excluded specific app name in the metrics " );
318351 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 );
320354 checkIncluded .add ("app=\" myear1\" " );
321355 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 );
323358 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 );
326365 }
327366
328367 /**
@@ -336,9 +375,13 @@ void testFilterIncludedTopExcludedKeysSubLevels() throws Exception {
336375 List <String > checkIncluded = new ArrayList <>();
337376 checkIncluded .add ("app=\" wls-exporter\" " );
338377 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 );
342385 }
343386
344387 /**
@@ -368,11 +411,16 @@ void testFilterIncludedExcludedKeysComboTopLevel() throws Exception {
368411 void testFilterIncludedExcludedKeysComboSubLevel () throws Exception {
369412 logger .info ("Testing filtering included and excluded specific app names in the metrics " );
370413 List <String > checkIncluded = new ArrayList <>();
371- checkIncluded .add ("servletName=\" com.oracle.wls.exporter.webapp" );
414+ checkIncluded .add ("servletName=\" " + servletPath );
372415 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+
376424 }
377425
378426 /**
@@ -728,17 +776,21 @@ private void replaceConfigurationWithFilter(String configurationFile,
728776 }
729777
730778 private static void verifyMetrics (List <String > checkIncluded , List <String > checkExcluded ) {
779+ boolean isRegexInc = false ;
780+ boolean isRegexExc = false ;
731781 for (String includedString : checkIncluded ) {
782+
732783 assertTrue (verifyMonExpAppAccess ("wls-exporter/metrics" ,
733- includedString ,
784+ includedString , isRegexInc ,
734785 domain1Uid ,
735786 domain1Namespace ,
736787 false , cluster1Name ),
737788 "monitoring exporter metrics can't filter to included " + includedString );
738789 }
739790 for (String excludedString : checkExcluded ) {
791+
740792 assertFalse (verifyMonExpAppAccess ("wls-exporter/metrics" ,
741- excludedString ,
793+ excludedString , isRegexExc ,
742794 domain1Uid ,
743795 domain1Namespace ,
744796 false , cluster1Name ),
@@ -759,7 +811,6 @@ private void appendConfiguration(String configFile) throws Exception {
759811 "Page does not contain expected Unable to Update Configuration" );
760812 }
761813
762-
763814 private static void installTraefikIngressController () throws IOException {
764815 // install and verify Traefik
765816 logger .info ("Installing Traefik controller using helm" );
@@ -781,5 +832,22 @@ private int getTraefikLbNodePort(boolean isHttps) {
781832 -> getServiceNodePort (traefikNamespace , traefikHelmParams .getReleaseName (), isHttps ? "websecure" : "web" ),
782833 "Getting web node port for Traefik loadbalancer failed" );
783834 }
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+ }
784852}
785853
0 commit comments