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

INC-1064: update to DPS Gradle Plugin v5 which includes Spring Boot v3 and AWS SDK v2 #407

Merged
merged 9 commits into from
Apr 6, 2023

Conversation

neilmendum
Copy link
Contributor

@neilmendum neilmendum changed the title INC-1064: update to DPS Gradle Plugin 5 which includes Spring Boot v3 and AWS SDK v2 INC-1064: update to DPS Gradle Plugin v5 which includes Spring Boot v3 and AWS SDK v2 Apr 6, 2023
@@ -10,7 +10,7 @@ import org.springframework.security.web.server.SecurityWebFilterChain

@Configuration
@EnableWebFluxSecurity
@EnableReactiveMethodSecurity
@EnableReactiveMethodSecurity(useAuthorizationManager = false)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -6,6 +6,9 @@
"service.version": "${BUILD_NUMBER}"
},
"instrumentation": {
"springScheduling": {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

microsoft/ApplicationInsights-Java#2870 (comment) – can’t tell if this is still required to throttle app insights logging?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good spot! Removed with be9b7a0

@@ -17,14 +17,19 @@ configurations {
testImplementation { exclude(group = "org.junit.vintage") }
}

repositories {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -768,7 +768,7 @@ class IepLevelResourceTest : IncentiveLevelResourceTestBase() {
}""",
)
.exchange()
.expectErrorResponse(HttpStatus.BAD_REQUEST, "Invalid parameters: `iepLevel` must have length of at most 6")
.expectErrorResponse(HttpStatus.BAD_REQUEST, "Parameter conversion failure: 400 BAD_REQUEST \"Failed to read HTTP message\"")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a funny one - putting a debug break point on HmppsIncentivesApiExceptionHandlerhandleServerWebInputException the e.cause is

org.springframework.core.codec.DecodingException:
  JSON decoding error:
    Cannot construct instance of `uk.gov.justice.digital.hmpps.incentivesapi.dto.SyncPostRequest`,
      problem: Invalid parameters: `iepLevel` must have length of at most 6

I'm not entirely sure why it now drops into there, rather than handleParameterValidationException which it previously used to do, perhaps because a change to jakarta.validation.ValidationException 🤔 Do folks think it's worth investigating further?

Copy link
Contributor

Choose a reason for hiding this comment

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

i would like to look into it. we should either assert that the "cause" still has the right message, or (if not too tough) make the right exception bubble up

Copy link
Contributor Author

Choose a reason for hiding this comment

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

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

/**
* Application insights now controlled by the spring-boot-starter dependency. However when the key is not specified
* we don't get a telemetry bean and application won't start. Therefore need this backup configuration.
* TelemetryClient gets altered at runtime by the java agent and so is a no-op otherwise
Copy link
Contributor Author

Choose a reason for hiding this comment

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

dependencies {
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.springframework.boot:spring-boot-starter-data-r2dbc")
implementation("org.springframework.boot:spring-boot-starter-oauth2-resource-server")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-oauth2-client")

implementation("uk.gov.justice.service.hmpps:hmpps-sqs-spring-boot-starter:1.2.0")
implementation("uk.gov.justice.service.hmpps:hmpps-sqs-spring-boot-starter:2.0.0-beta-14")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

import uk.gov.justice.digital.hmpps.incentivesapi.jpa.IncentiveLevel
import uk.gov.justice.digital.hmpps.incentivesapi.jpa.PrisonIncentiveLevel
import uk.gov.justice.digital.hmpps.incentivesapi.jpa.repository.IncentiveLevelRepository
import uk.gov.justice.digital.hmpps.incentivesapi.jpa.repository.PrisonIncentiveLevelRepository
import uk.gov.justice.digital.hmpps.incentivesapi.service.AuditEvent
import uk.gov.justice.digital.hmpps.incentivesapi.service.HMPPSDomainEvent
import uk.gov.justice.digital.hmpps.incentivesapi.service.HMPPSMessage
import uk.gov.justice.hmpps.sqs.countMessagesOnQueue
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was added with ministryofjustice/hmpps-spring-boot-sqs#122 so removed our function AmazonSQS.getApproxQueueSize

import uk.gov.justice.digital.hmpps.incentivesapi.integration.LocalStackContainer.setLocalStackProperties
import uk.gov.justice.hmpps.sqs.HmppsQueue
import uk.gov.justice.hmpps.sqs.HmppsQueueService
import uk.gov.justice.hmpps.sqs.HmppsSqsProperties
import uk.gov.justice.hmpps.sqs.MissingQueueException
import uk.gov.justice.hmpps.sqs.MissingTopicException
import uk.gov.justice.hmpps.sqs.countMessagesOnQueue
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was added with ministryofjustice/hmpps-spring-boot-sqs#122 so removed our function getNumberOfMessagesCurrentlyOnQueue

@@ -16,7 +16,7 @@ class PrisonOffenderEventListener(
val log: Logger = LoggerFactory.getLogger(this::class.java)
}

@JmsListener(destination = "incentives", containerFactory = "hmppsQueueContainerFactoryProxy")
@SqsListener("incentives", factory = "hmppsQueueContainerFactoryProxy")
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 spotted ministryofjustice/hmpps-prisoner-to-nomis-update#164 - which we could also include if folks think it would be helpful?

Copy link
Contributor

Choose a reason for hiding this comment

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

not a bad idea. maybe we can do that in a separate pr as there are probs other methods that would benefit with span annotations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@neilmendum neilmendum marked this pull request as ready for review April 6, 2023 11:43
@neilmendum neilmendum requested a review from a team as a code owner April 6, 2023 11:43
@@ -6,6 +6,9 @@
"service.version": "${BUILD_NUMBER}"
},
"instrumentation": {
"springScheduling": {
Copy link
Contributor

Choose a reason for hiding this comment

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

microsoft/ApplicationInsights-Java#2870 (comment) – can’t tell if this is still required to throttle app insights logging?

@@ -13,7 +13,7 @@ import io.swagger.v3.oas.models.security.Scopes
import io.swagger.v3.oas.models.security.SecurityRequirement
import io.swagger.v3.oas.models.security.SecurityScheme
import io.swagger.v3.oas.models.servers.Server
import org.springdoc.core.customizers.OpenApiCustomiser
import org.springdoc.core.customizers.OpenApiCustomizer
Copy link
Contributor

Choose a reason for hiding this comment

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

😒

@@ -16,7 +16,7 @@ class PrisonOffenderEventListener(
val log: Logger = LoggerFactory.getLogger(this::class.java)
}

@JmsListener(destination = "incentives", containerFactory = "hmppsQueueContainerFactoryProxy")
@SqsListener("incentives", factory = "hmppsQueueContainerFactoryProxy")
Copy link
Contributor

Choose a reason for hiding this comment

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

not a bad idea. maybe we can do that in a separate pr as there are probs other methods that would benefit with span annotations

@@ -59,7 +59,7 @@ class JwtAuthHelper {
.setSubject(subject)
.addClaims(it.toMap())
.setExpiration(Date(System.currentTimeMillis() + expiryTime.toMillis()))
.signWith(SignatureAlgorithm.RS256, keyPair.private)
.signWith(keyPair.private, SignatureAlgorithm.RS256)
Copy link
Contributor

Choose a reason for hiding this comment

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

🤣

@@ -768,7 +768,7 @@ class IepLevelResourceTest : IncentiveLevelResourceTestBase() {
}""",
)
.exchange()
.expectErrorResponse(HttpStatus.BAD_REQUEST, "Invalid parameters: `iepLevel` must have length of at most 6")
.expectErrorResponse(HttpStatus.BAD_REQUEST, "Parameter conversion failure: 400 BAD_REQUEST \"Failed to read HTTP message\"")
Copy link
Contributor

Choose a reason for hiding this comment

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

i would like to look into it. we should either assert that the "cause" still has the right message, or (if not too tough) make the right exception bubble up

@@ -134,7 +134,7 @@ class IncentiveReviewsResourceTest : IncentiveLevelResourceTestBase() {
.uri("/incentives-reviews/prison/MDI/location/MDI-1/level/STD?sort=PRISON")
.headers(setAuthorisation(roles = listOf("ROLE_INCENTIVES")))
.exchange()
.expectErrorResponse(HttpStatus.BAD_REQUEST, "No enum constant")
.expectErrorResponse(HttpStatus.BAD_REQUEST, "Parameter conversion failure: 400 BAD_REQUEST \"Type mismatch.\"")
Copy link
Contributor

Choose a reason for hiding this comment

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

if "No enum constant" doesn't appear anywhere including the "cause", then this seems reasonable. though i'd only search for "Type mismatch".

related to https://github.com/ministryofjustice/hmpps-incentives-api/pull/407/files#r1159704464

ushkarev
ushkarev previously approved these changes Apr 6, 2023
Copy link
Contributor

@ushkarev ushkarev left a comment

Choose a reason for hiding this comment

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

happy to approve, but i would like to re-evaluate that exception testing to see if it can assert for the right message. or you can if you have an idea how to :)

@neilmendum neilmendum merged commit 53e5b48 into main Apr 6, 2023
@neilmendum neilmendum deleted the spring-3 branch April 6, 2023 12:55
assertThat(queueSize).isEqualTo(0)
}

protected fun assertDomainEventSent(eventType: String): HMPPSDomainEvent {
val sqsClient = incentivesQueue.sqsClient
val queueSize = sqsClient.getApproxQueueSize(testDomainEventQueueUrl!!)
assertThat(queueSize).isEqualTo(1)
await untilCallTo { sqsClient.countMessagesOnQueue(testDomainEventQueueUrl!!).get() } matches { it == 1 }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this, and other awaits, because was finding tests were consistently failing

Assumed it was because we're now using software.amazon.awssdk.services.sqs.SqsAsyncClient (via uk.gov.justice.service.hmpps:hmpps-sqs-spring-boot-starter:2.0.0-beta-14) whereas previously we were using the synchronous class com.amazonaws.services.sqs.AmazonSQS

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.

2 participants