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

Merge plugins #43

Merged
merged 14 commits into from
May 28, 2020
Merged

Merge plugins #43

merged 14 commits into from
May 28, 2020

Conversation

ememmr
Copy link

@ememmr ememmr commented May 20, 2020

Copy link
Member

@BenFradet BenFradet left a comment

Choose a reason for hiding this comment

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

👍


lazy val muSrcGenCompendiumServerPort: SettingKey[Int] =
settingKey[Int]("Port of the compendium server")

Copy link
Member

Choose a reason for hiding this comment

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

suggestion: I think it worth specifying what are the default values for every new setting. Thoughts?

Copy link
Author

Choose a reason for hiding this comment

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

I have to update documentation too, which has (or should have) the default values. But it's not a bad idea

@@ -17,6 +17,7 @@ object ProjectPlugin extends AutoPlugin {
lazy val V = new {
val avrohugger: String = "1.0.0-RC22"
val circe: String = "0.13.0"
val hammock = "0.10.0"
Copy link
Member

@juanpedromoreno juanpedromoreno May 22, 2020

Choose a reason for hiding this comment

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

Hammock 0.10.0 is bringing circe 0.12.1, as you can see here. However, that will provoke a collision with the circe version we are using in this build: 0.13.0.

My suggestion would be using an http4s client, as it is evolving at the same time as typelevel ecosystem does. The other option would be to work on Hammock and try to make it updated and released with the latest dependency versions.

Copy link
Author

Choose a reason for hiding this comment

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

ready, please take a look @juanpedromoreno

@ememmr ememmr marked this pull request as ready for review May 26, 2020 08:01
@ememmr ememmr requested a review from juanpedromoreno May 26, 2020 08:01
@@ -25,6 +25,7 @@ object ProjectPlugin extends AutoPlugin {
val scalatestplusScheck: String = "3.1.0.0-RC2"
val skeuomorph: String = "0.0.23"
val slf4j: String = "1.7.30"
val http4s: String = "0.21.1"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
val http4s: String = "0.21.1"
val http4s: String = "0.21.4"

Copy link
Author

Choose a reason for hiding this comment

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

I'll put all the changes in the same commit

F: Sync[F]
def apply[F[_]: Sync](
clientF: Client[F],
clientConfig: HttpConfig
): CompendiumClient[F] =
new CompendiumClient[F] {

val baseUrl: String = s"http://${clientConfig.host}:${clientConfig.port}"
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: I'd parametrize the http part of the Url (it could be https).

Copy link
Contributor

Choose a reason for hiding this comment

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

Or merge both in a single property called "connectionUrl" or something like that

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I would put the whole URL, including the port number, into a single property (connectionUrl? serverUrl?). Fewer things for the user to configure, and no assumptions about how they want to host the server.

Copy link
Author

Choose a reason for hiding this comment

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

for now, it could be merged. It was split because we had, at least, two endpoints to call.

So, does this work for both of you?

val versionParam = version.fold("")(v => s"?version=${v.show}")
        val connectionUrl = s"https://${clientConfig.host}:${clientConfig.port}/v0/protocol/$identifier$versionParam"

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I wasn't very clear. My suggestion was to have the server's base URL (e.g. https://devtools.mycorp.com:1234/compendium) passed in as a single property inside HttpConfig. Inside this method we would construct the full URL:

val connectionUrl = s"${clientConfig.serverUrl}/v0/protocol/$identifier$versionParam"

case Status.OK => request.as[RawProtocol].map(Option(_)).exec[F]
clientF.get(uri)(res =>
res.status match {
case Status.Ok => res.as[RawProtocol].map(Option(_))
case Status.NotFound => Sync[F].pure(None)
Copy link
Member

Choose a reason for hiding this comment

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

question: If something is not found, it worth to notify the user?

Copy link
Author

Choose a reason for hiding this comment

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

With the current development, it raises an error:

case None =>
              Async[F].raiseError[File](
                ProtocolNotFound(s"Protocol ${protocolAndVersion.name} not found in Compendium. ")
              )

on run function

Copy link
Member

Choose a reason for hiding this comment

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

I think it makes sense to just return None at this point, because we are just an HTTP client and we don't know what we are being used for. It's pretty reasonable to try to get a resource which might not exist, so it's not an exceptional circumstance.

Whoever is using the client can decide whether a missing resource should be an error or not.


final case class ProtocolAndVersion(name: String, version: Option[String])
final case class FilePrintWriter(file: File, pw: PrintWriter)

case class CompendiumMode[F[_]: Async](
case class CompendiumMode[F[_]: Async: ConcurrentEffect](
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
case class CompendiumMode[F[_]: Async: ConcurrentEffect](
final case class CompendiumMode[F[_]: ConcurrentEffect](

@@ -1,46 +1,52 @@
package higherkindness.mu.rpc.srcgen.compendium

import java.io.{File, PrintWriter}
import cats.effect.{Async, Resource, Sync}

import cats.effect.{Async, ConcurrentEffect, Resource, Sync}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
import cats.effect.{Async, ConcurrentEffect, Resource, Sync}
import cats.effect.{Resource, ConcurrentEffect}

I think you have a mix of effects here, but I believe that you are just requesting ConcurrentEffect for the client resource usage.

path = path
)
case None =>
Async[F].raiseError[File](
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Async[F].raiseError[File](
ConcurrentEffect[F].raiseError[File](

)
}
} yield file
})
Copy link
Member

Choose a reason for hiding this comment

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

You will need to replace the Sync[F] below by ConcurrentEffect[F] (writeTempFile function).

* @param version optional protocol version number
* @return a protocol
*/
def retrieveProtocol(identifier: String, version: Option[Int]): F[Option[RawProtocol]]
Copy link
Member

Choose a reason for hiding this comment

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

Should we make the version a String or something, in anticipation of higherkindness/compendium#284 ?

)

lazy val muSrcGenCompendiumServerUrl: SettingKey[String] =
settingKey[String]("Url of the compendium server. By default, `http://localhost:47047`.")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
settingKey[String]("Url of the compendium server. By default, `http://localhost:47047`.")
settingKey[String]("Url of the compendium server. By default, `https://localhost:47047`.")

@@ -17,13 +17,15 @@ object ProjectPlugin extends AutoPlugin {
lazy val V = new {
val avrohugger: String = "1.0.0-RC22"
val circe: String = "0.13.0"
val hammock = "0.10.0"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
val hammock = "0.10.0"

muSrcGenStreamingImplementation := Fs2Stream,
muSrcGenExecutionMode := Local,
muSrcGenCompendiumProtocolIdentifiers := Nil,
muSrcGenCompendiumServerUrl := "https://localhost:47047"
Copy link
Member

Choose a reason for hiding this comment

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

Is the server likely to use HTTPS if it's running on localhost?

Copy link
Author

Choose a reason for hiding this comment

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

ok, just checked aaaand nop. At least not by default 😞

)

lazy val muSrcGenCompendiumServerUrl: SettingKey[String] =
settingKey[String]("Url of the compendium server. By default, `https://localhost:47047`.")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
settingKey[String]("Url of the compendium server. By default, `https://localhost:47047`.")
settingKey[String]("Url of the compendium server. By default, `http://localhost:47047`.")

muSrcGenStreamingImplementation := Fs2Stream,
muSrcGenExecutionMode := Local,
muSrcGenCompendiumProtocolIdentifiers := Nil,
muSrcGenCompendiumServerUrl := "https://localhost:47047"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
muSrcGenCompendiumServerUrl := "https://localhost:47047"
muSrcGenCompendiumServerUrl := "http://localhost:47047"

Comment on lines 42 to 45
case Status.InternalServerError =>
Sync[F].raiseError(UnknownError(s"Error in compendium server"))
case _ =>
Sync[F].raiseError(UnknownError(s"Unknown error with status code ${res.status.code}"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
case Status.InternalServerError =>
Sync[F].raiseError(UnknownError(s"Error in compendium server"))
case _ =>
Sync[F].raiseError(UnknownError(s"Unknown error with status code ${res.status.code}"))
case s => Sync[F].raiseError(UnexpectedStatus(s))

Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines 43 to 45
ConcurrentEffect[F].raiseError[File](
ProtocolNotFound(s"Protocol ${protocolAndVersion.name} not found in Compendium. ")
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ConcurrentEffect[F].raiseError[File](
ProtocolNotFound(s"Protocol ${protocolAndVersion.name} not found in Compendium. ")
)
ProtocolNotFound(s"Protocol ${protocolAndVersion.name} not found in Compendium. ")
.raiseError[F, File]

@ememmr ememmr merged commit cfac9f3 into master May 28, 2020
@ememmr ememmr deleted the merge-plugins branch May 28, 2020 16:22
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.

5 participants