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

fix: default empty string value properties #304

Closed

Conversation

justenwalker
Copy link
Contributor

What

The log4j2.xml configuration is missing a default value for S3_MINIO_ENDPOINT which is causing issues writing logs S3 Cloud Storage location.

When these environment variables are not set and do not have a default value in the replacement string - they remain set to their un-replaced value, which is never a valid configuration.

<Property name="s3-minio-endpoint">${sys:S3_MINIO_ENDPOINT:-${env:S3_MINIO_ENDPOINT}}</Property>

When S3_MINIO_ENDPOINT is set to an empty string, the replacement fails because the environment value is treated as unset; so the property s3-minio-endpoint gets set to literally ${env:S3_MINIO_ENDPOINT} (since the sys: property is not set, and it uses this as the default value)

ie: it becomes literally this, no substitution:

<Property name="s3-minio-endpoint">${env:S3_MINIO_ENDPOINT}</Property>

This causes problems down-stream for S3 since now technically both s3-region and s3-minio-endpoint is set; which is an invalid configuration, and results in a runtime exception:

ERROR StatusConsoleListener Could not create plugin of type class com.van.logging.log4j2.Log4j2Appender for element Log4j2Appender: java.lang.RuntimeException: Cannot build appender due to errors
 java.lang.RuntimeException: Cannot build appender due to errors
	at com.van.logging.log4j2.Log4j2AppenderBuilder.build(Log4j2AppenderBuilder.java:147)
	at com.van.logging.log4j2.Log4j2AppenderBuilder.build(Log4j2AppenderBuilder.java:25)
	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:124)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:1162)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1083)
	at org.apache.logging.log4j.core.appender.routing.RoutingAppender.createAppender(RoutingAppender.java:323)
	at org.apache.logging.log4j.core.appender.routing.RoutingAppender.getControl(RoutingAppender.java:295)
	at org.apache.logging.log4j.core.appender.routing.RoutingAppender.append(RoutingAppender.java:253)
	at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:160)
	at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:133)
	at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:124)
	at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:88)
	at org.apache.logging.log4j.core.appender.rewrite.RewriteAppender.append(RewriteAppender.java:89)
	at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:160)
	at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:133)
	at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:124)
	at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:88)
	at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:705)
	at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:663)
	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:639)
	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:575)
	at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:92)
	at org.apache.logging.log4j.core.Logger.log(Logger.java:169)
	at org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2933)
	at org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2886)
	at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2868)
	at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2652)
	at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:2400)
	at org.apache.logging.slf4j.Log4jLogger.warn(Log4jLogger.java:239)
	at io.airbyte.workers.temporal.scheduling.activities.AppendToAttemptLogActivityImpl.log(AppendToAttemptLogActivityImpl.java:61)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at io.temporal.internal.activity.RootActivityInboundCallsInterceptor$POJOActivityInboundCallsInterceptor.executeActivity(RootActivityInboundCallsInterceptor.java:64)
	at io.temporal.internal.activity.RootActivityInboundCallsInterceptor.execute(RootActivityInboundCallsInterceptor.java:43)
	at io.temporal.internal.activity.ActivityTaskExecutors$BaseActivityTaskExecutor.execute(ActivityTaskExecutors.java:107)
	at io.temporal.internal.activity.ActivityTaskHandlerImpl.handle(ActivityTaskHandlerImpl.java:124)
	at io.temporal.internal.worker.ActivityWorker$TaskHandlerImpl.handleActivity(ActivityWorker.java:278)
	at io.temporal.internal.worker.ActivityWorker$TaskHandlerImpl.handle(ActivityWorker.java:243)
	at io.temporal.internal.worker.ActivityWorker$TaskHandlerImpl.handle(ActivityWorker.java:216)
	at io.temporal.internal.worker.PollTaskExecutor.lambda$process$0(PollTaskExecutor.java:105)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.IllegalStateException: Only one of Region or EndpointConfiguration may be set.
	at com.amazonaws.client.builder.AwsClientBuilder.setRegion(AwsClientBuilder.java:450)
	at com.amazonaws.client.builder.AwsClientBuilder.configureMutableProperties(AwsClientBuilder.java:424)
	at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46)
	at com.van.logging.aws.AwsClientHelpers.buildClient(AwsClientHelpers.java:88)
	at com.van.logging.aws.S3PublishHelper.<init>(S3PublishHelper.java:52)
	at com.van.logging.log4j2.Log4j2AppenderBuilder.lambda$createCachePublisher$0(Log4j2AppenderBuilder.java:276)
	at java.base/java.util.Optional.ifPresent(Optional.java:178)
	at com.van.logging.log4j2.Log4j2AppenderBuilder.createCachePublisher(Log4j2AppenderBuilder.java:271)
	at com.van.logging.log4j2.Log4j2AppenderBuilder.build(Log4j2AppenderBuilder.java:140)
	... 42 more

Related Isssues

How

This change adds a default value for:

  • env:S3_MINIO_ENDPOINT
  • env:S3_PATH_STYLE_ACCESS

Recommended reading order

  1. airbyte-commons/src/main/resources/log4j2.xml

Can this PR be safely reverted / rolled back?

If you know that your PR is backwards-compatible and can be simply reverted or rolled back, check the YES box.

Otherwise if your PR has a breaking change, like a database migration for example, check the NO box.

If unsure, leave it blank.

  • YES 💚

🚨 User Impact 🚨

should be no breaking changes

When these environment variables are not set and do not have a default
value in the replacement string - they remain set to their un-replaced
value, which is never a valid configuration.

This change adds a default value for:

- env:S3_MINIO_ENDPOINT
- env:S3_PATH_STYLE_ACCESS
Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@marcosmarxm
Copy link
Member

@jdpgrailsdev @colesnodgrass can you take a quick look in this fix proposed by Justen?

@justenwalker
Copy link
Contributor Author

justenwalker commented Feb 16, 2024

You can sort of test this fix without actually applying it by setting S3_MINIO_ENDPOINT to a single space " " which will make the config behave like it has a default value; This works because StringUtils.isTruthy treats a trimmed string as Falsey in addition to null and "" for the purposes of setting the EndpointConfiguration:

Copy link
Contributor

@jdpgrailsdev jdpgrailsdev left a comment

Choose a reason for hiding this comment

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

:shipit: I think that @colesnodgrass may be working on cleaning some of this up too, so we should make sure that he takes a look as well.

Copy link
Member

@colesnodgrass colesnodgrass left a comment

Choose a reason for hiding this comment

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

I recently went down a similar approach and was unable to get it to work, ultimately ended up having to fork the log4j2.xml file into a minio-free version.

You can set the environment-variable LOG4J_CONFIGURATION_FILE to tell java which file to use.

That being said, if this works for you, then I'm ok with this being merged in.

It's also work noting that a lot of these environment-variables around logging are currently being renamed and consolidated to help simplify our configuration settings.

@booleanbetrayal
Copy link

👀 Running into this issue as well in a Helm environment and not sure how to dance around it atm.

Copy link
Contributor

Your branch is not currently up-to-date with main. Please update your branch before attempting to snapshot your PR.

@colesnodgrass
Copy link
Member

I'm going to close this PR, as I believe this issue has been fixed via a different approach.

The log4j2 file has been split into four different files, one for each possible output. The helm charts should now automatically set the correct log4j2 file based on the global.storage.type type defined.

The plan is to eventually migrate the log4j configuration out of xml and into code, but I am unsure when that will happen (definitely won't be until after log4j3 is released).

Copy link
Contributor

github-actions bot commented Mar 7, 2024

Your branch is not currently up-to-date with main. Please update your branch before attempting to snapshot your PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants