2424import java .util .List ;
2525import java .util .Map ;
2626import javax .xml .bind .DatatypeConverter ;
27- import oracle .kubernetes .operator .utils .Domain ;
28- import oracle .kubernetes .operator .utils .Operator ;
29- import oracle .kubernetes .operator .utils .TestUtils ;
27+ import oracle .kubernetes .operator .utils .*;
3028import org .junit .AfterClass ;
3129import org .junit .Assert ;
3230import org .junit .Assume ;
@@ -56,6 +54,7 @@ public class ITMonitoringExporter extends BaseTest {
5654 String oprelease = "op" + number ;
5755 private int waitTime = 5 ;
5856 private int maxIterations = 30 ;
57+ private static String loadBalancer = "TRAEFIK" ;
5958
6059 /**
6160 * This method gets called only once before any of the test methods are executed. It does the
@@ -80,13 +79,13 @@ public static void staticPrepare() throws Exception {
8079 domain = createVerifyDomain (number , operator );
8180 Assert .assertNotNull (domain );
8281 }
82+
8383 myhost = domain .getHostNameForCurl ();
8484 exporterUrl = "http://" + myhost + ":" + domain .getLoadBalancerWebPort () + "/wls-exporter/" ;
8585 metricsUrl = exporterUrl + "metrics" ;
8686 configPath = BaseTest .getProjectRoot () + "/integration-tests/src/test/resources/exporter/" ;
87-
88- deployRunMonitoringExporter (domain , operator );
8987 upgradeTraefikHostName ();
88+ deployRunMonitoringExporter (domain , operator );
9089 buildDeployWebServiceApp (domain , TESTWSAPP , TESTWSSERVICE );
9190 }
9291 }
@@ -148,6 +147,43 @@ private static Domain createVerifyDomain(int number, Operator operator) throws E
148147 return domain ;
149148 }
150149
150+ /**
151+ * call webapp and verify load balancing by checking server name in the response
152+ *
153+ * @param searchKey - metric query expression
154+ * @throws Exception
155+ */
156+ public String checkMetricsViaPrometheus (String searchKey ) throws Exception {
157+
158+ // url
159+ StringBuffer testAppUrl = new StringBuffer ("http://" );
160+ testAppUrl
161+ .append (domain .getHostNameForCurl ())
162+ .append (":" )
163+ .append ("32000" )
164+ .append ("/api/v1/query?query=" );
165+ if (loadBalancer .equals ("APACHE" )) {
166+ testAppUrl .append ("weblogic/" );
167+ }
168+ testAppUrl .append (searchKey );
169+ // curl cmd to call webapp
170+ StringBuffer curlCmd = new StringBuffer ("curl --silent --noproxy '*'" );
171+ curlCmd
172+ .append (" -H 'host: " )
173+ .append (domain .getDomainUid ())
174+ .append (".org' " )
175+ .append (testAppUrl .toString ());
176+ // curl cmd to get response code
177+ StringBuffer curlCmdResCode = new StringBuffer (curlCmd .toString ());
178+ curlCmdResCode .append (" --write-out %{http_code} -o /dev/null" );
179+
180+ logger .info ("Curl cmd with response code " + curlCmdResCode );
181+ logger .info ("Curl cmd " + curlCmd );
182+ ExecResult result = ExecCommand .exec (curlCmd .toString ());
183+ logger .info ("webapp invoked successfully for curlCmd:" + curlCmd );
184+ return result .stdout ().trim ();
185+ }
186+
151187 private static void startExporterPrometheusGrafana (Domain domain , Operator operator )
152188 throws Exception {
153189
@@ -238,6 +274,25 @@ public void test01_ReplaceConfiguration() throws Exception {
238274 String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
239275 logTestBegin (testMethodName );
240276 boolean testCompletedSuccessfully = false ;
277+ String checkPrometheus = checkMetricsViaPrometheus ("webapp_config_open_sessions_current_count" );
278+ assertTrue (checkPrometheus .contains ("testwsapp" ));
279+
280+ testCompletedSuccessfully = true ;
281+ logger .info ("SUCCESS - " + testMethodName );
282+ }
283+
284+ /**
285+ * Replace monitoring exporter configuration and verify it was applied to both managed servers
286+ *
287+ * @throws Exception
288+ */
289+ @ Test
290+ public void test02_ReplaceConfiguration () throws Exception {
291+ Assume .assumeFalse (QUICKTEST );
292+ String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
293+ logTestBegin (testMethodName );
294+ boolean testCompletedSuccessfully = false ;
295+ logger .info (checkMetricsViaPrometheus ("heap_size_current" ));
241296 /*
242297 exporterUrl = "http://slc13kef.us.oracle.com:" + "30305" + "/wls-exporter/";
243298 metricsUrl = exporterUrl + "metrics";
0 commit comments