Skip to content

Commit a2308da

Browse files
committed
added monitoring exporter test and utility to build and start it part 4
1 parent 1dbbbbc commit a2308da

File tree

1 file changed

+60
-5
lines changed

1 file changed

+60
-5
lines changed

integration-tests/src/test/java/oracle/kubernetes/operator/ITMonitoringExporter.java

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
import java.util.List;
2525
import java.util.Map;
2626
import 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.*;
3028
import org.junit.AfterClass;
3129
import org.junit.Assert;
3230
import 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

Comments
 (0)