Skip to content
This repository has been archived by the owner on Oct 18, 2021. It is now read-only.

Swap out spray for Akka http #111

Merged
merged 6 commits into from Apr 20, 2017

Conversation

seanpquig
Copy link
Contributor

@seanpquig seanpquig commented Apr 18, 2017

Apologies, didn't mean to edit your description - Russell

@rcoh
Copy link
Contributor

rcoh commented Apr 18, 2017

Thanks for this long needed change! It's not building on CI for some reason -- I assume it builds for you locally?

@seanpquig
Copy link
Contributor Author

It does build, and all tests run for me locally @rcoh. However, I'm using Java 8. I can revert to Akka versions that still support Java 7? Unless there are plans to migrate to Java 8 for the project?

@codecov-io
Copy link

codecov-io commented Apr 18, 2017

Codecov Report

Merging #111 into master will increase coverage by 0.3%.
The diff coverage is 94.73%.

Impacted file tree graph

@@            Coverage Diff             @@
##             master    #111     +/-   ##
==========================================
+ Coverage      61.2%   61.5%   +0.3%     
- Complexity       75      77      +2     
==========================================
  Files            14      15      +1     
  Lines           946     956     +10     
  Branches        232     232             
==========================================
+ Hits            579     588      +9     
- Misses          214     215      +1     
  Partials        153     153
Impacted Files Coverage Δ Complexity Δ
...sticsearch/restlastic/RestlasticSearchClient.scala 68.55% <100%> (+0.4%) 31 <1> (ø) ⬇️
...umologic/elasticsearch/util/AwsRequestSigner.scala 81.81% <100%> (+0.48%) 29 <4> (+2) ⬆️
...om/sumologic/elasticsearch/util/AkkaHttpUtil.scala 83.33% <83.33%> (ø) 0 <0> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e7f2104...f913b2c. Read the comment docs.

@@ -171,7 +179,8 @@ class AwsRequestSigner(awsCredentialsProvider: AWSCredentialsProvider, region: S
}

private def hashedPayloadByteArray(httpRequest: HttpRequest): Array[Byte] = {
val data = httpRequest.entity.asString
val dataFuture = AkkaHttpUtil.entityToString(httpRequest.entity)
val data = Await.result(dataFuture, 1.second)
Copy link
Contributor

Choose a reason for hiding this comment

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

what precisely is being waited for here? Are we waiting for the request to finish or is it just for some sort of string conversion?

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 an artifact of all Akka HTTP request/response entities being modeled as streams, so in this instance the full payload string is being pulled from that stream abstraction. It does not involve an HTTP request/network call.

More on streaming nature of entities: http://doc.akka.io/docs/akka-http/current/scala/http/implications-of-streaming-http-entity.html#implications-of-streaming-http-entities

if (response.status.isFailure) {
logger.warn(s"Failure response: ${response.entity.asString.take(500)}")
val entityString = Await.result(entityFuture, 100.millis)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe cleaner to use .recover or .recoverWith to handle the failure without having to Await on the entity?

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'll try that 👍

streamTimeout: FiniteDuration = 1000.millis)
(implicit ec: ExecutionContext = ExecutionContext.global,
materializer: ActorMaterializer): Future[String] = {
entity.toStrict(streamTimeout).map(_.data.utf8String)
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 prefer doing the Await here -- we wait for seemingly arbitrary amounts of time for this in other places. I'd rather standardize in one place even if it makes the API a little less flexible. Does this only return a future as a semantic side effect of akka-http or is there really something that we're waiting for?

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 future is a side effect of Akka HTTP modeling entities as streams. I'll try refactor to better consolidate necessary waiting, and think through all the implications.

@CCheSumo
Copy link
Contributor

@rcoh Regarding the java version, I have seen two PRs having problem with java 7. As a matter of fact, our infrastructure is also moving to java 8. What do you think about we upgrade the scala/akka version? I will create a PR if that sounds reasonable.

@rcoh
Copy link
Contributor

rcoh commented Apr 20, 2017

@CCheSumo upgrading the scala/java version is fine with me

@seanpquig
Copy link
Contributor Author

How do you guys want to coordinate Java 8 switch with Akka versions in this PR? Java 8 would enable these changes to use stable Akka HTTP and not the old experimental jar.

@CCheSumo CCheSumo merged commit 7d6a030 into SumoLogic:master Apr 20, 2017
@CCheSumo
Copy link
Contributor

@seanpquig let's keep the changes in this PR. After Java 8 is enabled, we have serval libs we will upgrade, the akka core included.

@seanpquig
Copy link
Contributor Author

Sounds good @CCheSumo. Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants