Skip to content

Commit 2316d0f

Browse files
marinakogrjeberhard
authored andcommitted
Fixed firealert issue in MonitoringExporterSamples test - OWLS-127302
1 parent 28bb363 commit 2316d0f

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMonitoringExporterSamples.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
import static oracle.weblogic.kubernetes.utils.LoadBalancerUtils.createIngressForDomainAndVerify;
108108
import static oracle.weblogic.kubernetes.utils.LoadBalancerUtils.installAndVerifyNginx;
109109
import static oracle.weblogic.kubernetes.utils.MonitoringUtils.checkMetricsViaPrometheus;
110+
import static oracle.weblogic.kubernetes.utils.MonitoringUtils.checkPrometheusAlert;
110111
import static oracle.weblogic.kubernetes.utils.MonitoringUtils.cleanupPromGrafanaClusterRoles;
111112
import static oracle.weblogic.kubernetes.utils.MonitoringUtils.createAndVerifyDomain;
112113
import static oracle.weblogic.kubernetes.utils.MonitoringUtils.createAndVerifyMiiImage;
@@ -379,7 +380,7 @@ void testEndToEndViaChart() throws Exception {
379380
}
380381
}
381382

382-
private void fireAlert() throws ApiException {
383+
private void fireAlert() throws Exception {
383384
// scale domain2
384385
logger.info("Scaling cluster {0} of domain {1} in namespace {2} to {3} servers.",
385386
cluster1Name, domain2Uid, domain2Namespace, 1);
@@ -388,6 +389,15 @@ private void fireAlert() throws ApiException {
388389
domain2Uid + "-" + MANAGED_SERVER_NAME_BASE, replicaCount, managedServersCount,
389390
null, null);
390391

392+
logger.info("Wait for the prometheus to create alert ");
393+
checkPrometheusAlert("ClusterWarning", hostPortPrometheus,
394+
prometheusReleaseName
395+
+ "." + monitoringNS);
396+
397+
logger.info("Wait for the prometheus to fire alert ");
398+
checkPrometheusAlert("firing", hostPortPrometheus,
399+
prometheusReleaseName
400+
+ "." + monitoringNS);
391401
//check webhook log for firing alert
392402
List<V1Pod> pods = listPods(webhookNS, "app=webhook").getItems();
393403
assertNotNull((pods), "No pods are running in namespace : " + webhookNS);
@@ -402,7 +412,7 @@ private void fireAlert() throws ApiException {
402412

403413
testUntil(withLongRetryPolicy,
404414
assertDoesNotThrow(() -> searchPodLogForKey(pod,
405-
"Some WLS cluster has only one running server for more than 1 minutes"),
415+
"Some WLS cluster has only one running server for more than 15 secs"),
406416
"webhook failed to fire alert"),
407417
logger,
408418
"webhook to fire alert");
@@ -554,7 +564,7 @@ public void tearDownAll() {
554564
deletePersistentVolumeClaim("pvc-" + grafanaReleaseName, monitoringNS);
555565
deletePersistentVolume("pv-test" + grafanaReleaseName);
556566
deleteNamespace(monitoringNS);
557-
uninstallDeploymentService(webhookDepl, webhookService);
567+
//uninstallDeploymentService(webhookDepl, webhookService);
558568
uninstallDeploymentService(coordinatorDepl, coordinatorService);
559569
if (nginxHelmParams != null) {
560570
assertThat(uninstallNginx(nginxHelmParams.getHelmParams()))

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/MonitoringUtils.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,33 @@ public static void checkMetricsViaPrometheus(String searchKey, String expectedVa
324324
expectedVal);
325325
}
326326

327+
/**
328+
* Check metrics using Prometheus.
329+
*
330+
* @param expectedVal - expected alert data to search
331+
* @param hostPortPrometheus host:nodePort for prometheus
332+
* @throws Exception if command to check metrics fails
333+
*/
334+
public static void checkPrometheusAlert(String expectedVal,
335+
String hostPortPrometheus, String ingressHost)
336+
throws Exception {
337+
338+
LoggingFacade logger = getLogger();
339+
// url
340+
String curlCmd =
341+
String.format("curl -g --silent --show-error --noproxy '*' -v -H 'host: " + ingressHost + "'"
342+
+ " http://%s/api/v1/alerts",
343+
hostPortPrometheus);
344+
345+
logger.info("Executing Curl cmd {0}", curlCmd);
346+
logger.info(" expected Value {0} ", expectedVal);
347+
testUntil(
348+
searchForKey(curlCmd, expectedVal),
349+
logger,
350+
"Check prometheus alert against expected {0}",
351+
expectedVal);
352+
}
353+
327354
/**
328355
* Check output of the command against expected output.
329356
*

integration-tests/src/test/resources/exporter/promvalues.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ serverFiles:
143143
rules:
144144
- alert: ClusterWarning
145145
for: 15s
146-
expr: sum by(weblogic_domainUID, weblogic_clusterName) (up{weblogic_domainUID=~'.+'}) == 1
146+
expr: sum by(weblogic_domainUID, weblogic_clusterName) (up{weblogic_domainUID=~'.+', job="wls-domain1"}) == 1
147147
labels:
148148
severity: page
149149
annotations:
150-
description: 'Some WLS cluster has only one running server for more than 1 minutes.'
150+
description: 'Some WLS cluster has only one running server for more than 15 secs.'
151151
summary: 'Some wls cluster is in warning state.'
152152

153153
extraScrapeConfigs: |

integration-tests/src/test/resources/exporter/promvaluesoke.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ serverFiles:
147147
rules:
148148
- alert: ClusterWarning
149149
for: 15s
150-
expr: sum by(weblogic_domainUID, weblogic_clusterName) (up{weblogic_domainUID=~'.+'}) == 1
150+
expr: sum by(weblogic_domainUID, weblogic_clusterName) (up{weblogic_domainUID=~'.+', job="wls-domain1"}) == 1
151151
labels:
152152
severity: page
153153
annotations:
154-
description: 'Some WLS cluster has only one running server for more than 1 minutes.'
154+
description: 'Some WLS cluster has only one running server for more than 15 secs.'
155155
summary: 'Some wls cluster is in warning state.'
156156

157157
extraScrapeConfigs: |

0 commit comments

Comments
 (0)