Skip to content

Commit ff22de4

Browse files
committed
added alert manager
1 parent c0f5112 commit ff22de4

File tree

1 file changed

+81
-4
lines changed

1 file changed

+81
-4
lines changed

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

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -817,9 +817,35 @@ public void test19_EndToEndViaChart() throws Exception {
817817
throw new RuntimeException("FAILURE: failed to install database ");
818818
}
819819
createWLSImageAndDeploy();
820+
installWebHookAndAlertManager();
820821
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+
821847
} finally {
822-
uninstallPrometheusGrafanaViaChart();
848+
uninstallWebHookPrometheusGrafanaViaChart();
823849
uninstallMySQL();
824850
String crdCmd =
825851
" kubectl delete -f " + monitoringExporterEndToEndDir + "/demo-domains/domain1.yaml";
@@ -933,6 +959,8 @@ private static void setupPVMYSQL() throws Exception {
933959
monitoringExporterEndToEndDir + "/mysql/persistence.yaml", "%PV_ROOT%", pvDir);
934960
replaceStringInFile(
935961
monitoringExporterEndToEndDir + "/prometheus/persistence.yaml", "%PV_ROOT%", pvDir);
962+
replaceStringInFile(
963+
monitoringExporterEndToEndDir + "/prometheus/alert-persistence.yaml", "%PV_ROOT%", pvDir);
936964
replaceStringInFile(
937965
monitoringExporterEndToEndDir + "/grafana/persistence.yaml", "%PV_ROOT%", pvDir);
938966
// deploy PV and PVC
@@ -1071,6 +1099,9 @@ private static void installPrometheusGrafanaViaChart() throws Exception {
10711099
TestUtils.exec(crdCmd);
10721100
crdCmd = "kubectl apply -f " + monitoringExporterEndToEndDir + "/prometheus/persistence.yaml";
10731101
TestUtils.exec(crdCmd);
1102+
1103+
crdCmd = "kubectl apply -f " + monitoringExporterEndToEndDir + "/prometheus/alert-persistence.yaml";
1104+
TestUtils.exec(crdCmd);
10741105
// install prometheus
10751106
crdCmd =
10761107
"helm install --wait --name prometheus --namespace monitoring --values "
@@ -1114,17 +1145,59 @@ private static void installPrometheusGrafanaViaChart() throws Exception {
11141145
assertTrue(checkMetricsViaPrometheus("wls_servlet_execution_time_average", "test-webapp"));
11151146
}
11161147

1148+
/**
1149+
* Install Prometheus and Grafana using helm chart
1150+
*
1151+
* @throws Exception if could not run the command successfully to clone from github
1152+
*/
1153+
private static void installWebHookAndAlertManager() throws Exception {
1154+
String monitoringExporterEndToEndDir =
1155+
monitoringExporterDir + "/src/samples/kubernetes/end2end/";
1156+
// delete any running pods
1157+
deletePrometheusGrafana();
1158+
prometheusPort = "30000";
1159+
String crdCmd = "kubectl create ns monitoring";
1160+
TestUtils.exec(crdCmd);
1161+
crdCmd = "cd " + monitoringExporterEndToEndDir + " && docker build ./webhook -t webhook-log:1.0";
1162+
TestUtils.exec(crdCmd);
1163+
1164+
// install webhook
1165+
crdCmd = "create ns webhook ";
1166+
TestUtils.exec(crdCmd);
1167+
1168+
crdCmd = "kubectl apply -f " + monitoringExporterEndToEndDir + "/webhook/server.yaml";
1169+
TestUtils.exec(crdCmd);
1170+
1171+
StringBuffer cmd = new StringBuffer();
1172+
cmd.append("kubectl get pod -l app=webhook -o jsonpath=\"{.items[0].metadata.name} \"");
1173+
logger.info("webhook pod name cmd =" + cmd);
1174+
ExecResult result = ExecCommand.exec(cmd.toString());
1175+
String webhookPod = null;
1176+
if (result.exitValue() == 0) {
1177+
webhookPod = result.stdout().trim();
1178+
}
1179+
assertNotNull("Webhook was not created, can't find running pod", webhookPod);
1180+
TestUtils.checkPodReady(webhookPod, "webhook");
1181+
1182+
}
1183+
11171184
/**
11181185
* Uninstall Prometheus and Grafana using helm chart
11191186
*
11201187
* @throws Exception if could not run the command successfully to clone from github
11211188
*/
1122-
private static void uninstallPrometheusGrafanaViaChart() throws Exception {
1189+
private static void uninstallWebHookPrometheusGrafanaViaChart() throws Exception {
11231190
String monitoringExporterEndToEndDir =
11241191
monitoringExporterDir + "/src/samples/kubernetes/end2end/";
1192+
logger.info("Uninstalling webhook");
1193+
String crdCmd = "kubectl delete -f " + monitoringExporterEndToEndDir + "/webhook/server.yaml";
1194+
ExecCommand.exec(crdCmd);
1195+
Thread.sleep(15000);
1196+
crdCmd = "kubectl delete ns webhook ";
1197+
ExecCommand.exec(crdCmd);
11251198
logger.info("Uninstalling grafana");
11261199
// uninstall grafana
1127-
String crdCmd = "helm delete --purge grafana";
1200+
crdCmd = "helm delete --purge grafana";
11281201
ExecCommand.exec(crdCmd);
11291202
crdCmd = "kubectl -n monitoring delete secret grafana-secret";
11301203
ExecCommand.exec(crdCmd);
@@ -1142,7 +1215,11 @@ private static void uninstallPrometheusGrafanaViaChart() throws Exception {
11421215
ExecCommand.exec(crdCmd);
11431216
Thread.sleep(15000);
11441217

1145-
logger.info("Uninstalling namespace monitoring ");
1218+
crdCmd = "kubectl delete -f " + monitoringExporterEndToEndDir + "/prometheus/alert-persistence.yaml";
1219+
ExecCommand.exec(crdCmd);
1220+
Thread.sleep(15000);
1221+
1222+
//logger.info("Uninstalling namespace monitoring ");
11461223
crdCmd = "kubectl delete namespace monitoring";
11471224
//TestUtils.exec(crdCmd);
11481225
}

0 commit comments

Comments
 (0)