@@ -817,9 +817,35 @@ public void test19_EndToEndViaChart() throws Exception {
817
817
throw new RuntimeException ("FAILURE: failed to install database " );
818
818
}
819
819
createWLSImageAndDeploy ();
820
+ installWebHookAndAlertManager ();
820
821
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
+
821
847
} finally {
822
- uninstallPrometheusGrafanaViaChart ();
848
+ uninstallWebHookPrometheusGrafanaViaChart ();
823
849
uninstallMySQL ();
824
850
String crdCmd =
825
851
" kubectl delete -f " + monitoringExporterEndToEndDir + "/demo-domains/domain1.yaml" ;
@@ -933,6 +959,8 @@ private static void setupPVMYSQL() throws Exception {
933
959
monitoringExporterEndToEndDir + "/mysql/persistence.yaml" , "%PV_ROOT%" , pvDir );
934
960
replaceStringInFile (
935
961
monitoringExporterEndToEndDir + "/prometheus/persistence.yaml" , "%PV_ROOT%" , pvDir );
962
+ replaceStringInFile (
963
+ monitoringExporterEndToEndDir + "/prometheus/alert-persistence.yaml" , "%PV_ROOT%" , pvDir );
936
964
replaceStringInFile (
937
965
monitoringExporterEndToEndDir + "/grafana/persistence.yaml" , "%PV_ROOT%" , pvDir );
938
966
// deploy PV and PVC
@@ -1071,6 +1099,9 @@ private static void installPrometheusGrafanaViaChart() throws Exception {
1071
1099
TestUtils .exec (crdCmd );
1072
1100
crdCmd = "kubectl apply -f " + monitoringExporterEndToEndDir + "/prometheus/persistence.yaml" ;
1073
1101
TestUtils .exec (crdCmd );
1102
+
1103
+ crdCmd = "kubectl apply -f " + monitoringExporterEndToEndDir + "/prometheus/alert-persistence.yaml" ;
1104
+ TestUtils .exec (crdCmd );
1074
1105
// install prometheus
1075
1106
crdCmd =
1076
1107
"helm install --wait --name prometheus --namespace monitoring --values "
@@ -1114,17 +1145,59 @@ private static void installPrometheusGrafanaViaChart() throws Exception {
1114
1145
assertTrue (checkMetricsViaPrometheus ("wls_servlet_execution_time_average" , "test-webapp" ));
1115
1146
}
1116
1147
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
+
1117
1184
/**
1118
1185
* Uninstall Prometheus and Grafana using helm chart
1119
1186
*
1120
1187
* @throws Exception if could not run the command successfully to clone from github
1121
1188
*/
1122
- private static void uninstallPrometheusGrafanaViaChart () throws Exception {
1189
+ private static void uninstallWebHookPrometheusGrafanaViaChart () throws Exception {
1123
1190
String monitoringExporterEndToEndDir =
1124
1191
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 );
1125
1198
logger .info ("Uninstalling grafana" );
1126
1199
// uninstall grafana
1127
- String crdCmd = "helm delete --purge grafana" ;
1200
+ crdCmd = "helm delete --purge grafana" ;
1128
1201
ExecCommand .exec (crdCmd );
1129
1202
crdCmd = "kubectl -n monitoring delete secret grafana-secret" ;
1130
1203
ExecCommand .exec (crdCmd );
@@ -1142,7 +1215,11 @@ private static void uninstallPrometheusGrafanaViaChart() throws Exception {
1142
1215
ExecCommand .exec (crdCmd );
1143
1216
Thread .sleep (15000 );
1144
1217
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 ");
1146
1223
crdCmd = "kubectl delete namespace monitoring" ;
1147
1224
//TestUtils.exec(crdCmd);
1148
1225
}
0 commit comments