1515import com .gargoylesoftware .htmlunit .html .HtmlPage ;
1616import com .gargoylesoftware .htmlunit .html .HtmlRadioButtonInput ;
1717import com .gargoylesoftware .htmlunit .html .HtmlSubmitInput ;
18- import java .io .BufferedReader ;
19- import java .io .InputStream ;
20- import java .io .InputStreamReader ;
2118import java .net .Authenticator ;
2219import java .net .PasswordAuthentication ;
23- import java .net .URL ;
2420import java .util .List ;
2521import java .util .Map ;
2622import javax .xml .bind .DatatypeConverter ;
@@ -45,26 +41,18 @@ public class ITMonitoringExporter extends BaseTest {
4541 private static Operator operator = null ;
4642 private static Domain domain = null ;
4743 private static String myhost = "" ;
48- private static String metricsUrl = "" ;
4944 private static String exporterUrl = "" ;
50- private static String serverName = "managed-server" ;
5145 private static String configPath = "" ;
52- private static String appName = TESTWSAPP ;
53- private static String appNameUC = "TestWSApp" ;
54- private static String testWSAppTotalServletInvokesSearchKey1 =
55- "weblogic_servlet_invocation_total_count{app=\" testwsapp\" ,name=\" managed-server1_/TestWSApp\" ,servletName=\" TestWSAppServlethttp\" }" ;
56- private static String testWSAppTotalServletInvokesSearchKey2 =
57- "weblogic_servlet_invocation_total_count{app=\" testwsapp\" ,name=\" managed-server2_/TestWSApp\" ,servletName=\" TestWSAppServlethttp\" }" ;
58- private static String loadBalancer = "TRAEFIK" ;
46+ private static String metricsUrl = "" ;
47+ // "heap_free_current{name="managed-server1"}[15s]" search for results for last 15secs
5948 private static String prometheusSearchKey1 =
60- "heap_free_current%7Bname%3D%22managed-server1%22%7D" ;
49+ "heap_free_current%7Bname%3D%22managed-server1%22%7D%5B15s%5D " ;
6150 private static String prometheusSearchKey2 =
62- "heap_free_current%7Bname%3D%22managed-server2%22%7D" ;
51+ "heap_free_current%7Bname%3D%22managed-server2%22%7D%5B15s%5D " ;
6352 private static String testwsappPrometheusSearchKey =
64- "weblogic_servlet_invocation_total_count%7Bapp%3D%22testwsapp%22%7D" ;
53+ "weblogic_servlet_invocation_total_count%7Bapp%3D%22testwsapp%22%7D%5B15s%5D " ;
6554 String oprelease = "op" + number ;
6655 private int waitTime = 5 ;
67- private int maxIterations = 30 ;
6856
6957 /**
7058 * This method gets called only once before any of the test methods are executed. It does the
@@ -91,7 +79,7 @@ public static void staticPrepare() throws Exception {
9179 myhost = domain .getHostNameForCurl ();
9280 exporterUrl = "http://" + myhost + ":" + domain .getLoadBalancerWebPort () + "/wls-exporter/" ;
9381 metricsUrl = exporterUrl + "metrics" ;
94- configPath = BaseTest .getProjectRoot () + "/integration-tests/src/test/resources/exporter/ " ;
82+ configPath = BaseTest .getProjectRoot () + "/integration-tests/src/test/resources/exporter" ;
9583 upgradeTraefikHostName ();
9684 deployRunMonitoringExporter (domain , operator );
9785 buildDeployWebServiceApp (domain , TESTWSAPP , TESTWSSERVICE );
@@ -158,47 +146,9 @@ private static void startExporterPrometheusGrafana(Domain domain, Operator opera
158146 throws Exception {
159147 logger .info ("deploy exporter, prometheus, grafana " );
160148 TestUtils .deployMonitoringExporterPrometethusGrafana (
161- TestUtils .monitoringDir + "/apps/monitoringexporter/wls-exporter.war" , domain , operator );
162- }
163-
164- private static Object getMetricsValue (BufferedReader contents , String metricKey )
165- throws Exception {
166- boolean found = false ;
167- String line ;
168- String result = null ;
169- while ((line = contents .readLine ()) != null ) {
170- if (line .contains (metricKey )) {
171- found = true ;
172- result = line .substring (line .lastIndexOf (" " ) + 1 );
173- }
174- }
175- return result ;
176- }
177-
178- private static boolean containsWordsIndexOf (String inputString , String [] words ) {
179- boolean found = true ;
180- for (String word : words ) {
181- logger .info (" Checking inputString" + inputString + " word " + word );
182- if (inputString .indexOf (word ) == -1 ) {
183- found = false ;
184- break ;
185- }
186- }
187- return found ;
188- }
189-
190- private static Object getMetricsValue (BufferedReader contents , String ... metricExp )
191- throws Exception {
192- boolean found = false ;
193- String line ;
194- String result = null ;
195- while ((line = contents .readLine ()) != null ) {
196- if (containsWordsIndexOf (line , metricExp )) {
197- logger .info ("found metric value for " + line + " :" );
198- result = line .substring (line .lastIndexOf (" " ) + 1 );
199- }
200- }
201- return result ;
149+ TestUtils .monitoringExporterDir + "/apps/monitoringexporter/wls-exporter.war" ,
150+ domain ,
151+ operator );
202152 }
203153
204154 private static void setCredentials (WebClient webClient ) {
@@ -280,28 +230,23 @@ public void test01_CheckMetricsViaPrometheus() throws Exception {
280230 *
281231 * @throws Exception
282232 */
283- // commenting out due bug OWLS-74163
284- // @Test
233+ @ Test
285234 public void test02_ReplaceConfiguration () throws Exception {
286235 Assume .assumeFalse (QUICKTEST );
287236 String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
288237 logTestBegin (testMethodName );
289238 boolean testCompletedSuccessfully = false ;
290-
291239 HtmlPage page = submitConfigureForm (exporterUrl , "replace" , configPath + "/rest_jvm.yml" );
292240
293- // check for updated metrics
294- String searchKey1 = "heap_free_current{name=\" managed-server1\" }" ;
295- String searchKey2 = "heap_free_current{name=\" managed-server2\" }" ;
296241 boolean isFoundNewKey1 = false ;
297242 boolean isFoundNewKey2 = false ;
298243 boolean isFoundOldKey1 = true ;
299244 boolean isFoundOldKey2 = true ;
300245
301- isFoundNewKey1 = checkMetrics ( searchKey1 );
302- isFoundNewKey2 = checkMetrics ( searchKey2 );
303- isFoundOldKey1 = checkMetrics ( testWSAppTotalServletInvokesSearchKey1 );
304- isFoundOldKey2 = checkMetrics ( testWSAppTotalServletInvokesSearchKey2 );
246+ isFoundNewKey1 = checkMetricsViaPrometheus ( prometheusSearchKey1 , "managed-server1" );
247+ isFoundNewKey2 = checkMetricsViaPrometheus ( prometheusSearchKey2 , "managed-server2" );
248+ isFoundOldKey1 = checkMetricsViaPrometheus ( testwsappPrometheusSearchKey , "managed-server1" );
249+ isFoundOldKey2 = checkMetricsViaPrometheus ( testwsappPrometheusSearchKey , "managed-server2" );
305250 String foundResults =
306251 " server1: ( newMetrics:"
307252 + isFoundNewKey1
@@ -659,10 +604,10 @@ public void test14_AppendMetricsNameSnakeCaseTrueToSnakeCaseFalseConfiguration()
659604 String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
660605 logTestBegin (testMethodName );
661606 boolean testCompletedSuccessfully = false ;
607+
662608 HtmlPage page =
663609 submitConfigureForm (exporterUrl , "append" , configPath + "/rest_snakecasetrue.yml" );
664610 assertNotNull (page );
665- assertTrue (page .asText ().contains ("metricsNameSnakeCase" ));
666611 String searchKey = "weblogic_servlet_executionTimeAverage%7Bapp%3D%22testwsapp%22%7D" ;
667612 assertFalse (checkMetricsViaPrometheus (searchKey , "testwsapp" ));
668613 testCompletedSuccessfully = true ;
@@ -798,15 +743,6 @@ private void changeConfigNegativeAuth(
798743 }
799744 }
800745
801- private Object getMetricsFromPage (String testUrl , String searchKey ) throws Exception {
802- Authenticator .setDefault (new MyTestAuthenticator ());
803- InputStream stream = new URL (testUrl ).openStream ();
804- BufferedReader contents = new BufferedReader (new InputStreamReader (stream ));
805- assertNotNull (contents );
806-
807- return getMetricsValue (contents , searchKey );
808- }
809-
810746 private HtmlPage submitConfigureForm (
811747 String exporterUrl , String effect , String configFile , String username , String password )
812748 throws Exception {
@@ -858,7 +794,7 @@ private HtmlPage submitConfigureForm(
858794 assertNotNull (page2 );
859795 return page2 ;
860796 }
861-
797+ /*
862798 private boolean checkMetrics(String searchKey) throws Exception {
863799 boolean result = false;
864800 int i = 0;
@@ -878,6 +814,7 @@ private boolean checkMetrics(String searchKey) throws Exception {
878814 }
879815 return result;
880816 }
817+ */
881818}
882819
883820class MyTestAuthenticator extends Authenticator {
0 commit comments