Skip to content

Commit

Permalink
fix: backport Spring Boot 3.2 compatibility updates to Spring Cloud G…
Browse files Browse the repository at this point in the history
…CP 4.x (#2397)

* feat: Spring Boot 3.2 compatibility (#2319)

* deps: spring cloud 2023.0.0-M2 and spring boot 3.2.0-RC1

* fix: SpannerCompositeKeyProperty implements isReadable

* fix: PubSubHealthIndicatorAutoConfiguration uses indicator factory injection

* fix: SpannerHealthIndicatorAutoConfiguration uses indicator factory injection

* chore: add PubSubSubscriptionHealthIndicatorAutoConfigurationTests

* fix: PubSubSubscriptionHealthIndicatorAutoConfiguration explicitly does not support indicator creation

* fix: Remove @OverRide from SpannerCompositeKeyProperty.isReadable

* fix: PubSubSubscriptionHealthIndicatorAutoConfiguration generics changed

* chore: Test PubSubSubscriptionHealthIndicatorAutoConfiguration

* fix: imports

* fix: GqlDatastoreQuery isPaged logic

* chore: maintain spring boot 3.1.5 dependency after 3.2.x compatibility updates

* fix: use mock MetricServiceClient in test

* chore: formatting
  • Loading branch information
burkedavison authored Dec 4, 2023
1 parent 325f513 commit a640b75
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@
<name>Apache License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
<comments>
Copyright 2015-2022 the original author or authors.
Copyright 2015-2023 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@
public class PubSubHealthIndicatorAutoConfiguration
extends CompositeHealthContributorConfiguration<PubSubHealthIndicator, PubSubTemplate> {

private PubSubHealthIndicatorProperties pubSubHealthProperties;

public PubSubHealthIndicatorAutoConfiguration(
PubSubHealthIndicatorProperties pubSubHealthProperties) {
this.pubSubHealthProperties = pubSubHealthProperties;
super(pubSubTemplate ->
new PubSubHealthIndicator(
pubSubTemplate,
pubSubHealthProperties.getSubscription(),
pubSubHealthProperties.getTimeoutMillis(),
pubSubHealthProperties.isAcknowledgeMessages()));
}

@Bean
Expand All @@ -62,13 +65,4 @@ public HealthContributor pubSubHealthContributor(Map<String, PubSubTemplate> pub
Assert.notNull(pubSubTemplates, "pubSubTemplates must be provided");
return createContributor(pubSubTemplates);
}

@Override
protected PubSubHealthIndicator createIndicator(PubSubTemplate pubSubTemplate) {
return new PubSubHealthIndicator(
pubSubTemplate,
this.pubSubHealthProperties.getSubscription(),
this.pubSubHealthProperties.getTimeoutMillis(),
this.pubSubHealthProperties.isAcknowledgeMessages());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.cloud.spring.autoconfigure.pubsub.GcpPubSubAutoConfiguration;
import com.google.cloud.spring.autoconfigure.pubsub.GcpPubSubProperties;
import com.google.cloud.spring.core.GcpProjectIdProvider;
import com.google.cloud.spring.pubsub.core.PubSubTemplate;
import com.google.cloud.spring.pubsub.core.health.HealthTrackerRegistry;
import com.google.cloud.spring.pubsub.core.health.HealthTrackerRegistryImpl;
import java.io.IOException;
Expand All @@ -46,20 +45,22 @@
@ConditionalOnClass({HealthIndicator.class, MetricServiceClient.class})
@ConditionalOnEnabledHealthIndicator("pubsub-subscriber")
@ConditionalOnProperty({
"spring.cloud.gcp.pubsub.health.lagThreshold",
"spring.cloud.gcp.pubsub.health.backlogThreshold"
"spring.cloud.gcp.pubsub.health.lagThreshold",
"spring.cloud.gcp.pubsub.health.backlogThreshold"
})
@AutoConfigureBefore(GcpPubSubAutoConfiguration.class)
@EnableConfigurationProperties(GcpPubSubProperties.class)
public class PubSubSubscriptionHealthIndicatorAutoConfiguration
extends CompositeHealthContributorConfiguration<PubSubHealthIndicator, PubSubTemplate> {
extends
CompositeHealthContributorConfiguration<PubSubSubscriptionHealthIndicator, HealthTrackerRegistry> {

private final GcpPubSubProperties gcpPubSubProperties;

private final String projectId;

public PubSubSubscriptionHealthIndicatorAutoConfiguration(
GcpPubSubProperties gcpPubSubProperties, GcpProjectIdProvider projectIdProvider) {
super(PubSubSubscriptionHealthIndicator::new);
this.projectId =
(gcpPubSubProperties.getProjectId() != null)
? gcpPubSubProperties.getProjectId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
import org.springframework.util.Assert;

/**
* {@link HealthContributorAutoConfiguration Auto-configuration} for {@link SpannerHealthIndicator}.
* {@link HealthContributorAutoConfiguration Auto-configuration} for
* {@link SpannerHealthIndicator}.
*
* @since 2.0.6
*/
Expand All @@ -49,11 +50,12 @@
public class SpannerHealthIndicatorAutoConfiguration
extends CompositeHealthContributorConfiguration<SpannerHealthIndicator, SpannerTemplate> {

private SpannerHealthIndicatorProperties spannerHealthProperties;

public SpannerHealthIndicatorAutoConfiguration(
SpannerHealthIndicatorProperties spannerHealthProperties) {
this.spannerHealthProperties = spannerHealthProperties;
super(spannerTemplate ->
new SpannerHealthIndicator(
spannerTemplate,
spannerHealthProperties.getQuery()));
}

@Bean
Expand All @@ -62,9 +64,4 @@ public HealthContributor spannerHealthContributor(Map<String, SpannerTemplate> s
Assert.notNull(spannerTemplates, "SpannerTemplates must be provided");
return createContributor(spannerTemplates);
}

@Override
protected SpannerHealthIndicator createIndicator(SpannerTemplate spannerTemplate) {
return new SpannerHealthIndicator(spannerTemplate, this.spannerHealthProperties.getQuery());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2018-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.spring.autoconfigure.pubsub.health;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;

import com.google.api.gax.core.CredentialsProvider;
import com.google.auth.Credentials;
import com.google.cloud.monitoring.v3.MetricServiceClient;
import com.google.cloud.spring.autoconfigure.pubsub.GcpPubSubAutoConfiguration;
import com.google.cloud.spring.core.GcpProjectIdProvider;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;

/**
* Tests for Pub/Sub Health Indicator autoconfiguration.
*/
class PubSubSubscriptionHealthIndicatorAutoConfigurationTests {

private final ApplicationContextRunner contextRunner =
new ApplicationContextRunner()
.withConfiguration(
AutoConfigurations.of(
PubSubSubscriptionHealthIndicatorAutoConfiguration.class,
GcpPubSubAutoConfiguration.class))
.withBean(GcpProjectIdProvider.class, () -> () -> "fake project")
.withBean(CredentialsProvider.class, () -> () -> mock(Credentials.class))
.withBean(MetricServiceClient.class, () -> mock(MetricServiceClient.class));

@Test
void healthIndicatorPresent_defaults() {
this.contextRunner
.withPropertyValues(
"spring.cloud.gcp.pubsub.health.lagThreshold=1",
"spring.cloud.gcp.pubsub.health.backlogThreshold=1")
.run(ctx -> assertThat(ctx).hasSingleBean(PubSubSubscriptionHealthIndicator.class));
}

@Test
void healthIndicatorNotPresent_whenDisabled() {
this.contextRunner
.withPropertyValues(
"management.health.pubsub-subscriber.enabled:false",
"spring.cloud.gcp.pubsub.health.lagThreshold=1",
"spring.cloud.gcp.pubsub.health.backlogThreshold=1")
.run(ctx -> assertThat(ctx).doesNotHaveBean(PubSubSubscriptionHealthIndicator.class));
}

@Test
void healthIndicatorNotPresent_whenMissingLagThreshold() {
this.contextRunner
.withPropertyValues(
"spring.cloud.gcp.pubsub.health.backlogThreshold=1")
.run(ctx -> assertThat(ctx).doesNotHaveBean(PubSubSubscriptionHealthIndicator.class));
}

@Test
void healthIndicatorNotPresent_whenMissingBacklogThreshold() {
this.contextRunner
.withPropertyValues(
"spring.cloud.gcp.pubsub.health.lagThreshold=1")
.run(ctx -> assertThat(ctx).doesNotHaveBean(PubSubSubscriptionHealthIndicator.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ private class ParsedQueryWithTagsAndValues {

this.noLimitQuery = this.finalGql;
Pageable pageable = paramAccessor.getPageable();
if (!pageable.equals(Pageable.unpaged())) {
if (pageable.isPaged()) {
this.finalGql += LIMIT_CLAUSE;
this.tagsOrdered.add(LIMIT_TAG_NAME);
this.limitPosition = this.params.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ public boolean isTransient() {
return false;
}

public boolean isReadable() {
return true;
}

@Override
public boolean isWritable() {
return false;
Expand Down

0 comments on commit a640b75

Please sign in to comment.