2121import java .net .Authenticator ;
2222import java .net .PasswordAuthentication ;
2323import java .net .URL ;
24- import java .util .Arrays ;
2524import java .util .List ;
2625import java .util .Map ;
2726import javax .xml .bind .DatatypeConverter ;
@@ -56,22 +55,16 @@ public class ITMonitoringExporter extends BaseTest {
5655 "weblogic_servlet_invocation_total_count{app=\" testwsapp\" ,name=\" managed-server1_/TestWSApp\" ,servletName=\" TestWSAppServlethttp\" }" ;
5756 private static String testWSAppTotalServletInvokesSearchKey2 =
5857 "weblogic_servlet_invocation_total_count{app=\" testwsapp\" ,name=\" managed-server2_/TestWSApp\" ,servletName=\" TestWSAppServlethttp\" }" ;
59- private static String [] testWSAppTotalServletInvokesSearchKey = {
60- "weblogic_servlet_invocation_total_count{app=\" testwsapp\" ,name=\" managed-server" ,
61- "_/TestWSApp\" ,servletName=\" TestWSAppServlethttp\" }"
62- };
63- String oprelease = "op" + number ;
64- private int waitTime = 5 ;
65- private int maxIterations = 30 ;
6658 private static String loadBalancer = "TRAEFIK" ;
67- // private static String prometheusSearchKey1 = "curl --noproxy '*' -X GET
68- // http://slc13kef.us.oracle.com:32000/api/v1/query?query=heap_free_current%7Bname%3D%22managed-server2%22%7D";
6959 private static String prometheusSearchKey1 =
7060 "heap_free_current%7Bname%3D%22managed-server1%22%7D" ;
7161 private static String prometheusSearchKey2 =
7262 "heap_free_current%7Bname%3D%22managed-server2%22%7D" ;
7363 private static String testwsappPrometheusSearchKey =
7464 "weblogic_servlet_invocation_total_count%7Bapp%3D%22testwsapp%22%7D" ;
65+ String oprelease = "op" + number ;
66+ private int waitTime = 5 ;
67+ private int maxIterations = 30 ;
7568
7669 /**
7770 * This method gets called only once before any of the test methods are executed. It does the
@@ -84,7 +77,6 @@ public class ITMonitoringExporter extends BaseTest {
8477 public static void staticPrepare () throws Exception {
8578 if (!QUICKTEST ) {
8679 initialize (APP_PROPS_FILE );
87-
8880 logger .info ("Checking if operator and domain are running, if not creating" );
8981 if (operator == null ) {
9082 Map <String , Object > operatorMap = TestUtils .createOperatorMap (number , true );
@@ -96,7 +88,6 @@ public static void staticPrepare() throws Exception {
9688 domain = createVerifyDomain (number , operator );
9789 Assert .assertNotNull (domain );
9890 }
99-
10091 myhost = domain .getHostNameForCurl ();
10192 exporterUrl = "http://" + myhost + ":" + domain .getLoadBalancerWebPort () + "/wls-exporter/" ;
10293 metricsUrl = exporterUrl + "metrics" ;
@@ -138,7 +129,6 @@ public static void staticUnPrepare() throws Exception {
138129 */
139130 private static void deployRunMonitoringExporter (Domain domain , Operator operator )
140131 throws Exception {
141-
142132 TestUtils .gitCloneBuildMonitoringExporter ();
143133 logger .info ("Creating Operator & waiting for the script to complete execution" );
144134 boolean testCompletedSuccessfully = false ;
@@ -164,37 +154,8 @@ private static Domain createVerifyDomain(int number, Operator operator) throws E
164154 return domain ;
165155 }
166156
167- /**
168- * call webapp and verify load balancing by checking server name in the response
169- *
170- * @param searchKey - metric query expression
171- * @param expectedVal - expected metrics to search
172- * @throws Exception
173- */
174- public boolean checkMetricsViaPrometheus (String searchKey , String expectedVal ) throws Exception {
175-
176- // sleep 15 secs to scrap metrics
177- Thread .sleep (15 * 1000 );
178- // url
179- StringBuffer testAppUrl = new StringBuffer ("http://" );
180- testAppUrl .append (myhost ).append (":" ).append ("32000" ).append ("/api/v1/query?query=" );
181-
182- testAppUrl .append (searchKey );
183- // curl cmd to call webapp
184- StringBuffer curlCmd = new StringBuffer ("curl --noproxy '*' " );
185- curlCmd .append (testAppUrl .toString ());
186- logger .info ("Curl cmd " + curlCmd );
187- ExecResult result = ExecCommand .exec (curlCmd .toString ());
188- logger .info ("Prometheus application invoked successfully with curlCmd:" + curlCmd );
189-
190- String checkPrometheus = result .stdout ().trim ();
191- logger .info ("Result :" + checkPrometheus );
192- return checkPrometheus .contains (expectedVal );
193- }
194-
195157 private static void startExporterPrometheusGrafana (Domain domain , Operator operator )
196158 throws Exception {
197-
198159 logger .info ("deploy exporter, prometheus, grafana " );
199160 TestUtils .deployMonitoringExporterPrometethusGrafana (
200161 TestUtils .monitoringDir + "/apps/monitoringexporter/wls-exporter.war" , domain , operator );
@@ -214,7 +175,7 @@ private static Object getMetricsValue(BufferedReader contents, String metricKey)
214175 return result ;
215176 }
216177
217- public static boolean containsWordsIndexOf (String inputString , String [] words ) {
178+ private static boolean containsWordsIndexOf (String inputString , String [] words ) {
218179 boolean found = true ;
219180 for (String word : words ) {
220181 logger .info (" Checking inputString" + inputString + " word " + word );
@@ -272,7 +233,34 @@ private static void upgradeTraefikHostName() throws Exception {
272233 }
273234
274235 /**
275- * Replace monitoring exporter configuration and verify it was applied to both managed servers
236+ * call webapp and verify load balancing by checking server name in the response
237+ *
238+ * @param searchKey - metric query expression
239+ * @param expectedVal - expected metrics to search
240+ * @throws Exception
241+ */
242+ private boolean checkMetricsViaPrometheus (String searchKey , String expectedVal ) throws Exception {
243+ // sleep 15 secs to scrap metrics
244+ Thread .sleep (15 * 1000 );
245+ // url
246+ StringBuffer testAppUrl = new StringBuffer ("http://" );
247+ testAppUrl .append (myhost ).append (":" ).append ("32000" ).append ("/api/v1/query?query=" );
248+
249+ testAppUrl .append (searchKey );
250+ // curl cmd to call webapp
251+ StringBuffer curlCmd = new StringBuffer ("curl --noproxy '*' " );
252+ curlCmd .append (testAppUrl .toString ());
253+ logger .info ("Curl cmd " + curlCmd );
254+ ExecResult result = ExecCommand .exec (curlCmd .toString ());
255+ logger .info ("Prometheus application invoked successfully with curlCmd:" + curlCmd );
256+
257+ String checkPrometheus = result .stdout ().trim ();
258+ logger .info ("Result :" + checkPrometheus );
259+ return checkPrometheus .contains (expectedVal );
260+ }
261+
262+ /**
263+ * Check that configuration can be reviewed via Prometheus
276264 *
277265 * @throws Exception
278266 */
@@ -300,16 +288,6 @@ public void test02_ReplaceConfiguration() throws Exception {
300288 logTestBegin (testMethodName );
301289 boolean testCompletedSuccessfully = false ;
302290
303- /*
304- exporterUrl = "http://slc13kef.us.oracle.com:" + "30305" + "/wls-exporter/";
305- metricsUrl = exporterUrl + "metrics";
306- configPath =
307- "/scratch/mkogan/weblogic-kubernetes-operator/integration-tests/src/test/resources/exporter";
308- String testWSAppTotalServletInvokesSearchKey1 =
309- "weblogic_servlet_invocation_total_count{app=\"testwsapp\",name=\"managed-server1_/TestWSApp\",servletName=\"TestWSAppServlethttp\"}";
310- String testWSAppTotalServletInvokesSearchKey2 =
311- "weblogic_servlet_invocation_total_count{app=\"testwsapp\",name=\"managed-server2_/TestWSApp\",servletName=\"TestWSAppServlethttp\"}";
312- */
313291 HtmlPage page = submitConfigureForm (exporterUrl , "replace" , configPath + "/rest_jvm.yml" );
314292
315293 // check for updated metrics
@@ -357,7 +335,6 @@ public void test02_ReplaceConfiguration() throws Exception {
357335 */
358336 @ Test
359337 public void test03_AppendConfiguration () throws Exception {
360-
361338 Assume .assumeFalse (QUICKTEST );
362339 String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
363340 logTestBegin (testMethodName );
@@ -366,7 +343,7 @@ public void test03_AppendConfiguration() throws Exception {
366343 HtmlPage page = submitConfigureForm (exporterUrl , "replace" , configPath + "/rest_jvm.yml" );
367344 assertTrue (page .asText ().contains ("JVMRuntime" ));
368345 assertFalse (page .asText ().contains ("WebAppComponentRuntime" ));
369- // run append more
346+ // run append
370347 page = submitConfigureForm (exporterUrl , "append" , configPath + "/rest_webapp.yml" );
371348 assertTrue (page .asText ().contains ("WebAppComponentRuntime" ));
372349 // check previous config is there
@@ -389,7 +366,6 @@ public void test03_AppendConfiguration() throws Exception {
389366 */
390367 @ Test
391368 public void test04_ReplaceOneAttributeValueAsArrayConfiguration () throws Exception {
392-
393369 Assume .assumeFalse (QUICKTEST );
394370 String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
395371 logTestBegin (testMethodName );
@@ -412,7 +388,6 @@ public void test04_ReplaceOneAttributeValueAsArrayConfiguration() throws Excepti
412388 @ Test
413389 public void test05_AppendArrayWithOneExistedAndOneDifferentAttributeValueAsArrayConfiguration ()
414390 throws Exception {
415-
416391 Assume .assumeFalse (QUICKTEST );
417392 String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
418393 logTestBegin (testMethodName );
@@ -680,7 +655,6 @@ public void test13_ReplaceMetricsNameSnakeCaseFalseConfiguration() throws Except
680655 @ Test
681656 public void test14_AppendMetricsNameSnakeCaseTrueToSnakeCaseFalseConfiguration ()
682657 throws Exception {
683-
684658 Assume .assumeFalse (QUICKTEST );
685659 String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
686660 logTestBegin (testMethodName );
@@ -824,14 +798,6 @@ private void changeConfigNegativeAuth(
824798 }
825799 }
826800
827- private Object getMetricsFromPage (String testUrl , String ... args ) throws Exception {
828- Authenticator .setDefault (new MyTestAuthenticator ());
829- InputStream stream = new URL (testUrl ).openStream ();
830- BufferedReader contents = new BufferedReader (new InputStreamReader (stream ));
831- assertNotNull (contents );
832- return getMetricsValue (contents , args );
833- }
834-
835801 private Object getMetricsFromPage (String testUrl , String searchKey ) throws Exception {
836802 Authenticator .setDefault (new MyTestAuthenticator ());
837803 InputStream stream = new URL (testUrl ).openStream ();
@@ -858,7 +824,6 @@ private HtmlPage submitConfigureForm(String exporterUrl, String effect, String c
858824
859825 private HtmlPage submitConfigureForm (
860826 String exporterUrl , String effect , String configFile , WebClient webClient ) throws Exception {
861-
862827 // Get the first page
863828 final HtmlPage page1 = webClient .getPage (exporterUrl );
864829 assertNotNull (page1 );
@@ -913,26 +878,6 @@ private boolean checkMetrics(String searchKey) throws Exception {
913878 }
914879 return result ;
915880 }
916-
917- private boolean checkMetrics (String ... searchKeys ) throws Exception {
918- boolean result = false ;
919- int i = 0 ;
920- while (i < maxIterations ) {
921- Object searchResult = getMetricsFromPage (metricsUrl , searchKeys );
922- if (searchResult == null ) {
923- // check for last iteration
924- if (i == (BaseTest .getMaxIterationsPod () - 1 )) {
925- return false ;
926- }
927- i ++;
928- } else {
929- logger .info ("Found value for metric " + Arrays .toString (searchKeys ) + " : " + searchResult );
930- result = true ;
931- break ;
932- }
933- }
934- return result ;
935- }
936881}
937882
938883class MyTestAuthenticator extends Authenticator {
0 commit comments