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 zuora auth logging so we can debug failures easily #192

Merged
merged 2 commits into from
Oct 2, 2023

Conversation

johnduffell
Copy link
Member

@johnduffell johnduffell commented Oct 2, 2023

There's an exception in initialiser error in CODE for zuora auth and we can't work out why it doesn't work.

This logging should tell us more about the interaction with zuora.

Logging looks something like this in DEV locally (I've replaced all ids with 1234)

Oct 02, 2023 2:35:32 PM com.gu.invoicing.common.ZuoraAuth$ com$gu$invoicing$common$ZuoraAuth$$getAccessToken
INFO: Authenticating with Zuora on https://rest.apisandbox.zuora.com/oauth/token with client ID ending in: ...1234
Oct 02, 2023 2:35:33 PM com.gu.invoicing.common.ZuoraAuth$ $anonfun$getAccessToken$1
INFO: {"access_token":"***REDACTED***","token_type":"bearer","expires_in":1234,"scope":"service.usage.write tenant.1234 entity.1234-1234-1234-1234-1234 service.usage.update platform.write user.1234 service.usage.delete","jti":"1234"}

@@ -36,7 +36,10 @@ object ZuoraAuth extends JsonSupport {
*/
var accessToken: String = _
private def getAccessToken(): String = {
Http(s"$zuoraApiHost/oauth/token")
val logger = java.util.logging.Logger.getGlobal
Copy link
Member Author

Choose a reason for hiding this comment

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

this is what it uses elsewhere in this lambda

.pipe(read[AccessToken](_))
.access_token
}
private val timer = new Timer()
private val timer = new Timer(true)
Copy link
Member Author

Choose a reason for hiding this comment

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

makes this timer a daemon, meaning it doesn't keep the JVM running when the main thread has terminated
https://docs.oracle.com/javase/8/docs/api/java/util/Timer.html#Timer-boolean-

.foreach(token => accessToken = token)
}
},
0,
5 * 60 * 1000, // refresh token every 5 min
five_minutes, // wait 5 mins for first refresh
Copy link
Member Author

Choose a reason for hiding this comment

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

I noticed it was doing a double auth on startup.
the attempt below happens on app startup, so the initial delay should have been 5 minutes.
original PR it's not mentioned and was probably not considered #16

@@ -35,8 +35,11 @@ object ZuoraAuth extends JsonSupport {
* again. Hence now we periodically refreshes the token (making it def would have performance penalty)
*/
var accessToken: String = _
private def getAccessToken(): String = {
Http(s"$zuoraApiHost/oauth/token")
private def getAccessToken: String = {
Copy link
Member Author

Choose a reason for hiding this comment

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

empty brackets was a warning in intellij

@johnduffell johnduffell merged commit cfcbdd4 into main Oct 2, 2023
2 checks passed
@johnduffell johnduffell deleted the jd-auth-logging branch October 2, 2023 14:01
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