Skip to content

Commit

Permalink
Merge pull request #783 from quarkiverse/update_quarkus_to_3_17_0
Browse files Browse the repository at this point in the history
Update to latest Quarkus version and fix breaking changes in config m…
  • Loading branch information
bennetelli authored Nov 21, 2024
2 parents 0789322 + f999b08 commit f1eba1d
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 203 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.version>3.13.2</quarkus.version>
<quarkus.version>3.17.0</quarkus.version>
<awssdk.version>2.29.18</awssdk.version>
<aws.common.version>3.1.1</aws.common.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,127 +22,133 @@
import java.util.Optional;
import java.util.logging.Level;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;
import io.smallrye.config.WithName;

/**
* Configuration for CloudWatch logging.
*/
@ConfigRoot(phase = ConfigPhase.RUN_TIME, name = "log.cloudwatch")
public class LoggingCloudWatchConfig {
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
@ConfigMapping(prefix = "quarkus.log.cloudwatch")
public interface LoggingCloudWatchConfig {

/**
* Determine whether to enable the Cloudwatch logging extension.
*/
@ConfigItem(defaultValue = "true")
boolean enabled;
@WithName("enabled")
@WithDefault("true")
boolean enabled();

/**
* CW access key ID
* The AWS CloudWatch access key id
*/
@ConfigItem
public Optional<String> accessKeyId;
@WithName("access-key-id")
Optional<String> accessKeyId();

/**
* CW access key secret
* The AWS CloudWatch access key secret
*/
@ConfigItem
public Optional<String> accessKeySecret;
@WithName("access-key-secret")
Optional<String> accessKeySecret();

/**
* Region of deployment
*/
@ConfigItem
public Optional<String> region;
@WithName("region")
Optional<String> region();

/**
* CW log group
*/
@ConfigItem
public Optional<String> logGroup;
@WithName("log-group")
Optional<String> logGroup();

/**
* CW log stream
*/
@ConfigItem
public Optional<String> logStreamName;
@WithName("log-stream-name")
Optional<String> logStreamName();

/**
* The CW log level.
*/
@ConfigItem(defaultValue = "WARN")
public Level level;
@WithName("level")
@WithDefault("WARN")
Level level();

/**
* Number of log events sent to CloudWatch per batch.
* Defaults to 10,000 which is the maximum number of log events per batch allowed by CloudWatch.
*/
@ConfigItem(defaultValue = "10000")
public int batchSize;
@WithDefault("10000")
int batchSize();

/**
* Period between two batch executions.
* Defaults to 5 seconds.
*/
@ConfigItem(defaultValue = "5s")
public Duration batchPeriod;
@WithDefault("5s")
Duration batchPeriod();

/**
* Maximum size of the log events queue.
* If this is not set, the queue will have a capacity of {@link Integer#MAX_VALUE}.
*/
@ConfigItem
public Optional<Integer> maxQueueSize;
@WithName("max-queue-size")
Optional<Integer> maxQueueSize();

/**
* Service environment added as a {@code service.environment} field to each log record when available.
*/
@ConfigItem
public Optional<String> serviceEnvironment;
@WithName("service-environment")
Optional<String> serviceEnvironment();

/**
* Amount of time to allow the CloudWatch client to complete the execution of an API call. This timeout covers the
* entire client execution except for marshalling. This includes request handler execution, all HTTP requests
* including retries, unmarshalling, etc. This value should always be positive, if present.
*/
@ConfigItem
public Optional<Duration> apiCallTimeout;
@WithName("api-call-timeout")
Optional<Duration> apiCallTimeout();

/**
* Default credentials provider enabled added as a {@code quarkus.log.cloudwatch.default-credentials-provider.enabled}
*/
@ConfigItem(name = "default-credentials-provider.enabled", defaultValue = "false")
public boolean defaultCredentialsProviderEnabled;
@WithName("default-credentials-provider.enabled")
@WithDefault("false")
boolean defaultCredentialsProviderEnabled();

/**
* Endpoint override added as {@code endpoint-override}
*/
@ConfigItem(name = "endpoint-override")
public Optional<String> endpointOverride;
@WithName("endpoint-override")
Optional<String> endpointOverride();

/*
* We need to validate that the values are present, even if marked as optional.
* We need to mark them as optional, as otherwise the config would mark them
* as bad even before the extension can check if the values are needed at all.
*/
public List<String> validate() {
default List<String> validate() {
List<String> errors = new ArrayList<>();
if (!defaultCredentialsProviderEnabled) {
if (accessKeyId.isEmpty()) {
if (!defaultCredentialsProviderEnabled()) {
if (accessKeyId().isEmpty()) {
errors.add("quarkus.log.cloudwatch.access-key-id");
}
if (accessKeySecret.isEmpty()) {
if (accessKeySecret().isEmpty()) {
errors.add("quarkus.log.cloudwatch.access-key-secret");
}
}
if (region.isEmpty()) {
if (region().isEmpty()) {
errors.add("quarkus.log.cloudwatch.region");
}
if (logGroup.isEmpty()) {
if (logGroup().isEmpty()) {
errors.add("quarkus.log.cloudwatch.log-group");
}
if (logStreamName.isEmpty()) {
if (logStreamName().isEmpty()) {
errors.add("quarkus.log.cloudwatch.log-stream-name");
}
return errors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class LoggingCloudWatchHandlerValueFactory {
private static final Logger LOGGER = Logger.getLogger(LoggingCloudWatchHandlerValueFactory.class);

public RuntimeValue<Optional<Handler>> create(final LoggingCloudWatchConfig config) {
if (!config.enabled) {
if (!config.enabled()) {
LOGGER.info("Quarkus Logging Cloudwatch Extension is not enabled");
return new RuntimeValue<>(Optional.empty());
}
Expand All @@ -62,27 +62,27 @@ public RuntimeValue<Optional<Handler>> create(final LoggingCloudWatchConfig conf
}
}

LOGGER.infof("Logging to log-group: %s and log-stream: %s", config.logGroup.get(), config.logStreamName.get());
LOGGER.infof("Logging to log-group: %s and log-stream: %s", config.logGroup().get(), config.logStreamName().get());

CloudWatchLogsClientBuilder cloudWatchLogsClientBuilder = CloudWatchLogsClient.builder()
.credentialsProvider(new CloudWatchCredentialsProvider(config))
.region(Region.of(config.region.get()));
if (config.apiCallTimeout.isPresent()) {
.region(Region.of(config.region().get()));
if (config.apiCallTimeout().isPresent()) {
cloudWatchLogsClientBuilder = cloudWatchLogsClientBuilder.overrideConfiguration(
ClientOverrideConfiguration.builder().apiCallTimeout(config.apiCallTimeout.get()).build());
ClientOverrideConfiguration.builder().apiCallTimeout(config.apiCallTimeout().get()).build());
}
if (config.endpointOverride.isPresent()) {
cloudWatchLogsClientBuilder.endpointOverride(URI.create(config.endpointOverride.get()));
if (config.endpointOverride().isPresent()) {
cloudWatchLogsClientBuilder.endpointOverride(URI.create(config.endpointOverride().get()));
}

CloudWatchLogsClient cloudWatchLogsClient = cloudWatchLogsClientBuilder.build();

String token = createLogStreamIfNeeded(cloudWatchLogsClient, config);

LoggingCloudWatchHandler handler = new LoggingCloudWatchHandler(cloudWatchLogsClient, config.logGroup.get(),
config.logStreamName.get(), token, config.maxQueueSize, config.batchSize, config.batchPeriod,
config.serviceEnvironment);
handler.setLevel(config.level);
LoggingCloudWatchHandler handler = new LoggingCloudWatchHandler(cloudWatchLogsClient, config.logGroup().get(),
config.logStreamName().get(), token, config.maxQueueSize(), config.batchSize(), config.batchPeriod(),
config.serviceEnvironment());
handler.setLevel(config.level());

return new RuntimeValue<>(Optional.of(handler));
}
Expand All @@ -91,24 +91,24 @@ private String createLogStreamIfNeeded(CloudWatchLogsClient cloudWatchLogsClient
String token = null;

DescribeLogStreamsRequest describeLogStreamsRequest = DescribeLogStreamsRequest.builder()
.logGroupName(config.logGroup.get())
.logGroupName(config.logGroup().get())
// We need to filter down, as CW returns by default only 50 streams and ours may not be in it.
.logStreamNamePrefix(config.logStreamName.get())
.logStreamNamePrefix(config.logStreamName().get())
.build();
List<LogStream> logStreams = cloudWatchLogsClient.describeLogStreams(describeLogStreamsRequest).logStreams();

boolean found = false;
for (LogStream ls : logStreams) {
if (ls.logStreamName().equals(config.logStreamName.get())) {
if (ls.logStreamName().equals(config.logStreamName().get())) {
found = true;
token = ls.uploadSequenceToken();
}
}

if (!found) {
CreateLogStreamRequest createLogStreamRequest = CreateLogStreamRequest.builder()
.logGroupName(config.logGroup.get())
.logStreamName(config.logStreamName.get())
.logGroupName(config.logGroup().get())
.logStreamName(config.logStreamName().get())
.build();
cloudWatchLogsClient.createLogStream(createLogStreamRequest);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class CloudWatchCredentials implements AwsCredentials {

@Override
public String accessKeyId() {
return config.accessKeyId.get();
return config.accessKeyId().get();
}

@Override
public String secretAccessKey() {
return config.accessKeySecret.get();
return config.accessKeySecret().get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public CloudWatchCredentialsProvider(LoggingCloudWatchConfig config) {

@Override
public AwsCredentials resolveCredentials() {
return config.defaultCredentialsProviderEnabled ? DefaultCredentialsProvider.create().resolveCredentials()
return config.defaultCredentialsProviderEnabled() ? DefaultCredentialsProvider.create().resolveCredentials()
: new CloudWatchCredentials(config);
}
}

This file was deleted.

Loading

0 comments on commit f1eba1d

Please sign in to comment.