Skip to content

Commit fff4eab

Browse files
authored
back port elasticlogging and elasticloggingfluentd changes from main (#2836)
* backport elasticlogging and elasticloggingfluentd changes from main to release/3.3
1 parent b56607c commit fff4eab

File tree

5 files changed

+162
-79
lines changed

5 files changed

+162
-79
lines changed

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

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import oracle.weblogic.domain.Model;
2424
import oracle.weblogic.domain.ServerPod;
2525
import oracle.weblogic.kubernetes.actions.impl.LoggingExporterParams;
26+
import oracle.weblogic.kubernetes.actions.impl.OperatorParams;
27+
import oracle.weblogic.kubernetes.actions.impl.primitive.HelmParams;
2628
import oracle.weblogic.kubernetes.annotations.IntegrationTest;
2729
import oracle.weblogic.kubernetes.annotations.Namespaces;
2830
import oracle.weblogic.kubernetes.logging.LoggingFacade;
@@ -40,12 +42,10 @@
4042
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_USERNAME_DEFAULT;
4143
import static oracle.weblogic.kubernetes.TestConstants.COPY_WLS_LOGGING_EXPORTER_FILE_NAME;
4244
import static oracle.weblogic.kubernetes.TestConstants.DOMAIN_API_VERSION;
43-
import static oracle.weblogic.kubernetes.TestConstants.ELASTICSEARCH_HOST;
4445
import static oracle.weblogic.kubernetes.TestConstants.ELASTICSEARCH_HTTPS_PORT;
4546
import static oracle.weblogic.kubernetes.TestConstants.ELASTICSEARCH_HTTP_PORT;
4647
import static oracle.weblogic.kubernetes.TestConstants.ELASTICSEARCH_IMAGE;
4748
import static oracle.weblogic.kubernetes.TestConstants.ELASTICSEARCH_NAME;
48-
import static oracle.weblogic.kubernetes.TestConstants.ELKSTACK_NAMESPACE;
4949
import static oracle.weblogic.kubernetes.TestConstants.KIBANA_IMAGE;
5050
import static oracle.weblogic.kubernetes.TestConstants.KIBANA_INDEX_KEY;
5151
import static oracle.weblogic.kubernetes.TestConstants.KIBANA_NAME;
@@ -54,6 +54,7 @@
5454
import static oracle.weblogic.kubernetes.TestConstants.LOGSTASH_INDEX_KEY;
5555
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_APP_NAME;
5656
import static oracle.weblogic.kubernetes.TestConstants.OCIR_SECRET_NAME;
57+
import static oracle.weblogic.kubernetes.TestConstants.OPERATOR_CHART_DIR;
5758
import static oracle.weblogic.kubernetes.TestConstants.OPERATOR_RELEASE_NAME;
5859
import static oracle.weblogic.kubernetes.TestConstants.WEBLOGIC_INDEX_KEY;
5960
import static oracle.weblogic.kubernetes.TestConstants.WLS_LOGGING_EXPORTER_YAML_FILE_NAME;
@@ -64,8 +65,10 @@
6465
import static oracle.weblogic.kubernetes.actions.ActionConstants.WORK_DIR;
6566
import static oracle.weblogic.kubernetes.actions.TestActions.execCommand;
6667
import static oracle.weblogic.kubernetes.actions.TestActions.getOperatorPodName;
68+
import static oracle.weblogic.kubernetes.assertions.TestAssertions.operatorIsReady;
6769
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkServiceExists;
6870
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getNextFreePort;
71+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.testUntil;
6972
import static oracle.weblogic.kubernetes.utils.DomainUtils.createDomainAndVerify;
7073
import static oracle.weblogic.kubernetes.utils.ImageUtils.createMiiImageAndVerify;
7174
import static oracle.weblogic.kubernetes.utils.ImageUtils.createOcirRepoSecret;
@@ -77,6 +80,8 @@
7780
import static oracle.weblogic.kubernetes.utils.LoggingExporterUtils.uninstallAndVerifyKibana;
7881
import static oracle.weblogic.kubernetes.utils.LoggingExporterUtils.verifyLoggingExporterReady;
7982
import static oracle.weblogic.kubernetes.utils.OperatorUtils.installAndVerifyOperator;
83+
import static oracle.weblogic.kubernetes.utils.OperatorUtils.upgradeAndVerifyOperator;
84+
import static oracle.weblogic.kubernetes.utils.PodUtils.checkPodDoesNotExist;
8085
import static oracle.weblogic.kubernetes.utils.PodUtils.checkPodReady;
8186
import static oracle.weblogic.kubernetes.utils.PodUtils.setPodAntiAffinity;
8287
import static oracle.weblogic.kubernetes.utils.SecretUtils.createSecretWithUsernamePassword;
@@ -133,6 +138,9 @@ class ItElasticLogging {
133138
private static LoggingExporterParams kibanaParams = null;
134139
private static LoggingFacade logger = null;
135140

141+
static String elasticSearchHost;
142+
static String elasticSearchNs;
143+
136144
private static String k8sExecCmdPrefix;
137145
private static Map<String, String> testVarMap;
138146

@@ -145,7 +153,7 @@ class ItElasticLogging {
145153
* JUnit engine parameter resolution mechanism.
146154
*/
147155
@BeforeAll
148-
public static void init(@Namespaces(2) List<String> namespaces) {
156+
public static void init(@Namespaces(3) List<String> namespaces) {
149157
logger = getLogger();
150158
// create standard, reusable retry/backoff policy
151159
withStandardRetryPolicy = with().pollDelay(2, SECONDS)
@@ -163,24 +171,28 @@ public static void init(@Namespaces(2) List<String> namespaces) {
163171
domainNamespace = namespaces.get(1);
164172

165173
// install and verify Elasticsearch
174+
elasticSearchNs = namespaces.get(2);
166175
logger.info("install and verify Elasticsearch");
167-
elasticsearchParams = assertDoesNotThrow(() -> installAndVerifyElasticsearch(),
176+
elasticsearchParams = assertDoesNotThrow(() -> installAndVerifyElasticsearch(elasticSearchNs),
168177
String.format("Failed to install Elasticsearch"));
169178
assertTrue(elasticsearchParams != null, "Failed to install Elasticsearch");
170179

171180
// install and verify Kibana
172181
logger.info("install and verify Kibana");
173-
kibanaParams = assertDoesNotThrow(() -> installAndVerifyKibana(),
182+
kibanaParams = assertDoesNotThrow(() -> installAndVerifyKibana(elasticSearchNs),
174183
String.format("Failed to install Kibana"));
175184
assertTrue(kibanaParams != null, "Failed to install Kibana");
176185

177186
// install and verify Operator
178187
installAndVerifyOperator(opNamespace, opNamespace + "-sa",
179188
false, 0, true, domainNamespace);
180189

190+
String operatorPodName = assertDoesNotThrow(
191+
() -> getOperatorPodName(OPERATOR_RELEASE_NAME, opNamespace));
192+
181193
// install WebLogic Logging Exporter
182194
installAndVerifyWlsLoggingExporter(managedServerFilter,
183-
wlsLoggingExporterYamlFileLoc);
195+
wlsLoggingExporterYamlFileLoc, elasticSearchNs);
184196

185197
// create and verify WebLogic domain image using model in image with model files
186198
String imageName = createAndVerifyDomainImage();
@@ -190,18 +202,43 @@ public static void init(@Namespaces(2) List<String> namespaces) {
190202
createAndVerifyDomain(imageName);
191203

192204
testVarMap = new HashMap<String, String>();
193-
194-
StringBuffer elasticsearchUrlBuff =
195-
new StringBuffer("curl http://")
196-
.append(ELASTICSEARCH_HOST)
197-
.append(":")
198-
.append(ELASTICSEARCH_HTTP_PORT);
199-
k8sExecCmdPrefix = elasticsearchUrlBuff.toString();
205+
elasticSearchHost = "elasticsearch." + elasticSearchNs + ".svc.cluster.local";
206+
207+
// upgrade to latest operator
208+
HelmParams upgradeHelmParams = new HelmParams()
209+
.releaseName(OPERATOR_RELEASE_NAME)
210+
.namespace(opNamespace)
211+
.chartDir(OPERATOR_CHART_DIR);
212+
213+
// build operator chart values
214+
OperatorParams opParams = new OperatorParams()
215+
.helmParams(upgradeHelmParams)
216+
.elkIntegrationEnabled(true)
217+
.elasticSearchHost(elasticSearchHost);
218+
219+
assertTrue(upgradeAndVerifyOperator(opNamespace, opParams),
220+
String.format("Failed to upgrade operator in namespace %s", opNamespace));
221+
222+
// check operator pod is not running
223+
checkPodDoesNotExist(operatorPodName, null, opNamespace);
224+
225+
// wait for the operator to be ready
226+
logger.info("Wait for the operator pod is ready in namespace {0}", opNamespace);
227+
testUntil(
228+
assertDoesNotThrow(() -> operatorIsReady(opNamespace),
229+
"operatorIsReady failed with ApiException"),
230+
logger,
231+
"operator to be running in namespace {0}",
232+
opNamespace);
233+
234+
String elasticsearchUrlBuff
235+
= "curl http://" + elasticSearchHost + ":" + ELASTICSEARCH_HTTP_PORT;
236+
k8sExecCmdPrefix = elasticsearchUrlBuff;
200237
logger.info("Elasticsearch URL {0}", k8sExecCmdPrefix);
201238

202239
// Verify that ELK Stack is ready to use
203-
testVarMap = verifyLoggingExporterReady(opNamespace, null, LOGSTASH_INDEX_KEY);
204-
Map<String, String> kibanaMap = verifyLoggingExporterReady(opNamespace, null, KIBANA_INDEX_KEY);
240+
testVarMap = verifyLoggingExporterReady(opNamespace, elasticSearchNs, null, LOGSTASH_INDEX_KEY);
241+
Map<String, String> kibanaMap = verifyLoggingExporterReady(opNamespace, elasticSearchNs, null, KIBANA_INDEX_KEY);
205242

206243
// merge testVarMap and kibanaMap
207244
testVarMap.putAll(kibanaMap);
@@ -222,13 +259,13 @@ void tearDown() {
222259
.elasticsearchImage(ELASTICSEARCH_IMAGE)
223260
.elasticsearchHttpPort(ELASTICSEARCH_HTTP_PORT)
224261
.elasticsearchHttpsPort(ELASTICSEARCH_HTTPS_PORT)
225-
.loggingExporterNamespace(ELKSTACK_NAMESPACE);
262+
.loggingExporterNamespace(elasticSearchNs);
226263

227264
kibanaParams = new LoggingExporterParams()
228265
.kibanaName(KIBANA_NAME)
229266
.kibanaImage(KIBANA_IMAGE)
230267
.kibanaType(KIBANA_TYPE)
231-
.loggingExporterNamespace(ELKSTACK_NAMESPACE)
268+
.loggingExporterNamespace(elasticSearchNs)
232269
.kibanaContainerPort(KIBANA_PORT);
233270

234271
logger.info("Uninstall Elasticsearch pod");
@@ -298,7 +335,7 @@ void testWebLogicLogSearch() {
298335
@Test
299336
@DisplayName("Use Elasticsearch Search APIs to query WebLogic log info in WLS server pod and verify")
300337
void testWlsLoggingExporter() throws Exception {
301-
Map<String, String> wlsMap = verifyLoggingExporterReady(opNamespace, null, WEBLOGIC_INDEX_KEY);
338+
Map<String, String> wlsMap = verifyLoggingExporterReady(opNamespace, elasticSearchNs, null, WEBLOGIC_INDEX_KEY);
302339
// merge testVarMap and wlsMap
303340
testVarMap.putAll(wlsMap);
304341

@@ -367,7 +404,7 @@ private static void createAndVerifyDomain(String miiImage) {
367404
// create secret for admin credentials
368405
logger.info("Create secret for admin credentials");
369406
String adminSecretName = "weblogic-credentials";
370-
assertDoesNotThrow(() -> createSecretWithUsernamePassword(adminSecretName,
407+
assertDoesNotThrow(() -> createSecretWithUsernamePassword(adminSecretName,
371408
domainNamespace, ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT),
372409
String.format("create secret for admin credentials failed for %s", adminSecretName));
373410

0 commit comments

Comments
 (0)