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

Migrate Blazegraph module to Cats Effect #4478

Merged
merged 11 commits into from
Nov 8, 2023

Conversation

dantb
Copy link
Contributor

@dantb dantb commented Nov 8, 2023

Fixes #4432 and #4476

Sorry for the size, I started with just the client and followed the compiler - ended up doing the whole module

@dantb dantb changed the title Migrate Blazegraph client Migrate Blazegraph module Nov 8, 2023
@dantb dantb changed the title Migrate Blazegraph module Migrate Blazegraph module to Cats Effect Nov 8, 2023
shinyhappydan
shinyhappydan previously approved these changes Nov 8, 2023
Comment on lines +27 to +32
def timed[A](io: IO[A])(implicit c: Clock[IO]): IO[(A, FiniteDuration)] =
for {
start <- c.monotonic(MILLISECONDS)
result <- io
finish <- c.monotonic(MILLISECONDS)
} yield (result, (finish - start).millis)
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably worth a test

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'm reluctant since it's essentially copied stdlib code which you wouldn't normally test... Kinda covered in those slow query tests as well

Copy link
Contributor

Choose a reason for hiding this comment

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

I think copied code is still worth testing if we rely on it. Tests are there to make sure it works going forward as well as now. It should be super easy to write

@@ -135,7 +138,7 @@ class BlazegraphClient(
count <- countAsString.value.toLongOption
} yield count

IO.fromOption(count, InvalidCountRequest(index, sparqlQuery.value))
IO.fromOption(count)(InvalidCountRequest(index, sparqlQuery.value))
Copy link
Contributor

Choose a reason for hiding this comment

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

I will never forgive the Cats authors for this method signature

val queryString = queries.map(_.value).mkString("\n")
val pss = new ParameterizedSparqlString
pss.setCommandText(queryString)
for {
_ <- IO.fromTry(Try(pss.asUpdate())).mapError(th => InvalidUpdateRequest(index, queryString, th.getMessage))
_ <- IO(pss.asUpdate()).adaptError(e => InvalidUpdateRequest(index, queryString, e.getMessage))
Copy link
Contributor

Choose a reason for hiding this comment

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

If .apply is the same as .delay, we probably want to decide which one to use. I know most existing code would use delay

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'd go for apply, and not just because fewer characters 😛 it follows the same pattern as Try and Future

Copy link
Contributor

Choose a reason for hiding this comment

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

Personally I like the explicit nature and consistency with .pure that .delay has. But it's probably a team decision

.when(duration >= longQueryThreshold)(logSlowQuery(context, outcome.isLeft, duration))
def apply[A](context: BlazegraphQueryContext, query: IO[A]): IO[A] = {
IOInstant
.timed(query.attempt)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you have an implicit class method for this now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In your PR or somewhere else?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I thought .timed was an implicitly added method. Maybe it could be?

Comment on lines 52 to 53
IOInstant.now
.flatTap(_ => logger.warn(s"Slow blazegraph query recorded: duration '$duration', view '${context.view}'"))
Copy link
Contributor

Choose a reason for hiding this comment

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

I realise you're just doing the same as before, but it's a bit weird to flatTap when you aren't interested in the value. Maybe just the log >> Instant.now?

imsdu
imsdu previously approved these changes Nov 8, 2023
@dantb dantb dismissed stale reviews from imsdu and shinyhappydan via af84486 November 8, 2023 13:26
shinyhappydan
shinyhappydan previously approved these changes Nov 8, 2023
@dantb dantb merged commit 33cf07d into BlueBrain:master Nov 8, 2023
5 checks passed
@dantb dantb deleted the migrate-bg-client branch November 9, 2023 08:48
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.

Migrate Blazegraph client to CatsEffect
3 participants