Skip to content

Commit 13b7479

Browse files
committed
Merge branch 'monexpfixmain' into 'main'
forward changes from 4.2 for OWLS-127302 See merge request weblogic-cloud/weblogic-kubernetes-operator!4946
2 parents 2c735d2 + 50ef113 commit 13b7479

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

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

Lines changed: 13 additions & 2 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;
@@ -376,7 +377,7 @@ void testEndToEndViaChart() throws Exception {
376377
}
377378
}
378379

379-
private void fireAlert() throws ApiException {
380+
private void fireAlert() throws Exception {
380381
// scale domain2
381382
logger.info("Scaling cluster {0} of domain {1} in namespace {2} to {3} servers.",
382383
cluster1Name, domain2Uid, domain2Namespace, 1);
@@ -385,6 +386,16 @@ private void fireAlert() throws ApiException {
385386
domain2Uid + "-" + MANAGED_SERVER_NAME_BASE, replicaCount, managedServersCount,
386387
null, null);
387388

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

400411
testUntil(withLongRetryPolicy,
401412
assertDoesNotThrow(() -> searchPodLogForKey(pod,
402-
"Some WLS cluster has only one running server for more than 1 minutes"),
413+
"Some WLS cluster has only one running server for more than 15 secs"),
403414
"webhook failed to fire alert"),
404415
logger,
405416
"webhook to fire alert");

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

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,33 @@ public static void checkMetricsViaPrometheus(String searchKey, String expectedVa
318318
expectedVal);
319319
}
320320

321+
/**
322+
* Check metrics using Prometheus.
323+
*
324+
* @param expectedVal - expected alert data to search
325+
* @param hostPortPrometheus host:nodePort for prometheus
326+
* @throws Exception if command to check metrics fails
327+
*/
328+
public static void checkPrometheusAlert(String expectedVal,
329+
String hostPortPrometheus, String ingressHost)
330+
throws Exception {
331+
332+
LoggingFacade logger = getLogger();
333+
// url
334+
String curlCmd =
335+
String.format("curl -g --silent --show-error --noproxy '*' -v -H 'host: %s'"
336+
+ " http://%s/api/v1/alerts",
337+
ingressHost, hostPortPrometheus);
338+
339+
logger.info("Executing Curl cmd {0}", curlCmd);
340+
logger.info(" expected Value {0} ", expectedVal);
341+
testUntil(
342+
searchForKey(curlCmd, expectedVal),
343+
logger,
344+
"Check prometheus alert against expected {0}",
345+
expectedVal);
346+
}
347+
321348
/**
322349
* Check output of the command against expected output.
323350
*
@@ -1333,9 +1360,19 @@ public static boolean verifyMonExpAppAccess(String uri, String searchKey, Boolea
13331360
podName = domainUid + "-managed-server1";
13341361
}
13351362
// access metrics
1336-
final String command = String.format("%s exec -n %s %s -- curl -k %s://%s:%s@%s:%s/%s",
1337-
KUBERNETES_CLI, domainNS, podName, protocol, ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT,
1338-
podName, port, uri);
1363+
final String command = String.format(
1364+
"%s exec -n %s %s -- curl -k %s://%s:%s@%s:%s/%s",
1365+
KUBERNETES_CLI,
1366+
domainNS,
1367+
podName,
1368+
protocol,
1369+
ADMIN_USERNAME_DEFAULT,
1370+
ADMIN_PASSWORD_DEFAULT,
1371+
podName,
1372+
port,
1373+
uri
1374+
);
1375+
13391376
logger.info("accessing managed server exporter via " + command);
13401377

13411378
boolean isFound = false;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ serverFiles:
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ serverFiles:
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)