Skip to content

Issue CWMOT5100 only once #31223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ tested.features:\
mpconfig-1.3,\
mpconfig-2.0,\
mpConfig-3.1,\
mpMetrics-1.1,\
mpMetrics-3.0,\
mpMetrics-4.0,\
mpHealth-1.0,\
mpHealth-3.1,\
cdi-1.2,\
cdi-2.0,\
cdi-4.1,\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
TelemetryWithSpanErrorTest.class,
TelemetryAttributesTest.class,
TelemetryRuntimeInstanceTest.class,
TelemetrySdkDisabledTrueWarningTest.class

})
public class FATSuite {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*******************************************************************************
* Copyright (c) 2025 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package io.openliberty.microprofile.telemetry.internal_fat;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.util.HashSet;
import java.util.Set;

import javax.ws.rs.HttpMethod;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.ibm.websphere.simplicity.log.Log;

import componenttest.annotation.Server;
import componenttest.custom.junit.runner.FATRunner;
import componenttest.rules.repeater.RepeatTests;
import componenttest.topology.impl.LibertyServer;
import componenttest.topology.utils.FATServletClient;
import io.openliberty.microprofile.telemetry.internal_fat.shared.TelemetryActions;
import junit.framework.Assert;

/**
* Test to verify that only a singular CWMOT5100I is emitted for each unique internal WAB/application
* i.e. health, metrics, rest handler ,etc.
*
* This issue only affects mpTelemetry-2.0 when used with HTTP Metrics (supported only in mpTelemetry-2.0)
*/
@RunWith(FATRunner.class)
public class TelemetrySdkDisabledTrueWarningTest extends FATServletClient {

private static final String CLASS_NAME = TelemetrySdkDisabledTrueWarningTest.class.getName();

private static final String CWMOT5100I = "CWMOT5100I";

public static final String SERVER_NAME = "Telemetry10sdkDisbledTrueWarning";

@Server(SERVER_NAME)
public static LibertyServer server;

@ClassRule
public static RepeatTests r = TelemetryActions.telemetry20Repeats(SERVER_NAME);

@BeforeClass
public static void setUp() throws Exception {
server.startServer();
}

@AfterClass
public static void tearDown() throws Exception {
server.stopServer();
}

@Test
public void uniqeCWMOT5100ITest() throws Exception {
Assert.assertTrue(server.isStarted());

//Startup check.
validateCWMOT5100Iwarning();

//hit metrics
requestHttpServlet("/metrics");
//hit health
requestHttpServlet("/health");

//runtime check after hitting endpoints
validateCWMOT5100Iwarning();

}

private void validateCWMOT5100Iwarning() throws Exception {
Set<String> warningsIssued = new HashSet<String>();
for (String warning : server.findStringsInLogs(CWMOT5100I)) {

//returns false if string already exists in set
if (!warningsIssued.add(warning.split(CWMOT5100I)[1])) {
Assert.fail(String.format("Detected duplciate %s warning: %s", CWMOT5100I, warning));
}
}
}

protected String requestHttpServlet(String servletPath) {
HttpURLConnection con = null;
try {
String path = "http://" + server.getHostname() + ":"
+ server.getHttpDefaultPort() + servletPath;

URI theURI = new URI(path);

URL theURL = theURI.toURL();
con = (HttpURLConnection) theURL.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestMethod(HttpMethod.GET);
String sep = System.getProperty("line.separator");
String line = null;
StringBuilder lines = new StringBuilder();
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));

while ((line = br.readLine()) != null && line.length() > 0) {
lines.append(line).append(sep);
}

Assert.assertEquals("Did not recieve 200 response code while connecting to " + path, 200, con.getResponseCode());

return lines.toString();
} catch (IOException e) {
Log.info(this.getClass(), "requestHttpServlet", "Encountered IO exception " + e);
return null;
} catch (Exception e) {
Log.info(this.getClass(), "requestHttpServlet", "Encountered an exception " + e);
return null;
} finally {
if (con != null)
con.disconnect();
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bootstrap.include=../testports.properties
otel.sdk.disabled=true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Dio.opentelemetry.context.enableStrictContext=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<server description="Server for testing Telemetry10">

<include location="../fatTestPorts.xml" />

<featureManager>
<feature>mpHealth-4.0</feature>
<feature>mpMetrics-5.1</feature>
<feature>mpTelemetry-2.0</feature>
<feature>restfulWS-3.1</feature>
<feature>cdi-4.0</feature>
<feature>componentTest-2.0</feature>
</featureManager>

<mpMetrics authentication="false"/>

<!-- For the ExecutorService in SpanCurrentServlet.java -->
<javaPermission className="java.lang.RuntimePermission" name="modifyThread" />

</server>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 IBM Corporation and others.
* Copyright (c) 2024, 2025 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -10,6 +10,8 @@
package io.openliberty.microprofile.telemetry.internal.common.info;

import java.util.HashMap;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicReference;

import org.apache.commons.lang3.concurrent.LazyInitializer;
Expand Down Expand Up @@ -43,6 +45,9 @@ public class OpenTelemtryLifecycleManagerImpl implements ApplicationStateListene

private final MetaDataSlot slotForOpenTelemetryInfoHolder;
private final OpenTelemetryInfoFactory openTelemetryInfoFactory;

private final Set<String> warningsEmittedForInternalApps = ConcurrentHashMap.newKeySet();

boolean telemetry2OrLater;

//These three are set during activation, and refreshed on checkpoint restore. (runtimeInstance is only set if we need one)
Expand Down Expand Up @@ -236,8 +241,13 @@ public OpenTelemetryInfoInternal getOpenTelemetryInfo(ApplicationMetaData metaDa
if (atomicRef == null) {
//If this is triggered by a WAB or internal code that doesn't have an associated app, and we're in app mode, return a no-op
//(in runtime mode we do want to have OpenTelemetry enabled for internal code, e.g., for tracing)
//Issue CWMOT5100 only once for WAB or internal code.
String j2EEName = metaData.getJ2EEName().toString();
Tr.info(tc, "CWMOT5100.tracing.is.disabled", j2EEName);

if (j2EEName != null && warningsEmittedForInternalApps.add(j2EEName)) {
Tr.info(tc, "CWMOT5100.tracing.is.disabled", j2EEName);
}

return new DisabledOpenTelemetryInfo();

}
Expand Down