Skip to content

Commit bbffd98

Browse files
committed
added alert manager using alert branch temp3
1 parent f0898e5 commit bbffd98

File tree

1 file changed

+31
-48
lines changed

1 file changed

+31
-48
lines changed

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

Lines changed: 31 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ public class ItMonitoringExporter extends BaseTest {
4848
private static Operator operator1 = null;
4949
private static Domain domain = null;
5050
private static String myhost = "";
51+
private static String metricsUrl = "";
5152
private static String monitoringExporterDir = "";
53+
private static String monitoringExporterEndToEndDir = "";
5254
private static String resourceExporterDir = "";
5355
private static String exporterUrl = "";
5456
private static String configPath = "";
55-
private static String metricsUrl = "";
5657
private static String prometheusPort = "32000";
5758
// "heap_free_current{name="managed-server1"}[15s]" search for results for last 15secs
5859
private static String prometheusSearchKey1 =
@@ -93,7 +94,8 @@ public static void staticPrepare() throws Exception {
9394
resourceExporterDir =
9495
BaseTest.getProjectRoot() + "/integration-tests/src/test/resources/exporter";
9596
configPath = resourceExporterDir;
96-
97+
monitoringExporterEndToEndDir =
98+
monitoringExporterDir + "/src/samples/kubernetes/end2end/";
9799
upgradeTraefikHostName();
98100
deployRunMonitoringExporter(domain, operator);
99101
buildDeployWebServiceApp(domain, TESTWSAPP, TESTWSSERVICE);
@@ -799,8 +801,6 @@ public void test18_ChangeConfigEmptyPass() throws Exception {
799801
@Test
800802
public void test19_EndToEndViaChart() throws Exception {
801803
Assume.assumeFalse(QUICKTEST);
802-
String monitoringExporterEndToEndDir =
803-
monitoringExporterDir + "/src/samples/kubernetes/end2end/";
804804
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
805805
logTestBegin(testMethodName);
806806
boolean testCompletedSuccessfully = false;
@@ -819,31 +819,7 @@ public void test19_EndToEndViaChart() throws Exception {
819819
createWLSImageAndDeploy();
820820
installWebHookAndAlertManager();
821821
installPrometheusGrafanaViaChart();
822-
//fire alert by changing replicas
823-
replaceStringInFile(
824-
monitoringExporterEndToEndDir + "/demo-domains/domain1.yaml", "replicas: 2", "replicas: 1");
825-
// apply new domain yaml and verify pod restart
826-
String crdCmd =
827-
" kubectl apply -f " + monitoringExporterEndToEndDir + "/demo-domains/domain1.yaml";
828-
TestUtils.exec(crdCmd);
829-
830-
TestUtils.checkPodReady("domain1-admin-server", "default");
831-
TestUtils.checkPodReady("domain1-managed-server-1", "default");
832-
StringBuffer cmd = new StringBuffer();
833-
cmd.append("kubectl get pod -l app=webhook -o jsonpath=\"{.items[0].metadata.name} \"");
834-
logger.info("webhook pod name cmd =" + cmd);
835-
ExecResult result = ExecCommand.exec(cmd.toString());
836-
String webhookPod = null;
837-
if (result.exitValue() == 0) {
838-
webhookPod = result.stdout().trim();
839-
}
840-
String command = "kubectl -n webhook logs -f " + webhookPod;
841-
ExecResult webhookResult = ExecCommand.exec(command);
842-
if (webhookResult.exitValue() == 0) {
843-
assertTrue( webhookResult.stdout().contains("Some WLS cluster has only one running server for more than 1 minutes"));
844-
}
845-
846-
822+
fireAlert();
847823
} finally {
848824
uninstallWebHookPrometheusGrafanaViaChart();
849825
uninstallMySQL();
@@ -860,6 +836,32 @@ public void test19_EndToEndViaChart() throws Exception {
860836
logger.info("SUCCESS - " + testMethodName);
861837
}
862838

839+
private void fireAlert() throws Exception {
840+
logger.info("Fire Alert by changing replca count");
841+
replaceStringInFile(
842+
monitoringExporterEndToEndDir + "/demo-domains/domain1.yaml", "replicas: 2", "replicas: 1");
843+
// apply new domain yaml and verify pod restart
844+
String crdCmd =
845+
" kubectl apply -f " + monitoringExporterEndToEndDir + "/demo-domains/domain1.yaml";
846+
TestUtils.exec(crdCmd);
847+
848+
TestUtils.checkPodReady("domain1-admin-server", "default");
849+
TestUtils.checkPodReady("domain1-managed-server-1", "default");
850+
StringBuffer cmd = new StringBuffer();
851+
cmd.append("kubectl get pod -l app=webhook -o jsonpath=\"{.items[0].metadata.name} \"");
852+
logger.info("webhook pod name cmd =" + cmd);
853+
ExecResult result = ExecCommand.exec(cmd.toString());
854+
String webhookPod = null;
855+
if (result.exitValue() == 0) {
856+
webhookPod = result.stdout().trim();
857+
}
858+
String command = "kubectl -n webhook logs -f " + webhookPod;
859+
ExecResult webhookResult = ExecCommand.exec(command);
860+
if (webhookResult.exitValue() == 0) {
861+
assertTrue( webhookResult.stdout().contains("Some WLS cluster has only one running server for more than 1 minutes"));
862+
}
863+
}
864+
863865
private void changeConfigNegative(String effect, String configFile, String expectedErrorMsg)
864866
throws Exception {
865867
final WebClient webClient = new WebClient();
@@ -943,9 +945,6 @@ private HtmlPage submitConfigureForm(
943945
* @throws Exception if could not run the command successfully to clone from github
944946
*/
945947
private static void setupPVMYSQL() throws Exception {
946-
947-
String monitoringExporterEndToEndDir =
948-
monitoringExporterDir + "/src/samples/kubernetes/end2end/";
949948
String pvDir = monitoringExporterEndToEndDir + "pvDir";
950949
if (new File(pvDir).exists()) {
951950
logger.info(" PV dir already exists , cleaning ");
@@ -1043,9 +1042,6 @@ private static void setupPVMYSQL() throws Exception {
10431042
* @throws Exception if could not run the command successfully to clone from github
10441043
*/
10451044
private static void createWLSImageAndDeploy() throws Exception {
1046-
// monitoringExporterDir = "/scratch/opc/wl_k8s_test_results/acceptance_test_tmp/monitoring/";
1047-
String monitoringExporterEndToEndDir =
1048-
monitoringExporterDir + "/src/samples/kubernetes/end2end/";
10491045
operator1 = TestUtils.createOperator(OPERATOR1_YAML);
10501046

10511047
String command =
@@ -1090,8 +1086,6 @@ private static void createWLSImageAndDeploy() throws Exception {
10901086
* @throws Exception if could not run the command successfully to clone from github
10911087
*/
10921088
private static void installPrometheusGrafanaViaChart() throws Exception {
1093-
String monitoringExporterEndToEndDir =
1094-
monitoringExporterDir + "/src/samples/kubernetes/end2end/";
10951089
// delete any running pods
10961090
deletePrometheusGrafana();
10971091
prometheusPort = "30000";
@@ -1151,9 +1145,6 @@ private static void installPrometheusGrafanaViaChart() throws Exception {
11511145
* @throws Exception if could not run the command successfully to clone from github
11521146
*/
11531147
private static void installWebHookAndAlertManager() throws Exception {
1154-
String monitoringExporterEndToEndDir =
1155-
monitoringExporterDir + "/src/samples/kubernetes/end2end/";
1156-
11571148
String crdCmd = "cd " + monitoringExporterEndToEndDir + " && docker build ./webhook -t webhook-log:1.0";
11581149
TestUtils.exec(crdCmd);
11591150

@@ -1183,8 +1174,6 @@ private static void installWebHookAndAlertManager() throws Exception {
11831174
* @throws Exception if could not run the command successfully to clone from github
11841175
*/
11851176
private static void uninstallWebHookPrometheusGrafanaViaChart() throws Exception {
1186-
String monitoringExporterEndToEndDir =
1187-
monitoringExporterDir + "/src/samples/kubernetes/end2end/";
11881177
logger.info("Uninstalling webhook");
11891178
String crdCmd = "kubectl delete -f " + monitoringExporterEndToEndDir + "/webhook/server.yaml";
11901179
ExecCommand.exec(crdCmd);
@@ -1214,10 +1203,6 @@ private static void uninstallWebHookPrometheusGrafanaViaChart() throws Exception
12141203
crdCmd = "kubectl delete -f " + monitoringExporterEndToEndDir + "/prometheus/alert-persistence.yaml";
12151204
ExecCommand.exec(crdCmd);
12161205
Thread.sleep(15000);
1217-
1218-
//logger.info("Uninstalling namespace monitoring ");
1219-
crdCmd = "kubectl delete namespace monitoring";
1220-
//TestUtils.exec(crdCmd);
12211206
}
12221207

12231208
/**
@@ -1245,8 +1230,6 @@ private static void uninstallMySQL() throws Exception {
12451230
* @throws Exception if could not run the command successfully to clone from github
12461231
*/
12471232
private static void deletePvDir() throws Exception {
1248-
String monitoringExporterEndToEndDir =
1249-
monitoringExporterDir + "/src/samples/kubernetes/end2end/";
12501233
String pvDir = monitoringExporterEndToEndDir + "pvDir";
12511234
String crdCmd =
12521235
"cd "

0 commit comments

Comments
 (0)