Skip to content
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

Add a config to disable all logging appenders #3208

Merged
merged 5 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -226,6 +226,7 @@ public static class DatabaseMaskingConfiguration {

public static class LoggingInstrumentation {
public String level = "INFO";
public boolean enabled = true;

public int getSeverityThreshold() {
return getSeverityThreshold(level);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ public Map<String, String> apply(ConfigProperties otelConfig) {
properties.put("otel.instrumentation.log4j-appender.experimental-log-attributes", "true");
properties.put("otel.instrumentation.logback-appender.experimental-log-attributes", "true");

// disable logging appender
if (!configuration.instrumentation.logging.enabled) {
properties.put("otel.instrumentation.logback-appender.enabled", "false");
properties.put("otel.instrumentation.log4j-appender.enabled", "false");
properties.put("otel.instrumentation.java-util-logging.enabled", "false");
}

// custom instrumentation
if (!configuration.preview.customInstrumentation.isEmpty()) {
StringBuilder sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.microsoft.applicationinsights.smoketestapp;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/testDisabled")
public class JavaUtilLoggingDisabledServlet extends HttpServlet {

private static final Logger logger = Logger.getLogger("smoketestapp");

protected void doGet(HttpServletRequest request, HttpServletResponse response) {
logger.log(Level.WARNING, "this message will get suppressed.");
}
}
Comment on lines +13 to +21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need a separate Servlet for these tests, can just hit the same servlet that the normal test does (this is how other *DisabledTest smoke tests work)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i followed the existing setup.. one test per servlet. i think we can clean up later for all

Copy link
Contributor Author

@heyams heyams Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i noticed those are spring boot apps. not servlet. we can chat about it in tomorrow's standup

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.microsoft.applicationinsights.smoketest;

import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_11;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_11_OPENJ9;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_17;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_19;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_20;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8_OPENJ9;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9;
import static org.assertj.core.api.Assertions.assertThat;

import com.microsoft.applicationinsights.smoketest.schemav2.Data;
import com.microsoft.applicationinsights.smoketest.schemav2.Envelope;
import com.microsoft.applicationinsights.smoketest.schemav2.RequestData;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

@UseAgent("disabled_applicationinsights.json")
abstract class JavaUtilLoggingDisabledTest {
Copy link
Member

@trask trask Jul 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and then can remove all the subclasses (similar to the other disabled tests, no need to run these tests against envs)

Suggested change
abstract class JavaUtilLoggingDisabledTest {
@Environment(TOMCAT_8_JAVA_8)
class JavaUtilLoggingDisabledTest {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the purpose of doing subclass is to test all java versions.. this will cover one case?
our repo has this setup everywhere though
i can make the change but i think it needs to be consistent

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check the other *DisabledTest smoke tests, they also only test one case


@RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create();

@Test
@TargetUri("/testDisabled")
void testDisabled() throws Exception {
List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1);

Envelope rdEnvelope = rdList.get(0);
RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
assertThat(rd.getName()).isEqualTo("GET /JavaUtilLogging/testDisabled");

assertThat(testing.mockedIngestion.getCountForType("MessageData")).isZero();
}

@Environment(TOMCAT_8_JAVA_8)
static class Tomcat8Java8Test extends JavaUtilLoggingDisabledTest {}

@Environment(TOMCAT_8_JAVA_8_OPENJ9)
static class Tomcat8Java8OpenJ9Test extends JavaUtilLoggingDisabledTest {}

@Environment(TOMCAT_8_JAVA_11)
static class Tomcat8Java11Test extends JavaUtilLoggingDisabledTest {}

@Environment(TOMCAT_8_JAVA_11_OPENJ9)
static class Tomcat8Java11OpenJ9Test extends JavaUtilLoggingDisabledTest {}

@Environment(TOMCAT_8_JAVA_17)
static class Tomcat8Java17Test extends JavaUtilLoggingDisabledTest {}

@Environment(TOMCAT_8_JAVA_19)
static class Tomcat8Java19Test extends JavaUtilLoggingDisabledTest {}

@Environment(TOMCAT_8_JAVA_20)
static class Tomcat8Java20Test extends JavaUtilLoggingDisabledTest {}

@Environment(WILDFLY_13_JAVA_8)
static class Wildfly13Java8Test extends JavaUtilLoggingDisabledTest {}

@Environment(WILDFLY_13_JAVA_8_OPENJ9)
static class Wildfly13Java8OpenJ9Test extends JavaUtilLoggingDisabledTest {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

@UseAgent
@UseAgent("applicationinsights.json")
heyams marked this conversation as resolved.
Show resolved Hide resolved
abstract class JavaUtilLoggingTest {

@RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"role": {
"name": "testrolename",
"instance": "testroleinstance"
},
"sampling": {
"percentage": 100
},
"instrumentation": {
"logging": {
"enabled": "false"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.microsoft.applicationinsights.smoketestapp;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@WebServlet("/testDisabled")
public class Log4j2DisabledServlet extends HttpServlet {

private static final Logger logger = LogManager.getLogger("smoketestapp");

protected void doGet(HttpServletRequest request, HttpServletResponse response) {
logger.warn("This message will get suppressed");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.microsoft.applicationinsights.smoketest;

import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_11;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_11_OPENJ9;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_17;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_19;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_20;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8_OPENJ9;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9;
import static org.assertj.core.api.Assertions.assertThat;

import com.microsoft.applicationinsights.smoketest.schemav2.Data;
import com.microsoft.applicationinsights.smoketest.schemav2.Envelope;
import com.microsoft.applicationinsights.smoketest.schemav2.RequestData;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

@UseAgent("disabled_applicationinsights.json")
abstract class Log4j2DisabledTest {

@RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create();

@Test
@TargetUri("/testDisabled")
void testDisabled() throws Exception {
List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1);

Envelope rdEnvelope = rdList.get(0);
RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
assertThat(rd.getName()).isEqualTo("GET /Log4j2/testDisabled");

assertThat(testing.mockedIngestion.getCountForType("MessageData")).isZero();
}

@Environment(TOMCAT_8_JAVA_8)
static class Tomcat8Java8Test extends Log4j2DisabledTest {}

@Environment(TOMCAT_8_JAVA_8_OPENJ9)
static class Tomcat8Java8OpenJ9Test extends Log4j2DisabledTest {}

@Environment(TOMCAT_8_JAVA_11)
static class Tomcat8Java11Test extends Log4j2DisabledTest {}

@Environment(TOMCAT_8_JAVA_11_OPENJ9)
static class Tomcat8Java11OpenJ9Test extends Log4j2DisabledTest {}

@Environment(TOMCAT_8_JAVA_17)
static class Tomcat8Java17Test extends Log4j2DisabledTest {}

@Environment(TOMCAT_8_JAVA_19)
static class Tomcat8Java19Test extends Log4j2DisabledTest {}

@Environment(TOMCAT_8_JAVA_20)
static class Tomcat8Java20Test extends Log4j2DisabledTest {}

@Environment(WILDFLY_13_JAVA_8)
static class Wildfly13Java8Test extends Log4j2DisabledTest {}

@Environment(WILDFLY_13_JAVA_8_OPENJ9)
static class Wildfly13Java8OpenJ9Test extends Log4j2DisabledTest {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

@UseAgent
@UseAgent("applicationinsights.json")
abstract class Log4j2Test {

@RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"role": {
"name": "testrolename",
"instance": "testroleinstance"
},
"sampling": {
"percentage": 100
},
"instrumentation": {
"logging": {
"enabled": "false"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.microsoft.applicationinsights.smoketestapp;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@WebServlet("/testWithException")
public class LogbackDisabledServlet extends HttpServlet {

private static final Logger logger = LoggerFactory.getLogger("smoketestapp");

protected void doGet(HttpServletRequest request, HttpServletResponse response) {
logger.warn("This message will get suppressed");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.microsoft.applicationinsights.smoketest;

import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_11;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_11_OPENJ9;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_17;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_19;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_20;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8_OPENJ9;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9;
import static org.assertj.core.api.Assertions.assertThat;

import com.microsoft.applicationinsights.smoketest.schemav2.Data;
import com.microsoft.applicationinsights.smoketest.schemav2.Envelope;
import com.microsoft.applicationinsights.smoketest.schemav2.RequestData;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

@UseAgent
abstract class LogbackDisabledTest {

@RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create();

// Not really sure that Logback is enabled with Wildfly
// https://anotheria.net/blog/devops/enable-logback-in-jboss/
// https://www.oreilly.com/library/view/wildfly-cookbook/9781784392413/ch04s08.html
boolean isWildflyServer() {
return false;
}

@Test
@TargetUri("/testDisabled")
void testDisabled() throws Exception {
List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1);

Envelope rdEnvelope = rdList.get(0);
RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
assertThat(rd.getName()).isEqualTo("GET /Logback/testDisabled");

assertThat(testing.mockedIngestion.getCountForType("MessageData")).isZero();
}

@Environment(TOMCAT_8_JAVA_8)
static class Tomcat8Java8Test extends LogbackDisabledTest {}

@Environment(TOMCAT_8_JAVA_8_OPENJ9)
static class Tomcat8Java8OpenJ9Test extends LogbackDisabledTest {}

@Environment(TOMCAT_8_JAVA_11)
static class Tomcat8Java11Test extends LogbackDisabledTest {}

@Environment(TOMCAT_8_JAVA_11_OPENJ9)
static class Tomcat8Java11OpenJ9Test extends LogbackDisabledTest {}

@Environment(TOMCAT_8_JAVA_17)
static class Tomcat8Java17Test extends LogbackDisabledTest {}

@Environment(TOMCAT_8_JAVA_19)
static class Tomcat8Java19Test extends LogbackDisabledTest {}

@Environment(TOMCAT_8_JAVA_20)
static class Tomcat8Java20Test extends LogbackDisabledTest {}

@Environment(WILDFLY_13_JAVA_8)
static class Wildfly13Java8Test extends LogbackDisabledTest {
@Override
boolean isWildflyServer() {
return true;
}
}

@Environment(WILDFLY_13_JAVA_8_OPENJ9)
static class Wildfly13Java8OpenJ9Test extends LogbackDisabledTest {
@Override
boolean isWildflyServer() {
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

@UseAgent
@UseAgent("applicationinsights.json")
abstract class LogbackTest {

@RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"role": {
"name": "testrolename",
"instance": "testroleinstance"
},
"sampling": {
"percentage": 100
},
"instrumentation": {
"logging": {
"enabled": "false"
}
}
}
Loading